Skip to content

fix(antigravity): normalize per-turn prompt usage at driver boundary - #41337

Open
jieyuexing wants to merge 2 commits into
pingdotgg:mainfrom
jieyuexing:fix/antigravity-normalize-prompt-usage
Open

jieyuexing wants to merge 2 commits into
pingdotgg:mainfrom
jieyuexing:fix/antigravity-normalize-prompt-usage

Conversation

@jieyuexing

Copy link
Copy Markdown
Contributor

Note

Drafted by Claude Sonnet 5.5 and Gemini 4 Neon in T3 Code; reviewed and posted by @jieyuexing

Problem

Follow-up to #41311 (see #41311 (comment)).

Antigravity 1.5+ reports uncached input in PromptResponse.usage.inputTokens, omitting both cachedReadTokens and cachedWriteTokens. Previously, shared ACP code (acpPerTurnPromptUsage) handled this via a provider-specific geminiPromptUsage flag that only added cachedReadTokens and missed cachedWriteTokens. Because TurnTokenUsage expects total prompt input (uncached + cacheRead + cacheWrite) and clamps cacheCreationTokens to inputTokens - (cachedInputTokens ?? 0), turns with non-zero cachedWriteTokens under-reported inputTokens and truncated cacheCreationTokens.

Change

  • Move Antigravity's per-turn usage normalization to the Antigravity driver boundary before counters reach the shared ACP conversion:
    • Add normalizeAntigravityPromptUsage in apps/server/src/provider/acp/AntigravityProtocol.ts, adding both cachedReadTokens ?? 0 and cachedWriteTokens ?? 0 to inputTokens while leaving the other fields untouched.
    • Apply it to non-null response.usage inside makeAntigravityAcpAdapterFlavor's runtime.prompt wrapper in apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts.
  • Remove AcpAdapterV2Flavor.geminiPromptUsage and the geminiUsage branch/parameter from acpPerTurnPromptUsage in packages/provider-acp/src/server/adapter.ts, keeping shared ACP handling independent of provider identity.
  • Move Antigravity usage coverage out of AcpAdapterV2.test.ts into AntigravityProtocol.test.ts (unit tests for normalizeAntigravityPromptUsage) and AntigravityAdapterV2.test.ts (driver-boundary regression test verifying turnTokenUsage on provider_turn.updated).

Verification

  • Confirmed the new driver-boundary regression test fails on upstream/main (f0d160ff1e): with synthetic { inputTokens: 100, cachedReadTokens: 5000, cachedWriteTokens: 800 }, turnTokenUsage reported inputTokens: 5100 (expected 5900) and cacheCreationTokens: 100 (expected 800).
  • After the fix: vp test run apps/server/src/provider/acp/AntigravityProtocol.test.ts apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts passed (3 files / 241 tests).
  • vp run check:changed upstream/main passed across format, lint, knip, graphql, typecheck (14 packages), and tests (4 files / 243 tests).
  • Not checked: live online agy turn producing non-zero cachedWriteTokens or a recorded replay fixture; verified at the AntigravityAdapterV2 driver boundary with mocked PromptResponse.usage.

Built with Claude Sonnet 5.5 in T3 Code.

Antigravity 1.5+ reports inputTokens without cached reads and writes. The shared ACP
layer added only cachedReadTokens, so cache writes were missing from inputTokens and
cacheCreationTokens was clamped below the real value.

Normalize usage in the Antigravity driver before it enters the shared conversion, and
drop the geminiPromptUsage special case from the provider-agnostic ACP adapter.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Antigravity adapter now adds cached read and write token counts to prompt input tokens. The ACP adapter maps reported input and output counts directly and uses reportsPerTurnPromptUsage to control prompt usage capture.

Changes: Antigravity prompt usage

Layer / File(s) Summary
Prompt usage normalization
apps/server/src/provider/acp/AntigravityProtocol.ts, apps/server/src/provider/acp/AntigravityProtocol.test.ts
The normalizer adds cached read and write token counts to inputTokens. Tests check preserved counters and missing or null cache counts.
Per-turn usage contract
packages/provider-acp/src/server/adapter.ts
The adapter uses reported input and output counters directly. It replaces geminiPromptUsage with reportsPerTurnPromptUsage to control prompt usage capture.
Antigravity adapter integration
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts, apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
The prompt wrapper normalizes non-null usage. A test checks mapped token counts, and the prior prompt-usage test was removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#39686: Changes the same per-turn usage path and modifies how cached tokens affect input, output, and reasoning counts.
  • pingdotgg/t3code#41311: Changes the same input-token calculation to include cached write tokens.
  • pingdotgg/t3code#31703: Changes the Antigravity input-token calculation in acpPerTurnPromptUsage.

Suggested reviewers: juliusmarminge, mussejusse, macroscopeapp

Merge Risk: Minimal · up to d22ee

Antigravity prompt token usage now includes cached reads and writes at the driver boundary, and the shared ACP handling no longer carries a provider-specific branch. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(antigravity): normalize per-turn prompt usage at driver boundary" matches the main change. The PR adds normalizeAntigravityPromptUsage at the Antigravity driver boundary so cached-read …
Description check Passed The description covers the template's main sections: Problem, Change, Scope, and Verification. The Problem section explains that Antigravity 1.5+ omits cached-write tokens from inputTokens, which unde…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(antigravity): normalize per-turn prompt usage at driver boundary" matches the main change. The PR adds normalizeAntigravityPromptUsage at the Antigravity driver boundary so cached-read and cached-write tokens are folded into inputTokens. It also removes the provider-specific geminiPromptUsage flag from shared ACP code. The title is a conventional commit title, is a single sentence, and names the primary change.

Full details: Description check

Explanation

The description covers the template's main sections: Problem, Change, Scope, and Verification. The Problem section explains that Antigravity 1.5+ omits cached-write tokens from inputTokens, which under-reports input and truncates cacheCreationTokens. The Change section lists the touched files and the removed flag. The Verification section gives focused test commands, results, and a failing-before check on upstream main, and it states what was not checked. The Scope section does not link a specific issue. It links the follow-up to #41311 and does not explain why no issue is needed or whether a maintainer asked for the PR. The template asks for a bug-fix scope statement, so this is a minor gap. The note at the top about drafting by an agent also satisfies the template's request to name the model and harness.

Resolution

Optional: state the issue that shows the bug, or say why no issue is needed. The link to #41311 is a follow-up reference, not a bug issue. Also confirm whether a maintainer requested this PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e565888 and d22ee75.

Files selected for processing: 6

  • apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
  • apps/server/src/provider/acp/AntigravityProtocol.test.ts
  • apps/server/src/provider/acp/AntigravityProtocol.ts
  • packages/provider-acp/src/server/adapter.ts
Files with no reviewable changes: 1

  • apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@jieyuexing

Copy link
Copy Markdown
Contributor Author

Note

Drafted by Claude Fable 5.2 in T3 Code; reviewed and posted by @jieyuexing

Merged latest main (84a0c0516f) into this branch (d22ee7580f) to clear the conflict. No history was rewritten.

The only conflict was in AntigravityAdapterV2.test.ts: #41923 and this PR each appended a new describe block at the end of the file. I kept the file from main as is and re-appended this PR's AntigravityAdapterV2 prompt usage block after it. The diff against main is the same six files as before (+205 −36).

Verified locally on the merge commit:

  • vp test run on AntigravityAdapterV2.test.ts, AntigravityProtocol.test.ts, AcpAdapterV2.test.ts: 247 passed.
  • vp run check:changed upstream/main: format, lint, knip, graphql, typecheck (14 packages) and test (4 files, 249 tests) all pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant