[Bug] Code Mode nested exec output truncation causes repeated context growth and extreme cached-token quota consumption

Open 💬 1 comment Opened Aug 26, 2026 by koharyou1215

Hello,

I would like to report what appears to be an abnormal token/quota consumption issue in Codex CLI.

Environment

  • Codex CLI: 0.149.1
  • Model: gpt-5.6-terra
  • Reasoning effort: xhigh
  • OS: Windows 10
  • Shell: PowerShell
  • Repository: normal local source repository
  • Session duration: approximately 16 minutes

Observed quota consumption

  • 5-hour usage window: 0% -> 49%
  • Weekly usage: 16% -> 23%

Codex session telemetry

  • Model/token-count events: 52
  • Tool calls: 51
  • Input tokens: 7,238,294
  • Cached input tokens: 7,018,496
  • Uncached input tokens: 219,798
  • Output tokens: 39,590
  • Reasoning output tokens: 20,689
  • Total tokens: 7,277,884

The notable point is that approximately 97% of the input tokens were cached input.

The per-call model input grew during the same session from approximately:

21,403 tokens

to:

193,901 tokens

near the end of the session.

This caused an already-large context to be replayed repeatedly across more than 50 model calls.

I inspected the Codex rollout JSONL for the affected session.

A recurring pattern was:

  1. Codex generated parallel tool execution using Promise.all.
  2. Individual exec_command calls requested very large max_output_tokens values.
  3. Values observed included:
  • 10,000
  • 20,000
  • 30,000
  • 40,000
  • 50,000
  • 60,000
  1. Commands included broad rg searches, Get-Content -Raw, and large git diff output.
  2. The combined outer execution output was then truncated.
  3. Codex performed additional searches/reads because the previous result was incomplete.
  4. The returned portions of those tool results remained in the conversation context.
  5. The context continued growing and was replayed on subsequent model calls.
  6. No explicit compaction occurred before the model input reached approximately 194k tokens.

Examples from the rollout log include:

  • Promise.all with exec_command max_output_tokens=40,000

-> outer result:
"Warning: truncated output (original token count: 47141)"

  • multiple parallel exec_command calls with max_output_tokens=60,000

-> outer result:
"Warning: truncated output (original token count: 54274)"

  • Get-Content -Raw plus large git diff / rg calls

-> outer result:
"Warning: truncated output (original token count: 58618)"

The affected session contained:

  • 18 Promise.all tool batches
  • 46 exec calls returning JSON.stringify(...) style aggregate results
  • 8 visibly truncated tool-output batches

I also checked my project configuration to determine whether this was caused by custom instructions.

I could not find custom instructions requiring these large output budgets.

My project AGENTS.md actually contains rules intended to REDUCE context usage, including:

  • avoid unnecessary full-file reads
  • avoid repeated context retrieval
  • summarize successful command/test output
  • minimize shell/stdout/context expansion
  • avoid repository-wide audits for focused fixes

The task itself was also small and did not contain a huge initial prompt.

Therefore, the main issue appears to be the interaction between:

  • Codex's agent/tool execution strategy
  • large model-selected max_output_tokens values
  • parallel Promise.all execution
  • outer tool-output truncation
  • retry/re-read behavior
  • append-only context accumulation
  • delayed compaction

The practical result is a loop similar to:

large tool-output request
-> output truncation
-> incomplete evidence
-> additional tool call
-> more context retained
-> larger next model input
-> repeat

This turned a roughly 16-minute coding session into approximately 7.28 million cumulative tokens and consumed roughly half of my 5-hour Codex usage allowance.

This behavior is reproducible across recent sessions as well.

Two other recent Codex sessions showed similar patterns:

Session 2:

  • ~10m42s
  • 42 token-count events
  • 41 tool calls
  • ~5.76M total tokens
  • ~5.53M cached input tokens

Session 3:

  • ~21m38s
  • 63 token-count events
  • 59 tool calls
  • ~7.75M total tokens
  • ~7.43M cached input tokens

So this does not appear to be a single-session anomaly.

Questions / requested investigation:

  1. Is this amount of cached-input replay expected to consume Codex usage quota at this rate?
  2. Why is the model allowed to request 30k-60k tool-output budgets when the combined/outer result is subsequently truncated?
  3. Should Codex compact or prune tool outputs significantly earlier when context growth is dominated by cached tool results?
  4. Is there currently a known issue involving Promise.all / nested exec_command output budgets and outer output truncation?
  5. Is there a configuration or temporary workaround that can cap model-selected tool output before this behavior is fixed?

I can provide the affected rollout JSONL/session ID and additional diagnostic data if needed.

Affected session ID:
01a03d9d-bf4a-7563-a57a-5eb7f76ca213

Thank you.

View original on GitHub ↗

1 Comment

koharyou1215 · 1 day ago

Additional diagnostic information:

Codex /feedback was uploaded successfully for the affected session.

Uploaded thread ID: 01a03d9d-bf4a-7563-a57a-5eb7f76ca213

This is the same session described in the issue (Codex CLI 0.149.1 / gpt-5.6-terra), where model input grew from ~21k to ~194k tokens per call and cumulative usage reached ~7.28M tokens in ~16 minutes, including ~7.02M cached input tokens.

The observed Promise.all / nested exec_command output-budget + outer truncation pattern may also be related to #33402.