Skip to content

feat(rate-limits): fetch Antigravity usage from the CLI keychain session - #21999

Closed
Mivr wants to merge 2 commits into
stablyai:mainfrom
Mivr:feat/antigravity-native-usage
Closed

Mivr wants to merge 2 commits into
stablyai:mainfrom
Mivr:feat/antigravity-native-usage

Conversation

@Mivr

@Mivr Mivr commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

User impact

Antigravity usage in the status bar now comes from a native agy sign-in (macOS keychain or the CLI token file), so a Gemini CLI OAuth opt-in is no longer required for that chip to appear.

Implementation

  • Read the Google session Agy stores as gemini / antigravity in the macOS keychain (go-keyring-base64:…) or ~/.gemini/antigravity-cli/antigravity-oauth-token.
  • Fetch retrieveUserQuotaSummary and map five-hour / weekly buckets onto the existing Antigravity provider.
  • Stop mirroring Gemini quota into the Antigravity provider. A Gemini failure stays on Gemini.

Testing

  • Unit tests for secret decoding, quota mapping, the native fetcher, service independence from Gemini, and status-bar visibility.
  • Live check still needed on a signed-in Antigravity host after install.

Linked issue

Native Antigravity usage when agy is signed in on the machine.

Visual proof

Pending live install of the local Mac client with this branch.

AI disclosure

Implemented with Grok.

Read the agy Google session from the macOS keychain or the CLI token file
instead of mirroring Gemini quota, and show Antigravity in the status bar
when that native sign-in is present.
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

📝 Walkthrough

Walkthrough

This change adds Antigravity OAuth discovery from a token file or macOS Keychain, quota-response parsing, token refresh, and rate-limit fetching. The full-cycle service now fetches Antigravity independently from Gemini. Shared state records Antigravity authentication configuration. Status-bar visibility accepts native Antigravity authentication or usage configuration. Tests cover the new authentication, parsing, fetching, service, and visibility paths.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 7ace7

Antigravity quota reporting can stop after token expiry or fail despite valid Keychain credentials and fallback endpoints. Resolve these integration failures before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the user impact, implementation, testing, and AI usage, but it omits several required template sections and information. It has no ELI5, What Changed, Why, Review, Agent skill… Complete the required template sections. Add ELI5, What Changed, Why, Review, Agent skill upstream boundary, Notes, and Checklist. Provide a valid linked issue using Fixes #.... Add before-and-after visual proof for the status-bar behavio…
Docstring Coverage ⚠️ Warning Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 24 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fetching Antigravity usage from the CLI keychain session.
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: Description check

Explanation

The description explains the user impact, implementation, testing, and AI usage, but it omits several required template sections and information. It has no ELI5, What Changed, Why, Review, Agent skill upstream boundary, Notes, or Checklist sections; the linked issue is not provided as a Fixes #... reference; and visual proof remains pending.

Resolution

Complete the required template sections. Add ELI5, What Changed, Why, Review, Agent skill upstream boundary, Notes, and Checklist. Provide a valid linked issue using Fixes #.... Add before-and-after visual proof for the status-bar behavior, or write N/A with a brief reason if visual proof is not applicable. Record manual testing, platform coverage, automated test status, and command results.

  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 715b1fc6-f8ce-4fa3-99d2-1a89f101515c

📥 Commits

Reviewing files that changed from the base of the PR and between 4aaa6c7 and 7ace7d0.

📒 Files selected for processing (24)
  • src/main/rate-limits/antigravity-oauth-sources.test.ts
  • src/main/rate-limits/antigravity-oauth-sources.ts
  • src/main/rate-limits/antigravity-quota-summary.test.ts
  • src/main/rate-limits/antigravity-quota-summary.ts
  • src/main/rate-limits/antigravity-usage-fetcher.test.ts
  • src/main/rate-limits/antigravity-usage-fetcher.ts
  • src/main/rate-limits/rate-limit-service-test-harness.ts
  • src/main/rate-limits/service-account-target-selection.test.ts
  • src/main/rate-limits/service-antigravity-usage.test.ts
  • src/main/rate-limits/service-inactive-account-previews.test.ts
  • src/main/rate-limits/service-live-claude-usage.test.ts
  • src/main/rate-limits/service-minimax-usage.test.ts
  • src/main/rate-limits/service-refresh-orchestration.test.ts
  • src/main/rate-limits/service-window-activation.test.ts
  • src/main/rate-limits/service/service-configuration.ts
  • src/main/rate-limits/service/service-full-cycle-application.ts
  • src/main/rate-limits/service/service-full-cycle-preparation.ts
  • src/main/rate-limits/service/service-state.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.ts
  • src/renderer/src/components/status-bar/use-status-bar-controller.ts
  • src/shared/rate-limit-state-factory.ts
  • src/shared/rate-limit-types.test.ts
  • src/shared/rate-limit-types.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +188 to +189
if (fromFile.status !== 'missing') {
return fromFile

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Try the Keychain when the token file is invalid.

A malformed or unreadable token file returns immediately. This prevents a valid macOS Keychain session from being used.

Continue to readSessionFromKeychain() after a file error. Return the file error only if no valid Keychain session exists.

🧰 Tools
🪛 ast-grep (0.45.3)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

Comment on lines +107 to +109
const remaining = remainingFraction(bucketValue)
if (remaining === null) {
continue

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- target outline ---'
ast-grep outline src/main/rate-limits/antigravity-quota-summary.ts
printf '%s\n' '--- target source ---'
cat -n src/main/rate-limits/antigravity-quota-summary.ts
printf '%s\n' '--- direct references ---'
rg -n -C 3 "antigravity-quota-summary|remainingFraction|parse.*quota|quota.*summary" src test tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 17293


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings

Length of output: 25234


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- usage fetcher ---'
cat -n src/main/rate-limits/antigravity-usage-fetcher.ts
printf '%s\n' '--- parser tests ---'
cat -n src/main/rate-limits/antigravity-quota-summary.test.ts
printf '%s\n' '--- rate-limit result types and auth reader references ---'
rg -n -C 4 "parseAntigravityQuotaSummary|AntigravityQuotaSummary|status: 'ok'|readAntigravityAuthSession|RateLimitFetchResult" src/main/rate-limits src/shared

Repository: stablyai/orca

Length of output: 42263


Do not silently omit malformed quota buckets.

If a non-disabled bucket has an invalid fraction and another bucket is valid, fetchAntigravityRateLimits() returns status: 'ok' with incomplete data. Return an explicit parse failure for malformed present fields, while keeping missing optional fields distinct from malformed fields.

Source: Learnings

isAntigravityAccessTokenFresh: (session: {
accessToken: string | null
expiresAtMs: number | null
}) => Boolean(session.accessToken),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,90p' src/main/rate-limits/antigravity-usage-fetcher.test.ts
sed -n '180,215p' src/main/rate-limits/antigravity-oauth-sources.ts
sed -n '80,145p' src/main/rate-limits/antigravity-usage-fetcher.ts

Repository: stablyai/orca

Length of output: 4950


🏁 Script executed:

sed -n '1,115p' src/main/rate-limits/antigravity-usage-fetcher.ts
printf '\n--- oauth source bindings ---\n'
sed -n '1,70p' src/main/rate-limits/antigravity-oauth-sources.ts
printf '\n--- all relevant test references ---\n'
rg -n -C 3 'isAntigravityAccessTokenFresh|refreshBundle|refresh|native quota|fetchAntigravityRateLimits' src/main/rate-limits/antigravity-usage-fetcher.test.ts src/main/rate-limits/antigravity-usage-fetcher.ts

Repository: stablyai/orca

Length of output: 14419


Preserve the production expiry check in this mock.

The mock treats the fixture token as fresh because accessToken is present. Production treats the same token as stale because it expires in 60 seconds and applies a five-minute skew. The test therefore bypasses tryRefreshTokenFromBundle before the native quota fetch, and its assertions do not detect that omission.

Use the real isAntigravityAccessTokenFresh implementation, or reproduce its expiry calculation. Configure refreshBundle to return a refreshed token so the test still reaches the native fetch assertions.

Comment on lines +39 to +58
async function ensureFreshSession(
session: AntigravityAuthSession
): Promise<AntigravityAuthSession | null> {
if (isAntigravityAccessTokenFresh(session)) {
return session
}
if (!session.refreshToken) {
return null
}
const refreshed = await tryRefreshTokenFromBundle(session.refreshToken, true)
if (!refreshed?.accessToken) {
return null
}
return {
...session,
accessToken: refreshed.accessToken,
refreshToken: refreshed.newRefreshToken ?? session.refreshToken,
expiresAtMs: refreshed.expiresIn ? Date.now() + refreshed.expiresIn * 1000 : session.expiresAtMs
}
}

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'expiresAtMs|expires_in|fetchAll|refreshInterval|ANTIGRAVITY_SESSION_EXPIRED' src/main/rate-limits src/renderer
sed -n '35,60p' src/main/rate-limits/antigravity-usage-fetcher.ts
sed -n '80,105p' src/main/rate-limits/antigravity-usage-fetcher.ts

Repository: stablyai/orca

Length of output: 16009


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- service polling ---'
sed -n '1,210p' src/main/rate-limits/service/service-polling.ts
printf '%s\n' '--- full-cycle preparation ---'
sed -n '1,220p' src/main/rate-limits/service/service-full-cycle-preparation.ts
printf '%s\n' '--- antigravity fetcher ---'
sed -n '1,150p' src/main/rate-limits/antigravity-usage-fetcher.ts
printf '%s\n' '--- antigravity auth source ---'
sed -n '1,230p' src/main/rate-limits/antigravity-oauth-sources.ts
printf '%s\n' '--- relevant tests ---'
rg -n -C 5 'ANTIGRAVITY_SESSION_EXPIRED|antigravity|refresh|poll|interval|retry|stale' src/main/rate-limits/*test.ts src/main/rate-limits/service/*test.ts

Repository: stablyai/orca

Length of output: 45543


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings

Length of output: 33158


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- service-polling.ts ---'
sed -n '1,190p' src/main/rate-limits/service/service-polling.ts
printf '%s\n' '--- service-full-cycle-preparation.ts relevant lines ---'
sed -n '70,105p' src/main/rate-limits/service/service-full-cycle-preparation.ts
sed -n '155,200p' src/main/rate-limits/service/service-full-cycle-preparation.ts
printf '%s\n' '--- Antigravity references outside tests ---'
rg -n -g '*.ts' -g '!*.test.ts' 'fetchAntigravityRateLimits|ANTIGRAVITY_SESSION_EXPIRED|readAntigravityAuthSession|hasAntigravityAuthSession|antigravity.*login|login.*antigravity' src/main src/renderer
printf '%s\n' '--- focused Antigravity tests ---'
sed -n '1,180p' src/main/rate-limits/antigravity-usage-fetcher.test.ts

Repository: stablyai/orca

Length of output: 13720


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- provider retry configuration ---'
rg -n -C 4 'INDIVIDUALLY_REFRESHABLE_PROVIDERS|antigravity' src/main/rate-limits/service/service-types.ts
printf '%s\n' '--- fetch-cycle result application ---'
rg -n -C 5 'runFetchAllCycle|Promise.allSettled|results|status|updatedAt|antigravity' src/main/rate-limits/service -g '*.ts' -g '!*.test.ts'
printf '%s\n' '--- Antigravity auth writers and user actions ---'
rg -n -C 4 'write.*Antigravity|save.*Antigravity|persist.*Antigravity|refreshToken|antigravity' src/main -g '*.ts' -g '!*.test.ts' | head -n 260

Repository: stablyai/orca

Length of output: 41999


Use the Antigravity refresh flow for Antigravity sessions. When the Antigravity access token expires, the periodic full-cycle fetch reaches ensureFreshSession, which passes the Antigravity refresh token to Gemini CLI's tryRefreshTokenFromBundle. An agy-only installation lacks the Gemini OAuth client credentials required by that helper, so retries return ANTIGRAVITY_SESSION_EXPIRED instead of refreshed quota data. The service retries Antigravity through fetchAll(), but every retry repeats the same credential mismatch. Use Antigravity's own refresh endpoint and credential source at this call site.

Comment on lines +63 to +72
const response = await net.fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
'User-Agent': 'antigravity'
},
body: '{}',
signal: AbortSignal.timeout(API_TIMEOUT_MS)
})

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Continue to the fallback endpoint after a transport failure.

If net.fetch rejects for the first URL because of DNS, connection, or timeout failure, control exits the loop. The second URL is never attempted.

Catch errors inside the loop. Continue to the next URL when another endpoint remains.

})
}

let session = await ensureFreshSession(auth.session)

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '35,115p' src/main/rate-limits/antigravity-usage-fetcher.ts
sed -n '130,180p' src/main/rate-limits/gemini-oauth-sources.ts

Repository: stablyai/orca

Length of output: 3834


🏁 Script executed:

set -e
printf '%s\n' '--- imports and function context ---'
sed -n '1,145p' src/main/rate-limits/antigravity-usage-fetcher.ts
printf '%s\n' '--- refresh helper binding and implementation ---'
rg -n "function refreshAccessToken|const refreshAccessToken|export .*refreshAccessToken|refreshAccessToken\\(" src
printf '%s\n' '--- helper imports and nearby source ---'
rg -n -C 8 "export async function tryRefreshTokenFromBundle|import .*tryRefreshTokenFromBundle|from .*gemini-oauth-sources" src/main

Repository: stablyai/orca

Length of output: 9851


🏁 Script executed:

set -e
printf '%s\n' '--- refreshAccessToken ---'
sed -n '80,125p' src/main/rate-limits/gemini-oauth-sources.ts
printf '%s\n' '--- fetcher catch completion ---'
sed -n '140,170p' src/main/rate-limits/antigravity-usage-fetcher.ts

Repository: stablyai/orca

Length of output: 1906


Handle the initial token refresh inside the error boundary.

refreshAccessToken returns null for non-OK HTTP responses, but its net.fetch and response.json() calls can reject on transport, timeout, or response-parsing errors. tryRefreshTokenFromBundle does not catch those errors. Because the initial ensureFreshSession call runs before the try block, those failures can make fetchAntigravityRateLimits() reject instead of returning a network error result.

Move the initial refresh into the try block so thrown refresh failures receive failureKind: 'network'. Non-OK HTTP responses will still follow the existing expired-session path.

// Why: getState() is hot (renderer pushes + mobile snapshots); keep Grok's sync auth-file probe on fetch cycles instead.
const grokAuthReadResult = readGrokAuthSession()
this.grokAuthConfigured = grokAuthReadResult.status === 'ok'
this.antigravityAuthConfigured = hasAntigravityAuthFile()

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Detect Keychain authentication before clearing the configured state.

hasAntigravityAuthFile() only checks the token file. A macOS user authenticated only through Keychain sets antigravityAuthConfigured to false on every cycle. If quota parsing returns unavailable, the application phase does not restore the flag. The renderer can then hide Antigravity or show the setup CTA for a signed-in user.

Use an authentication-presence probe that checks both the token file and Keychain, such as hasAntigravityAuthSession().

Proposed fix
-import { hasAntigravityAuthFile } from '../antigravity-oauth-sources'
+import { hasAntigravityAuthSession } from '../antigravity-oauth-sources'
...
-    this.antigravityAuthConfigured = hasAntigravityAuthFile()
+    this.antigravityAuthConfigured = await hasAntigravityAuthSession()

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

Caution

This PR adds a new direct node:child_process import that fails the repo's child_process import-boundary ratchet test (reproduced locally: new offender plus offender count 156 vs the pin of 155). It needs to route through runProcess/spawnProcess before merge.

Reviewed changes

  • Native Antigravity credential reader — antigravity-oauth-sources.ts reads the agy session from ~/.gemini/antigravity-cli/antigravity-oauth-token or the macOS keychain (service=gemini, account=antigravity), decodes the go-keyring-base64: payload, and exposes a sync file probe plus an async reader.
  • Quota client and parser — antigravity-usage-fetcher.ts refreshes an expired token and POSTs to retrieveUserQuotaSummary against two base URLs; antigravity-quota-summary.ts maps the response into five-hour/weekly windows.
  • Service integration — the full-cycle fetch polls Antigravity directly instead of mirroring Gemini; a new antigravityAuthConfigured flag flows through main state into the status bar.
  • Visibility change — a checked Antigravity item (with agy detected) is now the durable signal; the Gemini OAuth requirement is removed, and the item counts as configured usage.
  • Removal — the Gemini→Antigravity mirror is no longer called and its tests were rewritten, but the module itself remains.

ℹ️ Orphaned antigravity-usage-mirror module left behind

Removing deriveAntigravityRateLimits from service-full-cycle-application.ts removed the module's only production importer, but src/main/rate-limits/antigravity-usage-mirror.ts and antigravity-usage-mirror.test.ts are still in the tree and still run. Deleting them keeps the retired mirror from being mistaken for a live path.

Technical details
# Retire the Gemini→Antigravity mirror

## Affected sites
- `src/main/rate-limits/antigravity-usage-mirror.ts` — only referenced by its own test now.
- `src/main/rate-limits/antigravity-usage-mirror.test.ts` — exercises a path no production code reaches.
- `src/main/rate-limits/service/service-full-cycle-application.ts` — dropped the `deriveAntigravityRateLimits` import in this PR.

## Required outcome
- The mirror module and its test are removed, or a live caller is reintroduced. A grep for `deriveAntigravityRateLimits` should return no hits outside the module's own test.

## Open questions for the human
- Is the mirror intended to stay as a fallback for a future provider re-merge, or is native the only path now?

ℹ️ Windows sign-in path is unaddressed

The keychain branch is gated on process.platform !== 'darwin', and agy uses the Windows Credential Locker (rather than a file) for credential storage on Windows. The module does read the on-disk token file on every platform, so if agy also writes antigravity-oauth-token on Windows this works — otherwise Antigravity usage is silently unavailable there.

Technical details
# Windows coverage for native Antigravity auth

## Affected sites
- `src/main/rate-limits/antigravity-oauth-sources.ts:140-182` — keychain reads return `missing` off macOS; only the file path is platform-agnostic.

## Required outcome
- Confirm whether `agy` writes `~/.gemini/antigravity-cli/antigravity-oauth-token` on Windows. If it does not, decide whether Windows is out of scope for this PR or needs a Credential Locker reader.

## Open questions for the human
- Is Windows (`agy` via Credential Locker) intended to be covered here, or tracked separately?

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

@@ -0,0 +1,202 @@
import { execFile } from 'node:child_process'

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.

This direct node:child_process import fails the repo's import-boundary ratchet. child-process-import-boundary.test.ts reports this file as a new offender and the offender count rises to 156 against a pin of 155, so CI fails on both assertions. Route the security call through runProcess/spawnProcess from src/shared/child-process (they pin windowsHide and encode .cmd args) instead.

Technical details
# New direct child_process import fails the ratchet

## Affected sites
- `src/main/rate-limits/antigravity-oauth-sources.ts:1` — `import { execFile } from 'node:child_process'`.
- `src/shared/child-process/child-process-import-boundary.test.ts:107-139` — asserts no unlisted offender and `offenders.length === 155`; runs in CI (`ci-shard-timings.json`).

## Verification
Locally reproduced:
- `has no direct importer outside the allowlist` → received `["src/main/rate-limits/antigravity-oauth-sources.ts"]`.
- `holds the offender count at the pin` → 156 > 155.

## Required outcome
- No direct `node:child_process` import; the test passes unmodified (the allowlist only shrinks — do not add an entry or raise the pin).
- Preserve the current `security find-generic-password` behavior and the 3s timeout.

## Suggested approach (optional)
Use `runProcess({ program: 'security', args, timeoutMs: KEYCHAIN_COMMAND_TIMEOUT_MS })` and read the exit code from the resolved result. Note `run-process.ts` never rejects on non-zero exit, which matches how `execSecurity` already treats the result. `src/main/claude-accounts/keychain.ts` is allowlisted precisely because it still imports directly, so do not copy that pattern.

if (!session.refreshToken) {
return null
}
const refreshed = await tryRefreshTokenFromBundle(session.refreshToken, 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.

This refresh path borrows the Gemini CLI's OAuth client to refresh an Antigravity-issued refresh token, then keeps the result only in memory. Gemini CLI and Antigravity use different OAuth client IDs, and RFC 6749 §6 requires the refresh token to have been issued to the authenticated client, so once the stored Antigravity access token expires this likely returns null and every poll degrades to ANTIGRAVITY_SESSION_EXPIRED — unless Gemini CLI happens to be installed and Google accepts the cross-client refresh. Unlike the Gemini fetcher, nothing writes the refreshed token back, so an expired session also re-refreshes on every poll.

Technical details
# Antigravity token refresh depends on Gemini CLI credentials and never persists

## Affected sites
- `src/main/rate-limits/antigravity-usage-fetcher.ts:39-58` — `ensureFreshSession` calls `tryRefreshTokenFromBundle(session.refreshToken, true)` and returns the new tokens in memory only.
- `src/main/rate-limits/gemini-oauth-sources.ts:150-162` — `tryRefreshTokenFromBundle` reads Gemini CLI `OAUTH_CLIENT_ID`/`OAUTH_CLIENT_SECRET` via `extractOAuthClientCredentials()`.
- `src/main/rate-limits/gemini-cli-oauth-extractor.ts:234-269` — returns `null` when the `gemini` binary/package cannot be found (GUI PATH often lacks it).
- `src/main/rate-limits/gemini-usage-fetcher.ts:163,189-195` — the Gemini path persists refreshed credentials via `saveGeminiCredentials`.

## Evidence
- Gemini CLI client: `681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com`; Antigravity client: `1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com` (distinct).
- RFC 6749 §6: the server must "ensure that the refresh token was issued to the authenticated client".

## Required outcome
- Either verify the cross-client refresh actually works (the PR body notes a live check is still pending), or make the fallback explicit: persist the refreshed access token/refresh token to the same store the session was read from, and/or obtain Antigravity's own client credentials.
- Avoid a refresh request on every poll when the stored record has no expiry; `isAntigravityAccessTokenFresh` returns `true` for `expiresAtMs === null`, so the file-backed path only refreshes after a 401 and then repeats each cycle.

## Open questions for the human
- Was the cross-client refresh observed to succeed against a live account, or is it best-effort? If best-effort, the error copy already tells users to run `agy`, which is fine — but the dead refresh branch should be documented or removed.

return existsSync(getAntigravityOAuthTokenPath(home))
}

export async function hasAntigravityAuthSession(home = homedir()): Promise<boolean> {

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.

hasAntigravityAuthSession is exported but never called outside test mocks — production uses the synchronous, file-only hasAntigravityAuthFile. As a result a keychain-only macOS sign-in never reaches antigravityAuthConfigured until a fetch settles, which makes the async helper (and its only consumer, hasAntigravityKeychainItem) dead weight. Either wire it into the preparation path or drop both.

Technical details
# Unused async auth-session probe

## Affected sites
- `src/main/rate-limits/antigravity-oauth-sources.ts:140-160` — `hasAntigravityKeychainItem` + `hasAntigravityAuthSession`; grep shows no production caller.
- `src/main/rate-limits/service/service-state.ts:38` and `service/service-full-cycle-preparation.ts:92` — both use the sync `hasAntigravityAuthFile`.

## Required outcome
- Either remove `hasAntigravityAuthSession`/`hasAntigravityKeychainItem`, or use the async probe where the durable keychain signal is meant to be captured.

## Open questions for the human
- Was the async helper intended to feed `antigravityAuthConfigured` for keychain-only macOS users? Today the flag is correct only after a fetch completes, and is reset from the file each cycle.

// Antigravity's durable signal requires geminiCliOAuthEnabled, so it is
// already covered by the gemini term above.
settings?.antigravityAuthConfigured === true ||
settings?.antigravityUsageConfigured === 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.

Adding antigravityUsageConfigured (the default-on status-bar item) to hasUsageProviderSettings suppresses the usage setup CTA for anyone with agy on PATH, even with no provider signed in — the code comment this PR removed explicitly guarded against that. The chip will still render a "not signed in" message, so this may be intentional, but confirming the empty-state behavior is worth it.

Technical details
# Checked Antigravity item now counts as configured usage

## Affected sites
- `src/renderer/src/components/status-bar/status-bar-provider-visibility.ts:75-76` — `hasUsageProviderSettings` now returns true for `antigravityUsageConfigured`.
- `src/renderer/src/components/status-bar/use-status-bar-controller.ts:105-116` — `antigravityUsageConfigured` is `statusBarItems.includes('antigravity') && isStatusBarItemAvailable(...)`, and the item is in `DEFAULT_STATUS_BAR_ITEMS`.
- `src/renderer/src/components/status-bar/status-bar-provider-visibility.ts:143-181` — `isUsageEmptyState` gates the setup CTA on `hasUsageProviderSettings`.

## Required outcome
- Confirm the empty-state CTA should disappear for `agy`-detected users who have not signed in; if not, gate the CTA on `antigravityAuthConfigured` rather than the checked item.

@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 new issues in the incremental delta. The prior review's findings are unchanged by this commit and remain open.

Reviewed changes

  • toWindow builds the window explicitly — antigravity-quota-summary.ts replaced the destructuring spread with an explicit { usedPercent, windowMinutes, resetsAt, resetDescription } object and defaults windowMinutes to SESSION_WINDOW_MINUTES. This is behavior-preserving (windowMinutes is always set when the bucket is pushed) and reads as a typing cleanup only.

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

@nwparker

Copy link
Copy Markdown
Contributor

Thanks for the work on this, and for your patience. Orca now reads Antigravity quota from the agy CLI (#24073), has native Antigravity Accounts (#24691), and short pool labels in the status bar (#31007), which covers what this PR set out to do. Closing as superseded; your effort here helped shape the problem, so thank you.

@nwparker nwparker closed this Oct 24, 2026
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.

2 participants