Skip to content

fix(antigravity): protect active account removal - #21797

Merged
nwparker merged 1 commit into
nwparker/agy-native-accountsfrom
nwparker/agy-account-removal-guard
Sep 21, 2026
Merged

nwparker merged 1 commit into
nwparker/agy-native-accountsfrom
nwparker/agy-account-removal-guard

Conversation

@nwparker

@nwparker nwparker commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

What changed

Protects the active native Antigravity account even when an account removal request arrives before the first Accounts list refresh. The service now resolves the live native credential inside removeAccount and rejects removal of that account; the existing in-memory active ID guard remains as a second protection.

ELI5: the Accounts screen normally tells the service which account is active. If a remove click arrives before that first refresh finishes, the service now checks the keychain itself before deleting anything.

Verification

  • 31 focused native-account/credential tests passed.
  • pnpm tc:node passed.
  • pnpm run check:code-quality:changed origin/main passed.
  • Added a regression test that calls removeAccount before listAccounts.

No UI changed, so visual proof is not applicable. This is stacked on #21784.

@nwparker

Copy link
Copy Markdown
Contributor Author

Independent verification (2026-09-20):

  • Native account/credential/removal-guard suites: 31/31 passed.
  • pnpm tc:node passed.
  • pnpm run check:code-quality:changed origin/main passed with 0 new findings across 197 changed files.
  • Installed agy 1.2.7 authenticated exact sentinel returned AGY_GUARD_OK.
  • Full CI 35513859585 is green across all test shards, typecheck, static analysis, and macOS/Windows packages.

Verdict: approve stacked on #21784. The active-account guard is verified, including protection before the first refresh; broader platform account backends remain outside the stack. No merge performed.

@nwparker

Copy link
Copy Markdown
Contributor Author

ELI5 / evidence / trade-offs audit

ELI5: Orca refuses to remove an account while another part of Orca still needs it, preventing an accidental sign-out.

Proof: Removal-guard tests and CI pass; no independent screenshot is applicable to this guard-path change.

User-facing trade-off: A removal can be blocked until the dependent session is closed.

This note scopes the claim to the evidence above; it does not claim untested remote, SSH, WSL, or vendor combinations.

@nwparker
nwparker marked this pull request as ready for review September 21, 2026 01:04
@nwparker
nwparker merged commit 2e59dae into nwparker/agy-native-accounts Sep 21, 2026
29 checks passed

@pullfrog pullfrog 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.

ℹ️ No blocking issues — the pre-refresh guard is correctly implemented and tested. One durability question and a small rough edge below.

Reviewed changes

  • removeAccount re-reads the live credential before deleting — src/main/antigravity/native-account-service.ts:111 now resolves the active account from the Keychain via knownActiveAccount before filtering the store, so a removal is refused when the target is active even if listAccounts never ran. The in-memory activeAccountId check stays as a secondary guard.
  • Regression test for removal before the first refresh — src/main/antigravity/native-account-service.test.ts:73 constructs the service and calls removeAccount with no prior listAccounts; it fails against the pre-PR code, so it genuinely pins the new behavior.

ℹ️ The live-read guard inherits knownActiveAccount's hash-equality contract

The guard is only as strong as the id match underneath it. knownActiveAccount compares accountId(current.contents) — a SHA-256 of the entire Keychain blob — against stored record ids, and nothing in the repo re-syncs a stored record after the live blob changes. Any external byte-level rewrite (an OAuth token refresh, or a CLI-upgrade re-serialization that selectAccount's own comment at line 94 already anticipates) makes the match fail, at which point both this guard and listAccounts' activeAccountId go null and the Remove button reappears on every row. This PR correctly covers the pre-refresh case it targets; the open question is whether it is expected to keep protecting after a rotation.

Technical details
# Active-account id is a hash of the mutable credential blob

## Affected sites
- `src/main/antigravity/native-account-service.ts:36` — `accountId()` hashes the whole `contents`, including `token.access_token`.
- `src/main/antigravity/native-account-service.ts:119` — `knownActiveAccount` re-hashes the live blob and returns `null` on any mismatch.
- `src/main/antigravity/native-account-service.ts:112` — the new guard, and `listAccounts` at line 62, both depend on that match.
- `src/main/antigravity/native-account-service.ts:66` — `addCurrentAccount` is the only writer of stored `credentials`; it appends a new record rather than updating the existing one.

## Required outcome
- Either confirm the `agy` Keychain blob is byte-stable across token refreshes (no change needed), or key the active-account match on a stable identity (e.g. `identity.subject`) instead of a hash of the volatile blob.

## Open questions for the human
- Does `agy` rewrite the `gemini`/`antigravity` Keychain item when it refreshes an OAuth token?
- Is "protect the active account" expected to survive an external credential rewrite, or is the pre-refresh window the whole scope here?

ℹ️ Nitpicks

  • removeAccount now fails closed on a Keychain read error: readAntigravityMacOSCredential throws on a security timeout or unexpected exit, so removing an unrelated account can now fail where it previously succeeded, surfacing the raw backend message as a toast.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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