Skip to content

fix(antigravity): keep the selected account across silent token refreshes - #33204

Closed
biojuho wants to merge 1 commit into
stablyai:mainfrom
biojuho:fix/antigravity-selection-after-refresh
Closed

biojuho wants to merge 1 commit into
stablyai:mainfrom
biojuho:fix/antigravity-selection-after-refresh

Conversation

@biojuho

@biojuho biojuho commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

ELI5

When agy quietly renews its login token (about once an hour), Orca thought the signed-in Antigravity account had changed and refused to start new agy sessions until you re-selected the account. This keeps the selection working across those renewals by asking Google which account the token belongs to.

What Changed

  • Before: matches() identifies the native account by the sub in the stored id_token. agy >= 1.4.7 no longer stores the signed id_token (it keeps id_token_email and the token only), and Google's refresh responses carry no new id_token. With no local sub, matches() falls back to comparing the whole credential string, which changes on every refresh, so prepareForLaunch() throws "The native Antigravity account changed…" and the account cannot be re-saved either (identityKnown: false).
  • After: AntigravityAccountService accepts an optional identity resolver. Each native read without an id_token identity is resolved through Google's tokeninfo endpoint to the stable sub of the access token agy already holds, so selection, active-account display, snapshot refresh and the launch check keep working. The host service wires createGoogleTokeninfoIdentityResolver().
  • Credentials that still carry an id_token behave exactly as before and never touch the network.

Observed Keychain shape on macOS with agy 1.4.7 (values redacted): {"auth_method":"consumer","id_token_email":"…","token":{"access_token":"…","refresh_token":"…","token_type":"Bearer","expiry":"…","expires_in":…}}.

Why

The existing design deliberately refuses to derive identity from rotating secrets or an unverified email (see does not fabricate a stable identity from rotating secrets or an email). Asking Google, the issuer, for the token's sub keeps that rule: the identity is still Google's sub, not a refresh token or email. Alternatives considered: matching by refresh_token (rotation is not guaranteed stable, and the existing fixtures treat it as rotating) and matching by id_token_email (unverified label, same account could be re-labelled).

Safety: the token is sent only in the HTTPS POST body to https://oauth2.googleapis.com/tokeninfo (never in the URL or logs), redirects are refused (redirect: 'error'), the request times out after 5 s, answers are cached in memory by a SHA-256 of the token (a refresh changes the key, so at most one call per token), and any failure leaves identity: null, i.e. the previous fail-closed behaviour. A different Google sub still refuses the launch.

Linked Issue

Fixes #31579

Visual Proof

N/A — no UI change. The visible effect is that "The native Antigravity account changed. Select the account again in Accounts before launching agy." no longer appears after a silent token refresh of the same account.

Testing

  • Automated tests added/updated

  • I manually tested these changes locally (not in a built app; see below)

  • native-account-service.test.ts: new block for [Bug]: Selected Antigravity account is lost after a silent token refresh; new launches fail with "The native Antigravity account changed" (macOS) #31579 — the selected account stays launchable after a refresh drops the id_token; still refuses when Google cannot confirm the account or names a different sub; never calls the resolver for credentials that carry an id_token. The first test fails on main and passes with this change.

  • native-identity-resolver.test.ts: live-answer parsing (sub, expiry, email_verified), POST-body-only token transport, redirect: 'error', per-token caching, no network for id_token credentials, null on 400 / network error / malformed JSON / malformed token.

  • Ran with vitest 5.0.5 in a sparse checkout (macOS, Apple Silicon): native-account-service, native-identity-resolver, native-credential-codec — 36 passed. oxlint 0 warnings, oxfmt --check clean, tsc --strict shows no errors in the changed files. I could not run the full pnpm lint/typecheck/test/build (sparse checkout without the workspace packages); relying on CI for those.

  • Real-world check of the premise: on Orca 1.4.238 with agy 1.4.7, the macOS Keychain item holds id_token_email and no id_token, and Google tokeninfo for the stored access token returns the expected sub/email/email_verified for the native AGY OAuth client.

AI Disclosure

Prepared with an AI coding agent (Antigravity, Claude Opus 5.5) under my review: investigation of the shipped bundle and local credential shape, the patch and the tests.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: token only to Google over HTTPS POST body, no logging, no redirects, fail-closed. Cross-platform: platform-independent; runs only for host-runtime account management (WSL/SSH paths unchanged). Remote SSH / Mobile: unaffected. Backwards compatibility: id_token credentials take the old path; the resolver parameter is optional. Performance: at most one tokeninfo call per access token (about hourly), cached in memory.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred) — targeted local checks only, CI will cover the rest

…shes

