You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(antigravity): restore the selected agy account at launch after another agy refreshes over it - #50104
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:
Isolating each launch's credentials (per-launch file store / app-data dir): the only real fix for the shared-slot race, but a much larger change to how terminals launch agy. Better as a follow-up.
Restarting idle chats on each restore (what explicit selection does via forgetAgyLogin): not done. A background refresh already moved chats onto the drifted login before this change without any invalidation. Restarting them on every launch-time restore would make them re-read a slot that background refreshes keep flipping. That adds churn across many chats and guarantees nothing, and the selection itself doesn't change.
Related: #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.
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:
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.
No actionable comments were generated in the recent review.
Walkthrough
selectAccount now uses switchNative to write credentials when needed and verify the readback. prepareForLaunch can restore the selected account when exactly one saved account matches the current native login. The new test checks that this restores native credentials while preserving the selected account and the other account’s refreshed credentials in the vault.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to fe8a7
This change restores the selected Antigravity account at launch when the native login has drifted to exactly one other saved account, which fixes the reported launch failure. No concrete blocking risk remains. An edge case with an in-app sign-in running at the same moment is being handled in a follow-up PR.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Out of Scope Changes check
The service file at head (native-account-service.ts) contains only the restore and switchNative extraction described in the PR. Those changes relate to #50100. The incremental diff from previous hea…
Provide a readable whole-PR diff against merge base 8adf1f2 (or a narrower per-path diff for the changed files, for example native-account-service.ts and native-account-store.test.ts). Confirm that the merge of origin/main into the branch i…
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title names the main change: Orca restores the selected agy account at launch after another agy process refreshes the shared native login. It matches the raw summary, which describes prepareForLau…
Description check
The description follows the repository template closely. It fills in ELI5, What Changed, Why, Linked Issue (Fixes #50100), Visual Proof (N/A with a reason), Testing, Performance, Risk (Level: Medium),…
Linked Issues check
[#50100] requires that a selected Antigravity account stay effective when another running agy refreshes a different saved account into the shared native slot, so new launches do not fail for that reas…
Full details: Title check
Explanation
The title names the main change: Orca restores the selected agy account at launch after another agy process refreshes the shared native login. It matches the raw summary, which describes prepareForLaunch restoring a selected account when the native login matches exactly one saved account, and the objectives, which describe the same restore behavior. The title uses the conventional fix(scope) prefix and is 96 characters long, which is slightly long but still readable.
Full details: Description check
Explanation
The description follows the repository template closely. It fills in ELI5, What Changed, Why, Linked Issue (Fixes #50100), Visual Proof (N/A with a reason), Testing, Performance, Risk (Level: Medium), AI Disclosure, Review, the agent skill upstream boundary, and the checklist. It gives concrete before/after behavior, the mechanism, alternatives considered, and a rollback plan. Minor gaps: the Testing section leaves the manual-test checkbox unchecked, and the Notes section repeats template text without a stated result. The Linked Issue section also relies on a related issue (#48739) that the objectives describe as a different symptom. These gaps are not critical.
Full details: Linked Issues check
Explanation
[#50100] requires that a selected Antigravity account stay effective when another running agy refreshes a different saved account into the shared native slot, so new launches do not fail for that reason. At the reviewed head fe8a79f, prepareForLaunch in native-account-service.ts restores the selection when the native login matches exactly one saved account other than the selected one. It calls switchNative, which writes the selected credentials and verifies the readback. It then re-reads the vault and refuses only if the selection changed. Unknown, signed-out, and ambiguous states still throw the 'native Antigravity account changed' error. The previous review covered the new drift test in native-account-store.test.ts. The head commit is a merge of main, and the merge base is 8adf1f2, so the whole-PR change set does not include the merged main commits. Live agy behavior was not tested, and that gap does not change the verdict on the code.
Full details: Out of Scope Changes check
Explanation
The service file at head (native-account-service.ts) contains only the restore and switchNative extraction described in the PR. Those changes relate to #50100. The incremental diff from previous head 3726f3e to fe8a79f could not be read, because the diff metadata exceeded the inspection buffer. The whole-PR diff for native-account-service.ts could not be read, because the changed blobs are missing from the checkout. Therefore the set of files changed by the merge of main is not established. The test file at head was not re-read in this review.
Resolution
Provide a readable whole-PR diff against merge base 8adf1f2 (or a narrower per-path diff for the changed files, for example native-account-service.ts and native-account-store.test.ts). Confirm that the merge of origin/main into the branch introduced no file changes outside the Antigravity account files. Then reassess.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 7a8779a1-5ff7-4b8a-8eb4-3fec2729a3ea
Commits
Reviewing files that changed from the base of the PR and between 3726f3e and fe8a79f.
Files selected for processing: 1
src/main/antigravity/native-account-service.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.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
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: 2b5eb401-fa50-4aa9-97d7-c2f4f8cd670e
Commits
Reviewing files that changed from the base of the PR and between aa7e2b6 and 3726f3e.
Files selected for processing: 2
src/main/antigravity/native-account-service.ts
src/main/antigravity/native-account-store.test.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.
Thanks for the careful trace and fix, @stone16. This branch conflicts with main now, so I carried it over in #50206 with your three commits as they are (you stay the author). I added two things on top: launches won't restore while Orca's in-app agy sign-in may have an unsaved login in the slot, and Settings and orca account list show which account new launches use. I'll leave this open until #50206 merges.
The upstream workflow runs on this PR are waiting for first-time-contributor approval, so I ran the same workflow files on my fork against the current head.
Head fe8a79f merges main at 8adf1f2 to clear the conflict with #50137 (the removed usage-read methods); the fix itself is unchanged. The fork PR (stone16#1) targets a branch pinned at that main commit, so the runs test the same merge result.
PR Checks ran typecheck, static analysis, ratchets, code quality, orcad terminal smoke and all 24 unit shards. Its packaging, Windows, WSL and mobile jobs, and the Headless Node server build jobs, skipped on their path filters, as they would here for this diff.
Could a maintainer approve the workflow runs on this PR so the upstream checks can report?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.prepareForLaunchrefused 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.
reconcilehas 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 asswitchNative. The launch still refuses, as before, when the native login is: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):
browser.go:268] token refreshedroughly every 55 minutes.gemini/antigravitykeychain item's modification time matches one of those refresh lines to the second.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:
forgetAgyLogin): not done. A background refresh already moved chats onto the drifted login before this change without any invalidation. Restarting them on every launch-time restore would make them re-read a slot that background refreshes keep flipping. That adds churn across many chats and guarantees nothing, and the selection itself doesn't change.Linked Issue
Fixes #50100
Related: #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, thenprepareForLaunch. 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 withThe 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
agylogin 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.reconcilehas already saved and whose access token lives on in that process's memory.prepareAntigravityAccountForLaunchreturns early on win32), WSL or SSH/remote launches.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.forgetAgyLogin(catalog forget and idle-chat restart).Round 2 — Codex, on
c43520f3b8e:3726f3e9482: a restore no longer writes the vault at all. The interleaving was checked with a throwaway deterministic test, which fails onc43520f3b8eand passes on HEAD.Round 3 — Claude Sonnet 5.5 (fresh session, read-only), on
3726f3e9482: approve.selectAccountbehaves the same as on main:switchNativeis the old inline code, and the publication order is unchanged.Compatibility summary:
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)