fix(ai): record Codex compact usage diagnostics#4713
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
No code change needed for this directive. Codex review is blocked by the repo’s code-review quota; a repo admin needs to enable/add review credits in the linked Codex settings before that bot can review this PR. |
|
Thanks — this looks like the right diagnostic hook, but I don't think this should auto-close #4707 yet. This PR records the key evidence we need ( But it does not resolve the reported uncached suffix itself. The regression test intentionally preserves the problematic path: So after this PR, a compact/resume delta turn with no Could you change the PR footer from: to: or: I think this PR is good as a diagnostics improvement, but #4707 should stay open until either:
|
Added Codex turn diagnostics that pair WebSocket/SSE request shape with raw provider usage and displayed usage buckets, including delta-chain state for previous_response_id requests. Covered the compact/resume WebSocket delta path where raw usage lacks orchestration fields but reports a persistent uncached suffix. Refs #4707
271c525 to
ea4e913
Compare
|
Amended and pushed the branch commit footer from |
Repro
A synthetic Codex Responses usage payload matching the reporter's post-#4471 capture reproduces the remaining path: calling
populateResponsesUsageFromResponsewith{input_tokens:132278,input_tokens_details:{cached_tokens:124416},output_tokens:29,total_tokens:132307}and noorchestration_*fields emitsusage.input=7862,usage.cacheRead=124416, and no orchestration bucket. The existing request stats only exposed request counts, so the raw uncached suffix could not be correlated with the WebSocket delta shape.Cause
packages/ai/src/providers/openai-shared.tscorrectly treats provider-reportedinput_tokens - cached_tokensas ordinary input when no explicit orchestration fields exist. The Codex transport inpackages/ai/src/providers/openai-codex-responses.tsrecorded only coarseOpenAICodexWebSocketDebugStatscounters, so compact/resume WebSocket delta turns could proveprevious_response_idchaining but could not show request input bytes/types, raw cached/uncached usage, or the normalized OMP buckets side by side.Fix
OpenAICodexWebSocketDebugStatswithlastTurndiagnostics covering transport,previous_response_idpresence, input item count/types, serialized input bytes, prompt cache key, tools/options hashes, and append-chain state.orchestration_*fields only when the provider reports them.onPayloadhooks, and added a regression test for a delta turn whose raw usage lacks orchestration fields.Verification
Reproduced the narrow raw-usage path with a JS eval against
packages/ai/src/providers/openai-shared.ts: output was{"input":7862,"output":29,"cacheRead":124416,"cacheWrite":0,"totalTokens":132307,...}. Ranbun test packages/ai/test/openai-codex-stream.test.ts -t diagnostics(1 pass, 52 filtered). Ranbun test packages/ai/test/openai-codex-stream.test.ts(53 pass). Ranbun check(passed). Fixes #4707