Repository navigation
fix(usage): read Gemini usageMetadata out of the antigravity response envelope - #10430
diegosouzapw merged 13 commits into
Conversation
… envelope
Port decolua/9router#59d858b: antigravity/gemini-cli wrap non-streaming
payloads in { response: {...} }, so extractUsageFromResponse only saw the
top-level usageMetadata and every non-streaming antigravity request logged
zero usage (IN 0 | OUT 0) and zeroed usage-dashboard rows. Top-level
metadata keeps priority; OpenAI/Claude branches untouched.
…avity-usage-envelope
…avity-usage-envelope
…avity-usage-envelope
…age-envelopefix/antigravity-usage-envelope)
|
Thanks for the port, @rqzbeh — this is a clean, surgical fix. Verified locally against No changes requested — this looks merge-ready as-is. One small thought for a possible follow-up (not blocking this PR): the Gemini branch of Nice work on tracing this all the way to the upstream issue and matching the existing envelope-read pattern. |
…avity-usage-envelope
|
Thanks @diegosouzapw — good call on that gap. I've opened the follow-up as a separate PR: #10465 (fix(usage): surface Gemini cachedContentTokenCount as cached_tokens). It adds One note: the branch is stacked on the #10430 branch, so the PR diff currently includes the envelope fix too — once #10430 merges, #10465 reduces to just its own delta. Happy to rebase onto |
…avity-usage-envelope
…avity-usage-envelope
…avity-usage-envelope
…avity-usage-envelope
df226e5
into
cheaper-inference:release/v3.8.50
|
Validated in local merge-train |
…10465) * fix(usage): read Gemini usageMetadata out of the antigravity response envelope Port decolua/9router#59d858b: antigravity/gemini-cli wrap non-streaming payloads in { response: {...} }, so extractUsageFromResponse only saw the top-level usageMetadata and every non-streaming antigravity request logged zero usage (IN 0 | OUT 0) and zeroed usage-dashboard rows. Top-level metadata keeps priority; OpenAI/Claude branches untouched. * chore(changelog): fragment for #10430 antigravity usage envelope * fix(usage): surface Gemini cachedContentTokenCount as cached_tokens Review follow-up on #10430: the Gemini branch of extractUsageFromResponse ignored cachedContentTokenCount, so non-streaming cache-hit tokens never reached the cached_tokens field the OpenAI/Claude/Responses branches already populate (and the streaming path surfaces at usageTracking.ts:684). Adds cached_tokens: usageMetadata.cachedContentTokenCount || 0, updates the three Gemini assertions (envelope fixture already carried cachedContentTokenCount: 7), and adds a dedicated regression test. * chore(changelog): fragment for #10465 Gemini cached_tokens surfacing * test(fix): refresh expired alibaba quota sample validity and onnxruntime pin for v3.8.50 base - alibaba-free-tier-quota-fetcher.test.ts: sample quotaValidityPeriod (2026-08-16 16:00 UTC) is in the past, making every quota entry classify as expired/not_capable; bump to 2028-01-01 UTC so the text/merge classification tests exercise the intended path again. - optional-transformers-dependency.test.ts: onnxruntime-node pin assertion updated from ~1.24.3 to ~1.27.0 to match package.json (bumped by #10403); the regular-not-optional intent is unchanged. --------- Co-authored-by: Rouzbeh <rqzbeh@users.noreply.github.com>
… envelope (cheaper-inference#10430) * fix(usage): read Gemini usageMetadata out of the antigravity response envelope Port decolua/9router#59d858b: antigravity/gemini-cli wrap non-streaming payloads in { response: {...} }, so extractUsageFromResponse only saw the top-level usageMetadata and every non-streaming antigravity request logged zero usage (IN 0 | OUT 0) and zeroed usage-dashboard rows. Top-level metadata keeps priority; OpenAI/Claude branches untouched. * chore(changelog): fragment for cheaper-inference#10430 antigravity usage envelope * ci: re-run dast-smoke (Build CLI bundle runner timeout flake) --------- Co-authored-by: Rouzbeh <rqzbeh@users.noreply.github.com>
… envelope (cheaper-inference#10430) * fix(usage): read Gemini usageMetadata out of the antigravity response envelope Port decolua/9router#59d858b: antigravity/gemini-cli wrap non-streaming payloads in { response: {...} }, so extractUsageFromResponse only saw the top-level usageMetadata and every non-streaming antigravity request logged zero usage (IN 0 | OUT 0) and zeroed usage-dashboard rows. Top-level metadata keeps priority; OpenAI/Claude branches untouched. * chore(changelog): fragment for cheaper-inference#10430 antigravity usage envelope * ci: re-run dast-smoke (Build CLI bundle runner timeout flake) --------- Co-authored-by: Rouzbeh <rqzbeh@users.noreply.github.com>
…heaper-inference#10465) * fix(usage): read Gemini usageMetadata out of the antigravity response envelope Port decolua/9router#59d858b: antigravity/gemini-cli wrap non-streaming payloads in { response: {...} }, so extractUsageFromResponse only saw the top-level usageMetadata and every non-streaming antigravity request logged zero usage (IN 0 | OUT 0) and zeroed usage-dashboard rows. Top-level metadata keeps priority; OpenAI/Claude branches untouched. * chore(changelog): fragment for cheaper-inference#10430 antigravity usage envelope * fix(usage): surface Gemini cachedContentTokenCount as cached_tokens Review follow-up on cheaper-inference#10430: the Gemini branch of extractUsageFromResponse ignored cachedContentTokenCount, so non-streaming cache-hit tokens never reached the cached_tokens field the OpenAI/Claude/Responses branches already populate (and the streaming path surfaces at usageTracking.ts:684). Adds cached_tokens: usageMetadata.cachedContentTokenCount || 0, updates the three Gemini assertions (envelope fixture already carried cachedContentTokenCount: 7), and adds a dedicated regression test. * chore(changelog): fragment for cheaper-inference#10465 Gemini cached_tokens surfacing * test(fix): refresh expired alibaba quota sample validity and onnxruntime pin for v3.8.50 base - alibaba-free-tier-quota-fetcher.test.ts: sample quotaValidityPeriod (2026-08-16 16:00 UTC) is in the past, making every quota entry classify as expired/not_capable; bump to 2028-01-01 UTC so the text/merge classification tests exercise the intended path again. - optional-transformers-dependency.test.ts: onnxruntime-node pin assertion updated from ~1.24.3 to ~1.27.0 to match package.json (bumped by cheaper-inference#10403); the regular-not-optional intent is unchanged. --------- Co-authored-by: Rouzbeh <rqzbeh@users.noreply.github.com>
Summary
Non-streaming Antigravity / gemini-cli requests wrapped their payloads in
{ response: { ... } }, butextractUsageFromResponseonly tested thetop-level
usageMetadata— so every non-streaming antigravity requestlogged
IN 0 | OUT 0and zeroed rows in the usage dashboard. This is theport of upstream
decolua/9router#59d858b("fix(usage): read GeminiusageMetadata out of the antigravity response envelope").
The fix reads
responseBody.usageMetadata || responseBody.response?.usageMetadata(the same envelope read the streaming path and
usageTrackingalready use);top-level metadata keeps priority and the OpenAI / Claude branches are
untouched.
Related Issues
Validation
npm run lint— no issues in changed files (repo-wide baseline noise documented)Tests Added Or Updated
tests/unit/usage-extractor.test.ts: two new tests —usageMetadatafrom the antigravity{ response: {...} }envelopeusageMetadataover the envelope when both are presentCoverage Notes
usageTracking.ts) already unwrapped the envelope; thiscloses the non-streaming gap (
chatCore.ts:4367+ semantic-cache path).Reviewer Notes
against the OmniRoute codebase before implementing.