codex icon indicating copy to clipboard operation
codex copied to clipboard

Historical reasoning double-counted in 0.162.0-alpha.17.2, causing premature auto-compaction

Open KiwiGeorge opened this issue 1 month ago • 16 comments

What version of the Codex App are you using (From “About Codex” dialog)?

0.162.0-alpha.17.2

What subscription do you have?

Pro Max $500

What platform is your computer?

arm

What issue are you seeing?

Environment

  • Bundled Codex CLI: 0.162.0-alpha.17.2
  • macOS / Apple Silicon
  • Native Sign in with ChatGPT
  • Model: gpt-6.1-sol
  • Reasoning effort: high
  • Reproduced with both WebSocket and HTTPS/SSE

Configuration: model_context_window = 1000000 model_auto_compact_token_limit = 900000

Runtime effective window: 828400 Runtime auto-compaction threshold: 784800

Problem

Historical reasoning already represented in server input usage is estimated again by the client, inflating the counter used for auto-compaction.

In a long session, the UI showed 459164 tokens used, approximately 55%, while compaction started:

459164 server-reported tokens +324498 estimated historical reasoning tokens +4737 estimated pending tool-result tokens =788399 client compaction count

This crossed the effective threshold of 784800. The arithmetic was reconstructed exactly from the recorded history. Compaction took approximately 199 seconds.

Minimal reproduction

  1. Start an ephemeral app-server thread with gpt-6.1-sol and effort=high.
  2. Ask it to find the smallest positive integer x satisfying: x mod 7=2, x mod 11=3, x mod 13=5. Request only the answer, without tools.
  3. Wait for completion, then send another user message requesting only OK.
  4. Compare server usage / thread/tokenUsage/updated with the core post-sampling token counter.

Observed results:

Transport Server total Client compaction count Extra estimate
HTTPS/SSE 20815 21059 244
WebSocket 20830 21098 268

In the SSE capture, both responses returned reasoning.context="all_turns".

The second response's per-item attribution reported 81 input tokens for the earlier reasoning item, confirming it was already counted by the server. Its encrypted length was 2168 bytes, but the client added another 244-token estimate.

Signal observations

Successful native codex doctor WebSocket handshakes reported: reasoning header: false

The inspected code adds historical reasoning estimates when server_reasoning_included=false. It relies on x-reasoning-included, while the effective response.reasoning.context="all_turns" is not used to correct that flag.

Expected behavior

Use server-reported usage plus genuinely new local items, without estimating already-counted historical reasoning again.

Please investigate whether the per-response effective reasoning context or usage attribution should determine this accounting contract, instead of relying exclusively on a handshake/response header.

Limits

The original session's raw headers and per-item attribution were not captured. The entire historical estimate cannot be equated one-for-one with actual duplicate server tokens.

The minimal reproduction directly demonstrates double-accounting. No answer-quality benchmark or installed-patch comparison was performed.

Related reports: #39767 and #49026.

No credentials, private prompts, local paths, account/session identifiers, or raw business logs are included.

What steps can reproduce the bug?

  1. Start an ephemeral app-server thread with gpt-6.1-sol and effort=high.
  2. Ask it to find the smallest positive integer x satisfying: x mod 7=2, x mod 11=3, x mod 13=5. Request only the answer, without tools.
  3. Wait for completion, then send another user message requesting only OK.
  4. Compare server usage / thread/tokenUsage/updated with the core post-sampling token counter.

Observed results:

Transport Server total Client compaction count Extra estimate
HTTPS/SSE 20815 21059 244
WebSocket 20830 21098 268

In the SSE capture, both responses returned reasoning.context="all_turns".

The second response's per-item attribution reported 81 input tokens for the earlier reasoning item, confirming it was already counted by the server. Its encrypted length was 2168 bytes, but the client added another 244-token estimate.

Signal observations

Successful native codex doctor WebSocket handshakes reported: reasoning header: false

The inspected code adds historical reasoning estimates when server_reasoning_included=false. It relies on x-reasoning-included, while the effective response.reasoning.context="all_turns" is not used to correct that flag.

What is the expected behavior?

Use server-reported usage plus genuinely new local items, without estimating already-counted historical reasoning again.

Please investigate whether the per-response effective reasoning context or usage attribution should determine this accounting contract, instead of relying exclusively on a handshake/response header.

Additional information

No response

KiwiGeorge avatar Oct 12 '26 08:10 KiwiGeorge

Additional Windows Desktop evidence for the same version and symptom.

Environment:

  • ChatGPT desktop app for Windows, installed package OpenAI.Codex 26.1007.2314.0.
  • Actual running/bundled Codex executable: 0.162.0-alpha.17.2.
  • Model: gpt-6.1-sol; reasoning effort: ultra.
  • Native OpenAI provider. CC Switch proxy/takeover is disabled.
  • Current updater check returned up_to_date for the installed production channel.
  • User-level configuration is model_context_window=1000000 and model_auto_compact_token_limit=900000. No project context override or profile was found.

This is not just a config-file inspection: allowlisted runtime tags record model_context_window=1000000, model_context_window_effective=828400, model_context_window_override=true, model_auto_compact_token_limit=900000, and codex.turn.reasoning_effort=ultra.

