Repository navigation
fix(proxy): parse usage from protocol fields - #69
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b89589589
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fn for_each_response_json(buf: &[u8], mut visit: impl FnMut(&serde_json::Value)) { | ||
| if let Ok(value) = serde_json::from_slice::<serde_json::Value>(buf) { | ||
| visit(&value); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Preserve usage parsing for large non-streaming bodies
When a non-streaming JSON response exceeds USAGE_SCAN_CAP, the tee passes only partial documents to this function: head is truncated at 2 MB and tail begins in the middle of the response. The full-document parse therefore fails, and the line fallback cannot recover the top-level usage object from a one-line JSON fragment. Such responses stop updating cache-hit monitors, output-feedback state, and output-token counters, whereas the previous scanner could recover the usage fields from the tail; retain a protocol-safe way to extract usage from capped non-streaming responses.
Useful? React with 👍 / 👎.
Usage accounting scanned raw response bytes, so assistant text or tool payloads that mentioned provider usage field names could corrupt token metrics and the compression feedback controller.
This change parses complete JSON/SSE protocol payloads and reads only top-level usage or Anthropic message usage objects. It preserves non-streaming and streaming handling while ignoring lookalike fields in model output.
Verified with cargo fmt, tare-proxy tests (42 passed), clippy with warnings denied, and git diff --check.