Skip to content

fix(antigravity): keep the selected account after agy refreshes its token - #33656

Merged
nwparker merged 1 commit into
mainfrom
nwparker/agint-antigravity-account-silent-refresh
Oct 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/agint-antigravity-account-silent-refresh

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

ELI5

About once an hour agy quietly renews its Google login. Once it has, Orca stopped recognizing the saved Antigravity account and refused to launch agy: "The native Antigravity account changed. Select the account again in Accounts before launching agy." Now Orca still recognizes the same login after a renewal.

Root cause

  • agy is a Go binary. Its credential (Keychain gemini/antigravity on macOS, ~/.gemini/antigravity-cli/antigravity-oauth-token elsewhere) is refreshed with Go's oauth2 tokenRefresher (the installed agy 1.4.7 binary contains google3/third_party/golang/oauth2/oauth2.(*tokenRefresher).Token and json:"id_token_email,omitempty"). Google's refresh response has no id_token, so the refreshed credential has none: {auth_method, id_token_email, token:{access_token, refresh_token, ...}}.
  • Go's oauth2 keeps the refresh token when the refresh response omits it (golang.org/x/[email protected]/internal/token.go:250-253, oauth2.go:288-289), so the refresh token stays the same across refreshes of one sign-in.
  • Orca's matches() (native-account-service.ts) only knew id_token sub. Without it, it compared the whole credential string, which changes on every refresh. So the account showed as inactive and prepareForLaunch() threw.
  • The encrypted vault's read check also needed the snapshot's id_token sub to equal the account's subject. So even storing a refreshed snapshot would have made the vault unreadable.

What changed

  • parseAntigravityNativeCredential also returns token.refresh_token.
  • matches() falls back to same auth method + same refresh token when the current credential has no id_token identity. Credentials that do have an id_token still match by sub only, exactly as before.
  • Vault read check: still rejects an id_token sub that doesn't match the account, but accepts a snapshot with no id_token.
  • state() / addCurrentAccount() use the matched saved account's subject/email when the native credential has no id_token. The Accounts page then shows the account and the Usage subject guard keeps working.

No network calls, no new modules.

Why not #33204 (tokeninfo lookup)

I reviewed #33204 adversarially:

  • Vault breakage (blocking): after the first refresh it writes the id_token-less snapshot into the vault. The vault's read check then rejects it, so every later Accounts read fails with "Antigravity account snapshots could not be read" for all saved accounts. Its tests use the in-memory harness store, so they miss this. I reproduced it by running fix(antigravity): keep the selected account across silent token refreshes #33204's service against the real createEncryptedAntigravityAccountStore.
  • agy only refreshes while it runs. A stored access token that has expired (any idle period over ~1h) gets a 400 from tokeninfo, so the launch is still refused in the most common case.
  • Failures, including timeouts and offline, are cached per token, so one network blip blocks launches until the next refresh. It uses global fetch (not the proxy-aware client) and adds up to 5 s to prepareForLaunch.

The refresh-token match has no network dependency and covers expired tokens. It also can't give a false positive: a refresh token belongs to exactly one grant. The approach follows @thefrikidude's matching rule in #33580, and the diagnosis and repro shape come from @biojuho's #33204. Both are credited as co-authors.

Not covered (follow-up / product decision)

