Repository navigation
fix(core): stop auto-compaction looping when compaction cannot get below the limit (WI-2832) - #36
Closed
thedancingdeveloper wants to merge 2 commits into
Closed
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>
thedancingdeveloper
pushed a commit
that referenced
this pull request
Nov 18, 2026
…low the limit (WI-2832) Re-applied onto fork/main (5c4381b) instead of merging PR #36's 2026-10-19 base, which produced 4678 changed files of drift. The real change is 6 files. The guard flag is set inside the `Ok(true)` arm of the compaction match, before the `continue` that restarts the loop; setting it after that `continue` (as the first re-apply did) meant it was never observed and the loop still recursed. The existing `mid_turn_auto_compact_session_start_hooks_run_before_each_continuation` fixture asserted the old loop (two consecutive over-limit prompts each compacting). Under the new contract the turn stops after the first ineffective compaction, so the fixture now runs one under-limit continuation before the second over-limit step: two compactions still happen, and both hooks still run. Verification (CI runs tests with RUST_MIN_STACK=8388608; without it the debug-build futures overflow the 2 MiB tokio worker stack, which is why the repo sets it in every test job): - cargo fmt --all -- --check: clean - cargo clippy -p codex-core --all-targets -- -D warnings: clean - cargo test -p codex-core turn (lib): 359 passed, 0 failed - cargo test -p codex-core --test all compaction: 128 passed, 17 failed — the identical failure set to unmodified fork/main (13 unique names, all pre-existing: code_mode harness, guardian, scenario snapshots) - cargo test -p codex-core --test all suite::hooks::: 87 passed, 6 failed — identical to unmodified fork/main - the new test passes: suite::compact::auto_compact_stops_when_compaction_cannot_get_below_limit
thedancingdeveloper
pushed a commit
that referenced
this pull request
Nov 18, 2026
…low the limit (WI-2832) Re-applied onto fork/main (5c4381b) instead of merging PR #36's 2026-10-19 base, which produced 4678 changed files of drift. The real change is 6 files. The guard flag is set inside the `Ok(true)` arm of the compaction match, before the `continue` that restarts the loop; setting it after that `continue` (as the first re-apply did) meant it was never observed and the loop still recursed. Two existing fixtures asserted the old loop (two consecutive over-limit prompts each compacting). Under the new contract the turn stops after the first ineffective compaction, so each fixture now runs an under-limit continuation before the next over-limit step: the same number of compactions still happens, and every hook still runs. - `mid_turn_auto_compact_session_start_hooks_run_before_each_continuation`: one under-limit continuation before the second over-limit step. - `multiple_auto_compact_per_task_runs_after_token_limit_hit`: the fixture's work steps report 270_000 tokens, which is still above this model's 244_800 auto-compact limit, so the new guard correctly stopped the turn. An under-limit (100_000) continuation is inserted after the first and second compactions; the third compaction and the final response are unchanged, so the test still proves legitimate repeated compactions run. The guard's stop path is covered separately by `auto_compact_stops_when_compaction_cannot_get_below_limit`. Verification (CI runs tests with RUST_MIN_STACK=8388608; without it the debug-build futures overflow the 2 MiB tokio worker stack, which is why the repo sets it in every test job): - cargo fmt --all -- --check: clean - cargo clippy -p codex-core --all-targets -- -D warnings: clean - cargo test -p codex-core --lib turn: 359 passed, 0 failed - cargo test -p codex-core --test all suite::compact::: 89 passed, 0 failed, 1 ignored - cargo test -p codex-core --test all suite::hooks::: 87 passed, 6 failed — the identical six names fail on unmodified fork/main 5c4381b - cargo test -p codex-core --test all (whole binary): 2540 passed, 665 failed, 8 ignored; unmodified fork/main on the same host: 2538 passed, 666 failed. The unique failing-name set on this branch (636) is a strict subset of fork/main's (637) — zero branch-only failures. The residual failures are sandbox/harness/environment failures that also fail on the baseline. - the previously red test passes: suite::compact::multiple_auto_compact_per_task_runs_after_token_limit_hit
Author
auto-merge was automatically disabled
November 19, 2026 05:30
Pull request was closed
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