[Bug?] Claude subscription bridge: Codex input-token counts alternate ~2x; possible cumulative/context usage mismatch
magpie version
Inspected on 2026-11-13:
- Local Magpie: 0.1.3199
- Remote Magpie: 0.1.2534
- Client: Codex Desktop on macOS 27.0.1; exact Desktop/embedded backend version was not captured.
- Remote gateway OS: Linux.
- Route: Codex Desktop → local Magpie → private remote Magpie → Claude subscription.
- Model: claude-opus-5-5.
The events below occurred on 2026-11-11. The exact binary versions at the event time were not independently recorded, so the inspected versions above are not claimed as a historical version lock. This has not been reproduced on the latest release.
Where
Gateway / Claude subscription bridge, as observed in Codex Desktop's recorded token_count.info.last_token_usage.
What happened
Within one recorded model turn, five consecutive token-count records show input usage rising to approximately twice its previous value and then falling back, twice within about one minute. The recorded model stays the same, model_context_window is 950000 throughout, and there is no recorded compaction or new turn_context in this interval. There are tool calls and a tool-discovery operation in the interval.
Times below are relative to the first selected event; private session IDs, absolute timestamps, hostnames, endpoints, and conversation/tool contents are omitted.
| Relative time (seconds) | input_tokens | cached_input_tokens | cache_write_input_tokens | output_tokens | total_tokens |
|---|---|---|---|---|---|
| 0.000 | 120807 | 119597 | 1208 | 854 | 121661 |
| 25.760 | 245431 | 242696 | 2731 | 296 | 245727 |
| 31.037 | 125172 | 123536 | 1634 | 76 | 125248 |
| 48.384 | 252732 | 250586 | 2142 | 84 | 252816 |
| 60.170 | 127439 | 127312 | 125 | 198 | 127637 |
For context, the inspected function/custom-tool outputs between three positive usage jumps were:
| Input change | Number of function/custom-tool outputs | Raw output characters |
|---|---|---|
| 120807 → 245431 | 1 | 3546 |
| 125172 → 252732 | 1 | 192 |
| 162809 → 341325 (later in the same turn) | 1 | 326 |
These character counts cover those tool-output records only, not the full next request. They do not bound token growth: tool arguments, built-in tool outputs, instructions, truncation, and native request assembly are not fully represented here.
The longer session contains three compaction events. The last usage record before the first one reports input 341325 / total 345309. That is not an exact capture of the compaction trigger and does not establish that a usage spike caused it.
Steps / reproducibility
- Use the Claude subscription route above from Codex Desktop during an ordinary long task with tool calls.
- Read the client's recorded per-response
last_token_usagefields and model/turn/compaction metadata. - Compare adjacent records; the sequence above is an observed example, not a deterministic minimal reproducer.
Only metadata was extracted. No new long-context requests or service restarts were performed to manufacture a reproduction, and corresponding raw upstream per-message usage was not captured.
Expected behavior / question for maintainers
Please confirm whether the counts forwarded to Codex can include the billable usage of multiple underlying Claude messages, while Codex treats them as the input/context size of one response.
In the inspected v0.1.2534 bridge source, usage is carried across messages. Continuation/retry and delayed-message handling and the lateUsage path appear relevant. This is a hypothesis, not a proven double-counting bug.
Could you check:
- Whether cumulative billing usage and the current native message's input/context usage are being mixed in the client-facing fields.
- Whether these temporary spikes can influence Codex's context meter or automatic-compaction decisions.
- If aggregation is intentional, how the current-context estimate should remain accurate while preserving valid billing totals, and what minimal diagnostic fields would help verify this without exposing message content.
The separately configured 272000 compaction threshold is already understood; raising that threshold would not establish that this counting question is resolved.
Related issues
- #5110: displayed capacity versus the separate 272k threshold.
- #4863: Claude bridge cache behavior during compaction; no evidence yet that it is the same cause.
- #5674: duplicate rows in Magpie's Usage page; this report concerns the usage fields recorded by Codex, not row deduplication in that page.