-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Auto-compaction never triggers #16033
Description
What version of Codex CLI is running?
codex-cli 0.117.0
What subscription do you have?
Pro
Which model were you using?
gpt-5.3-codex
What platform is your computer?
macOS Darwin 25.3.0 (Apple Silicon)
What terminal emulator and version are you using (if applicable)?
Headless mode via codex exec (spawned programmatically)
What issue are you seeing?
Auto-compaction never fires when running Codex in headless exec mode. The session accumulates tool outputs until it hits the context window limit, then crashes with "Codex ran out of room in the model's context window." The watcher retries, each retry adds to the session, and it enters a permanent crash loop.
Config:
model_context_window = 400000
model_auto_compact_token_limit = 350000Evidence from Codex session file:
- 86 shell commands executed, producing ~242K tokens of tool output
token_countevents in session file all show emptyinput_tokens_used— token tracking appears broken in exec mode- Zero
compactevents in the session — compaction never triggered - Session crashes at context limit without any compaction attempt
Evidence from traces:
turn_contextevents appear (which I believe are compaction triggers) but they are followed immediately bytask_completewithlast_agent_message: null— suggesting compaction was attempted but failed silently- After first crash, every retry fails within 4-5 seconds with the same context overflow error
Codex session ID: 019d30b8-c263-7190-9072-14650024a1ae
This is blocking automated workflows where agents need to read large codebases. The agent reads files incrementally (200-300 line chunks via sed), but after ~86 commands the accumulated context exceeds the window. In interactive mode, compaction would presumably trigger and summarize earlier context. In exec mode, it never fires.
What steps can reproduce the bug?
- Set
model_auto_compact_token_limit = 350000andmodel_context_window = 400000in config.toml - Run codex in headless exec mode:
codex exec --resume <session-id> "Read a large codebase by running sed on many files" - The agent will read files until it accumulates ~350K+ tokens
- Expected: auto-compact triggers at 350K, summarizes context, continues
- Actual: no compaction, crashes at 400K, permanent crash loop on retry
What is the expected behavior?
model_auto_compact_token_limit should trigger auto-compaction in exec mode the same way it does in interactive mode. Token counting should work (currently reports empty values in exec mode).
Additional information
Related issues: #14860, #14913, #13279 (compaction death spiral)
This may be the same underlying issue as #14860 (TCP timeout on compaction endpoint), but the symptom is different — in our case compaction never even attempts to fire, rather than timing out mid-compact.