codex - 💡(How to fix) Fix Clarify rollout token counters and add local compact/prune path

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

The current behavior makes it easy for local tools to misdiagnose "current context is huge" by reading a cumulative lifetime field. When that happens, the next instinct is to trigger compaction, and compaction may spend scarce budget rather than reducing pressure locally.

Related issues I found before filing: #20311, #16258, #21269, #13733. This issue is specifically about the rollout field naming/semantics plus a deterministic local prune/compact path.

Code Example

{
  "payload": {
    "type": "token_count",
    "info": {
      "total_token_usage": { "input_tokens": 76218, "total_tokens": 76484 },
      "last_token_usage": { "input_tokens": 38235, "total_tokens": 38325 },
      "model_context_window": 258400
    }
  }
}
RAW_BUFFERClick to expand / collapse

What changed from a user's point of view

While building tooling against Codex CLI rollout JSONL files, two related compaction/token-budget issues came up.

1. total_token_usage.total_tokens is easy to misread as current context

In rollout token_count events, payload.info.total_token_usage.total_tokens appears to be cumulative over the session, while payload.info.last_token_usage.input_tokens is the useful value for the most recent/current turn context.

Example shape from local rollout JSONL:

{
  "payload": {
    "type": "token_count",
    "info": {
      "total_token_usage": { "input_tokens": 76218, "total_tokens": 76484 },
      "last_token_usage": { "input_tokens": 38235, "total_tokens": 38325 },
      "model_context_window": 258400
    }
  }
}

A later event in the same rollout can show total_token_usage.total_tokens growing past 500k while last_token_usage.input_tokens is about 100k. That is internally coherent if total_token_usage is lifetime/session usage, but the field name is a trap for anyone writing context-window or compaction tooling. The name reads like "the total token count of the current context" rather than "cumulative token usage across turns."

Request: either rename/document the field semantics in emitted schema docs, or add clearer aliases such as:

  • session_cumulative_token_usage
  • last_turn_token_usage
  • current_context_input_tokens if that is the intended context-window signal

2. Local deterministic compact/prune path

Codex CLI currently relies on model/API compaction for context reduction. That means trying to compact can itself consume the same provider budget that is already under pressure. It also leaves no deterministic local path for tooling that just wants to prune large tool outputs, stale command logs, or older rollout payloads before the next turn.

Request: add a local compact/prune operation that can run without a model call, for example:

  • prune or summarize tool-output blocks using deterministic size/age rules
  • remove older command stdout while keeping command, exit code, and artifact paths
  • preserve developer/system/user messages and explicit memory/handoff content
  • emit before/after token estimates so operators can see whether API compaction is still needed

Why this matters

The current behavior makes it easy for local tools to misdiagnose "current context is huge" by reading a cumulative lifetime field. When that happens, the next instinct is to trigger compaction, and compaction may spend scarce budget rather than reducing pressure locally.

Related issues I found before filing: #20311, #16258, #21269, #13733. This issue is specifically about the rollout field naming/semantics plus a deterministic local prune/compact path.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Clarify rollout token counters and add local compact/prune path