9.47M tokens + 183.9M cached in one 5.9h CLI session (gpt-5.3-codex-spark): 74 compactions sustained ~every 3.7min, 95% followed by re-reading files/tests already read this session - used 100% of a week

Resolved 💬 3 comments Opened Aug 3, 2026 by daveladouceur Closed Aug 6, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex are you using?

  • Product: Codex CLI (TUI)
  • Codex CLI: 0.146.0
  • Model: gpt-5.3-codex-spark (session started on gpt-5.5 for one turn, then /model spark switched to gpt-5.3-codex-spark for the remaining 114 turns)
  • Approval policy: never
  • Filesystem sandbox: danger-full-access
  • Session: 019fc42f-e008-79e2-9d11-b7a5b2eb7f43 (resumable via codex resume 019fc42f-e008-79e2-9d11-b7a5b2eb7f43)
  • Observed: 2026-08-02/03

Summary

A single 5.9-hour CLI session (20:39:03Z to 02:32:57Z) accumulated 9,469,686 total tokens (8,416,873 input, 1,052,813 output) plus 183,934,336 cached-input tokens across 2,607 model turns. Analysis of the session rollout JSONL shows this was not driven by legitimate work volume — it was driven by a sustained compact → forget → re-fetch → refill → compact cycle.

The session underwent 74 context-compaction events, averaging one every 3.7 minutes (median 192s), sustained essentially unchanged from the first 10 minutes of the session through the last 10 minutes (min gap 74s, max gap 522s) — i.e. this was not a one-time startup burst, it was the session's steady state for its entire duration.

70 of the 74 compactions (95%) were followed within 2 minutes by the agent re-reading a file it had already read earlier in the session, or re-running a test command it had already run (99% within 5 minutes). A handful of large source files were each re-fetched via Get-Content between 6 and 25 times over the session (e.g. one ~40K-line-count React component was read 9 separate times; one API route file was read 25 times across quoting variants; a browser-debug JS file was read 17 times), and two test commands were re-run 11 and 7 times respectively with no edits visible in between several of the repeats.

Net effect measured directly from the transcript: of the ~24.2M characters of accumulated tool-output content in this session, 89.8% is function_call_output (tool/shell results), and within that, 119 individual command outputs hit a ~40,000-character truncation ceiling — meaning the real output was even larger before Codex's own truncation cut it. Only ~1.2% of total accumulated content was session-startup/hook boilerplate; the overwhelming majority is this re-read/re-run pattern.

Why this looks like a Codex-side bug, not agent misbehavior

The agent had no way to know a compaction had just discarded the specific fact "I already have the full content of file X in context" — nothing in the post-compaction context appears to preserve that as retrievable state, so the very next action is almost always to re-fetch exactly what was just summarized away. Each re-fetch (large file, or large test output) is itself big enough to immediately re-trigger compaction, producing a self-sustaining loop for the session's entire 5.9-hour lifetime rather than compaction ever actually relieving context pressure.

This compounds directly into the cached-token bill: the same re-created content gets resent and cache-hit on every one of the following turns until it next ages out, so (large, repeatedly-recreated context) × (2,607 turns) is what produces the 183.9M cached-token total.

Reproduction outline

  1. Start a long CLI session in a large monorepo workspace doing iterative file-editing/testing work on a handful of sizeable source files (>1000 lines) with a full test suite that produces large (>20K char) output.
  2. Let the session run long enough to trigger repeated context compaction (in this case, every ~3-4 minutes sustained).
  3. Observe: does the agent re-fetch full file contents / re-run full test output shortly after each compaction, for files/commands it had already fetched/run earlier in the same session?
  4. Compare cumulative cached_input_tokens growth rate against the compaction frequency.

