Skip to content

fix(proxy): parse usage from protocol fields - #69

Merged
mstuart merged 1 commit into
mainfrom
fix/usage-protocol-parsing
Sep 25, 2026
Merged

mstuart merged 1 commit into
mainfrom
fix/usage-protocol-parsing

Conversation

@mstuart

@mstuart mstuart commented Sep 25, 2026

Copy link
Copy Markdown
Owner

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T22:40:01.482361Z 3b89589 PR opened
🔒 Security Review ✅ Completed 2026-09-25T22:39:46.901331Z 3b89589 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mstuart
mstuart merged commit 60f8a79 into main Sep 25, 2026
7 checks passed
@mstuart
mstuart deleted the fix/usage-protocol-parsing branch September 25, 2026 22:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +132 to +136
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant