Skip to content

feat(antigravity): detect a host's API key and gcloud login, and offer them in Chat - #44965

Merged
nwparker merged 9 commits into
mainfrom
nwparker/agy-auth-detect
Nov 20, 2026
Merged

nwparker merged 9 commits into
mainfrom
nwparker/agy-auth-detect

Conversation

@nwparker

@nwparker nwparker commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you already have a Gemini API key or a gcloud login, Antigravity Chat now finds it and offers it as a one-click button. You no longer have to know that Settings has a "Sign in with" dropdown. A small chip under the composer always shows how the chat signs in, and lets you change it.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​256 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​256
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1743 $\color{#cf222e}{\Huge{\mathbf{−}}}$​206 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1537

What Changed

  • Detection RPC accounts.antigravityChatAuthDetect (accounts-admin, no params), gated by a new capability accounts.antigravity-chat-auth-detect.v1. Older SSH/WSL hosts show no detections. It returns only flags and labels, never a secret:
    • the saved method;
    • whether Orca's managed server has a saved Google sign-in, for both personal and Enterprise;
    • apiKey: {available, source: 'saved' | 'environment'};
    • adc: {available, project}, from GOOGLE_APPLICATION_CREDENTIALS or gcloud's default file (%APPDATA%\gcloud on Windows, ~/.config/gcloud elsewhere, or CLOUDSDK_CONFIG). The project comes from the existing resolver, which reads files and never runs gcloud;
    • liveChats, the number of running chats a switch would restart.
  • Signed-out strip becomes a chooser. Detected options come first, each a one-click switch with a hint: "Use your Gemini API key" ("Found GEMINI_API_KEY in your environment" or "Saved in Orca"), then "Use gcloud (project)". Below them are "Sign in with Google" (starts the flow right there) and "More options…". When nothing is detected, it shows "Sign in with Google" and a clear "Use an API key or gcloud instead" link to Settings.
  • Failure recovery. A failed sign-in with no subscription or an ineligible account now says so plainly in the strip. Antigravity transcript rows for Google auth failures (PERMISSION_DENIED, UNAUTHENTICATED, a 401/403 next to "unauthorized" or "forbidden", or an invalid API key), quota errors (RESOURCE_EXHAUSTED, "Usage limit reached") or not signed in now offer the detected alternative. Example: "This Google account has no Antigravity subscription. Use the Gemini API key found in your environment instead?" A bare 401, 403 or 429 from a tool's own request does not trigger the offer.
  • Method chip in the composer footer ("Gemini API key ▾", "Google Agent Platform · project ▾", …). Its menu marks the active method, tags detected ones "Detected", and sends methods that need input (Enterprise, or a key or gcloud that isn't set up) to Settings.
  • STA-15489: after a restart, a saved Google token (file exists and parses as JSON) seeds the host's chat auth as signed in, so Settings and the chat no longer ask to sign in again until a chat runs. It never starts the server, never overrides the server's own answer, and waits while a sign-in flow is running.
  • One-click switches keep a saved project and location (never Enterprise's), and detection names the same project the switch will use.

Why

A teammate reported "our agy chat is still broken, might be our GCP setup or broken for subs". People with an API key or gcloud set up don't realize Chat can use those instead of a Google subscription sign-in. #43939 added those methods, but they sat in a Settings dropdown. This puts them in front of people at the moment they're blocked.

Perf

  • No polling. The renderer reads on mount, on window focus, and once per new sign-in revision on the host. One shared per-host store dedupes reads and keeps the last good answer when a read fails.
  • On the host, detection is a few stat and small file reads, plus the shell environment chat launches already use. That one is cached and refreshed in the background at most every 10s.
  • Context values are memoized, and an unchanged detection keeps its reference, so surfaces don't re-render.

Tests

  • antigravity-chat-auth-detect.test.ts:
    • detection: key from the environment vs saved, ADC via gcloud vs GOOGLE_APPLICATION_CREDENTIALS, nothing found, both Google tokens, a config mid-save, the project a switch keeps, and that the key never appears in the result;
    • seeding: a valid token, a missing or malformed token, key and ADC methods, a newer server answer, a running flow.
  • antigravity-chat-auth-choices.test.ts: ranking of alternatives, menu items for current and older hosts, and failure classification, including that a tool's bare 401, 403 or 429 is ignored.

Visual Proof

Real dev Orca (this branch, rebased on main) with Orca's managed Antigravity server 1.5.0 installed from Settings. To hide ADC, Orca ran with HOME and CLOUDSDK_CONFIG pointed at empty folders, and without GEMINI_API_KEY.

Nothing detected. A send while signed out shows Google sign-in and "Use an API key or gcloud instead". The failed row stays plain, so only one Sign in shows:
(screenshot removed: contained real product data)

gcloud ADC detected (real application_default_credentials.json):
(screenshot removed: contained real product data)

One click on "Use gcloud", then a real reply over Agent Platform:
(screenshot removed: contained real product data)

API key and gcloud both detected (GEMINI_API_KEY=dummy-not-a-real-key):
(screenshot removed: contained real product data)

After a click on "Use your Gemini API key", Google rejects the dummy key. The turn fails, and the row offers the other detected method:
(screenshot removed: contained real product data)

Method chip. The menu marks the active method and tags the detected ones:
(screenshot removed: contained real product data)

Switching while a chat is running asks first:
(screenshot removed: contained real product data)

After the switch to gcloud and a reply, the old rejected-key row no longer offers that key again:
(screenshot removed: contained real product data)

STA-15489. Settings before the token is planted:
(screenshot removed: contained real product data)

After a restart with a token file planted at <userData>/antigravity-chat/antigravity-acp/acp_token.json, and no server started, Settings shows Signed in:
(screenshot removed: contained real product data)

Linked Issue

Closes #44911. Follows #43939. Fixes STA-15489.

Fixed during end-to-end testing (after rebasing on main)

  • The chooser now also appears when a model listing finds the server signed out, before the first send fails. Before, only a chat's own connection reported the signed-out state. This path was not reproduced live: a fresh chat lists models only on demand, so the chooser was seen after a send.
  • While the sign-in strip is up, the failed message's row stays plain instead of adding a second Sign in button (fix(native-chat): show "not signed in" as one line with a small Sign in button #44659's one-Sign-in rule).
  • A rejected API key's row stopped offering the same key after the chat switched to another method.
  • Rebase: Google sign-in from the chooser passes main's new sign-in intent (Let Antigravity Chat Change account start a fresh sign-in #37998). The provider moved inline because main's NativeChatSurface now owns link clicks. The usage-limit offer moved into NativeChatUsageLimitRow to stay under the notice row's line limit.

Remaining gaps

  • A real Google sign-in and a working Gemini API key reply were not exercised. No subscription or valid key was available, so STA-15489 was checked with a planted token file.
  • SSH/WSL hosts, older or newer, were not exercised live. Capability gating is covered only by unit tests.
  • An offer can still show on an older failure row from the current method, such as a quota error.

…r them in Chat

Antigravity chats now find a Gemini API key, gcloud ADC and a saved Google
sign-in on the chat's host, rank them in the signed-out strip as one-click
switches, offer them when sign-in or a turn fails for want of a subscription
or with 401/403/quota, and show the method in use as a footer chip.

A saved Google token now reads as signed in after a restart (STA-15489).
Re-read detection before a switch so the restart confirm sees chats that
started since mount, refresh it on every sign-in revision, report each Google
method's saved sign-in, keep a saved project and location across switches,
start only Google sign-in when the method is unknown, and match only Google's
auth words for the refused offer.
…ion cheap

Google sign-in from the chooser goes through the same live-chat confirm as a
switch, and a failed detection read keeps the last answer and asks instead of
applying. Detection re-reads once per sign-in revision and reads the cached
shell environment, never a new login shell. The saved-sign-in seed waits for a
running flow.
…t gcloud keeps

A failed forced re-read can't rule out chats started since mount, so the
switch asks. A one-click gcloud switch keeps a saved project (never
Enterprise's), and detection names that same project. Detection reads the
same shell capture chats launch from, so a profile-exported key is seen
right after start.
Main now requires a sign-in intent (#37998); the chooser and a switch to
Google sign-in start a plain sign-in.
The usage-limit row renders Antigravity's sign-in offer itself, and the
notice row passes only its block.
…nds it signed out

The listing session is often the first to reach a signed-out managed server,
but only a chat's own connection answered the host's sign-in state, so the
chooser waited for a failed send. The listing now answers it too.
…is up

The strip already offers Google sign-in, so the failed message's row reads
plain instead of adding a second Sign in button.
Once a chat moved off the API key that Google rejected, that failure row kept
offering to switch back to the same key. A rejected-key failure is now history
on any other method, as Google-only failures already were.
@nwparker
nwparker force-pushed the nwparker/agy-auth-detect branch from e1c5d88 to b99d84a Compare November 20, 2026 03:28
@nwparker
nwparker changed the base branch from nwparker/agy-chat-key-adc to main November 20, 2026 03:28
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The change adds runtime detection for saved Google sign-in, Gemini API keys, and gcloud credentials, and exposes the results through an RPC. Native chat caches detection per host and adds controls to view and switch authentication methods. Authentication changes can require confirmation when chats are active or detection fails. Unresolved notices and usage-limit rows can display recovery actions. The change also updates signed-out probe handling and adds tests, fixtures, and localization strings.

Merge Risk: Low · up to b99d8

This adds detection and one-click selection of API-key and gcloud credentials in Antigravity Chat. A few edge cases remain: a stale model-list failure can briefly show the account as signed out, a chat started at the moment of a switch can be stopped without the confirmation prompt, and some recovery offers or Settings routes appear in the wrong situations. These are narrow, recoverable issues that are worth fixing before or soon after merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive Most changes connect to #44911. They cover key and ADC detection, the chooser, the chip, failure recovery for key and quota errors, and the related tests and i18n strings. Some changes do not map to #… Provide the STA-15489 issue, or confirm that it is a directly linked issue, so its requirements can be compared with the token-seeding changes. Alternatively, confirm that the token-seeding changes belong in a separate PR. Provide the gener…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: Orca now detects a host's Gemini API key and gcloud login and offers them in Antigravity Chat. The raw summary confirms this focus through the detection RPC, the choos…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Closes #44911), Visual Proof with many screenshots, Testing with test file names and a manual-testin…
Linked Issues check Passed [#44911] The issue asks that a user with a valid Gemini API key can start a native Chat, send a prompt, and get a reply without Google sign-in. The PR supplies the path that reaches this method. Per t…
Full details: Title check

Explanation

The title names the main change: Orca now detects a host's Gemini API key and gcloud login and offers them in Antigravity Chat. The raw summary confirms this focus through the detection RPC, the chooser, the composer chip, and the failure-recovery offers. The title is specific and uses the conventional feat(scope) form. Its length of 83 characters is acceptable.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Closes #44911), Visual Proof with many screenshots, Testing with test file names and a manual-testing note, Perf, and Remaining gaps. Several template sections are only partly filled in. The Risk section has no Level value and no backout plan. The Testing checkboxes are not ticked, and the checklist is not marked. The AI Disclosure section is blank, and the Review and Agent skill upstream boundary sections are absent. Overall the description is mostly complete, so the check passes, but the Risk section and the missing disclosure need attention.

Full details: Linked Issues check

Explanation

[#44911] The issue asks that a user with a valid Gemini API key can start a native Chat, send a prompt, and get a reply without Google sign-in. The PR supplies the path that reaches this method. Per the PR description, the Gemini API-key method already exists from #43939 in a Settings dropdown. This PR adds: (1) accounts.antigravityChatAuthDetect, which reports apiKey: {available, source: 'saved' | 'environment'} without returning the secret; (2) a signed-out chooser with a one-click 'Use your Gemini API key' option; (3) a composer chip that switches the method; and (4) failure-row offers that switch to the key method. The visual proof shows the key path sends the request to Google. Image 5 and the 'invalid key recovery' step show Google rejecting the dummy key, so the key reaches the backend. A reply with a valid key was not exercised live, as the PR states. Code paths for the request itself were not changed in the summary, so the valid-key reply depends on the pre-existing #43939 behavior. No automated test in the summary covers a valid-key reply end to end. The coding objective of exposing and selecting the key method is implemented. The unverified live reply is a residual risk, not a demonstrated gap.

Full details: Out of Scope Changes check

Explanation

Most changes connect to #44911. They cover key and ADC detection, the chooser, the chip, failure recovery for key and quota errors, and the related tests and i18n strings. Some changes do not map to #44911's requirements. These are: (a) saved Google token seeding in antigravity-chat-saved-sign-in.ts, seedAntigravityChatAuth, and the ANTIGRAVITY_OAUTH_TOKEN_FILES move in antigravity-sign-in-server.ts; (b) the Google sign-in confirmation and restart behavior tied to running chats; and (c) the subscription and ineligible sign-in messages in antigravity-sign-in-sentences.ts. The PR states that item (a) fixes STA-15489. STA-15489 is not in the linked issue set, so its requirements cannot be checked here. Item (a) has no clear link to a Gemini API key. Items (b) and (c) may follow from the chooser UI, but this was not confirmed. Also, src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by the !**/*.generated.* rule. Its contents were not inspected, so the RPC catalog registration for the new method cannot be confirmed from the available evidence.

Resolution

Provide the STA-15489 issue, or confirm that it is a directly linked issue, so its requirements can be compared with the token-seeding changes. Alternatively, confirm that the token-seeding changes belong in a separate PR. Provide the generated RPC catalog evidence by another path, or confirm that the generated catalog includes accounts.antigravityChatAuthDetect with the capability gate.

  • 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

Minor comments: 1

src/renderer/src/components/native-chat/antigravity-auth/native-chat-antigravity-auth.tsx: 1

193-193: Minor · Stability & Availability · Poor tradeoff

Recheck live chats inside the launch gate before stopping them.

The count that decide() reads can be stale when the apply runs. applyAntigravityChatAuthMethod awaits a config read and a config write before accounts.antigravityChatAuthApply reaches applyAntigravityChatAuthConfig. A chat that starts during those awaits is loaded when ANTIGRAVITY_LAUNCH_GATE.run(stopLiveChats, …) runs. stopStructuredAgentChats then closes it without the confirmation the dialog shows.

The host must count running Antigravity chats inside the launch gate, before it stops them. If chats are running and the request is not already confirmed, the host must return a confirmation-required result and stop nothing. A confirmed request must still stop running chats.

The impact is narrow. The window spans a few RPC round trips, and a new chat must start within it. In that case, one reply in progress stops, and the conversation remains.

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: 5b4648d4-692e-4ace-99aa-2380583222ff
Commits

Reviewing files that changed from the base of the PR and between d3a843d and b99d84a.

Files ignored due to path filters: 1

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

  • src/main/acp/discovery/acp-model-catalog-probe.ts
  • src/main/antigravity/antigravity-agent-platform-project.ts
  • src/main/antigravity/antigravity-chat-auth-detect.test.ts
  • src/main/antigravity/antigravity-chat-auth-detect.ts
  • src/main/antigravity/antigravity-chat-saved-sign-in.ts
  • src/main/antigravity/antigravity-sign-in-failure.ts
  • src/main/antigravity/antigravity-sign-in-server.ts
  • src/main/runtime/agent-session/lifecycle/structured-agent-chat-stop.ts
  • src/main/runtime/rpc/methods/accounts/antigravity-accounts.ts
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/antigravity-auth/NativeChatAntigravityAuth.fixture.tsx
  • src/renderer/src/components/native-chat/antigravity-auth/NativeChatAntigravityAuthChip.tsx
  • src/renderer/src/components/native-chat/antigravity-auth/NativeChatAntigravityAuthChooser.tsx
  • src/renderer/src/components/native-chat/antigravity-auth/NativeChatAntigravityAuthRecovery.tsx
  • src/renderer/src/components/native-chat/antigravity-auth/antigravity-auth-words.ts
  • src/renderer/src/components/native-chat/antigravity-auth/antigravity-chat-auth-choices.test.ts
  • src/renderer/src/components/native-chat/antigravity-auth/antigravity-chat-auth-choices.ts
  • src/renderer/src/components/native-chat/antigravity-auth/native-chat-antigravity-auth.tsx
  • src/renderer/src/components/native-chat/composer/controls/NativeChatComposerWorkspace.tsx
  • src/renderer/src/components/native-chat/host-access/NativeChatInstallSlot.tsx
  • src/renderer/src/components/native-chat/host-access/NativeChatSignInStrip.tsx
  • src/renderer/src/components/native-chat/messages/notices/NativeChatNoticeRow.tsx
  • src/renderer/src/components/native-chat/messages/notices/use-native-chat-structured-pane-notices.ts
  • src/renderer/src/components/native-chat/usage/NativeChatUsageLimitRow.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/runtime/provider-accounts/sign-in/antigravity-chat-auth-detection.ts
  • src/renderer/src/runtime/provider-accounts/sign-in/runtime-antigravity-accounts-client.ts
  • src/shared/agent-accounts/antigravity/antigravity-sign-in-sentences.ts
  • src/shared/remote-runtime/protocol/account-runtime-capabilities.ts
  • src/shared/rpc-contract/accounts/antigravity-accounts-params.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.

throw error
}
throw error
answerSignIn?.(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.

Minor · Stability & Availability · Quick win

Guard the signed-out answer against newer sign-in state.

signedOutAsUnavailable calls answerSignIn(false) for any -32000 failure from a listing run. answerAntigravityChatAuth then sets the shared auth state to signedOut with no revision or operation check. A listing that started before a sign-in, and fails after that sign-in publishes signedIn, can therefore overwrite the newer state. The chooser then shows the account as signed out even though the sign-in succeeded.

Only record the signed-out answer when it is still the newest sign-in state. Skip it when the listing operation has been superseded, or when a newer sign-in answer has already been recorded. The guard must run before answerAntigravityChatAuth writes.

detection,
keyAndAdc,
switching,
switchTo: (method) => void decide(host, method),

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

Restrict managed authentication switches to managed chats.

For backend === 'agy', this action still writes Orca's managed authentication configuration. The supplied recovery component can render this action without checking backend. The action can report success, but the affected agy chat retains its own login.

Do not offer managed credential recovery for an agy target. Provide guidance for the host's agy authentication instead.

)}
</div>
{/* A browser that didn't open still needs Copy link and Cancel, which live in Settings. */}
{signingIn && view.openFailed ? (

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

Keep a Settings action available during sign-in.

If sign-in waits in the browser and view.openFailed is false, this condition hides the Settings action. The other conditions also hide the chooser and fallback action. On an older host with null detection, the auth chip is absent too.

The user then loses the in-chat route to the cancellation controls in Settings. Show this action whenever signingIn is true, or provide a direct Cancel action. Keep the existing recovery route when browser opening fails.

return (
<div className="space-y-2">
<UsageLimitCard {...props} />
<NativeChatNoticeAuthRecovery block={props.block} agentName={props.agentName} />

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

Hide authentication recovery on historical usage-limit rows.

When a later turn makes active false, UsageLimitCard removes the row's recovery controls. This new child still classifies the stored failure as usageLimit and offers any detected alternative. An old, resolved limit can therefore keep suggesting a host-wide authentication change.

Render NativeChatNoticeAuthRecovery only when props.active is true. This preserves the offer for the current usage-limit stop.

Comment on lines +106 to +110
// The first revision seen only records where this client starts; mount already reads.
const first = entry.revision < 0
entry.revision = revision
if (!first) {
void refreshAntigravityChatAuthDetection(owner, { force: 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.

Minor · Functional Correctness · Quick win

Refresh when the first known revision arrives.

A mount read can capture method A before another client saves method B. If the first sign-in snapshot then contains B's revision, this branch records the revision without scheduling another read. The pending read can subsequently publish A.

Queue a forced read for the first known revision too, or establish that the pending read started after that revision.

@nwparker
nwparker merged commit 04c88e0 into main Nov 20, 2026
55 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.

[Feature]: Support Gemini API-key authentication in native Antigravity Chat

1 participant