Saving an account from a fresh agy ≥1.4.7 sign-in that never had an id_token (#33323, "Save current account" disabled) still needs a verified identity source, e.g. the Google userinfo lookup on Save in #33580. This PR doesn't change that.

Verification

  • New regression test (native-account-store.test.ts) drives the service against the real encrypted store: save + select → refresh without id_token → launch OK → restart → another refresh → active/selected/subject preserved, vault readable, snapshot updated → a different grant is still refused. It fails on main with "The native Antigravity account changed".
  • pnpm test src/main/antigravity/ (105 passed), pnpm tc, pnpm run check:code-quality:changed clean.
  • I didn't run a real agy refresh: it needs a real Google account, and on macOS agy uses the login Keychain, which can't be isolated with a temp HOME. Reporter retest requested.

Risk

Low. The change only affects the case where the credential has no id_token; before this PR that case always failed. Cross-platform: parsing is shared by the macOS Keychain, Linux, and Windows file backends. Remote/WSL: the runtime state shape is unchanged.

Fixes #31579

…oken

agy's token refresh stores no id_token, so the saved account stopped
matching and launches were refused. Match an id_token-less credential to
its saved account by the grant's refresh token, which Go's oauth2 keeps
across refreshes, and let the vault hold such snapshots.

Co-authored-by: ju-ho park <[email protected]>
Co-authored-by: Manan <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3d665d9-3b89-4f2a-8d94-4433695727ae
Commits

Reviewing files that changed from the base of the PR and between 47ed6e1 and eb58154.

Files selected for processing: 6
  • src/main/antigravity/native-account-service.ts
  • src/main/antigravity/native-account-store.test.ts
  • src/main/antigravity/native-account-store.ts
  • src/main/antigravity/native-account-test-fixtures.ts
  • src/main/antigravity/native-credential-codec.test.ts
  • src/main/antigravity/native-credential-codec.ts

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

Walkthrough

Credential parsing now exposes a nullable refresh token. Account matching can reuse a saved account when the current credential has the same nonempty refresh token and auth method, even when identity data is absent. State can use the matched account's subject and email. Store reads permit credentials without identity data. Tests cover persistence across a service restart and rejection of a different grant.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to eb581

The selected account remains identifiable in the tested refresh and restart paths. The change is mergeable after normal checks; a live account refresh has not been verified.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Linked issue #31579 has three Expected outcomes. This PR implements the first one. The diff at head changes AntigravityAccountService matches() in native-account-service.ts. The new branch matches the… Either (1) implement the two remaining Expected outcomes of #31579: write a selection to both the Keychain item and the token file, and re-apply the saved snapshot or prompt when the selected account cannot be confirmed, with automated test…
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preserving the selected Antigravity account after token refreshes.
Description check Passed The description is detailed and covers the user impact, root cause, implementation, rationale, linked issue, testing, limitations, and risk. Some template headings and checklist items are omitted, inc…
Out of Scope Changes check Passed All changed files are in src/main/antigravity/. Each change supports the refresh-token matching fix for #31579. native-credential-codec.ts adds refreshToken to the parsed credential, which matches() n…
Full details: Description check

Explanation

The description is detailed and covers the user impact, root cause, implementation, rationale, linked issue, testing, limitations, and risk. Some template headings and checklist items are omitted, including explicit visual-proof and checklist sections, but the description is substantially complete and on topic.

Full details: Out of Scope Changes check

Explanation

All changed files are in src/main/antigravity/. Each change supports the refresh-token matching fix for #31579. native-credential-codec.ts adds refreshToken to the parsed credential, which matches() needs. native-account-service.ts adds the refresh-token branch to matches(). It also moves the no-identity check in addCurrentAccount() so that an existing match is reused before a new account requires an identity. The state() subject and email fallback keeps currentAccount consistent with the matched account. native-account-store.ts relaxes the subject check only when the parsed credential has no identity, so the vault can read refreshed snapshots. native-account-test-fixtures.ts and native-credential-codec.test.ts add the fixture and the expected refreshToken values. native-account-store.test.ts adds the regression tests. The diff shows no unrelated changes. This assessment does not check the test results.

Full details: Linked Issues check

Explanation

Linked issue #31579 has three Expected outcomes. This PR implements the first one. The diff at head changes AntigravityAccountService matches() in native-account-service.ts. The new branch matches the current credential to a saved account when both have the same nonempty refreshToken and the same authMethod. The codec (native-credential-codec.ts) now parses token.refresh_token. Credentials with an id_token still match by subject only. The vault read check (native-account-store.ts) accepts a snapshot with no identity. state() and addCurrentAccount() use the matched account's subject and email. Together these keep the selection across silent refreshes, which covers the stable-identity bullet [#31579]. Two Expected outcomes have no code change at head: (a) selecting an account must write both the Keychain item and the token file; the diff changes no write path for the token file. (b) when the selected account cannot be confirmed, the saved snapshot must be re-applied or the user must be asked once; the diff adds no re-apply or prompt path. The PR description and the objectives state that these two items are not claimed by this PR. [#31579]

Resolution

Either (1) implement the two remaining Expected outcomes of #31579: write a selection to both the Keychain item and the token file, and re-apply the saved snapshot or prompt when the selected account cannot be confirmed, with automated tests for each; or (2) narrow the scope of this PR and its 'Fixes #31579' line so it refers only to the refresh-token matching fix, and link a separate issue or follow-up for the other two outcomes.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[Bug]: Selected Antigravity account is lost after a silent token refresh; new launches fail with "The native Antigravity account changed" (macOS)

1 participant