Skip to content

fix(antigravity): read token usage from the conversation, not the Step - #201

Open
uipreliga wants to merge 1 commit into
mainfrom
fix/antigravity-turn-usage
Open

uipreliga wants to merge 1 commit into
mainfrom
fix/antigravity-turn-usage

Conversation

@uipreliga

Copy link
Copy Markdown
Collaborator

Summary

google-antigravity 0.1.18 (bumped in #196, 3aa2db30) deprecated Step.usage_metadata. Usage is now billed per model invocation on the conversation (conversation.total_usage), and the per-step field is always None. The adapter still read the per-step field. The result, since 0.12.7:

  • Every Antigravity turn recorded no tokens and no cost (total_token_usage: null).
  • max_turns never tripped on Antigravity. api_calls is incremented when a new MODEL step opens a call, and the call is closed only by a usage-bearing step. With no usage, the first call never closed, so the count stayed at 1.
  • Nothing failed loudly. make verify stayed green, because the test fakes still put usage on the Step.

Fix

  • _AntigravityTurnState takes a cumulative_usage source (the conversation's total_usage). It books each rise since the last reading as one generation, and books any remainder at finalize. So the per-message buckets still sum to the turn total, and the reconciliation invariant holds.
  • The per-step read is removed completely. The SDK pin is 0.1.18, so there is no fallback to maintain.
  • The test fakes now bill through a _UsageMeter, the same way the SDK connection accumulates usage, and no longer put usage on the Step. The existing scenarios therefore exercise the new source.
  • Two regression tests fail on the old code:
    • a Step that still carries usage_metadata books nothing;
    • usage billed after the last Step is booked at finalize, with the correct call count.
  • The notes and docs that described usage "on a Step" are updated (.claude/notes/timing.md, docs/agents/HARNESS_PARITY.md).
  • A guardrail candidate is added to .claude/harness-candidates.md: a static rule cannot see an SDK field go dead, but a one-turn live-telemetry smoke in the harness-bump checklist would have.

Verification

  • make verify: pass (6101 passed; format, lint, pyright, custom rules, docs budget).
  • Live run, hello_date on gemini-3.8-flash, before and after the fix:
    • before: total_token_usage: null, num_turns: 1
    • after: 30,774 input / 803 output tokens, 3 generations, num_turns: 3, $0.052 at list price
  • Also exercised in a 15-row, five-agent run (gemini-3.8-flash, 3 repeats): every Antigravity row has tokens and cost.

🤖 Generated with Claude Code

google-antigravity 0.1.18 (bumped in 3aa2db3) deprecated Step.usage_metadata:
usage is now billed per model invocation on the conversation
(conversation.total_usage). The adapter still read the per-step field, so
every Antigravity turn since that bump booked no tokens and no cost, and
api_calls stayed at 1 because only a usage-bearing step closes a call, so
max_turns never tripped. Nothing failed loudly; make verify stayed green.

The turn state now takes a cumulative_usage source, books each rise since
the last reading as one generation, and books any remainder at finalize,
so the per-message buckets still sum to the turn total. The test fakes
bill through a meter the way the SDK connection does, and no longer put
usage on the Step, so the suite exercises the new source.

Verified live on gemini-3.8-flash: 30,774 input / 803 output tokens,
3 generations, 3 counted calls, $0.052 at list price (previously None).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Claude finished @uipreliga's task in 1m 49s —— View job


Code Review in Progress

  • Read review guidelines in .github/code_review.md
  • Read CLAUDE.md for project conventions
  • Review full diff (git diff origin/main...HEAD)
  • Analyze each changed file with full context
  • Check cross-file consistency
  • Perform "what's missing" analysis
  • Post structured review feedback

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant