Repository navigation
fix(antigravity): keep the selected account after agy refreshes its token - #33656
Conversation
…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]>
|
No actionable comments were generated in the recent review.
|
ELI5
About once an hour
agyquietly renews its Google login. Once it has, Orca stopped recognizing the saved Antigravity account and refused to launchagy: "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
agyis a Go binary. Its credential (Keychaingemini/antigravityon macOS,~/.gemini/antigravity-cli/antigravity-oauth-tokenelsewhere) is refreshed with Go's oauth2tokenRefresher(the installed agy 1.4.7 binary containsgoogle3/third_party/golang/oauth2/oauth2.(*tokenRefresher).Tokenandjson:"id_token_email,omitempty"). Google's refresh response has noid_token, so the refreshed credential has none:{auth_method, id_token_email, token:{access_token, refresh_token, ...}}.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.matches()(native-account-service.ts) only knewid_tokensub. Without it, it compared the whole credential string, which changes on every refresh. So the account showed as inactive andprepareForLaunch()threw.id_tokensubto equal the account's subject. So even storing a refreshed snapshot would have made the vault unreadable.What changed
parseAntigravityNativeCredentialalso returnstoken.refresh_token.matches()falls back to same auth method + same refresh token when the current credential has noid_tokenidentity. Credentials that do have anid_tokenstill match bysubonly, exactly as before.id_tokensubthat doesn't match the account, but accepts a snapshot with noid_token.state()/addCurrentAccount()use the matched saved account's subject/email when the native credential has noid_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:
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 realcreateEncryptedAntigravityAccountStore.agyonly 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.fetch(not the proxy-aware client) and adds up to 5 s toprepareForLaunch.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
native-account-store.test.ts) drives the service against the real encrypted store: save + select → refresh withoutid_token→ launch OK → restart → another refresh → active/selected/subject preserved, vault readable, snapshot updated → a different grant is still refused. It fails onmainwith "The native Antigravity account changed".pnpm test src/main/antigravity/(105 passed),pnpm tc,pnpm run check:code-quality:changedclean.agyrefresh: it needs a real Google account, and on macOSagyuses 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