From f232d8712c18b5c67aaaf9493a29d210fff32abf Mon Sep 17 00:00:00 2001 From: Resham Joshi <65915470+iamtoruk@users.noreply.github.com> Date: Fri, 6 Nov 2026 04:52:04 -0800 Subject: [PATCH] fix(antigravity): keep RPC output tokens when the response/thinking split is absent Generator metadata from the language server omits unset proto3 fields, so an entry carrying only outputTokens was stored and priced with 0 output. The RPC path now reconciles the split the way the SQLite path already does. Results cache v11 and an antigravity parse-version bump re-read cached cascades. --- src/providers/antigravity.ts | 12 ++++++++++-- src/session-cache.ts | 4 +++- tests/providers/antigravity.test.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/providers/antigravity.ts b/src/providers/antigravity.ts index 5a8bbc88..5cc53751 100644 --- a/src/providers/antigravity.ts +++ b/src/providers/antigravity.ts @@ -52,7 +52,7 @@ function conversationRoots(): readonly AntigravityConversationRoot[] { }, ] } -const CACHE_VERSION = 10 +const CACHE_VERSION = 11 export const ANTIGRAVITY_CACHE_VERSION = CACHE_VERSION export const ANTIGRAVITY_LEGACY_CACHE_FILE = 'antigravity-results.json' export function antigravityCacheFileName(version = CACHE_VERSION): string { @@ -1326,12 +1326,20 @@ export function buildCallsFromGeneratorMetadata( const inputTokens = parseInt(usage.inputTokens ?? '0', 10) const outputTokens = parseInt(usage.outputTokens ?? '0', 10) const thinkingTokens = parseInt(usage.thinkingOutputTokens ?? '0', 10) - const responseTokens = parseInt(usage.responseOutputTokens ?? '0', 10) + let responseTokens = parseInt(usage.responseOutputTokens ?? '0', 10) const cacheReadTokens = parseInt(usage.cacheReadTokens ?? '0', 10) const cacheWriteTokens = parseInt(usage.cacheWriteTokens ?? '0', 10) if (inputTokens === 0 && outputTokens === 0) continue + // Proto3 JSON omits unset fields, so the response/thinking split can be + // missing while outputTokens holds the total. Same rule as the SQLite path. + if (responseTokens === 0 && thinkingTokens === 0) { + responseTokens = outputTokens + } else if (outputTokens > 0 && responseTokens + thinkingTokens !== outputTokens && outputTokens - thinkingTokens >= 0) { + responseTokens = outputTokens - thinkingTokens + } + const responseId = usage.responseId || String(i) const dedupKey = `antigravity:${cascadeId}:${responseId}` diff --git a/src/session-cache.ts b/src/session-cache.ts index 9f8f9306..14cace07 100644 --- a/src/session-cache.ts +++ b/src/session-cache.ts @@ -648,7 +648,9 @@ export const PROVIDER_PARSE_VERSIONS: Record = { // cli-workspace-v1: Antigravity CLI (.db) conversations now attribute // projectPath and project from trajectory_metadata_blob instead of collapsing // into a generic antigravity-cli bucket. - antigravity: 'worktree-project-grouping-v7-cache-read-v1-est-cost-model-fallback-v1-user-msg-v1-cli-workspace-v1', + // rpc-output-total-v1: RPC calls without a response/thinking split now keep + // outputTokens as their output instead of 0 (results cache v11 in lockstep). + antigravity: 'worktree-project-grouping-v7-cache-read-v1-est-cost-model-fallback-v1-user-msg-v1-cli-workspace-v1-rpc-output-total-v1', // pr-attribution-v1: the parser now reads the `message`/`part` tables for // per-turn user prompt text and the GitHub PR URLs it references. Cached // ZCode sessions hold empty userMessage turns and no session prLinks, so diff --git a/tests/providers/antigravity.test.ts b/tests/providers/antigravity.test.ts index 5b902a29..37c319f4 100644 --- a/tests/providers/antigravity.test.ts +++ b/tests/providers/antigravity.test.ts @@ -876,6 +876,16 @@ describe('antigravity provider helpers', () => { expect(calls[1]!.model).toBe('unknown') }) + it('keeps outputTokens as output when an RPC entry has no response/thinking split', () => { + const calls = buildCallsFromGeneratorMetadata('split-less', [ + { chatModel: { model: 'gemini-3-pro', usage: { model: 'gemini-3-pro', inputTokens: '1000', outputTokens: '4000', responseId: 'r1' } } }, + { chatModel: { model: 'gemini-3-pro', usage: { model: 'gemini-3-pro', inputTokens: '1000', outputTokens: '4000', thinkingOutputTokens: '1000', responseId: 'r2' } } }, + ], {}) + expect(calls.map(c => [c.outputTokens, c.reasoningTokens])).toEqual([[4000, 0], [3000, 1000]]) + expect(calls[0]!.costUSD).toBeCloseTo(calls[1]!.costUSD, 12) + expect(calls[0]!.costUSD).toBeGreaterThan(0.04) + }) + it('stamps file mtime as fallback timestamp for SQLite-parsed calls', async () => { if (!isSqliteAvailable()) return