Skip to content

fix(server): stop Codex turns stuck in a compaction loop - #119

Closed
nullStack65 wants to merge 2 commits into
mainfrom
fix/clo-921-compaction-loop-guard
Closed

nullStack65 wants to merge 2 commits into
mainfrom
fix/clo-921-compaction-loop-guard

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Codex sessions were compacting in a loop. The token burn analysis (the parent token burn analysis, CLO-910) found 711 Codex compactions less than 5 minutes apart across 9 sessions, and two single-turn sessions that compacted 128 and 81 times. Each compaction re-reads about 372k of context. The evidence is docs/token-burn-analysis-20261119.md in the token burn analysis pull request, https://github.com/nullStack65/closura-agent-config/pull/953.

A Codex thread now keeps a short compaction history. The named default CODEX_COMPACTION_LOOP_LIMIT is 3 compactions in 5 minutes. Codex emits two signals for one compaction (the context_compaction item and the legacy thread/compacted notification); a 2 second window counts that pair once. A manual /compact is left alone. On the third compaction inside the window, while a turn is active, the thread gets an error activity, "Stopped a context compaction loop", and the active turn is interrupted. Nothing resumes it, and the interrupt also drops queued after-compaction turns. The history resets on that trip, so a continued loop trips again, and it clears when the session exits.

Out of scope: the Codex auto-compact limit, models, and account settings.

Verified here, on head 1fd3fae5bc20cd65490eb1939e01b5e5b26f72d4: the guard tests and the two ingestion replays (8 passed, 93 other tests in that file skipped), apps/server tsc --noEmit exit 0 after replacing new Date() with Effect DateTime, and targeted format and lint on the four changed files. An earlier full run of both test files passed (101 tests) before that DateTime swap. CI is not verified yet.

No human reviewers requested. Kameron is the only human reviewer.

Model: grok-4.7
Task: coding
Agent: T3 Codex, resuming the Claude Opus 5.5 implementation on the Codex compaction loop guard (CLO-921)

Track Codex compactions per thread. Three within five minutes appends a visible error activity and interrupts the active turn without resuming.

Model: claude-opus-5-5
Task: coding
Agent: T3 Claude Code (CLO-921 lane)
Lane: magpie
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A manual /compact tags only the first of Codex's two compaction signals, so the untagged pair was still counting. Three manual compacts, or one manual plus two automatic ones, could stop the turn. That pair is now ignored. A loop that trips while no turn is active keeps its history, so the next compaction on a live turn still stops.

Model: grok/grok-4.7
Task: coding
Agent: T3 Codex (CLO-921 lane)
Lane: magpie
@nullStack65

Copy link
Copy Markdown
Owner Author

Moved: main gets no CI and does not ship. This change is ported onto release/native-0.1.10, the line the fleet builds, in #126 (Linear CLO-941). The branch is kept.

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