Skip to content

fix(antigravity): free quota-limited chats when another saved account is selected, and switch it from the chat - #51498

Merged
AmoabaKelvin merged 4 commits into
mainfrom
fix/antigravity-usage-limit-account-switch
Nov 28, 2026
Merged

AmoabaKelvin merged 4 commits into
mainfrom
fix/antigravity-usage-limit-account-switch

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

When an Antigravity chat runs out of quota, switching to another saved Google account now frees it straight away. It continues on its own, or Continue works at once. The chat's usage-limit row also has a "Switch account" menu. If the account you switch to is itself out of quota, the row says so and waits for that account instead.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​241 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​241
Prod 42 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​793 $\color{#cf222e}{\Huge{\mathbf{−}}}$​80 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​713

What Changed

Builds on #50216 (merged), which records the saved account each agy launch ran on (launchedAccount.accountId).

Usage-limited chats move with the selection.

  • Release on a new selection. The usage-limit hold compared only account homes, and all of agy's saved accounts share one home. It now also checks the saved account the cut's launch ran on against the one a start would use now (new host dep launchAccountId). That launch account comes from the persisted record, so this also works after an Orca restart. A different account releases the chat at the moment of the switch. While a launch is known to fail to move agy's login to the selected account (fix(antigravity): switch saved accounts at once and move each chat at its next message #50216's latch), nothing is released, since the chat would only restart on the same spent login.
  • Accounts known to be out of quota. Each saved account's latest known reset is remembered. Switching to an account that is still out of quota doesn't release the chat. The hold waits for that account's reset, and the row says "personal@x is out of quota until 3:40 PM" ("That account is out of quota until 3:40 PM" when the saved account has no email). The phone waits for that later time too. The memory is per account and per cut, so the chat doesn't loop between two spent accounts.
  • Immediate re-check. The selection is part of the attribution witness. A committed switch wakes the auto-continue sweep at once instead of on its next 10-second tick.

Bot looks (generic, for any agent with saved accounts in one home):

  • A look cut short by a usage limit records the account it hit (usageLimited.accountId).
  • Selecting another saved account lifts the hold.
  • A switch wakes the look scheduler at once.

"Switch account" in an Antigravity chat's usage-limit row (desktop).

  • When the menu shows. A new host option field, canSwitchAntigravityAccount, controls it. All of these must hold:
    • the chat is a host Antigravity chat (not WSL);
    • it runs on agy's Google login (agy's own home, or an Orca home whose method is Google or Enterprise; not an API key or gcloud);
    • there are two or more saved accounts, including one other than the selected account;
    • no in-app sign-in is under way.
      It is computed from Orca's saved-accounts vault only; agy's keychain is never read. It is a separate field from canSwitchAccount because older phones show "Switch Account" for any agent that sets that field.
  • Menu contents. It lists the saved accounts by email with the selected one checked, plus "Manage Accounts…". It re-checks eligibility before switching, then shows the existing toast.

#50155: with #50216 this covers chats following an account switch and quota-limited chats moving to another account. The phone's "Switch account" menu is a separate PR.

Why

agy's saved accounts share one home, so "moved to another account" can only be decided by which saved account a launch ran on. Persisting that account (in #50216) means the hold still knows it after a restart. Remembering each account's reset is what stops a switch onto a spent account from releasing the chat just to hit the limit again.

Linked Issue

#50155

Visual Proof

The row after a switch onto an account that is itself out of quota (light / dark):

out of quota light
out of quota dark

The same, when that saved account has no email (light / dark):

unnamed out of quota light
unnamed out of quota dark

The "Switch account" button in the row, closed (light / dark):

closed light
closed dark

Open, with the selected account checked (light / dark):

open light
open dark

An account with no email (light / dark):

no email light
no email dark

Only one saved account (light / dark):

one account light
one account dark

All shots are from component fixtures: NativeChatUsageLimitRow:antigravityAccountOutOfQuota and AntigravityChatSwitcherMenu:*.