Observed sequence on 2026-10-13, UTC:

  1. 04:14:50: core context check reports auto_compact_scope_tokens=782018 and scope limit=784800; token_limit_reached=false.
  2. 04:15:05: session token_count reports last input_tokens=456201, total_tokens=456466 and model_context_window=828400. This matches the UI's approximately 456K / 828K (55%).
  3. The same context check reports auto_compact_scope_tokens=790681, scope limit=784800 and token_limit_reached=true. full_context_window=828400 and full_context_window_limit_reached=false.
  4. 04:18:20: a compacted event is recorded. Subsequent total_tokens=52955.

Therefore the 456K figure is a pre-compaction server usage figure, not the post-compaction count. The observed trigger/UI discrepancy is 334215 tokens. Historical reasoning double-accounting is a candidate explanation consistent with this issue; this original session did not capture raw response headers or per-item server usage attribution, so it does not by itself prove how many of those tokens were counted twice.

There is also a separate catalog/config limit concern (related to #41325):

  • Fresh model catalog: context_window=500000, max_context_window=872000, effective_context_window_percent=95.
  • The effective runtime window is 872000 * 95% = 828400.
  • The observed compaction limit is min(900000, 872000 * 90%) = 784800.
  • Both requested values reach the runtime but are silently reduced; changing the saved values or restarting alone does not establish a 1M runtime budget.

Please investigate the accounting contract between server usage, historical reasoning estimates, and the UI, and either enable or clearly document/warn about the effective ChatGPT-backed Codex context cap. The public API model page lists a 1,050,000-token model window; that alone does not prove equivalent usable input in the subscription-backed Desktop harness.

No raw conversation, encrypted reasoning, credentials, account identifiers, local project paths, or session/thread identifiers are included. This is an observed existing-session trace, not a fresh-session reproduction or a claim that an installed patch has been validated. Local config/cache and signed application files were not modified.

Local metadata-only replay now exactly reconstructs the trigger count, using the history estimator from the official rust-v0.162.0 source:

last server total usage                    456466
historical encrypted reasoning estimate    334207
pending local tool output estimate              8
client auto-compaction count               790681
resolved automatic-compaction threshold    784800
excess                                       5881

The historical term contains 287 encrypted reasoning items before the last instruction boundary. For each item, the byte estimate is max(floor(encoded_length * 3 / 4) - 650, 0), then rounded up to tokens at 4 bytes/token. The pending empty tool result contributes its 29-byte call-ID length, rounded up to 8 tokens. A current-turn reasoning item is excluded. No encrypted contents were decoded, printed, or uploaded.

Source: https://github.com/openai/codex/blob/rust-v0.162.0/codex-rs/core/src/context_manager/history.rs#L893-L950

This confirms where the extra client estimate comes from. It still does not establish whether the server already counted those historical reasoning items in this Windows occurrence; confirming duplication requires the server accounting/header or attribution contract.

xue-ding-e avatar Oct 13 '26 04:10 xue-ding-e

Additional Windows Desktop evidence for #53309, including an exact reconstruction of the UI/runtime gap with a 512K configuration.

Environment:

  • Windows Codex Desktop, installed MSIX package 26.1007.2314.0.
  • Bundled executable independently reports codex-cli 0.162.0-alpha.17.2.
  • Primary observed conversation: gpt-6.1-sol, max reasoning, native OpenAI provider.
  • model_context_window=512000; model_auto_compact_token_limit is unset; compaction scope is Total.
  • Logged effective window: 486400; automatic-compaction threshold: 460800.

At 2026-10-13 07:30:54 UTC, the context indicator showed approximately 307K / 486K, or 63.15%, while the runtime started automatic compaction. The retained history and official history estimator exactly reconstruct its counter:

Component Tokens
Latest server-reported input 300992
Latest server-reported output, including reasoning 6164
Latest server-reported total used by the UI 307156
Estimated earlier encrypted reasoning 158466
Estimated new local tool result 25
Reconstructed internal compaction count 465647
Independently logged internal compaction count 465647
Difference between reconstruction and log 0
Automatic-compaction threshold 460800

The historical term contains 134 encrypted reasoning items before the latest instruction boundary. For each item, the inspected source computes max(floor(encoded_length*3/4)-650, 0) bytes, then rounds up at 4 bytes per token. The pending custom-tool output contributes 62 content bytes plus a 37-byte call ID, giving ceil(99/4)=25 tokens. Only lengths were processed; ciphertext was not decoded, printed, or uploaded.

Sanitized runtime fields:

total_usage_tokens=465647
auto_compact_scope_tokens=465647
auto_compact_scope_limit=Some(460800)
auto_compact_limit_scope=Total
auto_compact_window_prefill_tokens=None
full_context_window_limit=Some(486400)
full_context_window_limit_reached=false
token_limit_reached=true

A completed compacted checkpoint is retained at 07:34:32 UTC, after which the reported context count falls to 28578 and model execution continues.

Additional bounded comparison: four selected successful compactions in different conversations (three Desktop chats and one subagent), all gpt-6.1-sol with the same 486400 effective window and 460800 automatic threshold. The percentage below is computed from each latest usage receipt using the Desktop indicator formula.

Anonymous sample Effort Kind Latest reported total UI formula percentage Runtime counter Gap
T01 max desktop 307156 63.15% 465647 158491
T02 max desktop 309462 63.62% 462747 153285
T03 max desktop 363580 74.75% 462563 98983
T04 medium subagent 366940 75.44% 469219 102279

All four have completed compacted checkpoints. This is a selected sample, not a frequency estimate. Only T01 has a complete independently reconstructed counter. A bounded replay of T02 left a 20546-token residual; the other gaps are observed counter differences, not fully attributed historical-reasoning terms.

The source get_total_token_usage() adds this historical term when server_reasoning_included is false. This exact arithmetic establishes where the extra client estimate comes from in this occurrence. It does not independently establish whether the server already counted each historical item: original response headers, effective reasoning.context, and per-item server attribution were not captured here. The original issue's controlled reproduction supplies stronger evidence about that accounting contract.

Source references:

  • https://github.com/openai/codex/blob/rust-v0.162.0/codex-rs/core/src/context_manager/history.rs#L893-L950
  • https://github.com/openai/codex/blob/rust-v0.162.0/codex-rs/core/src/context_manager/history.rs#L1053-L1074
  • https://github.com/openai/codex/blob/669449b02c4b58de4bcd22485eb60c98a6e38a54/codex-rs/core/src/session/context_window.rs

Please investigate the reasoning-included signal and align the displayed context usage with the actual compaction decision, or expose the additional estimated components. This report corroborates the existing issue; it does not claim that ordinary 63% usage is the intended automatic-compaction threshold.

These are observations from existing conversations. No fresh long-context model run, configuration change, installed-client patch, or answer-quality benchmark was performed. Private prompts, encrypted payloads, screenshots, account/thread identifiers, local paths, and raw session logs are omitted.

MarkTian-Long avatar Oct 13 '26 08:10 MarkTian-Long

Additional Windows observation:

Versions inspected after the event: desktop package 26.1007.9446.0, bundled codex-cli 0.162.0-alpha.17.2; model gpt-6.1-sol.

On 2026-10-14 (UTC), the internal context estimate was:

  • 11:52:05.528: 780,140 tokens; token_limit_reached=false
  • 11:55:14.874: 785,696 tokens; token_limit_reached=true
  • 11:58:03.454: 61,264 tokens; token_limit_reached=false

The automatic compaction threshold was 784,800 tokens and the full context limit was 828,400. At 11:55:14.874, full_context_window_limit_reached=false.

A screenshot during compaction showed approximately 491K/828K (59%). It was not captured at the exact log timestamp, so this is not a synchronized comparison.

Inspection of the currently installed UI shows displayed usage calculated as min(last.totalTokens, modelContextWindow), while compaction uses an internal active-context estimate. The logs establish crossing the automatic threshold; they do not establish a configured 59% threshold.

The estimate’s component breakdown and per-response attribution were not captured, so this observation does not independently prove historical-reasoning double-counting.

Could you investigate the accounting difference and either align the displayed usage with the compaction decision or expose the additional estimated components?

AlenSheng avatar Oct 14 '26 13:10 AlenSheng

Additional Windows Desktop occurrence on 2026-10-14: the historical-reasoning estimate and pending-tool estimate have now been reconstructed independently, with zero difference from the runtime compaction counter.

The latest server-reported total was 451,479 tokens (54.50% of the 828,400 effective window) when automatic compaction was triggered. The configured capacity was loaded correctly; the decisive difference was the extra historical-reasoning estimate.

Environment and effective configuration

  • Windows Codex Desktop.
  • Running/bundled core: codex-cli 0.162.0-alpha.17.2, also recorded in the session metadata.
  • Conversation model: gpt-6.1-sol; reasoning effort: xhigh.
  • OpenAI provider, ChatGPT sign-in.
  • User configuration: model_context_window = 872000.
  • model_auto_compact_token_limit and model_auto_compact_token_limit_scope are unset.
  • No project-level context/compaction override was found.
  • Runtime: effective window 828,400, automatic threshold 784,800, scope Total.
  • The current model catalog lists a 500,000 default, 872,000 maximum, and 95% effective-window percentage. The observed trigger was not a fallback to a 450,000 threshold.

Observed sequence

Times below are UTC on 2026-10-14.

Time Last server-reported total Internal compaction count Threshold reached
13:10:36 441,765 777,305 false
13:11:12 451,479 785,375 true

The runtime then recorded run_auto_compact{reason=ContextLimit phase=MidTurn}. The compaction item ran from 13:11:12.828 to 13:13:23.732, approximately 131 seconds, and a completed compaction checkpoint was persisted. Normal model execution resumed afterward.

Selected runtime fields at the trigger, with conversation identifiers omitted:

total_usage_tokens=785375
auto_compact_scope_tokens=785375
auto_compact_scope_limit=Some(784800)
auto_compact_limit_scope=Total
auto_compact_window_prefill_tokens=None
full_context_window_limit=Some(828400)
full_context_window_limit_reached=false
token_limit_reached=true
model_needs_follow_up=true

Exact local reconstruction

Component Tokens
Last response input 450,568
Last response output, including reasoning 911
Last reported total 451,479
Earlier encrypted-reasoning estimate, from 248 items before the latest user boundary 330,587
New local tool-result estimate 3,309
Reconstructed internal count 785,375
Independently logged internal count 785,375
Reconstruction difference 0

The reconstruction uses the official source tag matching the reported core version:

For each selected historical reasoning item, the byte estimate is max(floor(encoded_length * 3 / 4) - 650, 0), rounded up at four bytes per token. Summing the 248 item estimates gives 330,587.

The pending tool result contains two text parts totaling 13,197 UTF-8 bytes and a 37-byte call ID. Thus ceil((13197 + 37) / 4) = 3309. Both extra components were computed separately; neither is merely an unexplained residual.

451479 + 330587 + 3309 = 785375
785375 >= 784800  -> automatic compaction
451479 + 3309 = 454788 < 784800

The resulting compaction request itself reports 455,461 input tokens and 4,540 output tokens, total 460,001. These are recorded usage counts, not a claim about billing.

Earlier comparison and evidence limits

A selected earlier conversation on 2026-09-30, core version 0.159.0 with the same model and a 258,400 effective window, had five completed compactions whose preceding reported totals were 82.58%-91.69% of that window. This supports the user's observation that the present 54.50% behavior is materially different. It is not a controlled version comparison and does not establish when the defect began or that increasing the configured window caused it.

This replay establishes the source of the additional 333,896-token count and its role in triggering an actual compaction. The arithmetic matches the branch that adds historical reasoning when server_reasoning_included is false. Original response headers and per-item server attribution were not captured, so this occurrence alone does not prove that every one of the 330,587 estimated historical tokens was already counted by the server. The controlled reproduction in the original issue provides stronger evidence about that accounting contract.

Please investigate the server-reasoning-included signal and reconcile the displayed/reported usage with the compaction decision. The configured threshold reaching the client does not establish that the additional estimate is correct.

This was a read-only reconstruction of an existing occurrence. No new model reproduction, installed-client patch, or configuration change was performed. No private prompts, project details, local paths, credentials, account/conversation identifiers, raw logs, or encrypted payloads are included; the historical-reasoning reconstruction used lengths only.

fireking0608-spec avatar Oct 14 '26 15:10 fireking0608-spec

Same root cause as #39767 / #32483 / #49026. The client adds an encrypted-length estimate of older reasoning on top of usage that already includes it (server_reasoning_included == false branch in history.rs), and tasks/regular.rs clears the flag before pre-turn compaction reads it. ghzlatarev's mock in #32483 shows a compaction even with X-Reasoning-Included: true.

An unofficial client patch (three files in core, plus a regression test) is described in https://github.com/openai/codex/issues/39767#issuecomment-5984486657. A version for rust-v0.162.1 is now in the repo: its 7 compaction checks pass with the patch, and the 4 new cases fail when the fix is reverted. It also applies to current main. It covers CLI / app-server builds (terminal, Zed); it does not replace the core bundled inside Codex Desktop, which most reports here use. Patch and notes: https://github.com/coinman-dev/codex-context-accounting-fix

coinman-dev avatar Oct 14 '26 17:10 coinman-dev

Another occurrence on macOS with ChatGPT desktop version 26.1007.71326, bundled Codex CLI 0.162.0-alpha.17.2, GPT-6.1 Sol Ultra. Configured model_context_window = 543000, resulting in a displayed effective context of approximately 516K. Automatic compaction started at approximately 351K/516K (68%), whereas the expected 90%-of-raw-window threshold is 488.7K tokens. The discrepancy is approximately 138K tokens, consistent with the historical reasoning accounting issue described here. No explicit model_auto_compact_token_limit was configured.

danieljl avatar Oct 15 '26 15:10 danieljl

Additional Windows Desktop evidence on 2026-10-15, using the same core version with no explicit context-window or compaction-threshold override.

Environment and configuration

  • Windows Codex Desktop, MSIX package 26.1007.9446.0.
  • Running stock backend: codex-cli 0.162.0-alpha.17.2.
  • Conversation model: gpt-6.1-sol, reasoning effort xhigh.
  • model_context_window: unset.
  • model_auto_compact_token_limit: unset.
  • model_auto_compact_token_limit_scope = "total".
  • No relevant project-level override or custom model catalog found.
  • The desktop updater reports up_to_date on its configured production channel.

Experimental local backend builds had previously been tested, but neither was active for this capture. The running app-server was verified to use the stock executable.

Observed trigger

All times below are UTC on 2026-10-15.

The latest token-count event at 15:27:50.988 and the internal compaction check at 15:27:50.996 reported:

Measurement Tokens
Last server-reported input 310,417
Last server-reported output 1,103
Last server-reported total 311,520
Internal compaction count 450,227
Internal minus reported total 138,707
Automatic-compaction threshold 450,000
Effective context window 475,000

Reported usage was therefore approximately 65.58% of the effective window when the internal counter crossed the automatic-compaction threshold. This percentage is calculated from the recorded usage, not a synchronized screenshot.

Sanitized trigger fields:

total_usage_tokens=450227
auto_compact_scope_tokens=450227
auto_compact_scope_limit=Some(450000)
auto_compact_limit_scope=Total
auto_compact_window_prefill_tokens=None
full_context_window_limit=Some(475000)
full_context_window_limit_reached=false
token_limit_reached=true
needs_follow_up=true

A completed compacted checkpoint was persisted at 15:29:59.597, approximately 129 seconds after the trigger.

The same conversation also completed a compaction at 14:26:53.677, with a preceding reported total of 283,776 against the same 475,000-token effective window. An exact trigger counter was not retained for that earlier event, so I am not assigning it the same reconstructed breakdown.

Evidence limits and requested investigation

This confirms another reported-versus-internal accounting discrepancy and an actual threshold crossing on Windows with default model limits. It does not independently attribute the latest 138,707-token difference: raw response headers, effective reasoning.context, and per-item server attribution were not captured.

Please investigate the reasoning-included accounting contract and reconcile the context usage shown to users with the counter that triggers compaction. Removing numeric overrides and restarting did not resolve the behavior in this case.

Private prompts, encrypted payloads, credentials, local paths, and account/thread identifiers are omitted.

jeremygold02 avatar Oct 15 '26 15:10 jeremygold02

Additional Windows Desktop evidence

Another occurrence with bundled core 0.162.0-alpha.17.2, model gpt-6.1-sol, and reasoning effort max. This session used a custom Responses provider (api-router), so it is corroborating evidence rather than a native-provider reproduction.

Environment and effective runtime configuration

  • Windows Codex Desktop.
  • Bundled Codex CLI: 0.162.0-alpha.17.2.
  • Model: gpt-6.1-sol.
  • Provider: api-router.
  • Effective model_context_window: 828400 tokens.
  • Effective automatic-compaction threshold: 784800 tokens.
  • Compaction scope: Total.

Observed trigger

At 2026-10-16 06:30:38.802 UTC, the latest retained token usage reported:

last_token_usage.total_tokens: 483523
model_context_window:          828400
reported total / window:          58.37%

The ContextCompaction item was recorded as completed at 2026-10-16 06:34:29.517 UTC (approximately 231 seconds later). After compaction, the recorded context estimate was 14459 tokens.

Local reconstruction of the accounting difference

The retained history contains 344 earlier encrypted-reasoning items that become eligible for the historical-reasoning estimate after the latest user-message boundary. Applying the estimator from codex-rs/core/src/context_manager/history.rs to item lengths only gives:

Latest reported last.total_tokens:              483523
Estimated earlier encrypted reasoning:          304289
Subtotal before pending/local tail items:       787812
Automatic-compaction threshold:                 784800

483523 + 304289 = 787812 > 784800

Before the latest user boundary moved, the analogous subtotal was:

483387 + 297641 = 781028 < 784800

This is consistent with the historical-reasoning accounting path crossing the automatic-compaction threshold while the displayed latest usage remained around 58%.

Only encrypted item lengths were processed; encrypted contents were not decoded or printed.

Evidence limits

The detailed trigger-time trace and original response headers are no longer retained locally. The 787812 value is therefore a source-based reconstruction of the fallback accounting branch, not an independently logged exact active_context_tokens value. Retained runtime data does confirm the 784800 threshold and 828400 effective window.

The retained responses from this custom provider omit x-reasoning-included, but that does not establish whether the original response had the header or whether upstream usage already included every historical reasoning item. This occurrence alone does not prove that every estimated token was double-counted.

Please reconcile the context usage shown to users and app-server clients with the counter used for automatic compaction, and clarify whether the effective response reasoning context or server usage attribution should determine the historical-reasoning accounting contract. If the extra estimate is intentional, exposing its components in token-usage diagnostics would make the behavior understandable.

No private prompts, encrypted payloads, credentials, local project paths, account identifiers, or conversation identifiers are included. No fresh model reproduction, configuration change, or installed-client patch was performed for this observation.

SuifengKing avatar Oct 16 '26 09:10 SuifengKing

This might be related to https://github.com/openai/codex/issues/49961

thdoan avatar Oct 16 '26 20:10 thdoan

I'm also seeing premature auto-compaction in Codex Desktop. With model_context_window = 1000000 and model_auto_compact_token_limit = 900000, I have repeatedly observed compaction starting at around 480K or 650K tokens. This has been significantly affecting my day-to-day long-running tasks.

I don't have a verified client version or diagnostic logs to include here, so I can't confirm that my occurrences share the root cause described above. I'm currently interested in whether this also affects 6-Astra.

Is there a planned fix for this issue, and which sanitized diagnostic fields would help distinguish the accounting problem from effective model/context limits?

sdxqx avatar Oct 17 '26 09:10 sdxqx

Fresh native macOS reproduction on bundled CLI 0.163.0-alpha.10.2, followed by a locally tested candidate accounting/meter repair.

Baseline and final target configuration:

  • model_context_window = 500000
  • model_auto_compact_token_limit = 450000
  • runtime effective window: 475000
  • native ChatGPT sign-in, gpt-6.1-sol, high reasoning, no proxy.

Two short turns, with no tools, reproduce the duplicate addition:

Transport Second server receipt Prior reasoning already attributed to input Extra encrypted-length estimate Client compaction count
WebSocket 22,244 65 296 22,540
HTTPS/SSE 22,230 73 316 22,546

The SSE response.created and response.completed objects report reasoning.context = "all_turns". The earlier reasoning item has positive server input attribution, yet the client estimates it again. Only numeric attribution and payload sizes were inspected; encrypted reasoning was not decrypted.

The same Mac also had a long-chat trigger reconstructed exactly as 273783 + 164808 + 12014 = 450605: latest server receipt, historical-reasoning estimate, and pending tool-output estimate respectively. That explains the meter appearing around 274K while the 450K trigger fired. Historical records alone did not retain sufficient attribution to prove duplication; the fresh reproductions above do.

Candidate repair against source ce0323f2f2d3b25e82806cd555237da3db4e1897:

  • Recognize effective all_turns response metadata in both SSE and WebSocket decoding, retaining the legacy header path.
  • Bind the inclusion flag to the completed usage baseline, persist it through resume, and preserve it during incomplete-response spending updates. Remove the eager reset before pre-turn compaction; absent signals on a new completed receipt still use the legacy fallback.
  • Export a separate contextWindowUsedTokens snapshot from the same calculation used for compaction, including local pending input and replay/reconnect. Point the desktop meter at it; leave raw usage and cumulative spending intact.

Final native checks on the version-stamped local build 0.163.0-alpha.10.2+compactionfix.1:

Transport Server receipt Core compaction count Patched meter function Duplicate estimate avoided
WebSocket 22,714 22,714 22,714 484
HTTPS/SSE 22,642 22,642 22,642 292

Both runs retain the 450,000 trigger and 475,000 effective window. Raw receipts and cumulative spending match the server. A native command-execution smoke test also passed (exit 0).

Validation: parser regression fails before/passes after; 58 transport unit checks, 7 focused core checks, and 4 schema/export checks pass. The meter function extracted from the installed desktop bundle fails the occupancy regression before the change and passes in the patched copy. The meter values above were evaluated against the captured native notifications; live Electron activation is still pending.

Compatibility limit: old rollouts never persisted the inclusion flag or per-item attribution. They can still use the legacy estimate until a fresh completed receipt or context recomputation establishes the new baseline. The candidate does not infer historical inclusion from provider identity or rewrite old history.

Local activation status (updated after the first restart attempt): the desktop updater changed the app from build 20586 to 20770 during shutdown. The installer detected the changed hashes and stopped before writing any application files; no patched runtime was deployed. The two desktop edits have now been restaged against 26.1013.40934 / build 20770. Independent verification checked all 21,158 ASAR payloads and integrity hashes, with only the intended meter and runtime-selector changes. The updated meter regression fails before/passes after, and a new native command smoke test passes with the 450,000 trigger intact. Activation is being retried; live Electron activation and visual meter verification are not yet claimed. The compaction threshold was not raised.

anon5376 avatar Oct 17 '26 12:10 anon5376

Additional macOS reproduction on bundled CLI 0.163.0-alpha.10.2, with fresh real-response evidence and a separate pre-turn regression test. This is corroborating evidence for this issue, not a claim that an official fix has shipped.

Environment

  • macOS 26.5.1, Apple Silicon arm64.
  • Official bundled CLI 0.163.0-alpha.10.2, native ChatGPT sign-in.
  • Fresh no-tool probes: gpt-6.1-sol, first turn medium effort, second turn low effort.
  • Both native WebSocket and an isolated HTTPS/SSE provider pointed directly at the same first-party Codex backend reproduce the extra addition.
  • A separate official prebuilt 0.164.0-alpha.3 probe also reproduced it on October 18. It was not installed as the desktop runtime.

Configuration used for the fresh probes:

model_context_window = 750000
model_auto_compact_token_limit = 700000
model_auto_compact_token_limit_scope = "total"
model_post_turn_compact_threshold_percent = 100

1. Fresh real-response evidence, October 19

Transport Second API total Native compaction counter Extra local estimate
WebSocket 27,295 27,512 217
HTTPS/SSE 21,635 21,852 217

In the SSE probe, both response.created and response.completed report reasoning.context = "all_turns". The second completed response attributes 58 input tokens to the earlier reasoning item. That item's encoded length is 2,020 characters. The client additionally applies:

ceil(max(floor(2020 * 3 / 4) - 650, 0) / 4) = 217
21635 + 217 = 21852

Thus the estimate overlaps reasoning already represented in server usage. 217 is the fallback estimate, not the item's actual model-token count. Only lengths and numeric attribution were inspected; no ciphertext is included.

A later sample from the original desktop conversation reconciles exactly:

200970 latest API total
+ 3191 independently estimated new local tool-result tokens
+20536 historical-reasoning estimate
=224697 independently logged active-context counter

This long-chat arithmetic establishes which branch the client uses; the fresh probe above supplies the stronger server-attribution evidence. Original long-chat headers/attribution were not retained.

Minimal real-response reproduction

  1. Start an ephemeral app-server thread with gpt-6.1-sol and the configuration above.
  2. With medium effort and no tools, ask for the smallest positive integer satisfying n mod 17 = 5, n mod 19 = 7, and n mod 23 = 11; request only the integer.
  3. After completion, send a new user turn requesting only OK, at low effort.
  4. Compare the second thread/tokenUsage/updated receipt's last.totalTokens with post sampling token usage / total_usage_tokens. Inspect effective response reasoning context and numeric per-item input attribution where available.

2. Supplying the legacy header alone is insufficient

A synthetic, unauthenticated, loopback-only SSE fixture tested the unchanged signed CLI across three user turns:

  • Every response reports reasoning.context = "all_turns".
  • Every HTTP response includes x-reasoning-included: true.
  • Every synthetic receipt reports 674,000 total tokens.
  • Each response contains a synthetic 20,000-character opaque reasoning placeholder, solely to exercise the client's length estimator.

The first two post-sampling counters are exactly 674,000. Nevertheless, the third user turn produces a completed contextCompaction item and four service requests for three user turns.

This is consistent with tasks/regular.rs clearing the inclusion flag before pre-turn compaction reads the prior receipt. An HTTP response-header adapter alone is therefore not a complete fix. This fixture is not a real 674k model input or a natural boundary-crossing experiment.

3. Separate explicit-threshold/configuration mismatch

Both fresh real-provider probes resolve:

auto_compact_scope_limit = Some(675000)
auto_compact_limit_scope = Total
full_context_window_limit = Some(712500)

The requested 700,000 is below the existing 712,500 usable-window guard, but is reduced to min(700000, 750000 * 0.90) = 675000.

Isolated native tests also retain the 675,000 limit after:

  • supplying explicit 700,000 model-catalog metadata and changing effective headroom to 100%; or
  • enabling the official token-budget mode without a fallback buffer.

Please distinguish this clamp from duplicate accounting. If the 90% clamp is intentional, exposing/warning about the resolved value would help (#48616). Otherwise, an explicit limit could remain authoritative up to the existing usable-window guard, while preserving the current 90% default when no limit is set. Increasing the window does not repair the accounting bug.

Suggested repair and acceptance coverage

  • Recognize effective per-response all_turns / current_turn metadata in SSE and WebSocket decoding, while retaining conservative legacy handling for missing/unknown modes.
  • Bind the inclusion contract to its successful usage baseline, preserve it through the next pre-turn check, and persist/restore it through resume/fork.
  • Cover multiple user turns, missing headers, legacy/current-turn behavior, cold resume, and raw spending-versus-context separation.
  • Validate desktop MCP tools and a real scheduled-task trigger in addition to CLI arithmetic. A locally built candidate passed counting tests but was withdrawn because desktop MCP rejected its signing/process ancestry. No security checks were disabled; it is not a usable deployed desktop fix.

No private prompts, conversation/session/account identifiers, local paths, credentials, encrypted payloads, or raw logs are included. The original desktop remains on its unchanged official signed component; this report does not claim completed repair or a verified natural 700k crossing.

Liyuuuu111 avatar Oct 19 '26 06:10 Liyuuuu111

Additional Windows evidence with GPT-6 Astra

I can add evidence from a Windows Codex Desktop investigation: an exact reconstruction of a long-conversation compaction counter, followed by a small HTTPS/SSE probe using my current Codex account and GPT-6 Astra (gpt-6-astra).

The symptom was automatic compaction when the recent reported usage was around 386–387K tokens, despite a configured 500K trigger. The investigation found that the 500K threshold was in effect, but the internal counter had already reached 508,598.

Environment and configuration at the time of the event

  • Client environment: Windows / Codex Desktop.
  • Original desktop conversation transport: WebSocket.
  • Separate paired probe: HTTPS/SSE, using gpt-6-astra and a newly generated arithmetic sample.
  • Investigation date: October 19, 2026.

The retained investigation text does not include the outputs of the Desktop/CLI version checks, so I am leaving the exact build numbers unspecified. It also does not establish a verified reasoning-effort setting or proxy configuration.

Configuration at the time of the original event:

model_context_window = 600000
model_auto_compact_token_limit = 500000

The reported effective context window was 570,000 tokens. The subsequent log investigation confirmed an actual automatic-compaction limit of 500,000 tokens.

Exact reconstruction of the original trigger

The investigation identified the event at 18:08:46 on October 19, 2026, UTC+8 (10:08:46 UTC).

Component Tokens
Latest recorded request usage, last_token_usage.total_tokens 385,664
Estimated earlier encrypted reasoning 112,886
Estimated new local tool result 10,048
Reconstructed internal compaction count 508,598
Logged internal compaction count 508,598
Runtime automatic-compaction threshold 500,000
385664 + 112886 + 10048 = 508598
508598 - 385664 = 122934
508598 - 500000 = 8598

The historical component came from 109 retained encrypted reasoning items before the latest effective user-instruction boundary. For each item's encoded length L, the inspected estimator uses:

estimated_bytes  = max(floor(L * 3 / 4) - 650, 0)
estimated_tokens = ceil(estimated_bytes / 4)

Summing those item estimates gave 112,886. This is a length-based estimate, not an exact tokenization of the reasoning contents.

The pending tool result contained 40,153 UTF-8 bytes of text plus a 37-byte call identifier:

ceil((40153 + 37) / 4) = 10048

That tool result arrived after the most recent model output and was not yet represented in the corresponding usage receipt. The investigation also reported that five adjacent records matched the same reconstruction exactly.

Removing only the historical estimate from this arithmetic gives:

385664 + 10048 = 395712 < 500000

This explains why the historical estimate was decisive for this trigger. It does not, by itself, establish that all 112,886 estimated tokens were already counted by the server.

The reconstruction follows the inspected upstream history selection and total-usage calculation and encrypted-length estimator. These are source references used in the investigation, not a verified revision identifier for the installed executable.

Fresh HTTPS/SSE probe with GPT-6 Astra

A separate Python probe used a newly generated arithmetic sample (37 × 41). The paired follow-up inputs differed by one earlier reasoning item generated within that fresh probe. The recorded validation checked that the normalized inputs matched after removing that item.

Measurement Result
Server input usage without the earlier reasoning item 50 tokens
Server input usage with the earlier reasoning item 79 tokens
Increase in server input usage 29 tokens
Local fallback estimate for the added reasoning item 169 tokens

The probe reported all_turns reasoning context, while the completed pair had no x-reasoning-included header. An initial with-history request was interrupted; the reported comparison came from the completed pair after a limited retry.

The positive input delta shows that adding the earlier reasoning item and its structure affects server-reported input usage. The inspected missing-header fallback would nevertheless add the 169-token estimate. This supports the presence of overlapping accounting under the observed server/client contract.

The 29-token delta is not a per-item tokenization result, and 169 is a fallback estimate, not the item's actual model-token count. I am not presenting this small probe as a native Desktop/app-server end-to-end compaction test.

My direct paired probe covered HTTPS/SSE. For WebSocket, I have the separate long-conversation reconstruction and a successful local handshake diagnostic reporting no positive reasoning-included signal. I am not claiming a paired WebSocket usage test from this investigation. The inspected WebSocket implementation reads the reasoning-included response header.

Evidence limits

The original long conversation's response headers were not retained, and per-item server attribution is not available in the retained investigation text. The reconstruction identifies the additional client estimate and its role in crossing the threshold; the fresh probe supplies separate evidence about server input accounting. Neither makes the full 112,886-token historical estimate a one-to-one measurement of actual duplicated model tokens.

These figures concern context accounting and compaction decisions. They do not establish duplicate billing or the exact amount of genuinely usable context lost.

Requested investigation

Could you confirm the intended historical-reasoning accounting contract for gpt-6-astra, and ensure that:

  • Effective per-response reasoning context and server usage determine whether historical reasoning still needs a local estimate, while preserving appropriate fallback behavior for missing or unknown signals.
  • The inclusion decision remains associated with the correct completed usage baseline across subsequent turns and conversation resume.
  • The context usage shown to users can be reconciled with the counter used for compaction, including any additional local estimates.

Private paths, account/session identifiers, credentials, and encrypted payloads have been omitted from this report.

wanyunovo avatar Oct 19 '26 14:10 wanyunovo

100万規模に設定しても、約55万の表示で自動圧縮

Windows版Codex/GPT-6.1 Solで確認。コンテキストを約100万、自動圧縮を90万に設定していたにもかかわらず、約55万の表示で圧縮が発生。

ログ上の実効枠は約83万。公開実装には、過去の推論量を推定して使用量に加算する仕組みも存在。今回どこまで重複して数えられたかは未確定。

利用者が見ている数字だけでは、実際にいつ圧縮されるか判断できない。設定した上限の縮小や追加計数も見えず、長い仕事の文脈を維持したい利用者にとって、納得できない状態。

私はOpenAIに対して、実効上限と圧縮の開始基準を分かりやすく表示すること、表示と判定の整合、重複計数の検証・是正、正規Desktopでの修正を求めたい。

jibe-dev-ship-it avatar Oct 20 '26 08:10 jibe-dev-ship-it

Additional Windows Desktop evidence on core 0.163.0-alpha.10.2, using GPT-6.1 Sol with high reasoning effort.

Configuration:

  • model_context_window = 500000
  • model_auto_compact_token_limit = 450000
  • UI usable window: 475,000

Automatic compaction has occurred with the UI showing roughly 310K or 336K tokens, at different points. A prior reconstruction of one event gave: 315,771 latest server-reported tokens + 159,265 estimated historical encrypted-reasoning tokens + 59 newly appended tool-result tokens = 475,095 used by the client compaction check.

A separate, later paired test against the native ChatGPT backend retained 156 encrypted reasoning items from that conversation plus a short test prompt, without replaying the original user/tool text:

  • With those reasoning items: 57,480 input tokens.
  • Without them: 62 input tokens.
  • Difference: 57,418, matching the server's summed attribution to the 156 items.
  • These responses lacked x-reasoning-included, but their body reported reasoning.context = "all_turns".
  • The client's additional estimate for the same items was 159,265 tokens.

This strongly supports overlapping historical-reasoning accounting on the tested route. The length-based estimate is not the actual token count of those items.

Evidence boundary: the paired requests were made later, not captured from the original auto-compaction response. They therefore do not fully establish the original response's accounting contract. I am not alleging duplicate billing or duplicate quota deductions; this report concerns client context accounting and premature compaction.

Could maintainers confirm the intended usage-inclusion signal for this native route and identify a supported Desktop fix/version? It would also help to keep that signal tied to the corresponding usage snapshot across turns and expose the actual compaction counter alongside the UI usage figure.

No private prompts, encrypted payloads, credentials, local paths, or account/session identifiers are included.

Ruachmaninov avatar Oct 20 '26 19:10 Ruachmaninov

I’m another affected user on Windows Codex Desktop with GPT-6.1 Sol. Automatic compaction starts substantially before the displayed context window is full, despite checking my context-window and auto-compaction configuration. This interrupts long-running coding work and discards useful context earlier than expected.

I don't have a sanitized local token-accounting trace or verified current bundled runtime version to attach here, so I cannot independently confirm the root cause. However, the symptoms match the documented UI/server-versus-client accounting discrepancy in this issue and the independent evidence and proposed correction in #53913.

Could an OpenAI Codex maintainer please:

  1. Confirm whether the historical-reasoning accounting path / missing x-reasoning-included contract is under active investigation, with an owner?
  2. Indicate whether the candidate fix and regression tests in #53913 are being evaluated for upstream inclusion?
  3. Provide the intended official Codex Desktop release/version when a fix is available (or an issue to follow for release status)?
  4. Make the effective context limit and actual auto-compaction decision counter visible, so users can reconcile the UI percentage with the trigger?

I will submit this as a separate support escalation as well. I have deliberately omitted private project content, credentials, session IDs, and unverified numerical measurements.

martinmclee avatar Oct 21 '26 02:10 martinmclee