agy >= 1.4.7 stores `id_token_email` instead of the signed `id_token`, and Google's
refresh responses carry no new `id_token`. Without a local `sub`, the matcher fell back
to comparing whole credential strings, so every silent access-token refresh made the
selected account look different and `prepareForLaunch` refused new agy launches.

When the native credential has no `id_token` identity, ask Google's tokeninfo endpoint
for the stable `sub` of the access token agy already holds. The token goes only in the
HTTPS POST body (no URL, no logs), redirects are refused, answers are cached by token hash,
and any failure keeps the previous fail-closed behaviour. Credentials that still carry an
`id_token` never touch the network.

Fixes stablyai#31579
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The account service now resolves identity for native Antigravity credentials that lack an id_token. The Google tokeninfo resolver validates and caches identity results. Selection, removal, and reconciliation use the resolved credential. The host configures the resolver. Tests cover confirmed and unconfirmed identities, mismatched subjects, tokeninfo responses, caching, and failure cases.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to af8dc

A temporary lookup failure can keep launch blocked after service recovers, and removing an account can delete the current account’s saved credentials. Address both before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Directly linked issue #31579 has three expected behaviors. The PR fixes the first one. It does not fix the other two.

1. Stable identity across silent refreshes (met). readNative() in `native-accou…
Choose one of the following and record the choice in the PR description.

(a) Implement the remaining expected behaviors. In createAntigravityHostCredentialBackend().write() (macOS path), write the Keychain item and the token file on succ…
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Description check Passed The description is complete and follows the repository template. It explains the user impact, implementation, rationale, linked issue, security considerations, testing, compatibility, and known limits…
Title check Passed The title clearly and concisely describes the primary change: preserving the selected Antigravity account across silent token refreshes.
Out of Scope Changes check Passed All changed files relate to #31579 or to its tests. The changes are: native-identity-resolver.ts (new tokeninfo resolver, cache, and parser), native-account-service.ts (optional resolveIdentity …
Full details: Description check

Explanation

The description is complete and follows the repository template. It explains the user impact, implementation, rationale, linked issue, security considerations, testing, compatibility, and known limits of local validation.

Full details: Out of Scope Changes check

Explanation

All changed files relate to #31579 or to its tests. The changes are: native-identity-resolver.ts (new tokeninfo resolver, cache, and parser), native-account-service.ts (optional resolveIdentity parameter and the readNative() helper used in selection, removal, and reconciliation), native-account-host.ts (wiring of the resolver and Date.now), and tests for the service and the resolver. The resolver behavior matches the stated identity requirement: it returns an existing id_token identity unchanged and makes no network call for it. The parser requires a nonblank sub, and the HTTP call uses a POST body with redirect: 'error' and a timeout. These are supporting parts of the identity fix, not unrelated changes. The negative cache entries mean a transient failure keeps identity: null for that token until it refreshes. This is a design trade-off. It is not an out-of-scope change. The test files were not run in this review. Their results come from the PR description only.

Full details: Linked Issues check

Explanation

Directly linked issue #31579 has three expected behaviors. The PR fixes the first one. It does not fix the other two.

  1. Stable identity across silent refreshes (met). readNative() in native-account-service.ts resolves a missing identity through createGoogleTokeninfoIdentityResolver(). The result is Google's sub, not the full credential string. matches() therefore compares a stable subject after a refresh. The resolver is wired from native-account-host.ts. Tests cover the refreshed-credential launch and the refusal paths.

  2. Write both the Keychain item and the token file on selection (not met). The changed files do not touch the write path. At head, createAntigravityHostCredentialBackend().write() on macOS calls writeAntigravityMacOSCredential(contents) when a native Keychain item exists. It writes the token file only when no native item exists (file.write). The issue requires both stores to be written. The PR does not add this.

  3. Re-apply the saved snapshot or ask once when the selected account cannot be confirmed (not met). When the resolver returns null, readNative() returns the unresolved credential. prepareForLaunch() then keeps the fail-closed error. The PR does not add a re-apply or ask-once path. The PR objectives also state that this fallback is not claimed.

The PR body says Fixes #31579. That claims the full issue. Items 2 and 3 are stated in the issue Expected section, so they are not unrelated sibling work.

Resolution

Choose one of the following and record the choice in the PR description.

(a) Implement the remaining expected behaviors. In createAntigravityHostCredentialBackend().write() (macOS path), write the Keychain item and the token file on successful selection, and keep the read-back check. Add a test that asserts both stores receive the selected credential. Add the fallback for an unconfirmed selected account: re-apply the saved snapshot, or ask once, instead of refusing every launch. Add tests for both paths.

(b) Keep the identity fix only. Change Fixes #31579 to a non-closing reference, such as Refs #31579. In the PR description, state that the dual-store write and the re-apply or ask-once fallback are not included. Open a follow-up issue for those items.

  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


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: d85909ce-74a5-46ac-b81a-f8a937bc3c3a
Commits

Reviewing files that changed from the base of the PR and between d96dca3 and af8dc81.

Files selected for processing: 5
  • src/main/antigravity/native-account-host.ts
  • src/main/antigravity/native-account-service.test.ts
  • src/main/antigravity/native-account-service.ts
  • src/main/antigravity/native-identity-resolver.test.ts
  • src/main/antigravity/native-identity-resolver.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.

throw new Error('Select another Antigravity account before removing this account.')
}
const readback = await this.backend.read()
const readback = await this.readNative()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

🔎 Supported by static analysis

Script executed:

sed -n '70,165p' src/main/antigravity/native-account-service.ts

Repository: stablyai/orca

Length of output: 4110


Script executed:

set -o pipefail
printf '%s\n' '--- service definitions ---'
sed -n '1,85p' src/main/antigravity/native-account-service.ts
sed -n '150,230p' src/main/antigravity/native-account-service.ts
printf '%s\n' '--- related types and implementations ---'
rg -n -F --glob '*.ts' -e 'interface AntigravityAccountStore' -e 'type AntigravityAccountStore' -e 'class Antigravity' -e 'updateSnapshot' -e 'function matches' -e 'const matches' src/main/antigravity src/main/runtime/rpc/methods/antigravity-accounts.ts || test "$?" -eq 1
printf '%s\n' '--- tests around removal and reconciliation ---'
rg -n -F --glob '*native-account-service.test.ts' -e 'removeAccount' -e 'reconcile' -e 'selectedAccountId' -e 'resolver' src/main/antigravity
sed -n '1,240p' src/main/antigravity/native-account-service.test.ts

Repository: stablyai/orca

Length of output: 18756


Script executed:

set -o pipefail
printf '%s\n' '--- account store ---'
sed -n '1,220p' src/main/antigravity/native-account-store.ts
printf '%s\n' '--- test fixture ---'
sed -n '1,260p' src/main/antigravity/native-account-test-fixtures.ts
printf '%s\n' '--- base-to-head diff for service ---'
git diff --unified=30 fda92862c4c250e1c2b1373dbe46969887949848 af8dc81930a579f2e969e5f843fad40f2812abb1 -- src/main/antigravity/native-account-service.ts

Repository: stablyai/orca

Length of output: 14053


Block removal when the current identity is unresolved.

After a silent token rotation, readNative() can return the current credential without identity when resolution returns null. matches() then compares the rotated contents with the saved contents and can fail. If the current account is not selected, both removal guards can fail, so removeAccount() deletes that account's saved snapshot.

Reject removal when the native credential is present but has unresolved identity.

Suggested fix
-      if (vault.selectedAccountId === id || (current && matches(account, current))) {
+      if (
+        vault.selectedAccountId === id ||
+        (current && (!current.identity || matches(account, current)))
+      ) {
         throw new Error('Select another Antigravity account before removing this account.')
       }
@@
-      if (latest.selectedAccountId === id || (readback && matches(latestAccount, readback))) {
+      if (
+        latest.selectedAccountId === id ||
+        (readback && (!readback.identity || matches(latestAccount, readback)))
+      ) {
         throw new Error('Select another Antigravity account before removing this account.')
       }

if (cache.size >= MAX_CACHE_ENTRIES) {
cache.clear()
}
cache.set(key, identity)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Stability & Availability · Quick win

Do not cache transient lookup failures indefinitely.

If tokeninfo times out or returns a server error, identity remains null, and this line caches it. Later reads of the same access token return null without retrying. As a result, prepareForLaunch() can keep rejecting the selected account after the service recovers, until the token changes or the cache is cleared. Cache confirmed identities only, or give failed lookups a short expiry. Google also warns that tokeninfo requests can encounter intermittent errors. (developers.google.com)

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @biojuho! The fix landed in #33656 (merged, with your co-author credit). We matched the refreshed credential by refresh token instead of a tokeninfo lookup: saving an id_token-less snapshot made the vault's read check reject every Accounts read, and tokeninfo fails once the access token expires. Closing in favor of #33656.

nwparker added a commit that referenced this pull request Oct 25, 2026
…oken (#33656)

After agy silently refreshes its Google token (the new credential has no id_token), Orca still matches the saved Antigravity account by auth method + refresh token instead of refusing the launch with "native Antigravity account changed"; the vault accepts such refreshed snapshots while still rejecting one whose id_token names a different account.

Fixes #31579
Supersedes #33204

Co-authored-by: biojuho <258838639+biojuho@users.noreply.github.com>
Co-authored-by: Manan <100475418+thefrikidude@users.noreply.github.com>
@nwparker nwparker closed this Oct 25, 2026
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)

2 participants