Testing

  • 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

  • structured-agent-session-usage-limit-saved-accounts.test.ts:

    • A fresh hold (as after a restart) reads the cut's account from the persisted record and frees the chat when another saved account is selected.
    • A switch onto an account still out of quota waits for that account's reset and names it.
  • bot-look-around-saved-account.test.ts: a look's usage-limit hold survives the store round-trip with its account, and selecting another account lifts it.

  • antigravity-chat-can-switch-account.test.ts:

    • Each eligibility condition flips the answer.
    • Agy's credential backend is never read.
  • pnpm check:changed: everything passes except one unit test, agent-cli-update-timeout.test.ts ("expected 87 to be less than 30"). It also fails when run on its own. I haven't checked whether it fails on main.

Performance

  • Per sweep pass: one in-memory selection read per held agy chat.
  • On a switch: one immediate auto-continue sweep and one look-scheduler tick.
  • Eligibility check: reads the vault file (no keychain), and only for usage-limited Antigravity chats when their options are read.
  • Nothing new polls.

Risk

Level: Medium

  • Riskiest part: the hold's new saved-account comparison. If it is wrong, a held agy chat could release too early: it would continue on a spent account, hit the limit again, and then wait for that account.
  • Older clients and hosts: an older client or phone ignores limitedAccount and shows the earlier time. Older hosts never send canSwitchAntigravityAccount, so no button appears.
  • Backing out: a plain revert of this PR.

AI Disclosure

Review

One round, Codex and a Claude reviewer. Fixed:

  • An API-key or gcloud Antigravity chat could carry a saved-account id and be freed by a switch it doesn't use. Launches that don't run on agy's Google login now record no saved account (in fix(antigravity): switch saved accounts at once and move each chat at its next message #50216).
  • A saved account with no email left the row without the "out of quota" line. It now says "That account is out of quota until …".
  • The phone took the earlier of the two times, so it offered Continue before the account it moved to had reset. It now waits for that account.

Left as is: after an Orca restart the selection is unknown until the first vault read, so the first sweep pass can miss a switch. The next pass (at most 10 s) catches it.

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

  • Remote hosts: the menu calls accounts.antigravitySelect on the chat's own host.
  • Mobile: the phone waits for the moved-to account's reset. The host option is a plain boolean, so the phone's menu can use it.
  • Windows: has no chats on agy, so nothing changes there.

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-usage-limit-account-switch branch 2 times, most recently from fcf09a9 to 666b4bc Compare November 28, 2026 07:12
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from 2435688 to d0253d8 Compare November 28, 2026 07:21
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-usage-limit-account-switch branch from 666b4bc to e2c4197 Compare November 28, 2026 07:29
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from d0253d8 to 6dcb769 Compare November 28, 2026 08:01
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-usage-limit-account-switch branch from e2c4197 to d7ae4fb Compare November 28, 2026 08:03
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from 6dcb769 to 78f8e0e Compare November 28, 2026 08:32
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-usage-limit-account-switch branch from d7ae4fb to 137566a Compare November 28, 2026 08:35
@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 fix/antigravity-usage-limit-account-switch branch from 137566a to 432377e Compare November 28, 2026 09:02
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from 3d272e6 to b067019 Compare November 28, 2026 09:23
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-usage-limit-account-switch branch from 432377e to b266680 Compare November 28, 2026 09:28
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from b067019 to ca5e07d Compare November 28, 2026 09:39
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-usage-limit-account-switch branch from b266680 to 27e9de2 Compare November 28, 2026 09:39
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from ca5e07d to c355b7b Compare November 28, 2026 10:19
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-chats-follow-account-switch branch from c355b7b to f0d8b89 Compare November 28, 2026 10:43
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/antigravity-usage-limit-account-switch branch from 27e9de2 to a40a302 Compare November 28, 2026 10:55
@AmoabaKelvin
AmoabaKelvin changed the base branch from fix/antigravity-chats-follow-account-switch to main November 28, 2026 10:56
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The changes add saved-account identity to bot usage-limit scheduling and native-chat quota attribution. Eligible Antigravity chats can switch to another saved account. Desktop and mobile usage-limit views can identify a destination account that remains out of quota and use its account-specific continuation time.