Suggested fix directions

  • Compaction summaries should retain (or make cheaply re-derivable without a full re-fetch) a manifest of "files/commands already fully read this session and their content hash/location," so the agent can recognize it already has the data rather than re-fetching wholesale.
  • Consider a per-session dedup/cache layer for large tool outputs (keyed by exact command + file mtime) so an identical re-fetch after compaction is served from a lightweight reference instead of a full re-execution and full re-billing.
  • Surface compaction frequency (and pre/post compaction token deltas) in codex resume/session diagnostics so this pattern is visible without post-hoc JSONL analysis.

Data used for this report

Derived from the session's own rollout log (~/.codex/sessions/2026/08/02/rollout-2026-08-02T14-34-59-019fc42f-e008-79e2-9d11-b7a5b2eb7f43.jsonl, 16,456 lines / 49MB) — event_msg.type=token_count for cumulative usage, event_msg.type=context_compacted for the 74 compaction timestamps, and response_item entries for the re-read/re-run correlation. Happy to attach the raw analysis script or specific excerpts if useful.

View original on GitHub ↗

3 Comments

github-actions[bot] contributor · 25 days ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #36664

Powered by Codex Action

Free-LZJ · 25 days ago

Additional reproduction from Codex Desktop / VS Code:

  • Codex version: 0.146.0-alpha.3.1
  • OS: Windows
  • Model provider: custom
  • Context window: 258400
  • Session: [include only if approved]
  • 34 context compactions and 1,675 custom tool calls with matching outputs
  • Pre-compaction input ranged from 221,070 to 244,256 tokens, averaging 231,902
  • Within the first 20 tool calls after each compaction, Codex repeatedly re-read

AGENTS.md, MEMORY.md, skill files, the same source files, and reran
git status / git diff

  • Ponytail 4.8.4 was enabled with a SessionStart matcher including compact,

causing 35 full rule injections

  • This is a Desktop/VS Code reproduction, distinct from the CLI/TUI report

The raw rollout log is not attached because it contains private repository
paths and source content. The behavior appears consistent with compaction
losing a machine-readable read-set/progress ledger, causing a
compact -> forget -> re-read -> refill loop.

Sinnena-glitch · 25 days ago

Additional high-severity reproduction from Codex Desktop on Windows.

  • Codex Desktop package: 26.727.6591.0 (About/build resources observed around 26.727.51351)
  • Affected thread: 019f7d41-6ce5-7811-985d-5784539d8d2f
  • Observed: 2026-08-03 11:22:21–13:40:15 (Asia/Shanghai)
  • Single turn duration: 2h 17m 53s
  • Final turn state: interrupted, with no final answer

The most recent turn contained 150 recorded items:

  • 84 contextCompaction events
  • 56 assistant commentary messages
  • 7 reasoning summaries
  • 1 web search
  • 1 file creation
  • 0 shell/terminal command executions
  • 0 final answers

The assistant repeatedly restated essentially the same next step ("locate the CLI", "check auth", "read the receipt", "create the document") after each compaction. It also repeatedly claimed terminal output was truncated and that it was checking command results, but the transcript records no terminal execution in that turn. The only file created was a diagnostic PowerShell script; the expected report output was absent, indicating the script was never run.

This appears to be an even more severe variant of the compact → forget → repeat loop: after compaction, the agent loses not only its read-set but also whether it has actually executed the promised action, so it emits another progress message and compacts again without reaching the tool call.

A fresh diagnostic task invoked the same external CLI directly via its Windows .CMD shim. Authentication, token status, connectivity, and document-create capability all passed within seconds. This confirms the 2+ hour stall was not caused by the external service, user authorization, or network state.

Expected behavior:

  1. Preserve a compact machine-readable progress/action ledger across compactions.
  2. Detect repeated near-identical progress messages without intervening tool calls and stop/recover.
  3. Surface an actionable error or request user intervention instead of silently consuming time/credits.
  4. Provide diagnostics and usage remediation guidance for compaction loops that consume substantial tokens without useful execution.

Private project contents and local paths are intentionally omitted.