Intermittent zero cached_tokens on a persistent Codex WebSocket with stable requests; cache diagnostics always unavailable
What version of Codex CLI is running?
0.167.0-alpha.3.2, invoked through codex app-server --stdio.
Additional comparisons used Pi 1.5.0 and a custom locally developed harness.
What subscription do you have?
ChatGPT subscription authentication. No API-key billing was used for the direct Codex reproduction.
Which model were you using?
gpt-6.1-sol, gpt-6.1-terra, and gpt-6-luna, reasoning effort low. The detailed direct reproduction below is Sol.
Platform and terminal
Windows x64 (OS build 10.0.26200.0), PowerShell. The controlled reproduction drives app-server over stdio, so TUI rendering is not involved.
What issue are you seeing?
After successful cache hits, a subsequent request sometimes reports usage.input_tokens_details.cached_tokens = 0, followed immediately by normal high cache hits again.
This reproduces with Codex connecting to the official ChatGPT subscription Responses WebSocket endpoint, bypassing our gateway. A local observation relay records the upstream events. It also reproduces across Pi and our custom harness. The zero values are present in raw upstream usage, not just a UI percentage calculation.
Related reports: #30425, #33821, #35300, and #35925. This report contributes a serial, single-connection reproduction, response IDs for server-side tracing, and direct comparison-diagnostics results.
Strongest direct reproduction
Endpoint: wss://chatgpt.com/backend-api/codex/responses.
Twenty generation requests were sent serially on one upstream WebSocket, at least five seconds apart (approximately 12 requests/minute). No reconnects, HTTP model requests, tool calls, or context compaction occurred in this group.
The generation payload is frozen from the first actual Codex request, with tool_choice="none" and no previous_response_id. Instructions, tool definitions, input, model, reasoning effort, and cache key remain unchanged. The only field updated is prompt_cache_options.comparison_response_id, pointing to the immediately preceding completed response. Removing that diagnostic option yields the same request hash for all 20 calls.
The session-id header equals prompt_cache_key and remains constant. Returned values remain:
model: gpt-6.1-solservice_tier: defaultreasoning.effort: lowreasoning.context: all_turns
| Generation | Input tokens | Cached tokens | Cache hit rate | First text delta |
|---|---|---|---|---|
| 5 | 11,562 | 11,392 | 98.53% | 1.677 s |
| 6 | 11,562 | 0 | 0% | 1.550 s |
| 7 | 11,562 | 11,392 | 98.53% | 1.503 s |
Generation 6 was sent about 3.23 seconds after generation 5 completed.
Response IDs:
- 5:
resp_060ad64dae1575a0016af1adb60ae487d0a86a5dcf50861695 - 6:
resp_00099603d85220aa016af1adbb583487d094730118ef752ea4 - 7:
resp_0bb2913903a32d18016af1adc00ff087d08553b34305410d2c
Handshake x-oai-request-id: de848d07-719f-474e-b3d9-efdfe9b3aad9.
Run started around 2026-11-09 11:25:21 UTC.
The cached-token totals also match the sum of per-item usage.attribution.items values. Similar latency is included as an observation, not proof of physical cache reuse.
Diagnostics results
Two direct groups used comparison diagnostics: 13 calls comparing against the first completed response, and 20 calls comparing against the preceding completed response.
All 31 requested comparisons returned:
{"prompt_cache_diagnostics":{"type":"unavailable"}}
This occurred for both cache hits and zero-cache responses. The endpoint accepted and echoed comparison_response_id, with ttl="30m" and mode="implicit". The first generation in each group did not request a comparison.
Independent reproduction without diagnostics
An earlier direct Sol group sent 13 byte-identical generation request bodies over one upstream connection, without comparison diagnostics. Each request had 11,553 input tokens. Calls 3 and 10 reported zero cached tokens; other warm calls hit cache.
Request SHA256:
09cbe0cd7eccd1825abc9032d73f0e9c0e9e16dd9fc6e19307a818a4cf79851a
Zero-cache response IDs:
- Call 3:
resp_02bef99d9ce6add0016af1a9d9e6d487d0b4b80c0cfa2f8daa - Call 10:
resp_0b372d51b906b323016af1a9e7917887d09ecbd55fe9a3be7b
Direct Luna also reproduced a later zero-cache response in a 12-generation continuous-tool group:
resp_064f446a7226fb88016af1a9b6dd2887d0821c08dc66a95168 (11,128 input tokens).
Cross-client and model comparison
“Observed” means zero cached tokens on a successful response after the first generation, not an initial cold request or a failed request with no usage.
| Client | GPT-6.1 Sol | GPT-6.1 Terra | GPT-6 Luna |
|---|---|---|---|
| Custom harness, through gateway | Observed | Observed | Observed |
| Pi 1.5.0, through gateway | Observed | Observed | Observed |
| Codex app-server, through gateway | Observed | Not observed in the 12-call group | Observed |
| Codex app-server, direct official endpoint | Observed | Not observed in the 12-call group | Observed |
A locally deployed DeepSeek comparison model, accessed through the gateway, did not show post-first-request zero-cache responses in 25 successful calls: 12 continuous-tool calls and 13 frozen-request calls. That route uses Chat Completions upstream and a different cache implementation, so this is a comparison observation rather than a controlled attribution of the GPT failure mechanism.
Client prompts and input sizes differ; these groups compare occurrence of zero-cache responses, not client performance rankings.
Reproduction procedure
- Start an isolated Codex app-server session using ChatGPT subscription authentication,
lowreasoning, and WebSocket Responses transport. - Use a short deterministic user request, such as answering only
momo. Retain the actual Codex instructions and tool definitions so input exceeds the caching minimum. - In an observation relay, freeze the first generation payload, set
tool_choice="none", and removeprevious_response_id. Replay it serially on the same official upstream WebSocket, keeping the same cache key and session header. - Record
response.completed.response.usagefor 13–20 generations. Treatgenerate=falseprewarm responses separately. - Optionally repeat with
prompt_cache_options.comparison_response_idpointing to the preceding completed response; compare returned model, service tier, reasoning, and diagnostics alongside usage.
Instrumentation boundary: the local relay records upstream handshake headers but does not forward those response headers to Codex. The diagnostic runs' upstream handshake contained no x-codex-turn-state. The fixed-payload experiment intentionally controls the wire payload; separate continuous-tool groups preserve normal client-generated inputs.
Expected behavior / request for investigation
Please trace the adjacent response IDs above and clarify:
- Did the zero-cache response actually miss the physical KV cache, or was reused work excluded from cache accounting?
- Did backend routing, effective model configuration, or cache availability change despite the stable publicly returned model/tier and connection?
- Is comparison diagnosis supported on this subscription endpoint? Why is it
unavailablefor both hits and misses, and what supported diagnostic should we collect instead?
The goal is to explain and reduce these intermittent misses, not to assume that every repeated request must be guaranteed a cache hit.
Codex doctor report
Not collected for this isolated protocol reproduction. Credentials, account names, private routing prefixes, local configuration files, and full private logs are omitted.
Your stable-request and direct-connection controls are more useful than another batch of paid probes. Package one adjacent hit/miss pair from those existing runs with response IDs, exact serialized-prefix hashes and returned usage fields, and keep unavailable diagnostic fields separate from a reported zero cache count. First-token latency and a different provider's cache behavior cannot establish the cause here; the matched request evidence gives maintainers something narrower to correlate on their side.
Thanks for the suggestion. I extracted the following matched evidence from the existing runs; no additional model requests were made.
Primary evidence: byte-identical full requests, no comparison diagnostic option
One persistent official ChatGPT subscription Responses WebSocket; serial generation requests, no tools executed, no compaction, and no previous_response_id. Generations 2, 3 and 4 have the same SHA256 of the complete outgoing UTF-8 WebSocket JSON message:
09cbe0cd7eccd1825abc9032d73f0e9c0e9e16dd9fc6e19307a818a4cf79851a
This is a full wire-message hash, not a canonicalized JSON hash or a separately captured serialized-prefix hash. It covers the complete request, including the model-visible input.
| Generation | Request time (UTC) | Response ID | Input | Cached | Output |
|---|---|---|---|---|---|
| 2 | 2026-11-09T11:09:10.821490+00:00 | resp_06974466171c2d89016af1a9d7361c87d09a9b3bdf8b9fafc7 |
11553 | 11392 | 6 |
| 3 | 2026-11-09T11:09:13.440862+00:00 | resp_02bef99d9ce6add0016af1a9d9e6d487d0b4b80c0cfa2f8daa |
11553 | 0 | 6 |
| 4 | 2026-11-09T11:09:15.518587+00:00 | resp_0ad72fc48137f2f5016af1a9dbe5e487d0a28a88a037188c4f |
11553 | 11392 | 6 |
The selected raw usage fields are below. The hit responses (2 and 4) have identical values; the miss response (3) differs only in cached_tokens within these fields. Per-item attribution is omitted here.
Hit (generation 2, also generation 4):
{
"input_tokens": 11553,
"input_tokens_details": {
"cached_tokens": 11392,
"cache_write_tokens": 0
},
"output_tokens": 6,
"output_tokens_details": {
"reasoning_tokens": 0
},
"total_tokens": 11559
}
Miss (generation 3):
{
"input_tokens": 11553,
"input_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0
},
"output_tokens": 6,
"output_tokens_details": {
"reasoning_tokens": 0
},
"total_tokens": 11559
}
Comparison diagnostics were not requested in this group. The recorded null diagnostic value therefore means “not requested,” independently of the explicit numeric cached_tokens: 0.
Separate diagnostics group
For the adjacent generations 5 / 6 / 7 already listed in the issue, the returned diagnostic object is {"type":"unavailable"} for all three responses, while their cached counts are 11,392 / 0 / 11,392. Returned model, tier and reasoning remain gpt-6.1-sol, default, low / all_turns.
Their complete wire hashes differ because comparison_response_id changes. The hash below is instead the stable-request hash, computed by removing prompt_cache_options and hashing sorted-key JSON; it is identical across these calls:
538caf1f0a3b775533bc2a35535c40114f397a22bb0c4a353d265ec45137cc0e
Could someone with access to backend traces correlate the primary hit/miss pair above to distinguish cache lookup/routing behavior from cache-usage accounting? Also, what diagnostic can identify the difference when comparison diagnostics return unavailable?
Thanks for extracting this from the existing runs. The identical full wire-message hash across generations 2, 3 and 4, with cached input going 11,392 / 0 / 11,392, answers the request-matching question I raised. I'd lead with that three-row table and its response IDs. It gives maintainers a specific hit/miss pair to correlate while leaving the cause open.
I reproduced the drop to zero cached input on GPT-6.2 Sol with both WebSocket and HTTP/SSE, directly against the official ChatGPT subscription endpoint.
I used Codex CLI 0.167.0-alpha.4.1 on Windows with ChatGPT sign-in, standard service tier, and low reasoning. Each isolated app-server chat repeated a synthetic request for a short OK reply. Every turn completed successfully.
| Transport | Completed on Nov 21, 2026 (UTC) | Input tokens | Cached tokens | Response ID |
|---|---|---|---|---|
| WebSocket | 09:09:52.343 | 9,063 | 8,704 | resp_0a57586924d5a0b2016b015fee78ec87d0ba313dca654c7ecd |
| WebSocket | 09:09:55.471 | 9,084 | 0 | resp_0a57586924d5a0b2016b015ff17c0c87d08cd96490112f5cc6 |
| HTTP/SSE | 09:14:00.117 | 9,019 | 8,704 | resp_01918aca4931047a016b0160e57cf087d0b87818fdfe53f6d8 |
| HTTP/SSE | 09:14:02.302 | 9,040 | 0 | Usage reported by app-server |
Each pair contains adjacent turns in the same chat. The HTTP-only test used supports_websockets = false and saw three consecutive cache hits before the zero. I could correlate both WebSocket response IDs and the HTTP hit ID in the local log.
Could you trace the two WebSocket response IDs to determine whether the zero reflects a cache lookup miss or a discrepancy in reported cache usage, and whether it affected subscription usage accounting?
Another data point on GPT-6.2 Sol over the ChatGPT-backend Codex WebSocket (oh-my-pi 19.1.1, 2026-11-24 UTC). This one was an append continuation: same socket, no reconnect, previous_response_id set, only function_call_output items sent, x-codex-turn-state echoed from the previous codex.response.metadata event, same prompt_cache_key, same tools and options.
| request (UTC) | input_tokens | cached_tokens |
|---|---|---|
| 09:19:52 (first) | 17,168 | 0 |
| 09:19:54 | 19,057 | 16,896 |
| 09:20:02 | 27,699 | 18,944 |
| 09:20:12 | 46,968 | 0 (resp_066342583434ec8e016b0556cca54087d09d20dd1c60a19a7e) |
| 09:20:25 | 52,161 | 46,848 |
| 09:20:45 | 63,880 | 51,968 |
The next request hit the cache for the missed request's full prefix. Echoing the turn-state token didn't stop the misses: the zero-cache rate on continuations was 7/315 before the client captured turn-state and 1/23 after. Request size isn't the trigger: 11 continuations over 60 KB all hit. Possibly the same issue as #63302.
Additional synthetic HTTP/SSE reproduction on gpt-6-luna, reasoning none,
ChatGPT/Codex OAuth, store:false, no tools. A loopback relay copy forwards
the requests to the official chatgpt.com/backend-api/codex/responses endpoint.
The canonical session-id header and prompt_cache_key remain stable for MAIN;
x-client-request-id is a fresh UUID per request. Exact earlier input objects
are preserved on the outgoing wire. Short analyst requests on a different
session/key are interleaved; this is not a single-socket native CLI reproduction.
Adjacent MAIN requests in one session:
| Step | Input | Cached | Response ID | Upstream request ID |
|---|---|---|---|---|
| 2 | 2390 | 2176 | resp_0c75b328a7965330016b0c213be70887d2aec6cde40184c459 |
fadeaa9d-a58e-4785-8b3b-832f4e01e6f0 |
| 3 | 2412 | 0 | resp_0e29df5e3562e174016b0c213fb4d887d2bc28aee3c9a6a083 |
7c72aea0-10b4-41ed-bb1b-9e4d87a4a1aa |
| 4 | 2433 | 2176 | resp_0e4586710c9ea588016b0c2142553c87d2b363a510ffd136f6 |
8df4075d-255d-4691-ab57-c189646dfbb8 |
Observed shape: hit → zero → hit. The changing suffix is appended normally; we do not claim the full request bodies are byte-identical. The previous input object prefix is exact, with serialized hashes recorded locally.
Across two independent canonical-header sessions: 7/8 eligible continuations hit. The old underscore-header comparison happened to hit 8/8 in the same balanced series, so this is not evidence that the spelling change caused an improvement. It corrects protocol compatibility only.
Separate capability probes rejected prompt_cache_options.mode=explicit
and a content-block prompt_cache_breakpoint with HTTP 400 on this OAuth
route. Separate, very small turn-state echo control (server-issued token,
scoped to one role/work turn and discarded for a new user turn) did not
improve hit rate; it is not a causal result or a proposed workaround.
Can these response/request IDs distinguish cache placement misses from usage-accounting behavior? No private prompts, credentials or account identifiers are included.
Same input bytes, different prefix-cache behavior
Platform API adds a third run: the same GPT‑6‑Luna model and byte-identical input arrays, using an API key on the OpenAI Responses API, SSE, and a 24-token output cap (no explicit cap on SIWC). All 15 Platform requests completed without retries.
The two Responses implementations received byte-identical input arrays for all 15 requests (SHA‑256 checked by the runner and matched across both outputs). The HTTP envelope differed: GPT‑6‑Luna used the official Sign in with ChatGPT Responses endpoint with SSE; GPT‑OSS‑20B MXFP4 used llama.cpp b12633 on an RTX 3060 with one 16,384-token slot, Q8_0 K/V, prompt caching on, and context shift off.
The sequence is classic Q&A with identical synthetic user questions and prerecorded synthetic answers. Replays at #3 and #5 are exact. The cuts at #6 and #12 remove 1,440 UTF‑8 bytes of assistant text (1,472 bytes in the serialized input array; both lanes report 416 fewer input tokens). The following user message is unchanged. One run per lane, 15/15 completed on both; no retries.
| Request | Change | Input bytes | Local GPT‑OSS‑20B — cached / input | Platform API GPT‑6‑Luna — cached / input | SIWC GPT‑6‑Luna — cached / input |
|---|---|---|---|---|---|
| 1 | Developer + Q1 | 10,873 | 0 / 2,561 | 0 / 2,497 | 0 / 2,497 |
| 2 | Append A + Q | 13,985 | 2,562 / 3,425 | 2,494 / 3,361 | 0 / 3,361 |
| 3 | Exact replay | 13,985 | 3,424 / 3,425 | 3,358 / 3,361 | 0 / 3,361 |
| 4 | Append A + Q | 17,097 | 3,426 / 4,289 | 3,358 / 4,225 | 0 / 4,225 |
| 5 | Exact replay | 17,097 | 4,288 / 4,289 | 4,222 / 4,225 | 0 / 4,225 |
| 6 | Cut A2 | 15,625 | 3,423 / 3,873 | 3,358 / 3,809 | 0 / 3,809 |
| 7 | Append A + Q | 18,737 | 3,874 / 4,737 | 3,806 / 4,673 | 0 / 4,673 |
| 8 | Append A + Q | 21,849 | 4,738 / 5,601 | 4,670 / 5,537 | 3,200 / 5,537 |
| 9 | Append A + Q | 24,961 | 5,602 / 6,465 | 5,534 / 6,401 | 2,304 / 6,401 |
| 10 | Append A + Q | 28,073 | 6,466 / 7,329 | 6,398 / 7,265 | 0 / 7,265 |
| 11 | Append A + Q | 31,185 | 7,330 / 8,193 | 7,262 / 8,129 | 0 / 8,129 |
| 12 | Cut A7 | 29,713 | 7,324 / 7,777 | 7,262 / 7,713 | 0 / 7,713 |
| 13 | Append A + Q | 32,825 | 7,778 / 8,641 | 7,710 / 8,577 | 7,552 / 8,577 |
| 14 | Append A + Q | 35,937 | 8,642 / 9,505 | 8,574 / 9,441 | 0 / 9,441 |
| 15 | Append A + Q | 39,114 | 9,506 / 10,369 | 9,438 / 10,305 | 0 / 10,305 |
Observation: After the cold start, Platform API reported cache hits on 14/14 requests, including both exact replays and both cuts. SIWC reported hits on 3/14; neither exact replay nor either cut hit. Local llama.cpp also reused the prefix after both cuts. These are single runs; the comparison does not establish why SIWC missed.
Question: Is prefix reuse expected to behave differently on SIWC and Platform API for the same model and identical message inputs? If so, what cache behavior should SIWC clients expect, and is there a recommended request shape or configuration?