Repository navigation
fix(acp): Gemini per-turn usage includes cached write tokens - #41311
jieyuexing wants to merge 1 commit into
Conversation
Problem: In `acpPerTurnPromptUsage`, when `geminiUsage` (`geminiPromptUsage: true`) is enabled, `inputTokens` added `usage.cachedReadTokens` but omitted `usage.cachedWriteTokens`. Because `TurnTokenUsage` treats `inputTokens` as total prompt input (uncached + cache read + cache write) and clamps `cacheCreationTokens` to `inputTokens - cachedInputTokens`, turns with cached writes under-reported `inputTokens` and truncated `cacheCreationTokens` to uncached `inputTokens`. Fix: Include `usage.cachedWriteTokens ?? 0` alongside `usage.cachedReadTokens ?? 0` when computing `inputTokens` under `geminiUsage` in `packages/provider-acp/src/server/adapter.ts`, update the `geminiPromptUsage` doc comment, and add a regression assertion in `apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts`. Verification: - Confirmed the new `acpPerTurnPromptUsage` assertion fails on `upstream/main` (`inputTokens: 600` instead of `2600`, `cacheCreationTokens: 100` instead of `2000`). - `vp test run apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts` (158 passed). - `vp run check:changed upstream/main` (format, lint, knip, graphql, typecheck across 14 packages, and 2 test files / 160 tests all passed). Done with Gemini 4 Neon in T3 Code (Antigravity).
|
Thanks for this. T3 Code's ACP Registry support follows the ACP spec: the code every agent shares takes no changes that are specific to one agent, and the special cases already there are not a precedent for more (how providers are integrated). The accounting problem is valid, but this change widens the existing Gemini-only branch in shared ACP code. Its flag is enabled by Antigravity’s dedicated driver; it is not a capability advertised by every ACP agent. Antigravity already has a dedicated driver, so the usage normalization can live there before the counters reach the shared conversion. Please bring the correction back at that boundary, keeping shared ACP handling independent of provider identity. An integration that needs Antigravity's identity, credentials or private API is a dedicated provider driver, and we only add one when a maintainer has decided to own that integration. If you think Antigravity should have one, open an issue making that case first. Closing. |
Note
Drafted by Gemini 4 Neon in T3 Code; reviewed and posted by @jieyuexing
Problem
In
acpPerTurnPromptUsage, whengeminiUsage(geminiPromptUsage: true, used by Antigravity 1.5+) is enabled,inputTokensaddsusage.cachedReadTokenstousage.inputTokens(uncached input) but omitsusage.cachedWriteTokens.Because
TurnTokenUsagetreatsinputTokensas total prompt input (uncached + cacheRead + cacheWrite) and immediately clampscacheCreationTokenstoinputTokens - (cachedInputTokens ?? 0), any Gemini/Antigravity turn withcachedWriteTokensunder-reportsinputTokensby the full cache-write amount and truncatescacheCreationTokenstousage.inputTokens(uncached input). For example,inputTokens: 100, cachedReadTokens: 500, cachedWriteTokens: 2000producedinputTokens: 600andcacheCreationTokens: 100instead of2600and2000.Change
usage.cachedWriteTokens ?? 0alongsideusage.cachedReadTokens ?? 0when computinginputTokensundergeminiUsageinpackages/provider-acp/src/server/adapter.ts(matchingantigravityUsageReader.ts, where protobufinputTokensexcludes both cached reads and cached writes).geminiPromptUsagedoc comment inpackages/provider-acp/src/server/adapter.tsand extend the existingacpPerTurnPromptUsagetest case inapps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts.Scope
Small one-line logic fix for an obvious contract bug in
acpPerTurnPromptUsage, so no separate issue was filed. Checkedpackages/provider-acp/src/for any othergeminiUsagecalculations; none exist.Verification
upstream/main(9f24cac6d4):vp test run apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts -t "acpPerTurnPromptUsage"failed withinputTokens: 600(expected2600) andcacheCreationTokens: 100(expected2000).vp test run apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tspassed (158/158).vp run check:changed upstream/mainpassed across format, lint, knip, graphql, typecheck (14 packages), and tests (2 files / 160 tests).cachedWriteTokens; behavior is verified at theacpPerTurnPromptUsageunit boundary against theTurnTokenUsagecontract.Built with Gemini 4 Neon in T3 Code (Antigravity harness).