Repository navigation
Description
Scope update: repeated occurrences are now independently observed across GPT-6.1 Sol and GPT-6 Astra. See the cross-session measurements below.
What version of Codex CLI is running?
codex-cli 0.159.2
Which model were you using?
gpt-6.1-sol, reasoning effort high, ChatGPT sign-in.
Platform
Linux 6.6.87.2-microsoft-standard-WSL2, x86_64, interactive Codex CLI in Herdr.
What issue are you seeing?
Codex interrupted real work for over five minutes to compact a session whose last reported usage was 193,193 tokens. Its internal compaction counter said 266,425. The extra 73,232 tokens have been reconstructed exactly from the client's accounting code.
This is unacceptable behavior for a tool intended to improve engineering productivity. Users should not have to reverse-engineer the client's token estimator to understand why it stops working while the context indicator still shows roughly a quarter of the window available. The interruption also generated another large model request. Raising settings to compensate is a workaround, not a repair.
This report supplies a current GPT-6.1 Sol reproduction and exact local arithmetic for the problem reported in #39767 and #49026. It also resembles #45074. Please connect it to the owning issue and provide a concrete fix/status rather than treating this as a request for ordinary earlier compaction.
Configuration at the incident
model_auto_compact_token_limit = 258000
model_auto_compact_token_limit_scope = "body_after_prefix"
# model_context_window was unsetThe local model catalog reported a 272,000-token window with a 95% effective-window adjustment, yielding 258,400. This is the client's configured window, not a claim about GPT-6.1 Sol's maximum supported context.
The running process logged the configured 258,000 limit. This was not an assumed stale configuration or a manual /compact command.
Exact calculation
| Quantity | Tokens |
|---|---|
| Last server-reported input | 191,910 |
| Last server-reported output | 1,283 |
| Of that output, reasoning tokens (already included) | 1,034 |
| Last server-reported total | 193,193 |
| Client estimate of earlier encrypted reasoning, from 131 items | 69,286 |
| Client estimate of newly appended tool output | 3,946 |
| Count used for compaction | 266,425 |
| Effective full-context limit | 258,400 |
193193 + 69286 + 3946 = 266425
266425 >= 258400 -> automatic compaction
The older-reasoning estimate was reproduced by applying the source's encrypted-length heuristic to the retained items before the last user boundary, without decrypting their contents. The fresh-tool-output estimate was reconstructed separately. Their sum matches the runtime log exactly.
The relevant sanitized log fields at 2026-10-01 10:49:20 UTC were:
post sampling token usage
total_usage_tokens=266425
auto_compact_scope_tokens=93720
auto_compact_scope_limit=Some(258000)
auto_compact_limit_scope=BodyAfterPrefix
auto_compact_window_prefill_tokens=Some(172705)
full_context_window_limit=Some(258400)
full_context_window_limit_reached=true
token_limit_reached=true
The subsequent operation was logged as run_auto_compact{reason=ContextLimit phase=MidTurn}. The full-context guard triggered even though the body-after-prefix counter was below its configured limit.
Actual interruption and extra model operation
The preceding token event was recorded at 10:49:20.660 UTC. The completed compaction checkpoint was recorded at 10:54:30.101 UTC: approximately 309.4 seconds later.
The checkpoint's compaction response ID matches its usage receipt:
| Compaction request usage | Tokens |
|---|---|
| Input | 197,182 |
| Cached input, included above | 191,744 |
| Output | 8,202 |
| Total reported usage | 205,384 |
Cached tokens are not added a second time here. These are usage counts, not a claimed dollar charge. This was a real remote operation and interruption, not merely a misleading UI label.
Relevant source and what is established
The inspected source revision is d42056091aded7feb1d88ac7e83972108b2aa478; the running CLI identifies itself as 0.159.2. This report does not assume that source checkout is the exact binary build revision. Its accounting formula reproduces the observed runtime values exactly.
Relevant functions:
core/src/context_manager/history.rs:get_total_token_usage,get_non_last_reasoning_items_tokens,estimate_reasoning_length,estimate_item_token_count.core/src/session/context_window.rs:context_window_token_status_with_config.core/src/tasks/regular.rs: reset ofserver_reasoning_included.core/src/session/turn.rs: handling ofServerReasoningIncludedand the compaction decision.
When server_reasoning_included is false, the history calculation adds estimated earlier reasoning on top of the completed response's reported usage. The captured values exactly match that branch.
Evidence boundary: this capture establishes the extra accounting and the resulting compaction. It does not include a raw response/handshake capture, so it does not independently establish whether this backend already counted every historical reasoning item or where the reasoning-included signal was lost. The earlier reports provide evidence of double-counting through this same path. Please investigate that contract rather than assuming that an absent signal proves the extra estimate is needed.
What steps can reproduce the bug?
The observed shape is a long-running GPT-6.1 Sol session with retained encrypted reasoning across user turns:
- Use the configuration above and continue real tool-driven work across multiple user turns.
- Compare the latest rollout
token_countwith the internalpost sampling token usagelog immediately before automatic compaction. - Reconstruct the active history from its last
compacted.replacement_historyplus subsequent response items. - Apply the existing estimator to earlier encrypted reasoning and newly appended tool results.
- Observe that the additional reasoning allowance pushes the internal count over the full-context limit while reported usage remains far below it.
The figures above come from an actual captured incident, not fabricated fixture token totals. Private prompts, tool contents, raw encrypted payloads, thread identifiers and local project paths are deliberately omitted.
What is the expected behavior?
- Use a coherent, request-bound accounting contract for compaction. Do not add historical reasoning to reported usage unless those quantities are actually disjoint.
- Make the displayed context usage and the compaction decision explain the same budget. If an additional allowance is required, expose it instead of silently adding tens of thousands of tokens.
- Preserve the reasoning-accounting contract correctly across user turns, connection reuse and resume.
- Add coverage for the missing-header/reset paths and verify the correction with real reported usage, not only synthetic totals.
Please assign an owner and give users a fix or an explicit accounting explanation. A five-minute forced interruption caused by a hidden 69K reasoning adjustment, after closely related reports have already documented this behavior, is not an acceptable default.
Follow-up: repeated across multiple Sol 6.1 and Astra sessions
This is not limited to the single session documented above. The user reports repeated early compaction in that agent, other GPT-6.1 Sol agents, and GPT-6 Astra. A bounded read-only audit now independently confirms the broader scope.
Completed compactions in four sampled session rollouts
These are distinct completed compacted checkpoints from September 30–October 1, 2026. Model identity comes from the preceding recorded turn context. “Reported usage” is the latest server-reported total before each checkpoint, not cumulative session billing.
| Session (anonymous label) | Recorded model | Completed checkpoints | Reported usage before those checkpoints |
|---|---|---|---|
| A — initial report | GPT-6.1 Sol | 9 | 185,004–222,107 |
| B — separate session | GPT-6.1 Sol | 6 | 182,120–223,094 |
| C — separate session | GPT-6 Astra | 4 | 183,371–222,416 |
| D — separate session | GPT-6 Astra | 1 | 236,292 |
20 completed compactions across four distinct session histories. This is a sampled count, not a claim to have audited every agent or every historical event. A checkpoint plus its preceding usage proves that compaction occurred at that reported usage; it does not alone prove the trigger mechanism for every historical checkpoint.
Direct runtime confirmation of the accounting mismatch across models
For these events, the native trigger log can also be joined to the completed checkpoint:
| Session | Model | Trigger time (UTC) | Reported total | Internal compaction count | Effective window | Time from preceding token event to completed checkpoint |
|---|---|---|---|---|---|---|
| A | GPT-6.1 Sol | Oct 1 10:49:20 | 193,193 | 266,425 | 258,400 | 309.441s |
| C | GPT-6 Astra | Sep 30 07:33:23 | 207,168 | 261,140 | 258,400 | 213.133s |
| D | GPT-6 Astra | Sep 30 22:25:09 | 236,292 | 261,095 | 258,400 | 182.374s |
All three log full_context_window_limit_reached=true and token_limit_reached=true. Those three completed events alone occupy approximately 11 minutes 45 seconds between their preceding usage events and compaction checkpoints. This is summed across sessions, not a claim about one uninterrupted wall-clock interval.
A further GPT-6.1 Sol threshold event in session B at Oct 1 04:38:58 logged an internal count of 263,815 against 258,400, while the latest reported total was 187,840. The turn was subsequently interrupted at 04:41:44; it is not counted as a completed compaction in the table above.
The exact prior-reasoning/new-output arithmetic is reconstructed for session A in the initial report. The other logged events independently establish the same reported-versus-internal count mismatch and actual threshold crossing; their extra-count components have not all been reconstructed separately. Likewise, the installed CLI is 0.159.2, but this follow-up does not assign that build to every historical resume.
This is repeated lost working time across models, not an isolated bad session. Please investigate the shared accounting and signal propagation path, identify the affected versions/routes, and provide a fix with a regression test. Users should not need to inflate their context settings to compensate for an unexplained second token counter.
Activity
github-actions commentedon Oct 1, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
[-]GPT-6.1 Sol / CLI 0.159.2: 193K displayed usage becomes 266K and forces a 5-minute compaction[/-][+]Repeated early compaction across GPT-6.1 Sol and Astra: internal token counts exceed reported usage[/+]railway02 commentedon Oct 2, 2026
me too
coinman-dev commentedon Oct 4, 2026
Same cause here on Codex 0.159.2 with
gpt-6.1-solunder WSL2. A small client patch that stops the double count is described in #39767 (comment): with it the same chat went from being compacted at 734,065 tokens to 922,856 with no early compaction, and its regression test fails on unpatched 0.160.0. Patch and notes: https://github.com/coinman-dev/codex-context-accounting-fixjfet97 commentedon Oct 5, 2026
Another reproduction with CLI 0.160.0, GPT-6.1 Sol, and high reasoning effort. Automatic compaction started while the footer showed 21% context remaining.
The trigger log recorded
token_limit_reached=true, followed byrun_auto_compact{reason=ContextLimit phase=MidTurn}. Compaction completed approximately four minutes later.The footer's 21% matches the reported usage with the 12,000-token baseline adjustment. The internal count crossed the threshold despite that displayed headroom.
This confirms the reported-versus-internal accounting discrepancy on 0.160.0. It does not independently establish whether historical reasoning was already included by the backend or where the reasoning-included signal was lost.
Please investigate the shared accounting path and make the displayed percentage reflect the budget used for compaction.
johnnywang commentedon Oct 10, 2026
Additional reproduction on Codex CLI 0.162.1, model gpt-6.1-sol, reasoning effort xhigh, using the default compaction limits (no explicit context-window or auto-compaction-limit overrides).
The TUI showed 67% context used when automatic compaction started.
Reconstructed threshold decision
Applying the
rust-v0.162.1history-accounting formula to the retained records, without decrypting their contents, reproduces the runtime count exactly:Reviewed numeric/boolean fields from the trigger log:
The arithmetic matches the
server_reasoning_included == falsebranch. This capture does not establish why that signal was false or whether the backend had already included earlier reasoning in reported usage.Display mismatch
The TUI uses the latest reported total with its 12,000-token baseline adjustment. That calculation reproduces 33% remaining / 67% used exactly. The compaction guard simultaneously evaluates a much larger total.
This makes context-percentage-based handoff and stoppage rules unreliable: the displayed budget and the enforced budget are different.
Reasoning estimate worth validating
The 85 older reasoning records originally generated 16,823 server-reported reasoning-output tokens, while their replay estimate is 61,645, approximately 3.7 times larger.
This comparison is evidence to investigate the encrypted-length heuristic, not proof that replay occupies exactly the original number of generated tokens. A fully rendered server-side context count and verification of the reasoning-included contract are still needed to establish the correct total.
Relevant release source
Please validate the reasoning-accounting contract and heuristic, and expose a consistent, explicitly labeled context-budget metric for the compaction decision, UI, and agent stoppage rules.
Only reviewed numeric diagnostics and public source references are included here. No raw logs, prompts, project details, local paths, encrypted payloads, or session/turn/response identifiers are attached.
xue-ding-e commentedon Oct 11, 2026
Additional reproduction from the Windows desktop app on 2026-10-11 UTC, with an exact reconstruction of the discrepancy on a newer bundled core.
Environment
app-server.gpt-6.1-sol; reasoning effort:max; ChatGPT sign-in.resources/codex.exehave identical SHA-256 hashes. This is the desktop-bundled core, not an independently installed npm CLI.up_to_dateon its configuredprodchannel. This is not a claim about every release channel.Relevant configuration:
The runtime logged an effective window of 828,400 and an auto-compaction threshold of 784,800, with scope
Total.Exact reconstruction
At 16:43:39.966 UTC, the most recent rollout token event contained:
The desktop usage calculation uses the latest reported total divided by the effective context window.
Applying the published history estimator to the recorded items, without decrypting any reasoning, reproduces the native decision exactly:
The 304,613-token term comes from the 251 encrypted reasoning records before the latest user boundary, using the published encoded-length heuristic:
The fresh tool result contains 39,700 UTF-8 content bytes and a 37-byte call ID:
These calculations match the
get_non_last_reasoning_items_tokens,get_total_token_usage, andestimate_item_token_countpath in the publishedcodex-rs/core/src/context_manager/history.rs. This establishes arithmetic agreement; it does not establish that the currently published source revision is the exact binary build revision.Native trigger evidence
Tracing prefixes, thread/turn identifiers, paths, and conversation content are omitted:
A completed compaction checkpoint was recorded at 16:46:11.071 UTC, approximately 151.1 seconds after the trigger. Its response ID matches a usage receipt containing:
Thus this caused a real remote compaction operation and interruption while the desktop indicator showed approximately 60% occupancy. It was not a manual compaction request.
Expected behavior and limits of this capture
Please reconcile the budget shown by the desktop indicator with the budget used by the compaction guard, and investigate the extra historical-reasoning term on this desktop/core version.
The reconstruction matches the
server_reasoning_included == falseaccounting branch. This capture does not independently establish why that flag was false, whether the backend already included historical reasoning in reported input usage, or whether the reasoning-included compatibility signal was absent. Those require upstream investigation; the report does not claim to have proved double-counting for this particular request.This was observed in an existing, long-running conversation with many tool calls and screenshots. There is no deterministic minimal reproduction from a fresh conversation yet. Raw transcripts, encrypted reasoning blobs, credentials, and unrelated machine settings are not attached. No configuration or bundled binaries were modified as a workaround.
GuXinghai commentedon Oct 12, 2026
Additional Windows Codex Desktop reproduction with the default 373,000-token window, rather than a manually enlarged window.
Environment: bundled core
0.162.0-alpha.17.2,gpt-6.1-sol, reasoning effortmedium. No explicitmodel_context_windowormodel_auto_compact_token_limitoverrides. The catalog window was 373,000, the effective window 354,350, and the runtime auto-compaction threshold 335,700, with scopeTotal.At 2026-10-12 02:17:32 UTC, the completed ordinary response (R1) reported:
The 95,857-token difference is reconstructed exactly, without decrypting reasoning:
Sanitized native trigger fields:
This was followed by
ContextLimit / MidTurnautomatic compaction. The checkpoint completed at 02:19:45.800 UTC, approximately 132.8 seconds after the trigger. A continuous pre-compaction interval (01:27:01–02:17:32 UTC) containing 22 runtime nodes matchedU+R+Nexactly.The separate compaction response (R2) reported input 245,438, cached input 244,992, output 4,420, reasoning output 0, and total 249,858. R1 and R2 have distinct response identities in the same turn. Reconstructed local logical histories retained the same 96 reasoning items, verified by order, encoded lengths and SHA-256; the corresponding source preserves these items in the prompt paths. This is not a capture of the full wire payload. The 282-token input difference cannot independently establish whether historical reasoning was included: shared components cancel. The total-usage difference also includes the new compaction output.
Evidence boundary: the extra historical-reasoning estimate and resulting compaction are established. The arithmetic exactly matches the
server_reasoning_included=falsebranch, but no direct flag observation, handshake-response headers or per-item input attribution are available for this request. #49026's Sol Responses Lite / all-turns protocol observation and #39767 strongly motivate investigating overlap; they do not prove this particular WebSocket request double-counted reasoning.Version-matching public source: tag
rust-v0.162.0-alpha.17.2, commit740e5af33c71225640e0c1c1555c514c2c93ab74. The calculation matches exactly; an exact binary-to-source build correspondence has not been established.Could maintainers verify the GPT-6.1 Sol Responses Lite / all_turns / WebSocket input-usage contract, compatibility-header propagation, and request-bound compaction accounting? The catalog and source support Lite/all-turns for this configuration, and runtime logs identify WebSocket transport; complete request parameters were not captured. If reported usage already covers historical reasoning, the additional estimate should not be added again. Under that condition,
U+N=245405would leave 90,295 tokens below the auto-compaction threshold, making this compaction avoidable.Only sanitized numerical evidence and public source references are shared. No raw logs, transcripts, encrypted payloads, credentials, personal paths or session/turn/response identifiers are attached.
Zeno-Young-GitHub commentedon Oct 13, 2026
Another reproduction on Windows Codex Desktop with bundled core
0.162.0-alpha.17.2, modelgpt-6.1-sol, reasoning effortmax, and ChatGPT sign-in.Configuration:
On 2026-10-13 at approximately 02:42:09 UTC, automatic compaction started while the desktop indicator showed 60% used (498K / 828K).
The native runtime log recorded:
No manual compaction was requested. The same conversation previously compacted at approximately 66% displayed usage, so this is a repeated occurrence.
This closely matches the other Windows desktop reproduction in this issue. I have not yet reconstructed the extra 294,592 tokens or verified whether historical reasoning was already included by the backend; these observations establish the accounting/display discrepancy rather than independently proving double-counting.
Please investigate the historical-reasoning accounting path, reconcile the displayed and enforced context budgets, and clarify why the configured 900,000-token threshold becomes 784,800 at runtime.
martinmclee commentedon Oct 14, 2026
Additional reproduction on 2026-10-14 with Codex 0.162.0, GPT-6.1 Sol, and Max reasoning effort. Automatic compaction started at approximately 287K reported tokens, despite a catalog context window of 500K.
Environment
7.0.0-31-generic, x86_64.session_metarecords client version0.162.0, originatorCodex Desktop, and sourcevscode. The installed CLI also reportscodex-cli 0.162.0.gpt-6.1-sol; reasoning effort:max; ChatGPT sign-in.model_context_windowormodel_auto_compact_token_limitoverride was found in the host's globalconfig.toml.Reported usage versus the compaction decision
At approximately 03:39:10 UTC / 11:39:10 Hong Kong time, the latest model-reported usage and the matching native threshold check disagreed:
Cached input was 283,520, already included in input. Reasoning output was 14, already included in output. Those subtotals are not added again in the reported total above.
Sanitized native trigger fields:
The next operation was
run_auto_compact{reason=ContextLimit phase=MidTurn}. The completedcompactedcheckpoint was recorded at 03:41:49.482 UTC, approximately 159 seconds after the preceding token-count event at 03:39:10.472 UTC.Requested behavior and evidence limits
Please investigate the unexplained 164,905-token adjustment, reconcile displayed context usage with the budget enforced by the compaction guard, and avoid compaction while the actual request still has sufficient room. If an additional allowance is valid, the context display should expose and explain it.
This confirms the accounting discrepancy and a completed automatic compaction on 0.162.0. I have not reconstructed the extra-count components or captured the reasoning-included signal, so this incident does not independently prove historical-reasoning double-counting. It closely resembles the other incidents here and #49026.
This occurred in an existing long-running conversation, with no deterministic fresh-session reproduction yet. Only sanitized numerical diagnostics are included; raw conversation content, credentials, project paths, encrypted payloads, and session/turn/response identifiers are omitted.
Martin
Muelmue commentedon Oct 16, 2026
Additional reproduction on 2026-10-16: automatic compaction started at 59.84% displayed context usage.
Environment:
0.162.0-alpha.17.2gpt-6-astrahighmodel_context_window = 872000model_auto_compact_token_limit = 784800828400TotalAt 00:31:43 UTC, the latest reported usage and the internal compaction counter differed:
Reconstructing the retained history using the matching CLI source reproduces the runtime count exactly:
495710 + 410584 + 5266 = 911560The runtime logged both
token_limit_reached=trueandfull_context_window_limit_reached=true. Compaction completed at 00:33:44 UTC, about two minutes later. This was automatic compaction, not a manual request.The preceding successful HTTP response did not contain
X-Reasoning-Included.A separate two-turn synthetic HTTP probe against the ChatGPT Codex backend, using the same OAuth account and model, also returned HTTP 200 and
response.completedwithout that header. The second request replayed the first response's encrypted reasoning. Its usage attribution included 13 input tokens for historical reasoning, within 73 total input tokens; the attribution sum matched the reported input total.The probe used HTTP client-version header
0.163.0; the affected desktop CLI remained0.162.0-alpha.17.2. These were new short requests, not an exact replay of the long-session incident. They demonstrate that historical reasoning can be included in reported usage while the header is absent, but do not independently prove inclusion of every historical reasoning item in the original incident.Please investigate the header-dependent reasoning fallback and reconcile the displayed context usage with the count used to trigger compaction.
shaoxu-wang commentedon Nov 19, 2026
I observed a similar compaction event in a long-running Codex desktop chat using GPT-6.2 Sol through a custom Responses provider.
Environment
26.1111.2228.0, core0.170.0as recorded in the rolloutmaxreasoning effortv0.1.4504Observed behavior
On November 19, 2026 (UTC), the ordinary response reported 278,632 tokens at
02:43:09.127. After a tool result was appended, the matchingtoken_countevent at02:43:14.120recordedlast_usage_includes_reasoning=false.The gateway logged a compaction request at
02:43:14.149, and the rollout recordedcompactedat02:44:25.210in the same turn. The sequence is consistent with automatic mid-turn compaction. The capture has no explicit runtime trigger reason or scope.Token accounting reconstruction
The estimates below use the Codex 0.170.0 history estimator.
U)R)N)U + R + N)U + N)The reconstructed count crosses the configured limit, while the counterfactual stays below it. 385,050 is a reconstruction from the rollout. The runtime decision count was unavailable.