Skip to content

feat(antigravity): ask, restart or keep agy running in terminals when you switch accounts - #51652

Merged
AmoabaKelvin merged 11 commits into
mainfrom
feat/antigravity-switch-running-terminals
Nov 28, 2026
Merged

AmoabaKelvin merged 11 commits into
mainfrom
feat/antigravity-switch-running-terminals

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

agy keeps one Google login per computer. When you switch your Antigravity account in Orca, any agy already running in a terminal keeps working on the old account until you restart it. Now Orca deals with those terminals the same way it does for Claude: it asks you (by default), restarts them for you, or leaves them alone, depending on a new setting.

Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​479 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​469
Prod 56 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1987 $\color{#cf222e}{\Huge{\mathbf{−}}}$​392 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1595

What Changed

Before: after #50216, picking another saved Antigravity account switched new chats and new agy launches right away, but agy already running in Orca terminals stayed on the old account. Its hourly token refresh could even write the old login back over the switch until the next launch put the selected account back.

After, with the new setting When you switch accounts while agy is running in terminals (Settings → AI Provider Accounts → Antigravity):

  • Ask (default): a switch made in this window opens the same "Switched to {account}" dialog Claude uses, listing every terminal still running agy on the old account, with checkboxes, Keep as is and Restart N sessions. Terminals on some other earlier account are listed unticked under "Not on {account}".
  • Always restart: those terminals restart at once and a toast says so ("Restarting 2 Antigravity sessions on {account}", with Review when others were left).
  • Never restart: nothing restarts. The terminal finishes on the old account, and fix(antigravity): switch saved accounts at once and move each chat at its next message #50216's re-assert puts the selected login back at the next launch.

A restart stops that terminal's agy, waits for it to exit, and relaunches agy --conversation <id> with the conversation its hooks reported. A terminal whose conversation Orca doesn't know restarts fresh, and the dialog says so on its row and in its text. WSL and SSH terminals are never touched, since the switch only changes this host's login.

Switches made somewhere else follow the setting too. A switch from the CLI on a desktop host goes to the desktop window, where Ask restarts instead of opening a dialog nobody at the CLI can answer (as Claude does since #41064). Terminals the window shows no pane for (an agy started in the background in a workspace it never opened) are moved by the host by the window's rule. A server with no window restarts by the switching client's own setting, fresh where it doesn't know the conversation; under Ask it leaves them and the switching client gets a toast with Restart, which answers it.

Mechanism:

  • Main owns which terminals run agy and on which account (antigravity-running-pane-account-move.ts). At each switch it lists the host's own terminals with agy in front (status row, saved record or launch, checked by a foreground read), skipping SSH, WSL, other servers' and chat-owned panes, and terminals whose spawn environment gives agy another credential authority (the same agyLaunchIsForeign decision chat launches use, noted per pane as each terminal spawns and dropped when that terminal exits), and notes the account each agy invocation runs on, so switching back to it moves nothing. The note ends when the terminal's command finishes or exits, or its hooks report another conversation.
  • accounts.antigravitySelect takes movesRunningSessions (this desktop window restarts its own), runningSessions (another client's choice) and answersAsk; the previous selection is read inside the same serialized select. Clients send the new params only to hosts that advertise accounts.antigravity-running-terminals.v1, since older hosts reject unknown params. accounts.antigravityMoveUnheldTerminals takes the terminals the window can't show.
  • The window restarts through the existing per-pane restart queue (AccountRestartAgent now includes antigravity), which already handles mounted and unmounted tabs. The host uses restartAgentPaneInPlace, which now also starts an agent afresh when it is given no conversation.
  • Claude's dialog, session tree, toasts and setting are now shared by agent (account-switch-copy.ts, account-switch-prompt.ts, account-switch-toasts.ts, AccountSwitchPromptDialog, RunningSessionSwitchSetting). Claude's copy and behaviour are unchanged. The window notice is one accountSelectedElsewhere(agent, change) for both.

Mobile: Claude's running-session switch has no phone surface (the phone only switches; the host follows its policy), and the phone can't switch Antigravity accounts at all, so nothing changes on mobile.

Why

The product call was to match Claude: a setting with Ask / Always restart / Keep, the same dialog and toasts. agy has a single login per host, so unlike Claude there are no per-pane account folders to read; the only reliable record of which account a running agy is on is the selection when it started, which main notes at every switch. Main does the listing because it owns the PTYs, their foreground reads and the selection, and it is the only place a windowless server can act. The window still runs its own restarts so its panes keep their xterm and focus, and so a terminal without a known conversation can restart fresh, which the in-place restart can't.

Linked Issue

Builds on #50216 (merged; Antigravity chats follow an account switch). Part of #50155.

Visual Proof

Component fixtures from the production components, light and dark:

No before shots: none of these existed for Antigravity. Claude's dialog is included to show it is unchanged by the shared component.

Ask, several terminals (light) Ask, several terminals (dark)
One terminal, conversation unknown Review from the restart toast
Setting (light) Setting (dark)
Always restart toast Server left them under Ask
Claude's dialog, same component

Testing

  • I manually tested these changes locally (not in the running app: see below)

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

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

  • antigravity-running-pane-account-move.test.ts (main, real runtime with a fake PTY controller): a restart stops the terminal, waits for its exit, then relaunches agy --conversation conv; Keep never restarts; a windowless host under Ask leaves terminals until answersAsk; the client's choice overrides the host setting; a CLI switch on a desktop host goes to the window and restarts nothing in main; SSH and WSL terminals are skipped; a kept terminal is listed on its own account, so switching back lists nothing; agy run again in a kept terminal is listed on the account selected as it started; an unknown conversation restarts as a new agy and the reply says so; the host moves terminals the window lacks.

  • antigravity-account-switch-sessions.test.ts (renderer store): a switch made elsewhere under Ask queues restarts with no dialog; a switch made here under Ask opens the dialog and restarts what the answer picks; a switch back drops a queued restart; Keep never queues.

  • Fixture screenshots above. I didn't run agy against a real login (it would read and write the real keychain item), so the end-to-end check is the tests at the owner plus the fixtures.

  • pnpm check:changed passes. macOS only.

Performance

None that matters, because the work runs only when a saved Antigravity account is switched: main reads the foreground of each terminal with agy evidence, one at a time, and skips the process scan when the cached foreground is a shell. Nothing new runs on any hot path, timer or render. The account map holds one string per live agy terminal and is pruned at each switch.

Risk

The riskiest part is the shared restart queue and the generalized Claude dialog: a mistake there would change what a Claude account switch restarts. Claude's queue rules are kept as they were (agent !== 'codex' where the code said agent === 'claude'), and its copy is the same keys and strings. An older desktop talking to a new host sends no new params and gets the host's own setting; a new desktop talking to an older host sends none and gets today's behaviour. Back out with a plain revert; the new setting key is ignored afterwards.

Level: Medium

Review

One review round (Codex and a Claude reviewer with a performance pass). No P0. Fixed from it:

  • A terminal where agy was quit and run again kept the old invocation's account. Main now forgets the note when the terminal's command finishes or exits, and when its hooks report a different conversation.
  • Terminals the window shows no pane for (a background agy in a workspace it never opened) were dropped. The window now hands those to the host (accounts.antigravityMoveUnheldTerminals), which moves them by the window's rule, as Claude's unheld sessions are.
  • A queued restart survived a switch back to its terminal's account; each switch now drops queued agy restarts the host no longer lists. Every switch also clears a dialog left open by an earlier one.
  • A fresh restart could replace a pane that had since left agy; it now requires the pane to still show agy.
  • Concurrent selections could read the same previous account; the previous selection is now read inside the serialized select.
  • Foreground checks run one at a time and skip the process scan when the cached foreground is a shell; an unreadable foreground keeps its note.
  • A server with no window now restarts agy with an unknown conversation fresh, as the desktop does, and its toast says how many started a new conversation.

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

  • Windows host: the switch writes the host default credential, so running agy terminals there are listed and restarted the same way. WSL terminals are skipped.
  • Remote: a paired server moves its own terminals; SSH panes are never touched.

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)

@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from 78f8e0e to 3d272e6 Compare November 28, 2026 09:00
@AmoabaKelvin
AmoabaKelvin force-pushed the feat/antigravity-switch-running-terminals branch from 0a2f242 to f2a1319 Compare November 28, 2026 09:22
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch 2 times, most recently from b067019 to ca5e07d Compare November 28, 2026 09:39
@AmoabaKelvin
AmoabaKelvin force-pushed the feat/antigravity-switch-running-terminals branch from f2a1319 to 6f60629 Compare November 28, 2026 09:48
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch 2 times, most recently from c355b7b to f0d8b89 Compare November 28, 2026 10:43
@AmoabaKelvin
AmoabaKelvin force-pushed the feat/antigravity-switch-running-terminals branch from 6f60629 to ee5a5a8 Compare November 28, 2026 11:04
@AmoabaKelvin
AmoabaKelvin changed the base branch from fix/antigravity-chats-follow-account-switch to main November 28, 2026 11:04
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds Antigravity account-switch handling for running terminals, including terminal credential tracking, host-side move policies, and renderer prompts and settings. It extends account-selection RPCs and notifications to carry terminal-move results. Claude and Antigravity now share account-switch prompt, session-tree, setting, and toast components. Restart handling supports fresh Antigravity sessions when no conversation is available.

Merge Risk: Moderate · up to 8bc5b · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

This adds Ask, restart or keep handling for running agy terminals when you switch accounts. Several race and attribution cases remain open: a stale or superseded choice could stop a terminal that should have been left alone, and some terminals could be restarted or listed incorrectly. These are limited to opted-in agy terminals and can be avoided with Keep, but they should be resolved or explicitly accepted before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Antigravity (agy) terminals running under the old account can now be asked about, restarted, or kept when the user switches accounts. The raw summary and objectives co…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template closely. It has all required sections: ELI5, What Changed (before/after plus mechanism), Why (product rationale and alternatives), Linked Issue (referen…
Full details: Title check

Explanation

The title names the main change: Antigravity (agy) terminals running under the old account can now be asked about, restarted, or kept when the user switches accounts. The raw summary and objectives confirm a new setting with Ask, Always restart, and Never restart options, plus the dialog, restart queue, and host-side terminal tracking. The title is specific and matches the changeset. It is one sentence, though long at 89 characters.

Full details: Description check

Explanation

The description follows the repository template closely. It has all required sections: ELI5, What Changed (before/after plus mechanism), Why (product rationale and alternatives), Linked Issue (references #50216 as a builds-on link and #50155 as part of, but does not use a 'Fixes #' issue link), Visual Proof (fixture screenshots for light and dark modes, with the Claude comparison), Testing (automated tests listed with specific cases; manual testing explicitly not done in the running app), Performance (explained), Risk (level Medium, with rollback guidance), Review, Agent skill boundary (checked), Notes, and Checklist. The Linked Issue section does not contain a real issue that the template requires for outside contributors, and the manual-testing checkbox is left unchecked with an explanation. The AI Disclosure section is left blank with no statement about AI use, though the template says to omit it only for StablyAI team members. These gaps are minor, so the description is mostly complete.

  • 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

Recent 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: 2bcf9486-bed1-400a-9989-594254892283
Commits

Reviewing files that changed from the base of the PR and between ee5a5a8 and 8bc5b87.

Files ignored due to path filters: 1

  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 7

  • src/main/antigravity/native-account-login-view.ts
  • src/main/antigravity/native-account-service.ts
  • src/main/antigravity/native-account-store.test.ts
  • src/main/runtime/rpc/methods/accounts/antigravity-account-select.ts
  • src/main/runtime/rpc/methods/accounts/antigravity-accounts.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/remote-runtime/protocol/account-runtime-capabilities.ts
Files skipped from review as they are similar to previous changes: 1

  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@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: 11

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: 39a3e8cf-854b-4f07-b4e3-43eded87ca52
Commits

Reviewing files that changed from the base of the PR and between 1015f3d and ee5a5a8.

Files ignored due to path filters: 1

  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
Files selected for processing: 57

  • src/main/antigravity/agy-terminal-authority.test.ts
  • src/main/antigravity/agy-terminal-authority.ts
  • src/main/antigravity/native-account-launch.ts
  • src/main/antigravity/native-account-service.ts
  • src/main/runtime/client/events/runtime-notifier-contract.ts
  • src/main/runtime/construction/runtime-store-contract.ts
  • src/main/runtime/rpc/methods/accounts/antigravity-accounts.test.ts
  • src/main/runtime/rpc/methods/accounts/antigravity-accounts.ts
  • src/main/runtime/rpc/methods/accounts/antigravity-terminals-ask-answer.ts
  • src/main/runtime/session-lifecycle/projection/antigravity-running-pane-account-move.test.ts
  • src/main/runtime/session-lifecycle/projection/antigravity-running-pane-account-move.ts
  • src/main/runtime/session-lifecycle/projection/claude-running-pane-account-move.ts
  • src/main/runtime/session-lifecycle/projection/mcp-stale-terminal-restart.ts
  • src/main/runtime/session-lifecycle/projection/restart-agent-pane-in-place.ts
  • src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts
  • src/main/runtime/terminal/lifecycle/pty-registration.ts
  • src/main/runtime/terminal/output/terminal-orchestration-authority.ts
  • src/main/window/runtime-window-lifecycle.ts
  • src/preload/api-types.ts
  • src/preload/api/agent-accounts/agent-account-api.ts
  • src/preload/api/agent-accounts/antigravity-accounts-bridge.ts
  • src/preload/index.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/components/provider-accounts/account-switch/AccountSwitchDialog.tsx
  • src/renderer/src/components/provider-accounts/account-switch/AccountSwitchPromptDialog.fixture.tsx
  • src/renderer/src/components/provider-accounts/account-switch/AccountSwitchPromptDialog.tsx
  • src/renderer/src/components/provider-accounts/account-switch/AccountSwitchSessionTree.tsx
  • src/renderer/src/components/provider-accounts/claude/ClaudeAccountSwitchDialog.tsx
  • src/renderer/src/components/settings/accounts/claude/accounts-pane-claude-section.tsx
  • src/renderer/src/components/settings/accounts/providers/AntigravityAccountSwitchToast.fixture.tsx
  • src/renderer/src/components/settings/accounts/providers/AntigravityAccountsSection.tsx
  • src/renderer/src/components/settings/accounts/running-session-switch-setting.fixture.tsx
  • src/renderer/src/components/settings/accounts/running-session-switch-setting.tsx
  • src/renderer/src/components/terminal-pane/account-restart/detached/codex-detached-pane-restart.ts
  • src/renderer/src/components/terminal-pane/account-restart/pane-account-restart-readiness.ts
  • src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/agent-session/accounts/agent-account-restart-startup.ts
  • src/renderer/src/lib/agent-session/accounts/claude/claude-session-account-move.ts
  • src/renderer/src/lib/provider-accounts/account-switch-copy.ts
  • src/renderer/src/lib/provider-accounts/account-switch-prompt.ts
  • src/renderer/src/lib/provider-accounts/account-switch-toasts.ts
  • src/renderer/src/lib/provider-accounts/antigravity-account-switch-ipc-bridge.ts
  • src/renderer/src/lib/provider-accounts/antigravity-account-switch-sessions.test.ts
  • src/renderer/src/lib/provider-accounts/antigravity-account-switch-sessions.ts
  • src/renderer/src/lib/provider-accounts/claude-account-switch-sessions.ts
  • src/renderer/src/lib/provider-accounts/claude-account-switch-toasts.ts
  • src/renderer/src/runtime/provider-accounts/sign-in/runtime-antigravity-accounts-client.ts
  • src/renderer/src/store/terminals/pty/terminal-restart-state.ts
  • src/renderer/src/store/terminals/terminal-contracts.ts
  • src/shared/agent-accounts/antigravity/antigravity-account-switch-settings.ts
  • src/shared/agent-accounts/antigravity/antigravity-account-types.ts
  • src/shared/agent-accounts/managed-account-types.ts
  • src/shared/remote-runtime/protocol/account-runtime-capabilities.ts
  • src/shared/rpc-contract/accounts/antigravity-accounts-params.ts
  • src/shared/settings/global-settings-base.ts
Files with no reviewable changes: 2

  • src/renderer/src/components/provider-accounts/claude/ClaudeAccountSwitchDialog.tsx
  • src/renderer/src/lib/agent-session/accounts/claude/claude-session-account-move.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

/** Whether agy in this pane's terminal reads another login than the host's own; false when its
* spawn wasn't seen (it then inherited the host's environment). */
export function agyTerminalIsForeign(paneKey: string): Promise<boolean> {
return authorityByPaneKey.get(paneKey)?.foreign ?? Promise.resolve(false)

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 · Functional Correctness · Heavy lift

Restore the credential-authority verdict when a daemon terminal is reattached.

The verdict is kept only in authorityByPaneKey. That map starts empty and gains an entry only from noteAgyTerminalAuthority, which runs when a new host terminal is prepared. A daemon terminal that survives an application restart is reattached without that preparation. Its pane has no entry, so agyTerminalIsForeign returns false. The terminal then counts as host-owned and can be listed and restarted under a saved account. If the terminal was spawned with another HOME, its agy reads a different login, which the switch contract excludes.

Required behavior: a reattached terminal must keep the authority it was spawned with. Until that authority is known, the terminal must not be treated as host-owned in account-switch moves. Choose the restore mechanism and the exclusion rule for unknown authority in the implementation.

await this.store.write(latest)
if (switching) {
switched?.()
switched?.(previous)

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 · Functional Correctness · Quick win

Handle saved-account changes even when the native login needs no write.

If an A terminal is still running and agy's native login already holds B, selecting B saves the change from A to B without calling switched. The RPC then skips terminal handling, so neither Ask nor Always restart applies. A retry can reach the same state if the first attempt wrote B but failed to save the selection.

After a verified login and successful vault save, notify the terminal handler when the saved selection changes. Keep a repeated selection with no saved change and no native write as a no-op.

service: Awaited<ReturnType<typeof getAntigravityAccountService>>
): Promise<AntigravityAccountSelectResult> {
const moved =
target.runtime === 'host' ? await runtime.answerAntigravityAsk(accountId) : undefined

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

An Ask answer can stop agy terminals after a later switch selected Keep.

answerAntigravityAsk checks the selected account once, before it awaits listAgyTerminals. A switch that commits during that await changes the selection. The answer then still calls restartAgyTerminals. Its restart guard, agyTerminalStillMoves, compares only the terminal's noted account with the current selection. A terminal noted to the previous account passes that comparison, so restartAgentPaneInPlace can stop it and relaunch it on the newly selected account, even though that switch chose Keep.

The check that runs before the stop needs to confirm that the selection still equals the account the answer was given for. Apply that check after the last await and before the stop.

): Promise<ClaudeHostRunningSessionsMove | undefined> {
return this.planAgy(async () => {
// A later switch replaced this one: its own listing covers these terminals.
if (AGY_HOST_SELECTION.current() !== move.accountId) {

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 · Functional Correctness · Heavy lift

Reject unheld-terminal requests from earlier switches to the same account.

An A→B handoff with restart can arrive after B→A and a new A→B switch with Keep. The account check still matches B. If the terminal is still on A, the old handoff can stop it despite the newer Keep choice.

Include a switch ID in runningTerminals and require it in the handoff. Validate the ID before applying the request's policy, including after the asynchronous scan.

Comment on lines +183 to +188
const canRestart = onPrevious.filter((terminal) => this.agyTerminalRestartable(terminal)).length
if (canRestart > 0) {
this.askedAgyMove = {
from: move.from,
to: move.to,
...(move.ptyIds ? { ptyIds: move.ptyIds } : {})

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 · Functional Correctness · Quick win

Limit Ask replies to the terminals the toast offered.

If P is restartable and Q's foreground is unreadable, the toast can offer one restart while Q retains its earlier account note. If Q becomes readable before the reply, the headless answer scans both terminals and can restart both. The window handoff also stores the full requested set rather than the subset that qualified.

Store the PTY IDs that qualify when you build the offer. On reply, recheck only those IDs. This still allows P to restart and lets the final guard reject P if it is no longer eligible.

(noted.conversationId === null ||
conversationId === null ||
noted.conversationId === conversationId)
const account = sameInvocation ? noted.account : unnoted

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 · Heavy lift

Do not attribute a post-switch invocation to the outgoing account.

If the scan waits on one PTY, a user can start agy on B in another shell already in the scan snapshot. When the loop reaches that shell, it can see the new invocation but has no account note for it. The fallback records A, so Always restart can stop a session that already uses B.

Use invocation-level launch evidence to establish that an unnoted invocation predates the switch before attributing it to A. Keep pre-switch A invocations eligible. Do not stop a newly discovered invocation automatically when its account cannot be established.

Comment on lines +341 to +343
normalizeAgentProviderSession(
record?.agent === 'antigravity' ? record.providerSession : undefined
)

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 · Heavy lift

Clear or scope the saved Antigravity session before it resolves a new invocation.

The resolver falls back to the saved pane record when the live row has no providerSession. Nothing in the inspected paths removes that record when an agy invocation exits. A new invocation that has not yet reported its conversation can therefore inherit the previous conversation. A restart on account switch then resumes that conversation instead of starting fresh, which the PR describes as the behavior for an unknown conversation.

The fix needs a rule for invocation identity, such as clearing the record on invocation exit or accepting the fallback only for the invocation that wrote it. The inspected code does not establish which rule the design requires, so this comment does not propose a patch.

? copy.reviewBody(elsewhere.length + cantMove.length, prompt.nextAccountLabel)
: copy.body({
count: onAccount.length,
fresh: onAccount.filter((session) => session.reason).length,

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 · Functional Correctness · Quick win

Show a fresh-start warning for ticked elsewhere terminals.

Elsewhere terminals never get the new-conversation reason. This is because only onAccount terminals run the resume check. A terminal on a third account whose conversation is unknown restarts fresh when ticked, but the dialog does not say so. The body and the fresh count cover only onAccount. The restart button still counts the ticked elsewhere terminals.

Apply the same resume check to elsewhere terminals. Mark each one that cannot resume with the same fresh-start reason that onAccount terminals get. Derive the fresh-start count from the ticked sessions, not from onAccount alone, so the body text and the restart button both reflect every terminal that will restart without its conversation.

const reply = await callRuntimeRpc<AntigravityAccountSelectResult>(
owner,
'accounts.antigravitySelect',
{ target, accountId, answersAsk: true },

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 · Heavy lift

Bind each Antigravity Ask answer to the Ask it answers.

An Ask answer carries only accountId. The host accepts it whenever the latest Ask targets that account and the account is still selected. An answer from an older toast therefore acts on a newer Ask for the same account. After host B→C→B, a stale B answer restarts the terminals that the C→B Ask captured. The stale toast never listed those terminals, and busy agent turns stop without the user answering that prompt.

Claude avoids this with an Ask ID. The Antigravity contract needs the same guarantee. Assign each Ask an ID when the host records it. Pass that ID with the answer. Reject the answer when the IDs differ, as the Claude path does at claude-host-account-switch.ts:96.

next: savedAccountLabel(next, accountId)
},
() => answerHostAsk(owner, accountId, target),
replaceHostAsk(owner)

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 · Functional Correctness · Quick win

Do not dismiss the host Ask after a WSL account selection.

If this owner already has a host-terminal Ask, selecting a WSL account removes that toast. The WSL result has no terminal move, but this call still evaluates replaceHostAsk(owner). No replacement action appears, so the client loses its host-terminal restart action.

Return 'show-confirmation' for non-host targets before replacing the host Ask. Keep replacement enabled for later host selections.

@AmoabaKelvin
AmoabaKelvin force-pushed the feat/antigravity-switch-running-terminals branch from ee5a5a8 to 8bc5b87 Compare November 28, 2026 12:35
@AmoabaKelvin
AmoabaKelvin merged commit f44167e into main Nov 28, 2026
57 of 58 checks passed
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