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.
This commit is contained in:
Resham Joshi 2026-11-06 04:52:04 -08:00
parent 25ea32e85b
commit f232d8712c
3 changed files with 23 additions and 3 deletions

View file

@ -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}`

View file

@ -648,7 +648,9 @@ export const PROVIDER_PARSE_VERSIONS: Record<string, string> = {
// 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

View file

@ -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