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 when another agy refreshes over it - #50206
agy keeps one login per machine, and every running agy writes its own login back into that slot when it refreshes its token, about once an hour. If you switch accounts in Orca while an older agy is still running on the previous account, that agy 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 a launch puts the account you selected back first, as long as the login it finds is another account you saved.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$24
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$24
Prod
20
$\color{#1a7f37}{\Huge{\mathbf{+}}}$158
$\color{#cf222e}{\Huge{\mathbf{−}}}$35
$\color{#1a7f37}{\Huge{\mathbf{+}}}$123
What Changed
Before: with A and B saved and B selected, any agy still running on A put A back within the hour. New agy terminals, agent launches and orchestration workers then failed with "The native Antigravity account changed. Select the account again…". Settings showed A as Active and nothing said B was selected.
After:
Launch restores the selection (@stone16's commits). prepareForLaunch writes the selected snapshot back when exactly one other saved account holds the slot, through the same verified write and readback that selecting uses (now shared as switchNative). It still refuses when the slot holds a login Orca hasn't saved, is empty, or matches more than one saved account. It refuses too if the selection changed while it ran.
Orca's own sign-in is never overwritten. While the in-app agy sign-in runs, a launch won't restore. The slot may hold the new login before it's saved, so the launch says "Antigravity sign-in is in progress" instead. The sign-in waits for any restore already writing before agy acp --login starts. The flow now ends only after its new login is saved.
Settings and the CLI say which account launches use. When another saved account holds the login, Settings marks the selected account "New agy launches use this account" and the holder "agy's login right now". orca account list --agent antigravity adds (selected). Hosts with this fix say so in the account state (restoresSelectionAtLaunch), so a client paired to an older host keeps today's wording. Only the host's service restores; Windows launches aren't checked, so Windows keeps today's behaviour.
Why
Running agy processes read their login once at startup, keep it in memory, and write it back on every refresh without reading the slot again. Measured with agy 1.5.16 against a local fake Google token endpoint: with B in the slot, a running agy that had loaded A refreshed and wrote A over it. The slot only matters when a new agy starts, so restoring it right before a launch is the smallest fix that keeps the selection effective. agy has no per-process account choice and the macOS keychain item is fixed, so per-account isolation isn't available.
The sign-in guard covers the one writer that doesn't keep its login in memory: Orca's in-app sign-in writes a new login and exits, and a restore landing before the save would have lost it.
Not in this PR:
Antigravity chats never had this launch check and run on whatever login is in the slot. Making them follow the selection needs its own design: hook at spawn, store-authority checks, gateway and API-key auth.
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
macOS, real agy 1.5.16, dev build of this branch as a headless serve. Scratch HOME with SSH_CONNECTION set so agy and Orca use a token file, not the keychain. A local HTTPS proxy and test CA stand in for Google's token endpoint.
Saved A and B, selected A, started a long-lived agy, then selected B. Its next refresh wrote A back, and the account list showed A active and B selected.
On main, orca terminal create --command agy then fails with "The native Antigravity account changed".
On this branch the same launch succeeds. The new agy logged applyAuthResult: email=b@…, and the fake Google saw a refresh with B's refresh token. The old A process didn't react.
The account state reports restoresSelectionAtLaunch: true, and the branch's CLI prints (selected).
Not run live: the sign-in guard (unit-tested) and Linux or Windows hosts. Linux uses the same service and file/keyring backends; on Windows, behaviour is unchanged.
Tests: @stone16's test in native-account-store.test.ts now also checks that a launch never restores while Orca's sign-in holds the slot. pnpm check:changed passes.
Performance
None, because the restore runs only on agy launches that would otherwise have been refused. It adds one native credential write and readback to those launches, and nothing on other paths.
Risk
The risky part is that a launch now writes agy's login slot instead of only reading it. It writes only over a login that is already saved in Orca. Two residuals exist, both also present in today's explicit account selection:
An older agy refreshing in the second or so before the new agy reads the slot can still win. The new agy then starts on that account.
A login written by a hand-run agy in the few milliseconds between the check and the write can be overwritten. None of the stores offer compare-and-swap.
Older paired hosts keep today's behaviour and wording. A plain revert backs it out, and nothing is migrated.
Level: Medium
AI Disclosure
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
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.
… Orca's sign-in is still saving
A launch restore and Orca's in-app agy sign-in both write agy's one login slot. Launches now refuse to restore while a sign-in runs (until its new login is saved), and the sign-in waits for a restore already writing before agy can sign in. Only the host's service restores; Windows keeps refusing a moved login.
When an agy still running on another saved account holds the login, Settings marks the selected account as the one new launches use and the CLI list adds (selected). Hosts that restore at launch say so in the account state, so older paired hosts keep today's wording.
The account service can restore the selected Antigravity account before launch when configured, when exactly one saved account matches the current native login, and when sign-in is not in progress. The sign-in flow and launch path now wait for relevant account operations. The CLI and settings rows distinguish the selected account from the active login and indicate which account new launches will use.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to f0dee
With two Orca processes running, a selection change made in one can be overwritten by a credential refresh in the other. A later agy launch may then use an account the user had deselected. The window is narrow, but the selection should be preserved before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: launch-time restoration of the selected agy account when another running agy overwrites the shared login slot. It uses the conventional fix() prefix and stays specific…
Description check
The description follows the template closely: ELI5, What Changed (before/after and mechanism), Why, Linked Issue (Fixes #50100), Visual Proof with before/after images and CLI output, Testing with a ma…
Linked Issues check
Issue #50100 requires that the selected Antigravity account stay effective when another running agy refreshes the shared login slot, and that new agy launches not fail with "The native Antigravity acc…
Out of Scope Changes check
Changes outside the core restore path are tied to the issue or to the PR objectives. The Settings rows (AntigravityAgyAccountRows.tsx), the CLI (selected) marker (account-list-format.ts), and the new …
Full details: Title check
Explanation
The title names the main change: launch-time restoration of the selected agy account when another running agy overwrites the shared login slot. It uses the conventional fix() prefix and stays specific to the changeset. The 95-character length is long but acceptable.
Full details: Description check
Explanation
The description follows the template closely: ELI5, What Changed (before/after and mechanism), Why, Linked Issue (Fixes #50100), Visual Proof with before/after images and CLI output, Testing with a manual macOS run, Performance, Risk with level and revert path, and the checklist. The AI Disclosure section is empty, but the template marks it as optional for internal contributors. The Performance line is complete. The Review and Notes sections are unfilled, which is minor. The description is mostly complete.
Full details: Linked Issues check
Explanation
Issue #50100 requires that the selected Antigravity account stay effective when another running agy refreshes the shared login slot, and that new agy launches not fail with "The native Antigravity account changed" only because the slot holds another saved account. At head, AntigravityAccountService.prepareForLaunch (native-account-service.ts) restores the selected account when exactly one saved account matches the current slot login and a launchRestore hook is configured. It writes through switchNative (backend.write, then backend.read and matches check) and checks that the selected account ID is unchanged afterward. It refuses when the slot is empty, holds an unsaved login, or matches several saved accounts. The host factory supplies the hook on non-Windows hosts (native-account-host.ts, per the change summary), so the macOS/Linux launch path is covered. The sign-in guard (signInHoldsLogin) prevents a restore during Orca's own sign-in, and settled() serializes sign-in after a pending restore. Unit tests in native-account-store.test.ts cover the sign-in hold case. Remaining gaps, which the PR discloses: the write has no compare-and-swap, and Windows is intentionally unchanged, as the issue states Windows launches are not gated. Live testing was done on macOS only. The issue's reproduction steps are not all covered by live tests, but the unit tests and the code path support the fix.
Full details: Out of Scope Changes check
Explanation
Changes outside the core restore path are tied to the issue or to the PR objectives. The Settings rows (AntigravityAgyAccountRows.tsx), the CLI (selected) marker (account-list-format.ts), and the new restoresSelectionAtLaunch capability flag show which account launches use, matching issue step 4, which relies on orca account list. The flag keeps older paired clients on the previous wording. The sign-in changes (signedIn awaited, antigravitySignInHoldsNativeLogin, settled() in the RPC) are required to order sign-in against restores. The 13 locale files and the fixture add strings for the new UI text only. The fixture and test-harness updates support the new tests. The PR does not change Antigravity chats or Windows behaviour, which the PR description states. No unrelated functional change was found in the reviewed summary.
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.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Keep the saved selection when reconciliation writes refreshed… · native-account-service.ts:215
src/main/antigravity/native-account-service.ts:215 Major · Data Integrity & Integration · Heavy lift
Keep the saved selection when reconciliation writes refreshed credentials.
reconcile() reads the vault at line 205 and writes the whole vault at line 215, after updateSnapshot() refreshes the matched account's credentials. The write saves the selectedAccountId value from the earlier read. If another Orca process saves a different selection after the read and before the write lands, this write overwrites that selection with the stale value.
The new launch restore path makes this overwrite affect the launch. prepareForLaunch() uses the vault returned by reconcile(). If the stale selection no longer matches the native login, and exactly one saved account holds that login, the path switches the native login to the stale account. The post-switch check at line 168 then reads back the stale selection, so it does not detect the lost update. Before this change, the same mismatch raised an error. Now agy can launch with an account the user deselected.
The PR requires that launch restoration not overwrite a selection changed by another Orca process. The refresh write must keep the selection that is saved at write time. The inspected store exposes only a whole-vault write(vault) with no compare-and-set, and the service's queue does not coordinate across processes. Choose the mechanism that makes this write keep the newer selection. The required outcome is fixed; the mechanism is not.
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: 2c4c74ec-f6f8-407e-ab68-31c65dbac5c3
Commits
Reviewing files that changed from the base of the PR and between 88ae778 and f0dee25.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
@coderabbitai On the outside-diff Major about reconcile() keeping a stale selectedAccountId: this is the same finding you raised and withdrew on #50104, and it still can't happen here. It needs two Orca main processes writing one vault. Orca takes a single-instance lock per userData profile (src/main/startup/profile-startup/single-instance-lock.ts), skipped only by an explicit env opt-in or for throwaway E2E profiles. Inside the one process, reconcile, selectAccount and prepareForLaunch all run in the service's serialize queue, so a selection can't land between reconcile's read and write. This PR also leaves reconcile() unchanged. Leaving it as is.
For best results, initiate chat on the files or code changes.
Analysis chain
Script executed:
#!/bin/bashset -u
echo'=== Repository instructions ==='
fd -HI -t f '(^AGENTS\.md$|^CLAUDE\.md$|^\.coderabbit\.yaml$|^\.coderabbit\.yml$)'.| head -100
echo'=== Startup lock outline and file ==='
ast-grep outline src/main/startup/profile-startup/single-instance-lock.ts --items all
cat -n src/main/startup/profile-startup/single-instance-lock.ts
echo'=== Account service outline ==='
ast-grep outline src/main/antigravity/native-account-service.ts --items all
echo'=== Account service queue and methods ==='
rg -n -C 5 'serialize|reconcile|selectAccount|prepareForLaunch|settled' src/main/antigravity/native-account-service.ts
echo'=== Account service and vault creation ==='
rg -n -C 4 'new AntigravityAccountService|create.*AntigravityAccountService|native-account-service|AntigravityAccountStore|single.instance.lock|requestSingleInstanceLock' src/main
echo'=== PR/base diff for account service ==='
git diff origin/HEAD...HEAD -- src/main/antigravity/native-account-service.ts 2>&1| head -240
Length of output: 47718
Script executed:
#!/bin/bashset -u
echo'=== Repository instructions ==='
cat -n AGENTS.md
echo'=== Host service outline and contents ==='
ast-grep outline src/main/antigravity/native-account-host.ts --items all
cat -n src/main/antigravity/native-account-host.ts
echo'=== Account service relevant sections ==='
cat -n src/main/antigravity/native-account-service.ts | sed -n '40,180p'
cat -n src/main/antigravity/native-account-service.ts | sed -n '190,270p'echo'=== Store outline and relevant sections ==='
ast-grep outline src/main/antigravity/native-account-store.ts --items all
cat -n src/main/antigravity/native-account-store.ts | sed -n '1,110p'echo'=== Startup preflight lock usage ==='
ast-grep outline src/main/startup/main-process-preflight.ts --items all --match 'lock|Lock|Preflight'
cat -n src/main/startup/main-process-preflight.ts | sed -n '185,275p'echo'=== Other store factories and writers ==='
rg -n -C 3 'createEncryptedAntigravityAccountStore\s*\(|getAntigravityAccountService\s*\(|getAntigravityAccountVaultPath\s*\(' src/main/antigravity src/main/runtime
Length of output: 49640
@AmoabaKelvin You’re right. The normal profile lock prevents a second main process from using the same vault, and the shared service queue prevents selectAccount() from interleaving with reconcile(). The bypass and E2E exceptions do not establish this race in normal operation. The PR also leaves reconcile() unchanged.
I withdraw the finding. Sorry for repeating it.
Learnings added
Learnt from: AmoabaKelvin
URL: https://github.com/stablyai/orca/pull/50206
Timestamp: 2026-11-27T01:08:47.128Z
Learning: Within repository "stablyai/orca", only for files matching one of ["src/main/antigravity/native-account-service.ts"]: In src/main/antigravity/native-account-service.ts, reconcile(), selectAccount(), and prepareForLaunch() run through the service's serialize queue. Normal Orca startup also takes a single-instance lock per userData profile in src/main/startup/profile-startup/single-instance-lock.ts. Do not report a stale selectedAccountId race between reconcile() and account selection without establishing a feasible writer outside that queue. The lock can be bypassed by an explicit environment opt-in or skipped for throwaway E2E profiles.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
Learnings used
Learnt from: brennanb2025
Repo: stablyai/orca PR: 45128
File: src/main/native-chat/agent-session-journal/database/journal-legacy-adoption.ts:165-165
Timestamp: 2026-11-20T14:55:00.996Z
Learning: Within repository "stablyai/orca", only for files matching one of ["src/main/native-chat/agent-session-journal/database/journal-legacy-adoption.ts","src/main/native-chat/agent-session-journal/database/journal-legacy-reconcile.ts"]: In src/main/native-chat/agent-session-journal/database/journal-legacy-adoption.ts, readAdoption caches source claims for later copy adoption. For reviews of claim/revision consistency, do not assume that a read-only SQLite connection provides a snapshot across the pass. Ordinary app startup uses instance/profile locks before reconciliation, so establish a feasible writer interleaving and compare the ordering with the PR base before attributing a race to a change.
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.
Carries over #50104 by @stone16.
ELI5
agy keeps one login per machine, and every running agy writes its own login back into that slot when it refreshes its token, about once an hour. If you switch accounts in Orca while an older agy is still running on the previous account, that agy 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 a launch puts the account you selected back first, as long as the login it finds is another account you saved.
What Changed
Before: with A and B saved and B selected, any agy still running on A put A back within the hour. New agy terminals, agent launches and orchestration workers then failed with "The native Antigravity account changed. Select the account again…". Settings showed A as Active and nothing said B was selected.
After:
prepareForLaunchwrites the selected snapshot back when exactly one other saved account holds the slot, through the same verified write and readback that selecting uses (now shared asswitchNative). It still refuses when the slot holds a login Orca hasn't saved, is empty, or matches more than one saved account. It refuses too if the selection changed while it ran.agy acp --loginstarts. The flow now ends only after its new login is saved.orca account list --agent antigravityadds(selected). Hosts with this fix say so in the account state (restoresSelectionAtLaunch), so a client paired to an older host keeps today's wording. Only the host's service restores; Windows launches aren't checked, so Windows keeps today's behaviour.Why
Running agy processes read their login once at startup, keep it in memory, and write it back on every refresh without reading the slot again. Measured with agy 1.5.16 against a local fake Google token endpoint: with B in the slot, a running agy that had loaded A refreshed and wrote A over it. The slot only matters when a new agy starts, so restoring it right before a launch is the smallest fix that keeps the selection effective. agy has no per-process account choice and the macOS keychain item is fixed, so per-account isolation isn't available.
The sign-in guard covers the one writer that doesn't keep its login in memory: Orca's in-app sign-in writes a new login and exits, and a restore landing before the save would have lost it.
Not in this PR:
Linked Issue
Fixes #50100
Visual Proof
Settings with B (
work@) selected while an agy running on A (personal@) holds the login:CLI, same state:
Testing
macOS, real agy 1.5.16, dev build of this branch as a headless serve. Scratch HOME with
SSH_CONNECTIONset so agy and Orca use a token file, not the keychain. A local HTTPS proxy and test CA stand in for Google's token endpoint.orca terminal create --command agythen fails with "The native Antigravity account changed".applyAuthResult: email=b@…, and the fake Google saw a refresh with B's refresh token. The old A process didn't react.restoresSelectionAtLaunch: true, and the branch's CLI prints(selected).Not run live: the sign-in guard (unit-tested) and Linux or Windows hosts. Linux uses the same service and file/keyring backends; on Windows, behaviour is unchanged.
Tests: @stone16's test in
native-account-store.test.tsnow also checks that a launch never restores while Orca's sign-in holds the slot.pnpm check:changedpasses.Performance
None, because the restore runs only on agy launches that would otherwise have been refused. It adds one native credential write and readback to those launches, and nothing on other paths.
Risk
The risky part is that a launch now writes agy's login slot instead of only reading it. It writes only over a login that is already saved in Orca. Two residuals exist, both also present in today's explicit account selection:
agyin the few milliseconds between the check and the write can be overwritten. None of the stores offer compare-and-swap.Older paired hosts keep today's behaviour and wording. A plain revert backs it out, and nothing is migrated.
Level: Medium
AI Disclosure
Review
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)