Skip to content

fix(antigravity): restore the selected agy account at launch after another agy refreshes over it - #1

Closed
stone16 wants to merge 4 commits into
ci-base/pr-50104from
stone16/fix-antigravity-bug
Closed

stone16 wants to merge 4 commits into
ci-base/pr-50104from
stone16/fix-antigravity-bug

Conversation

@stone16

@stone16 stone16 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

agy keeps one login per machine, and every agy that is running writes its own login back into that slot about once an hour when it refreshes its token. If you switch accounts in Orca while older agy sessions are still running on the previous account, one of them soon puts the old login back. Orca then refused every new agy launch with "The native Antigravity account changed", even though nobody changed anything. Now Orca puts the account you selected back before the launch, as long as the login it finds is one of your saved accounts.

What Changed

Before: AntigravityAccountService.prepareForLaunch refused the launch whenever the native login wasn't the selected account. That included the case where it was simply another saved account, written back by a background agy refresh.

After: if the native login belongs to exactly one saved account other than the selected one, the launch switches the native login back to the selected account and proceeds. reconcile has just saved the drifted login into its own snapshot, so nothing is lost. It uses the same verified native write and readback as explicit selection, now shared as switchNative. The launch still refuses, as before, when the native login is:

  • not saved in Orca (unknown sign-in),
  • missing (signed out),
  • matched by more than one saved account (ambiguous).

A launch-time restore never writes the vault: by then both logins are already saved, so there's nothing to publish. Afterwards it re-reads the vault and refuses the launch if another Orca process changed the selection in the meantime, so a selection made elsewhere is never overwritten.

Why

Evidence from the reporting machine (macOS, Orca 1.4.268, agy 1.5.18):

  • About 69 long-lived agy processes were running (terminals, workers, agents), started under three saved accounts.
  • Every agy log shows browser.go:268] token refreshed roughly every 55 minutes.
  • Between 00:00 and 04:00 one night, 66 processes refreshed: 22 on account A, 34 on B, 10 on C.
  • The gemini/antigravity keychain item's modification time matches one of those refresh lines to the second.
  • Orca's only writer of that item is selectAccount, so the flips come from agy itself.

The selected account is Orca's source of truth: the error already told users to "Select the account again", and doing that only rewrote the same snapshot. Restoring it at launch does automatically what the user was told to do by hand, and only when that is lossless.

Alternatives considered:

Linked Issue

Fixes stablyai#50100

Related: stablyai#48739 (same mechanism on Windows; Windows launches are not gated by this preflight, see Risk)

Visual Proof

N/A: no UI change. The change is in the launch preflight, and the before/after is the launch either failing with the error or starting. It is covered by the test below, which fails with the exact field error when the fix is reverted.

Testing

  • New case in src/main/antigravity/native-account-store.test.ts: save A and B, select A, simulate an agy on B refreshing (no id_token, same grant) over the native slot, then prepareForLaunch. Asserts the native slot holds A again, B's refreshed login is kept in B's snapshot, and the selection is unchanged. With the service change reverted, it fails with The native Antigravity account changed….

  • Existing cases still cover the refusals: unsaved login, a rotated grant Google can't confirm, a different subject, and removal after an outside sign-in.

  • Concurrency check (a throwaway test, not committed, because it hooks internal call order): another Orca process saves a different selection right after the restore's last vault read. On this branch that selection survives. On the intermediate commit that still wrote the vault, it was reverted, which is the reviewer's P2 below.

  • pnpm check:changed: 26/26 checks pass (format, oxlint, typecheck, affected unit tests, ratchets).

  • Not tested against a live agy on purpose: switching the real keychain on the reporting machine would disturb its running sessions.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because the restore only runs on a launch whose native login has drifted. It is one keychain write plus a readback, the same work as an explicit selection. Launches whose login already matches return before any extra read or write.

Risk

