Repository navigation
fix(core): stop auto-compaction looping when compaction cannot get below the limit (WI-2832) - #36
Open
thedancingdeveloper wants to merge 2 commits into
Open
thedancingdeveloper wants to merge 2 commits into
thedancingdeveloper wants to merge 2 commits into
Conversation
…low the limit (WI-2832) When the part of the prompt that compaction cannot shrink (tool definitions, instructions, retained context) is by itself over model_auto_compact_token_limit, every request after a compaction is over the limit again. The turn loop compacted, ran one step, and compacted again with no bound: two swack-haiku sessions on 2026-11-01 did 235 and 143 compactions in one turn (60M tokens). After a context-limit compaction (pre-turn or mid-turn), check the first request's prompt size. If it alone is at or over the auto-compact limit (the body after the prefix for the body_after_prefix scope) or the usable context window, emit a warning naming the sizes, end the turn with ContextWindowExceeded, and do not compact again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thedancingdeveloper
enabled auto-merge
November 1, 2026 21:04
The rust-heavy label is also served by container runners such as nodef-gha-public-docker, which do not bake the build packages, so codex-bwrap's build.rs panics with "libcap not available via pkg-config" and the required "fmt, clippy, test" check fails (fork/main red since 529603b). Install libcap-dev and pkg-config there before the build, using sudo only when not root, and skip when libcap is already present (the baked image, whose jobs have no sudo). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a compaction loop seen on 2026-11-01 (Vogt WI-2832). Operator-approved one-off PR into
fork/main: the fork has no graft line.Root cause
model_auto_compact_token_limit = 128000), a compaction, one tool call, then ~132k again.~/.codex/config.toml. Compaction cannot shrink tool definitions, so the fixed prefix alone was over the limit.core/src/session/turn.rs, the turn loop compacted whenevertoken_limit_reachedwas true and continued, without checking whether compaction helped. The old comment read: "as long as compaction works well … we shouldn't worry about being in an infinite loop".The launch-side cause is tracked separately in Vogt (WI-2833: start Codex workers with the worker MCP set).
Fix
last_token_usage.input_tokens).model_auto_compact_token_limit;ContextWindowExceeded(non-retryable) and ends without compacting again.body_after_prefixscope, only the body after the prefix counts against the limit.run_pre_sampling_compactnow returns whether it compacted, so a pre-turn compaction is checked too.Tests
session::turn::tests::prompt_over_limit_detects_a_prefix_that_compaction_cannot_shrinkandprompt_over_limit_ignores_the_prefix_for_body_after_prefix_scope.suite::compact::auto_compact_stops_when_compaction_cannot_get_below_limit: a 400-token step against a limit of 300, one compaction, then a 400-token step. It asserts exactly three requests, aContextWindowExceedederror and the warning. With the guard disabled, the test fails.RUST_MIN_STACK=8388608):cargo check -p codex-core --tests: cleancargo clippy -p codex-core --tests -- -D warnings: cleanrustfmt --checkon the changed files: cleancargo test -p codex-core --lib prompt_over_limit: 2/2cargo test -p codex-core --test all -- suite::compact::auto_compact: 13/13FORK.md
Adds a carried-patch row describing the auto-compaction loop guard: the files touched, the tests, and the branch.
🤖 Generated with Claude Code