Skip to content

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

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

jieyuexing wants to merge 1 commit 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 change normalizes Antigravity prompt usage by adding cached read and write token counts to input tokens. The ACP adapter now uses usage.inputTokens directly for per-turn usage and replaces the Gemini-specific flavor flag with reportsPerTurnPromptUsage.

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 new normalizer adds cached read and write token counts to inputTokens. Tests check the other counters and missing or null cache counts.
Per-turn usage contract
packages/provider-acp/src/server/adapter.ts
The adapter reads usage.inputTokens directly and removes the geminiPromptUsage parameter and flavor property. The flavor interface now has reportsPerTurnPromptUsage.
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 Antigravity prompt wrapper normalizes non-null usage. A test checks the mapped token counts, and the prior prompt-usage test was removed from AcpAdapterV2.test.ts.

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#31703: Changes the same inputTokens calculation in acpPerTurnPromptUsage.
  • pingdotgg/t3code#41311: Changes the same Gemini-style input-token calculation to include cached write tokens.

Suggested reviewers: juliusmarminge, mussejusse, macroscopeapp

Merge Risk: Minimal · up to e5658

Antigravity turn usage now includes cached read and write tokens in input tokens, and the provider-specific branch is gone from shared ACP code. The change is narrow, tested with mocked usage, and has no outstanding merge risk.

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 follows the repository template. It has Problem, Change, Scope, and Verification sections, and each is filled in. The Problem section explains the under-reported inputTokens and cacheC…
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 write tokens are added to inputTokens. It also removes the provider-specific geminiPromptUsage flag from shared ACP code. The title is specific and follows a conventional commit format.

Full details: Description check

Explanation

The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and each is filled in. The Problem section explains the under-reported inputTokens and cacheCreationTokens with a reference to the follow-up issue. The Change section lists the files and functions touched. The Verification section gives the commands run, the pass counts, and a note on what was not checked. The Scope section links a prior PR as context, but it does not say directly whether this is a bug fix that needs an issue, and it does not explain why the change needs no issue. That gap is minor.

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 8851fb7 and e565888.

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.

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