Skip to content

Auto-compaction never triggers #16033

@brandomagnani

Description

@brandomagnani

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 = 350000

Evidence from Codex session file:

  • 86 shell commands executed, producing ~242K tokens of tool output
  • token_count events in session file all show empty input_tokens_used — token tracking appears broken in exec mode
  • Zero compact events in the session — compaction never triggered
  • Session crashes at context limit without any compaction attempt

Evidence from traces:

  • turn_context events appear (which I believe are compaction triggers) but they are followed immediately by task_complete with last_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?

  1. Set model_auto_compact_token_limit = 350000 and model_context_window = 400000 in config.toml
  2. Run codex in headless exec mode: codex exec --resume <session-id> "Read a large codebase by running sed on many files"
  3. The agent will read files until it accumulates ~350K+ tokens
  4. Expected: auto-compact triggers at 350K, summarizes context, continues
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    contextIssues related to context management (including compaction)regressionBehaviors that worked in previous versions but were broken due to an update

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions