Skip to content

Auto-compact again when the context refills in the same turn - #647

Merged
ericdallo merged 4 commits into
editor-code-assistant:masterfrom
brdloush:fix/auto-compact-again-in-same-turn
Nov 5, 2026
Merged

ericdallo merged 4 commits into
editor-code-assistant:masterfrom
brdloush:fix/auto-compact-again-in-same-turn

Conversation

@brdloush

Copy link
Copy Markdown
Contributor

Related to #615.

Problem

After an auto-compaction, ECA does not auto-compact again until the user turn ends. A long turn can fill the context a second time and end with Context window exceeded. Steering makes this common, because steered messages join the running turn.

Real case: 262k context, 75%. One compaction at ~196k, then 6 steered messages in the same turn, no second compaction, and finally Input length (267765) exceeds model's maximum context length (262144).

Cause: resume-after-compact! sets :auto-compacted? true on the chat-ctx, and every later tool-call round of the turn reuses it. So the threshold check and the context-overflow fallback stay blocked for the whole turn. The flag comes from #391 (stop a compact → overflow → compact loop). That goal is right, but it only needs to cover the request right after a compaction.

Changes

  • Per-compaction guard. The resumed turn gets a :post-compact-guard* atom. It is released on the first usage update that shows the compacted context under the threshold. After that, the turn can compact again. If the compacted context is still too big, the guard stays on, so the ECA becomes unresponsive when tool output causes LLM context overflow #391 protection holds.
  • autoCompactMaxPerTurn (default 3, global or per agent). Each compaction sends the whole context to the LLM, so a turn that keeps refilling it (e.g. re-reading a huge file) must not compact without end. When the limit is reached, the turn ends with the normal overflow error.
  • The "Continue with the task" prefix no longer stacks up. Docs and schema are updated. A separate commit fixes a stale autoCompactPercentage: 85 in the default config docs (the default is 75).

Alternatives

Tests

  • auto-compact-again-later-in-same-turn-test and context-overflow-later-in-same-turn-auto-compacts-test: a second compaction in the same turn (both fail on master), and no loop when the compacted context is still too big.
  • auto-compact-limit-per-turn-test: stops at the limit, including autoCompactMaxPerTurn 1.
  • context-overflow-auto-compact-guard-test now goes through the real resume-after-compact!.

A/B with the real server against a fake LLM: master overflows after one compaction. This PR compacts twice and finishes the task, and a longer task stops at 3 compactions.

  • I added a entry in changelog under unreleased section.
  • This is not an AI slop. (I have read, simplified and pinpointed the important parts myself, the human 😄)

🤖 Generated with Claude Code

@brdloush
brdloush force-pushed the fix/auto-compact-again-in-same-turn branch 2 times, most recently from a579155 to cc930df Compare October 26, 2026 19:56
brdloush and others added 2 commits November 2, 2026 17:03
After an auto-compaction, :auto-compacted? stayed true for the rest of
the turn, so neither the threshold check nor the context-overflow
fallback could compact again. Long turns, common with steered messages,
filled the context a second time and ended with "Context window
exceeded".

The turn-wide flag is now a per-compaction guard. It is released on the
first usage update that shows the compacted context under the
threshold, so later compactions can run. If the compacted context is
still too big the guard stays on, keeping the editor-code-assistant#391 loop protection. The
"Continue with the task" prefix no longer stacks on each compaction.

A turn auto-compacts at most autoCompactMaxPerTurn times (default 3,
global or per agent), so a turn that keeps refilling the context can't
keep sending full-context compaction requests.

Related to editor-code-assistant#615

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default config listed in introduction.md still showed 85. The
default was lowered to 75 in 3a26d6d, and the code, the schema and
context-management.md already say 75.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brdloush
brdloush force-pushed the fix/auto-compact-again-in-same-turn branch from cc930df to b44e7ab Compare November 2, 2026 16:06
ericdallo and others added 2 commits November 5, 2026 11:57
Fix auto-compaction to run multiple times per turn when context refills, up to a maximum limit.

@ericdallo ericdallo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@ericdallo
ericdallo merged commit f7e9952 into editor-code-assistant:master Nov 5, 2026
7 checks passed
@brdloush

brdloush commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

The pleasure is all mine. I was just checking some long running goals my agent was doing yesterday evening and indeed it survived those multi-compactions-per-turn thanks to this patch. I guess I'll be able to go back to master branch soon 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants