From 93af1add2ab716649623b937bef00eca02455416 Mon Sep 17 00:00:00 2001 From: Resham Joshi <65915470+iamtoruk@users.noreply.github.com> Date: Fri, 6 Nov 2026 06:21:47 -0800 Subject: [PATCH] fix(antigravity): apply the output-total rule to a total of 0 as well A record with output total 0 beside a nonzero thinking/response split kept the split, against the total-wins rule. Antigravity never writes that shape: a read-only scan of every gen_metadata row in the owner's Antigravity conversation databases (166 rows, 9 files) found 165 whose split sums exactly to the total and none with a zero total beside a nonzero split. The .pb conversations are readable only through the running app, so they were not scanned. A total of 0 now caps the split at 0 like any other total. --- src/providers/antigravity.ts | 9 +++++---- tests/providers/antigravity.test.ts | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/providers/antigravity.ts b/src/providers/antigravity.ts index 76687ee7..4bf9fbda 100644 --- a/src/providers/antigravity.ts +++ b/src/providers/antigravity.ts @@ -1011,11 +1011,12 @@ function decodePackedVarints(data: Uint8Array): number[] { } // ModelUsageStats' output total (field 3, thinking + response) wins over its -// split whenever it is set: an absent split (proto3 omits unset fields) takes -// the total as response, and a split that disagrees, even one whose thinking -// alone exceeds the total, is cut back to it. Returns [response, thinking]. +// split: an absent split (proto3 omits unset fields) takes the total as +// response, and a split that disagrees, even one whose thinking alone exceeds +// the total or one beside a total of 0, is cut back to it. Returns +// [response, thinking]. function reconcileOutputSplit(total: number, thinking: number, response: number): [number, number] { - if (total <= 0 || response + thinking === total) return [response, thinking] + if (response + thinking === total) return [response, thinking] const kept = Math.min(thinking, total) return [total - kept, kept] } diff --git a/tests/providers/antigravity.test.ts b/tests/providers/antigravity.test.ts index 3ad33df4..0f514c76 100644 --- a/tests/providers/antigravity.test.ts +++ b/tests/providers/antigravity.test.ts @@ -881,10 +881,11 @@ describe('antigravity provider helpers', () => { { 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' } } }, { chatModel: { model: 'gemini-3-pro', usage: { model: 'gemini-3-pro', inputTokens: '1000', outputTokens: '100', thinkingOutputTokens: '200', responseOutputTokens: '50', responseId: 'r3' } } }, + { chatModel: { model: 'gemini-3-pro', usage: { model: 'gemini-3-pro', inputTokens: '1000', outputTokens: '0', thinkingOutputTokens: '100', responseOutputTokens: '50', responseId: 'r4' } } }, ], {}) // The output total wins over a split that disagrees, even when thinking - // alone is larger than the total. - expect(calls.map(c => [c.outputTokens, c.reasoningTokens])).toEqual([[4000, 0], [3000, 1000], [0, 100]]) + // alone is larger than the total, or the total is 0. + expect(calls.map(c => [c.outputTokens, c.reasoningTokens])).toEqual([[4000, 0], [3000, 1000], [0, 100], [0, 0]]) expect(calls[0]!.costUSD).toBeCloseTo(calls[1]!.costUSD, 12) expect(calls[0]!.costUSD).toBeGreaterThan(0.04) })