Merge Risk: Low · up to a40a3

The feature works for the main flows, but several edge cases remain. A scheduled bot look can start on an account that is still out of quota after the user switches back to it. The usage-limit row can show stale account or reset text for a few seconds after a switch. The account switcher can stay disabled after one failed load. On mobile, manual Continue can be missing in a narrow case. These are minor, bounded issues worth fixing before or soon after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: releasing quota-limited Antigravity chats when another saved account is selected, and adding an account switch from the chat. The changeset covers both, including…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (#50155), Visual Proof with images, Testing with checkboxes and specific tests, a Performance section…
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.
Full details: Title check

Explanation

The title names the two main changes: releasing quota-limited Antigravity chats when another saved account is selected, and adding an account switch from the chat. The changeset covers both, including the hold logic, the bot look hold, and the desktop switcher menu. The title is specific and follows the conventional prefix format. The title is 110 characters, which is long, but it stays readable.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (#50155), Visual Proof with images, Testing with checkboxes and specific tests, a Performance section, a Risk section with level and backout plan, a Review section, and Notes. The description is detailed and covers the mechanism, the scope, and the known test failure. Gaps: the Performance line is filled in, but the 'None, because' sentence is not finished as the template asks. The AI Disclosure section is empty. The 'Fixes #' line is replaced by 'Linked Issue #50155', which does not use the closing keyword. The manual testing box is unchecked, and the lint/typecheck/test/build box is unchecked. The Review section lists a fix from a prior round, so it is not empty. The description is mostly complete, so the check passes.

  • 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

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

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: 1a5bc5c7-bd69-43ab-a960-de9234f613b7
Commits

Reviewing files that changed from the base of the PR and between 5d7416c and a40a302.

Files selected for processing: 45

  • mobile/src/session/native-chat/status/use-mobile-native-chat-usage-limit.ts
  • mobile/src/session/native-chat/transcript/notices/MobileNativeChatUsageLimitStatus.tsx
  • src/main/antigravity/agy-usage-limit-accounts.ts
  • src/main/antigravity/antigravity-chat-can-switch-account.test.ts
  • src/main/antigravity/antigravity-chat-can-switch-account.ts
  • src/main/antigravity/native-account-service.ts
  • src/main/bots/bot-activity-host.ts
  • src/main/bots/bot-background-run-history.ts
  • src/main/bots/bot-look-around-failures.ts
  • src/main/bots/bot-look-around-runner.ts
  • src/main/bots/bot-look-around-runtime.ts
  • src/main/bots/bot-look-around-saved-account.test.ts
  • src/main/bots/bot-look-around-schedule.ts
  • src/main/bots/bot-look-around-store.ts
  • src/main/native-chat/agent-session-wire/host/structured-agent-session-host-types.ts
  • src/main/native-chat/agent-session-wire/observations/structured-agent-session-status-summary-equality.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-recovery-read.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-hold.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-account-types.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-continue.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-published.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-relaunch.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-saved-accounts.test.ts
  • src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-saved-accounts.ts
  • src/main/providers/accounts/selected-saved-account.ts
  • src/main/runtime/agent-session/installation/runtime-structured-agent-host.ts
  • src/main/runtime/agent-session/installation/runtime-structured-agent-session-bootstrap.ts
  • src/main/runtime/agent-session/installation/structured-agent-session-host-assembly.ts
  • src/main/runtime/agent-session/installation/structured-agent-session-runtime-contract.ts
  • src/renderer/src/components/native-chat/messages/notices/native-chat-orca-stop-context.ts
  • src/renderer/src/components/native-chat/session/options/structured/use-structured-agent-session-option-state.ts
  • src/renderer/src/components/native-chat/usage/NativeChatInterruptedContinue.tsx
  • src/renderer/src/components/native-chat/usage/NativeChatUsageLimitActions.tsx
  • src/renderer/src/components/native-chat/usage/NativeChatUsageLimitRow.fixture.tsx
  • src/renderer/src/components/native-chat/usage/NativeChatUsageLimitRow.tsx
  • src/renderer/src/components/native-chat/usage/native-chat-usage-limit-row-words.ts
  • src/renderer/src/components/native-chat/usage/use-native-chat-usage-limit-auto-continue.ts
  • src/renderer/src/components/status-bar/accounts/AntigravityChatSwitcherMenu.fixture.tsx
  • src/renderer/src/components/status-bar/accounts/AntigravityChatSwitcherMenu.tsx
  • src/renderer/src/components/status-bar/accounts/ProviderAccountChatButton.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/agent-session/lifecycle/stopping/agent-session-usage-limit-continue-wire.ts
  • src/shared/agent-session/options/protocol/agent-session-options-result.ts
  • src/shared/agent-session/options/reconciliation/structured-agent-session-options-read-owner.ts
  • src/shared/native-chat/transcript/continuation/native-chat-usage-limit-auto-continue.ts

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

Comment on lines +90 to +92
? movedOutOfQuota
? actions.continueAt
: Math.min(resetsAt, actions.continueAt)

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

Select the reset for Continue from the published continue state, not the failure fact.

MobileNativeChatUsageLimitStatus reads resetsAt from failure.usageLimit?.resetsAt. The usage-limit type documents that this value can be absent. When the host supplies a reset through an account move or relaunch, the published continue summary carries the effective reset. When the failure has no reset and the chat moved to a limited saved account, resetPassed stays false. The Continue action then stays hidden after that reset passes. Auto-continuation still sends the message, so this affects only manual continuation from mobile.

Derive the reset that useResetPassed and the continueNow gate use from the published continue state. Use the failure reset only as a fallback. The exact published field must be confirmed in the mobile usage-limit contract before the change is made.

Comment on lines +43 to +44
if (!limit || (limit.accountId && selected && selected !== limit.accountId)) {
return 0

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

Retain the selected account's earlier quota hold.

If A hits quota until 12:00 and B then hits quota until 13:00, selecting A again returns 0. findLast chooses B, and this branch ignores A's earlier limit. An otherwise-due scheduled look can then start before A's reset.

Resolve outstanding limits per account. Returning to A must retain A's reset; selecting a fresh account must still release the hold.

// A new saved account lifts a look's wait for the limit another account hit: look now.
onSavedAccountSelected(() => {
void Promise.resolve()
.then(() => runtimeLookAroundRunner(runtime).tick())

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

Preserve selection-triggered ticks while a tick is active.

If a tick has already checked a limited bot and then awaits another bot's hadConversation, an account change calls tick() while ticking is true. That call returns immediately. The active tick does not revisit the limited bot, so the account change waits for the next scheduler tick.

Record one pending rerun and process it after the active tick. Keep the existing guard against concurrent ticks.

this.timer = setInterval(() => void this.tick(), 10_000)
this.timer.unref?.()
// A newly selected saved account can free a held chat at once.
this.stopAccounts = this.deps.host.usageLimitAutoContinue?.subscribeAccounts?.(this.tick)

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

Publish the updated schedule after account attribution.

This callback runs tick, but tick publishes schedules before it updates account attribution. If the selected account has a future quota reset, no send follows and the pass publishes no updated status. The row can show the previous account and reset until the next 10-second sweep.

Publish the affected status after attribution so the account-change pass exposes the new account and deadline.

Comment on lines +83 to +85
} catch (error) {
console.error('Failed to load Antigravity accounts for the chat:', error)
}

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

Provide a retry after the initial account-list failure.

If the first List request fails, state remains null. The shared control then disables the trigger because loaded is false. The user cannot open the menu to start another load(), and the mount effect does not retry.

Provide an error-state retry action or a bounded automatic retry. Keep the trigger disabled while a request is pending, not permanently after a temporary failure.

@AmoabaKelvin AmoabaKelvin reopened this Nov 28, 2026
@AmoabaKelvin
AmoabaKelvin merged commit b9a1d24 into main Nov 28, 2026
68 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