Repository navigation
fix(core): stop auto-compaction looping when compaction cannot get below the limit (WI-2832) - #42
Merged
Merged
Conversation
…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
thedancingdeveloper
force-pushed
the
wi-2832-reapply
branch
from
November 18, 2026 23:04
b5038cb to
0e45dc6
Compare
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.
Replacement for #36, which is based on a 2026-10-19 merge-base and is now
CONFLICTING(merging today'sfork/mainreports 4678 changed files of base drift). This branch carries the same change re-applied as a patch ontofork/main5c4381bb4; #36 is left untouched for the reviewer to close.What it does
Before: if the part of the prompt compaction cannot shrink (tool specs, instructions, retained context) was already at or over
model_auto_compact_token_limit, every request after a compaction was over the limit again, so the turn looped compaction -> one tool call -> compaction (235 compactions in one observed turn).After: immediately after a context-limit compaction, the first sampling request is checked against the limit. If that prompt alone is still at or over the limit (body after prefix for
BodyAfterPrefix, or the full usable window), the turn ends with a warning naming the token count and the limit, plusContextWindowExceeded, instead of compacting again.The flag that marks "a context-limit compaction just ran" is set inside the
Ok(true)arm before thecontinuethat restarts the turn loop. The first re-apply set it after thatcontinue, where it was dead code, and the loop still recurred.Files
codex-rs/core/src/session/turn.rs— the guard,compaction_left_prompt_over_limit,prompt_over_limitcodex-rs/core/src/session/turn_tests.rs— unit tests for the scope arithmeticcodex-rs/core/tests/suite/compact.rs—auto_compact_stops_when_compaction_cannot_get_below_limit, plus the repeated-compaction fixture adaptation (see below)codex-rs/core/tests/suite/hooks.rs— the existing mid-turn compaction hook fixture adapted to the new contract (see below)FORK.md— one row in the fork-only table.github/workflows/fork-ci.yml— the libcap install step on container-backed self-hosted runners (carried from fix(core): stop auto-compaction looping when compaction cannot get below the limit (WI-2832) #36)Fixture adaptations
Two fixtures asserted the old loop: two consecutive over-limit prompts, each compacting. Under the new contract the first of those stops the turn, so each fixture now runs one under-limit continuation before the next over-limit step. The number of compactions and hook drains is unchanged; the tests still prove their original property.
hooks.rs::mid_turn_auto_compact_session_start_hooks_run_before_each_continuation: one under-limit continuation before the second over-limit step, so two compactions still happen and each drains exactly one session-start hook.compact.rs::multiple_auto_compact_per_task_runs_after_token_limit_hit: the fixture's work steps report 270_000 total tokens, which is still above this model'smodel_auto_compact_token_limitof 244_800, so the guard correctly stopped the turn after the first compaction. 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 that legitimate repeated compactions run. The guard's stop path is covered byauto_compact_stops_when_compaction_cannot_get_below_limit.Regenerating the fixture's
expected_requests_inputsis what makes that diff look larger: the array is now nine entries (3 compactions + 2 continuations + the final request), each carrying the same per-request comment the original had.Verification
Run the way CI runs it: every test job in this repo sets
RUST_MIN_STACK=8388608. Without it, debug-build futures overflow the 2 MiB tokio worker stack; that is an environment fact, not a property of this change.cargo fmt --all -- --check— cleancargo clippy -p codex-core --all-targets -- -D warnings— cleancargo test -p codex-core --lib turn— 359 passed, 0 failedcargo test -p codex-core --test all suite::compact::— 89 passed, 0 failed, 1 ignoredcargo test -p codex-core --test all suite::hooks::— 87 passed, 6 failed, the identical six names fail on unmodifiedfork/main5c4381bb4on the same hostcargo test -p codex-core --test all(whole binary) — 2540 passed, 665 failed, 8 ignored; unmodifiedfork/mainon the same host: 2538 passed, 666 failed, 8 ignored. The unique failing-name set on this branch (636) is a strict subset offork/main's (637): zero branch-only failures. The residual suite failures are sandbox/harness/environment failures that also fail on the baseline.suite::compact::multiple_auto_compact_per_task_runs_after_token_limit_hitFor the reviewer
BodyAfterPrefixarithmetic inprompt_over_limit— it subtractsauto_compact_window_prefill_tokensfrom the last prompt and compares against the scope limit, and separately checks the full window. Worth a second pair of eyes.Known follow-ups (non-blocking, not addressed here)
BodyAfterPrefixwarning prints total prompt tokens against the body limit and names the scope limit even when the window limit tripped.Nothing was deployed; no prod or dev image was rebuilt from this branch.