[Bug] Code Mode nested exec output truncation causes repeated context growth and extreme cached-token quota consumption
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.4k
- PR merge metrics
- PR metrics pending
Description
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:
- Codex generated parallel tool execution using Promise.all.
- Individual exec_command calls requested very large max_output_tokens values.
- Values observed included:
- 10,000
- 20,000
- 30,000
- 40,000
- 50,000
- 60,000
- Commands included broad rg searches, Get-Content -Raw, and large git diff output.
- The combined outer execution output was then truncated.
- Codex performed additional searches/reads because the previous result was incomplete.
- The returned portions of those tool results remained in the conversation context.
- The context continued growing and was replayed on subsequent model calls.
- 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:
- Is this amount of cached-input replay expected to consume Codex usage quota at this rate?
- Why is the model allowed to request 30k-60k tool-output budgets when the combined/outer result is subsequently truncated?
- Should Codex compact or prune tool outputs significantly earlier when context growth is dominated by cached tool results?
- Is there currently a known issue involving Promise.all / nested exec_command output budgets and outer output truncation?
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the Codex CLI execution path for Promise.all batches, exec_command max_output_tokens, outer tool-output truncation, and context compaction. Use the affected rollout JSONL and session ID 01a03d9d-bf4a-7563-a57a-5eb7f76ca213 to reproduce or trace the behavior. Done means identifying whether large nested outputs are replayed unnecessarily and establishing a tested mitigation for quota-consuming context growth.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, rust
- Domain
- cli, performance, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100