Level: Medium

  • Behavior change: a deliberate sign-in to another saved account outside Orca's selection (for example agy login by hand, or Accounts → Add account while a selection exists) no longer blocks launches. The next launch switches back to the selected account; selecting the other account in Accounts switches for real. Unsaved logins and sign-outs still block, as before.
  • Residual race: the native stores have no compare-and-swap. A write landing in the few milliseconds between Orca's check and its write could be replaced. That gap already exists in explicit selection. The realistic writer there is another agy refresh, whose grant reconcile has already saved and whose access token lives on in that process's memory.
  • Not changed: this does not stop old agy processes from writing their login back (that needs credential isolation in agy or Orca), and it does not cover Windows (prepareAntigravityAccountForLaunch returns early on win32), WSL or SSH/remote launches.
  • Back out: plain revert; no saved data format changes.

AI Disclosure

Root-cause analysis and code written by Claude (Opus 5.5) in Claude Code, guided by the contributor. An independent read-only review was done by OpenAI Codex as a separate Orca worker; findings and resolution below.

Review

Independent reviews, read-only, by models other than the one that wrote the code:

Round 1 — OpenAI Codex (separate Orca worker), on 2fa29f34ab1: request changes.

  • P1: the native stores have no compare-and-swap, so an automatic restore can replace a write that lands mid-restore.
    • Resolved as accepted best-effort risk. The same gap already exists in explicit selection.
    • Narrowed the change: restore only when exactly one saved account holds the drifted login. Unknown, ambiguous and signed-out states still refuse.
    • The comment no longer claims any guarantee.
  • P2: a restore could overwrite a newer selection saved by another Orca process.
  • P3: a restore skips forgetAgyLogin (catalog forget and idle-chat restart).

Round 2 — Codex, on c43520f3b8e:

  • Accepted P1 as documented best-effort.
  • Withdrew P3, agreeing that a restore of the selection's native login is not a selection change, and that restarting idle chats on each restore is churn without a guarantee.
  • One P2 remained: the restore still wrote the whole vault after its guard.
  • Fixed in 3726f3e9482: a restore no longer writes the vault at all. The interleaving was checked with a throwaway deterministic test, which fails on c43520f3b8e and passes on HEAD.
  • Non-blocking note kept as follow-up: model catalogs listed during a drift window are not forgotten after a restore.

Round 3 — Claude Sonnet 5.5 (fresh session, read-only), on 3726f3e9482: approve.

  • The P2 blocker is resolved.
  • Explicit selectAccount behaves the same as on main: switchNative is the old inline code, and the publication order is unchanged.
  • No new correctness, data-loss or concurrency defects were found.
  • The Codex worker could not take a third round because its terminal was stuck on an agent update prompt.

Compatibility summary:

  • Cross-platform: macOS keychain and Linux keyring/file go through the same backend, with the keyring-fallback marker still refusing. Windows, WSL and client-routed SSH/remote launches return before this preflight, unchanged.
  • Agents and integrations: only Antigravity terminal launches are gated. Chats and usage reads are unchanged.
  • Performance: extra work only on launches whose login has drifted.
  • UI: no change.
  • Security: no new credential sources. A restore only writes a snapshot already in Orca's encrypted vault back to agy's own store, and refuses anything it can't attribute to exactly one saved account.

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

…other agy refreshes over it

agy keeps one shared native login (the macOS keychain item, or the Linux
keyring), and every running agy writes its own login back to it on each
hourly token refresh. After switching accounts, any agy still running on
the previous account flips the shared login back within the hour, and the
next launch failed with "The native Antigravity account changed" even
though nobody changed accounts.

When the shared login has drifted to another saved account, the launch now
switches it back to the selected one through the same verified write that
selection uses. reconcile has just saved the drifted login into its own
snapshot, so nothing is lost. A login Orca has not saved, or a signed-out
agy, still refuses the launch as before.
…ing a newer selection

Restore only when exactly one saved account holds the drifted login, and abort instead of rewriting selectedAccountId when another Orca process changed the selection mid-restore.
…e selected agy account

Both logins are already saved by then, so the restore only switches the native login and checks the selection; writing the whole vault back could replace a selection another Orca process saved meanwhile.
…ty-bug

# Conflicts:
#	src/main/antigravity/native-account-service.ts
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 502d7893-01a6-4c47-ba01-21fcbaec0d53

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@stone16

stone16 commented Nov 29, 2026

Copy link
Copy Markdown
Owner Author

Superseded by stablyai#50206.

@stone16 stone16 closed this Nov 29, 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.

1 participant