Repository navigation
[Bug] Code Mode nested exec output truncation causes repeated context growth and extreme cached-token quota consumption #40897
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.
Activity
koharyou1215 commentedon Aug 26, 2026
Additional diagnostic information:
Codex
/feedbackwas uploaded successfully for the affected session.Uploaded thread ID:
01a03d9d-bf4a-7563-a57a-5eb7f76ca213This 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/ nestedexec_commandoutput-budget + outer truncation pattern may also be related to #33402.razdgann commentedon Sep 3, 2026
51 tool calls producing 7.2M input tokens in ~16 minutes is a good example of why I’d want cost attribution attached to the execution graph itself.
Instead of only seeing total tokens, it would be useful to answer:
Which tool result caused context growth?
Which subsequent requests carried that context?
How many times was essentially the same context resent?
What did that behavior cost?
We’re building ModelGate around request-level LLM traffic visibility, and tool loops are particularly interesting because a relatively small application behavior can multiply into a very large amount of model traffic.
Tracing the first context expansion and everything downstream from it would probably make this much easier to diagnose.
dogancanbaris commentedon Sep 6, 2026
Adding a Windows 0.153.x data point in #43229. Our two largest Terra-medium workers requested nested output budgets of 30K+ at least 541 and 248 times, across 228 and 106 parallel batches. Their tool-result records contained explicit truncation markers 90 and 48 times, while their average per-request input reached approximately 142K and 151K tokens.
These are argument/marker counts, potentially including nested or reprinted notices, not independently established bug incidents. We counted unique
token_usage_recordresponse IDs rather than cumulativetoken_countevents. Our evidence supports a similar output/context-growth concern, but does not prove incorrect billing. The issue includes configuration, scope and limitations; sanitized screenshots are prepared for attachment.We are now preparing a bounded task comparison with smaller output budgets and explicit context handoffs to distinguish output amplification from mixed-model context-management behavior. I will add measured results rather than assume the cause.