Repository navigation
Description
T3 counts cached prompt tokens twice for the Antigravity (Gemini) provider. acpPerTurnPromptUsage adds cachedReadTokens on top of ACP inputTokens, but Antigravity 1.4.5 already includes cached reads in inputTokens. So each turn's input is roughly doubled, the cache hit rate shows about half its real value, and the list-price cost in Usage comes out about 5x too high.
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server (the mapping itself is in packages/provider-acp)
Steps to reproduce
- Use the Antigravity provider (Gemini 4 Hydrogen or Gemini 4 Argon) and run a few multi-step turns in one thread so the prompt cache warms up.
- Look at the turn's
turnTokenUsage(or the Usage view): compareinputTokensandcachedInputTokens. - Compare them with Antigravity's own per-call usage records for the same conversation (the
gen_metadataprotobuf in the conversation.db: field 2 = uncached prompt tokens, field 5 = cached; this is the field mappingantigravityUsageReader.tsuses).
Expected behavior
inputTokens equals the real prompt total (uncached + cached), and cachedInputTokens / inputTokens matches Antigravity's own cache hit rate (about 90% in a long agentic thread).
Actual behavior
inputTokens is the real prompt total plus the cached tokens a second time. Every Antigravity turn shows a cache rate of about 46-49%, whatever the turn size: with true hit rate h, T3 shows h / (1 + h).
Example turn: T3 recorded inputTokens 24,256,450 and cachedInputTokens 11,859,532. The real prompt total is about 12.4M, of which about 11.9M is cached (95.7%).
Aggregate over 63 completed turns where one T3 turn maps to exactly one Antigravity conversation (Gemini 4 Hydrogen):
| Metric | Antigravity's own records | T3 turnTokenUsage |
|---|---|---|
| Cache hit rate | 90.0% | 47.4% |
| Prompt tokens, raw / T3 | 0.52 | 1.00 |
| List-price cost | $25.18 | $120.01 |
List-price cost, recomputed with input = T3 inputTokens - cachedInputTokens |
$25.36 (within 1% of raw) |
One Gemini 4 Argon turn showed the same pattern: raw hit rate 95.1%, T3 shows 48.0%, and the raw/T3 prompt ratio is 0.50.
The repo's own fixture fits this too. In AcpAdapterV2.test.ts, the Antigravity sample has inputTokens: 42, outputTokens: 3, thoughtTokens: 9, cachedReadTokens: 24, totalTokens: 54. Since 42 + 3 + 9 = 54, the 24 cached tokens are already inside the 42. If they weren't, the total would be 78.
Suspected cause
packages/provider-acp/src/server/adapter.ts#L244-L246: whengeminiUsageis true,inputTokens = usage.inputTokens + (usage.cachedReadTokens ?? 0).packages/provider-acp/src/server/adapter.ts#L509: the flavor doc says "Gemini-style usage: inputTokens leaves out cachedReadTokens". That doesn't match what Antigravity 1.4.5 sends.apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts#L277-L278: Antigravity turns onreportsPerTurnPromptUsageandgeminiPromptUsage.apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts#L146-L171: the test expects 42 + 24 -> 66, which locks in the assumption.
These links are to 322f654. The same code is still on main @ 5a20d59 (adapter.ts L313 and L600, AntigravityAdapterV2.ts L283, AcpAdapterV2.test.ts L202-L221).
The output half (outputTokens + thoughtTokens) looks right: in the raw records, field 3 is about field 9 + field 10. That's our reading of the data, not something we've proven.
Suggested fix
- For Antigravity, use ACP
inputTokensas-is and don't addcachedReadTokens. KeepcachedInputTokensas a subset of it. Either splitgeminiPromptUsageinto separate input and output flags, or drop the input half for this flavor. - Fix the doc comment at adapter.ts L509.
- Update the
AcpAdapterV2.test.tsexpectation so it expectsinputTokens: 42, not 66, and keeptotalTokensconsistent. - Optional: flag a turn whose
input + output (+ thought)doesn't match the reportedtotalTokens. That check would have caught this.
Impact
Major degradation or frequent failure. Every Antigravity turn reports wrong input tokens, cache rate and cost. Only usage reporting is affected; runs themselves work.
Version or commit
Desktop 0.1.9, source 322f6544dfad0a3c8a0c8cbecf2c7f7874b14268; code unchanged on main @ 5a20d59db38abef8e0b98cfe47fed81d074bcecc
Environment
Windows 11, T3 Code desktop 0.1.9, Antigravity CLI 1.4.5 (ACP), Gemini 4 Hydrogen and Gemini 4 Argon
Workaround
None in the app. Recompute input as inputTokens - cachedInputTokens to get the real prompt total.
🤖 Generated with Claude Code
Activity
JinJieBeWater commentedon Nov 17, 2026
Related observation on
Antigravity ACP Server 1.5.9: unlike Claude Code and Codex,agy acp/ T3's provider event logs (events.<threadId>.log) also don't surface per-stepinput_tokensandcache_read_tokensbreakdowns (onlyagy --output-format stream-jsonCLI mode exposes per-stepusage.cache_read_tokens), making it difficult to verify prompt-cache hit rates or spot cache-busting behavior in T3 threads.test(server): Antigravity per-turn usage counts cached and thought to…
juliusmarminge commentedon Nov 19, 2026
I tried to reproduce this on the current build and could not.
Commit origin/main 410109d. Ran the Antigravity CLI that T3 uses when it has no managed runtime (
agy acp, Antigravity ACP Server 1.5.12) with T3's spawn arguments (acp --gemini-dir <dir> --app-data-dir antigravity-acp), GEMINI_API_KEY set and GOOGLE_GEMINI_BASE_URL pointing at the hub. Steps: initialize, then authenticate with methodId gemini-api-key, then session/new, then set_model gemini-4-hydrogen-low, then two tool-using prompts (create three files and list them; read them back and append text). The session/prompt results reported usage {inputTokens:18102, outputTokens:588, cachedReadTokens:29364, thoughtTokens:155, totalTokens:48054} and {inputTokens:15551, outputTokens:578, cachedReadTokens:59079, thoughtTokens:83, totalTokens:75208}. totalTokens equals input + cachedRead + output exactly. Decoded the conversation's gen_metadata rows (the field mapping antigravityUsageReader.ts uses). Summed over both turns: field 2 (uncached) is 33653 and equals the ACP inputTokens sum; field 5 (cached) is 88443 and equals the cachedReadTokens sum; field 3 is 1166, equals the outputTokens sum, and equals field 9 (thought, 238) plus field 10 (928). So on 1.5.12, inputTokens leaves out cached reads (main's input + cachedRead is correct) and outputTokens already holds thought tokens (main adds thoughtTokens again, giving output 743 instead of 588 for turn 1). The reporter's doubled input happens on Antigravity 1.4.5, which main's model-manifest.json still lists as supported. The repo fixture (42 + 3 + 9 = 54 with 24 cached) and the reporter's gen_metadata data confirm that shape, but I could not install 1.4.5 because T3's installer refuses versions below 1.5.0, so I did not see the doubled input myself. I did not run the full T3 server or UI; the adapter passes this per-turn usage straight to acpPerTurnPromptUsage (adapter.ts around line 7999). The failing test feeds both shapes to that function: on main, 1.4.5 gives inputTokens 66 instead of 42, and the real 1.5.12 sample gives outputTokens 743 instead of 588.Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.
juliusmarminge commentedon Nov 19, 2026
Reopening. The check above ran in a different setup from the report (an API key instead of a Google account, and Antigravity 1.5.12), so not seeing the bug there does not show it is gone.
test(server): Antigravity per-turn usage counts cached and thought to…
artursoler commentedon Nov 20, 2026
Same machine and the same Google sign-in (
oauth-personal), T3 Code 0.1.10 on Linux. One Gemini 4 Neon session on each Antigravity version. The decodedgen_metadatausage fields are summed over each session: 2 is uncached input, 5 is cache reads, 3 is output, 9 is thinking and 10 is text output.inputTokens/cachedInputTokensoutputTokens/reasoningTokensAntigravity reversed both ACP conventions between these versions. The account type doesn't matter: this matches the 1.5.12 API-key result above.
inputTokensincludes cache reads andoutputTokensexcludes thinking. T3's input is doubled (= 2 + 2 × 5), and its output is right.inputTokensexcludes cache reads andoutputTokensincludes thinking. T3's input is right, but its output counts thinking twice (4,926 = 2,720 + 2,206).#31703 as written would therefore fix 1.4.5 input but under-report 1.5.x input, and it leaves the 1.5.x output double count. Possible approaches:
initialize(agentInfo.version).totalTokens. On 1.4.5 it equals input + output + thought (the existing 42 + 3 + 9 fixture). On 1.5.12 it equals input + cachedRead + output (the run above).Dodhon commentedon Nov 21, 2026
Closing as resolved.
Both usage double-counts are addressed on
main:inputTokens, and T3 Code now refuses runtimes below 1.5.0 at startup (fix(server): refuse Antigravity runtimes below 1.5 #38970).+ thoughtTokensaddition so 1.5+ thinking tokens are no longer counted twice.Maintainer note: open PR #31703 targets the obsolete 1.4.5 input convention and would under-report input tokens on 1.5+, so it can be closed as superseded.