Repository navigation
Conversation
| async function waitForQuota( | ||
| port: number, | ||
| deadline: number | ||
| ): Promise<{ | ||
| session: RateLimitWindow | null | ||
| weekly: RateLimitWindow | null | ||
| }> { | ||
| let lastError: Error | null = null | ||
| while (Date.now() < deadline) { | ||
| try { | ||
| const parsed = parseAntigravityGeminiQuota(await requestQuota(port)) | ||
| if (parsed) { | ||
| return parsed | ||
| } | ||
| lastError = new Error('Antigravity Gemini quota is unavailable') | ||
| } catch (error) { | ||
| lastError = error instanceof Error ? error : new Error('Antigravity quota request failed') | ||
| } | ||
| await delay(POLL_INTERVAL_MS) | ||
| } | ||
| throw lastError ?? new Error('Antigravity Gemini quota is unavailable') | ||
| } |
There was a problem hiding this comment.
Retry loop spins for the full deadline on a consistent null parse
When agy is running and reachable (port found, HTTP 200 returned) but the response contains no Gemini quota group, parseAntigravityGeminiQuota returns null on every iteration. The loop treats this the same as a transient error and retries every 200 ms until the 12-second deadline expires — making ~55 requests to the loopback service before propagating the error and triggering the legacy fallback. The right retry target is startup timing (service not yet ready to answer), but a successful 200 response with missing Gemini data is a stable signal that won't change on the next poll. Breaking out immediately when the response parses cleanly but yields no Gemini group would prevent the ~11-second unnecessary wait for any user whose Antigravity installation has no Gemini quota configured.
Greptile SummaryThis PR adds a new
Confidence Score: 4/5Safe to merge with one behavioral gap worth addressing: Antigravity is never tried when the OAuth flag is off. The new Antigravity fetcher and its parser are well-tested and the fallback chain is correct when OAuth is enabled. The one concrete gap is that fetchGeminiRateLimits short-circuits to the legacy 'OAuth disabled' response before calling fetchGeminiRateLimitsViaAntigravity whenever geminiCliOAuthEnabled is false — meaning Antigravity users who have not enabled the OAuth path in settings receive no Gemini quota data despite having the new integration available to them. Files Needing Attention: src/main/rate-limits/gemini-usage-fetcher.ts — the fetchGeminiRateLimits wrapper needs a second look at the ordering of the geminiCliOAuthEnabled guard relative to the Antigravity call.
|
| Filename | Overview |
|---|---|
| src/main/rate-limits/gemini-usage-fetcher.ts | Refactored to rename old export as fetchLegacyGeminiRateLimits and add new fetchGeminiRateLimits that tries Antigravity first. The geminiCliOAuthEnabled=false guard short-circuits before Antigravity is tried, so users with Antigravity but OAuth disabled receive no Gemini quota data. |
| src/main/rate-limits/antigravity-usage-fetcher.ts | New module: spawns the agy PTY, polls a log file for the ephemeral HTTPS port, then fetches Gemini quota via loopback RPC with self-signed cert bypass. Logic is sound; the shared deadline between port-discovery and quota-polling can leave very little time for actual requests if startup is slow. |
| src/main/rate-limits/gemini-usage-fetcher.test.ts | Adds Antigravity mock and a new priority test; existing auth-json tests are preserved with Antigravity stubbed to 'unavailable'. Coverage is solid. |
| src/main/rate-limits/gemini-usage-fetcher.fallback.test.ts | Adds Antigravity mock to the fallback suite; all existing OAuth-creds tests continue to work correctly with the mock stubbed to 'unavailable'. |
| src/main/rate-limits/antigravity-usage-fetcher.test.ts | New unit tests for parseAntigravityGeminiQuota: covers Gemini-group filtering, correct bucket mapping, and null return when the group is absent. Correct and sufficient for the parser. |
Sequence Diagram
sequenceDiagram
participant Caller
participant fetchGeminiRateLimits
participant fetchGeminiRateLimitsViaAntigravity
participant agy as agy PTY process
participant fetchLegacyGeminiRateLimits
participant OAuthSources as OAuth sources
Caller->>fetchGeminiRateLimits: geminiCliOAuthEnabled
alt "geminiCliOAuthEnabled = false"
fetchGeminiRateLimits->>fetchLegacyGeminiRateLimits: false
fetchLegacyGeminiRateLimits-->>Caller: status: unavailable
else "geminiCliOAuthEnabled = true"
fetchGeminiRateLimits->>fetchGeminiRateLimitsViaAntigravity: (no args)
fetchGeminiRateLimitsViaAntigravity->>agy: pty.spawn agy --log-file tmplog
loop poll log every 200ms up to 12s
fetchGeminiRateLimitsViaAntigravity->>fetchGeminiRateLimitsViaAntigravity: readFile → extract HTTPS port
end
fetchGeminiRateLimitsViaAntigravity->>agy: POST RetrieveUserQuotaSummary loopback TLS
agy-->>fetchGeminiRateLimitsViaAntigravity: JSON quota response
fetchGeminiRateLimitsViaAntigravity->>fetchGeminiRateLimitsViaAntigravity: parseAntigravityGeminiQuota
alt Gemini quota parsed successfully
fetchGeminiRateLimitsViaAntigravity-->>fetchGeminiRateLimits: status: ok
fetchGeminiRateLimits-->>Caller: Antigravity quota
else Antigravity unavailable
fetchGeminiRateLimitsViaAntigravity-->>fetchGeminiRateLimits: status: unavailable
fetchGeminiRateLimits->>fetchLegacyGeminiRateLimits: "geminiCliOAuthEnabled=true"
fetchLegacyGeminiRateLimits->>OAuthSources: readAuthJson / readGeminiCredentials
OAuthSources-->>fetchLegacyGeminiRateLimits: credentials
fetchLegacyGeminiRateLimits-->>Caller: OAuth quota result
end
end
Reviews (2): Last reviewed commit: "Fix Gemini usage via Antigravity quota" | Re-trigger Greptile
📝 WalkthroughWalkthroughAdds an Antigravity-based Gemini quota fetcher that parses session and weekly limits, starts the local CLI, polls its HTTPS quota endpoint, and cleans up resources. Gemini rate-limit retrieval now tries Antigravity first when enabled, then falls back to the legacy OAuth implementation. Tests cover quota parsing, unavailable defaults, mocked Antigravity behavior, and precedence over 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/rate-limits/antigravity-usage-fetcher.ts (1)
169-233: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftConsider mocked unit tests for the pty/HTTPS polling path.
Only
parseAntigravityGeminiQuotais unit-tested; the spawn/poll/timeout/cleanup logic infetchGeminiRateLimitsViaAntigravity(process spawn failure, port-wait timeout, quota-poll timeout, cleanup ordering) has no direct coverage here. This is an external-call hazard path (process spawning, network I/O) worth exercising directly rather than only indirectly via the downstream mocked module.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0b267e44-cfb6-4e06-ab20-8ef4a9c7bacd
📥 Commits
Reviewing files that changed from the base of the PR and between 4e99602 and 9517ccd9a5e6ffe82212fd3a3e4d7b268a6af998.
📒 Files selected for processing (5)
src/main/rate-limits/antigravity-usage-fetcher.test.tssrc/main/rate-limits/antigravity-usage-fetcher.tssrc/main/rate-limits/gemini-usage-fetcher.fallback.test.tssrc/main/rate-limits/gemini-usage-fetcher.test.tssrc/main/rate-limits/gemini-usage-fetcher.ts
| const deadline = Date.now() + STARTUP_TIMEOUT_MS | ||
| const port = await waitForHttpsPort(logPath, deadline) | ||
| const quota = await waitForQuota(port, deadline) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Startup and quota-fetch phases share one 12s deadline.
waitForHttpsPort and waitForQuota both race against the same deadline computed once at line 192. If CLI startup takes most of STARTUP_TIMEOUT_MS, waitForQuota starts with almost no budget left and immediately throws "Antigravity Gemini quota is unavailable," even though the CLI itself started fine. Since this fallback path lands on the legacy Gemini OAuth flow — which is increasingly broken for accounts hitting UNSUPPORTED_CLIENT (the very problem this PR fixes) — a slow-but-successful Antigravity startup can silently degrade users back to a broken fallback.
Consider giving quota polling its own budget independent of startup time.
🔧 Proposed fix: separate startup and quota deadlines
- disposables.push(registerHiddenRateLimitPty(term))
- const deadline = Date.now() + STARTUP_TIMEOUT_MS
- const port = await waitForHttpsPort(logPath, deadline)
- const quota = await waitForQuota(port, deadline)
+ disposables.push(registerHiddenRateLimitPty(term))
+ const startupDeadline = Date.now() + STARTUP_TIMEOUT_MS
+ const port = await waitForHttpsPort(logPath, startupDeadline)
+ const quotaDeadline = Date.now() + QUOTA_TIMEOUT_MS
+ const quota = await waitForQuota(port, quotaDeadline)| export async function fetchGeminiRateLimits( | ||
| geminiCliOAuthEnabled = false | ||
| ): Promise<ProviderRateLimits> { | ||
| if (!geminiCliOAuthEnabled) { | ||
| return fetchLegacyGeminiRateLimits(false) | ||
| } | ||
|
|
||
| const antigravity = await fetchGeminiRateLimitsViaAntigravity() | ||
| return antigravity.status === 'ok' | ||
| ? antigravity | ||
| : fetchLegacyGeminiRateLimits(geminiCliOAuthEnabled) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect where fetchGeminiRateLimits is called and how geminiCliOAuthEnabled is sourced/defaulted.
rg -n -B3 -A3 'fetchGeminiRateLimits\(' src/main --type=ts -g '!*.test.ts'
rg -n 'geminiCliOAuthEnabled' src/main --type=ts -g '!*.test.ts'Repository: stablyai/orca
Length of output: 2965
🏁 Script executed:
#!/bin/bash
# Read the relevant sections of the file and settings definition without executing repository code.
wc -l src/main/rate-limits/gemini-usage-fetcher.ts src/main/rate-limits/service.ts
sed -n '1,275p' src/main/rate-limits/gemini-usage-fetcher.ts
sed -n '1530,1625p' src/main/rate-limits/service.ts
rg -n -B2 -A8 'geminiCliOAuthEnabled|Gemini CLI OAuth|geminiCli' src --type=ts --type=tsx --type=sh --type=ps1 -g '!*.test.ts'Repository: stablyai/orca
Length of output: 13013
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Files mentioning geminiCliOAuthEnabled:\n'
rg -n -B3 -A5 'geminiCliOAuthEnabled|Gemini CLI OAuth|geminiCli' src --glob '!*.test.ts'
printf '\nSettings type/definition candidates:\n'
rg -n -B2 -A8 'interface .*Setting|type .*Setting|geminiCliOAuthEnabled' src/shared src/main/preload src/**/*.ts --glob '!*.test.ts' 2>/dev/null || true
printf '\nStatus fetch behavior around previous gemini result:\n'
sed -n '1670,1760p' src/main/rate-limits/service.tsRepository: stablyai/orca
Length of output: 50369
Don’t gate Antigravity behind geminiCliOAuthEnabled.
geminiCliOAuthEnabled is false by default and controls the legacy OAuth sources that touch Gemini CLI data folders. fetchGeminiRateLimits() currently returns before fetchGeminiRateLimitsViaAntigravity() runs when the legacy toggle is off, so the Antigravity usage path can be disabled by a setting that only exists to avoid unrelated OAuth filesystem access. Fetch Antigravity independently or through its own opt-in.
| export async function fetchGeminiRateLimits( | ||
| geminiCliOAuthEnabled = false | ||
| ): Promise<ProviderRateLimits> { | ||
| if (!geminiCliOAuthEnabled) { | ||
| return fetchLegacyGeminiRateLimits(false) | ||
| } | ||
|
|
||
| const antigravity = await fetchGeminiRateLimitsViaAntigravity() | ||
| return antigravity.status === 'ok' | ||
| ? antigravity | ||
| : fetchLegacyGeminiRateLimits(geminiCliOAuthEnabled) | ||
| } |
There was a problem hiding this comment.
Antigravity bypassed when
geminiCliOAuthEnabled is false
The guard on line 254 routes directly to fetchLegacyGeminiRateLimits(false) — which immediately returns status: 'unavailable' — without ever calling fetchGeminiRateLimitsViaAntigravity. The macOS privacy concern that motivated the geminiCliOAuthEnabled gate (noted in the comment inside fetchLegacyGeminiRateLimits: "the OAuth sources include other apps' data folders") does not apply to Antigravity's loopback RPC, which makes no filesystem access into other applications' directories. As a result, any user who has Antigravity installed but has the OAuth path disabled in settings will never receive Gemini quota data through the new integration — exactly the case this PR is meant to serve.
There was a problem hiding this comment.
♻️ Duplicate comments (2)
src/main/rate-limits/antigravity-usage-fetcher.ts (1)
169-233: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winStartup and quota-fetch phases still share one deadline.
waitForHttpsPort(line 193) andwaitForQuota(line 194) both race against the singledeadlinecomputed at line 192. A slow-but-successful CLI startup leaves little/no budget for quota polling, causing an immediate "Antigravity Gemini quota is unavailable" failure and silent fallback to the legacy OAuth path — the very path this PR is meant to route around forUNSUPPORTED_CLIENTaccounts. This was flagged on a previous revision and remains unresolved.🔧 Proposed fix: separate startup and quota deadlines
- const deadline = Date.now() + STARTUP_TIMEOUT_MS - const port = await waitForHttpsPort(logPath, deadline) - const quota = await waitForQuota(port, deadline) + const startupDeadline = Date.now() + STARTUP_TIMEOUT_MS + const port = await waitForHttpsPort(logPath, startupDeadline) + const quotaDeadline = Date.now() + QUOTA_TIMEOUT_MS + const quota = await waitForQuota(port, quotaDeadline)src/main/rate-limits/gemini-usage-fetcher.ts (1)
251-262: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAntigravity is still gated behind
geminiCliOAuthEnabled.When
geminiCliOAuthEnabledisfalse(the default),fetchGeminiRateLimitsreturns at line 255 before ever callingfetchGeminiRateLimitsViaAntigravity(). That flag exists to gate the legacy OAuth path's access to other apps' data folders (see thefetchLegacyGeminiRateLimitscomment at lines 208-209) — it has no relation to Antigravity's local keyring/RPC mechanism. This means users with the OAuth toggle off (the default) never benefit from the Antigravity fix forUNSUPPORTED_CLIENT, contradicting the PR's stated goal that "Antigravity usage becomes the primary source ... with fallback to the existing Gemini OAuth path." This exact gating was flagged on a prior revision and remains unresolved.🔧 Proposed fix: fetch Antigravity independently of the OAuth toggle
export async function fetchGeminiRateLimits( geminiCliOAuthEnabled = false ): Promise<ProviderRateLimits> { - if (!geminiCliOAuthEnabled) { - return fetchLegacyGeminiRateLimits(false) - } - const antigravity = await fetchGeminiRateLimitsViaAntigravity() return antigravity.status === 'ok' ? antigravity : fetchLegacyGeminiRateLimits(geminiCliOAuthEnabled) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d7d54de5-4074-428d-9aa9-402657c5de10
📥 Commits
Reviewing files that changed from the base of the PR and between 9517ccd9a5e6ffe82212fd3a3e4d7b268a6af998 and 21783f2.
📒 Files selected for processing (5)
src/main/rate-limits/antigravity-usage-fetcher.test.tssrc/main/rate-limits/antigravity-usage-fetcher.tssrc/main/rate-limits/gemini-usage-fetcher.fallback.test.tssrc/main/rate-limits/gemini-usage-fetcher.test.tssrc/main/rate-limits/gemini-usage-fetcher.ts
English title
Fix Gemini usage via Antigravity quotaChanges
Root cause
Personal Gemini CLI accounts no longer provide quota (
UNSUPPORTED_CLIENT), but Orca's Antigravity item was still cloning the failed Gemini snapshot. Antigravity CLI, using the logged-in keyring, exposes real Gemini quota via a local API.Verification
pnpm exec vitest run --config config/vitest.config.ts src/main/rate-limits/antigravity-usage-fetcher.test.ts src/main/rate-limits/gemini-usage-fetcher.test.ts src/main/rate-limits/gemini-usage-fetcher.fallback.test.ts src/main/rate-limits/service.test.ts(88 tests)pnpm run typecheck:nodeoxlinton changed filesOriginal (한국어 / Korean) — title: Fix Gemini usage via Antigravity quota
변경 사항
원인
Gemini CLI 개인 계정은
UNSUPPORTED_CLIENT로 더 이상 quota를 제공하지 않지만, 현재 Orca의 Antigravity 항목은 실패한 Gemini snapshot을 그대로 복제하고 있었습니다. Antigravity CLI는 로그인된 keyring을 사용해 실제 Gemini quota를 로컬 API로 제공합니다.검증
pnpm exec vitest run --config config/vitest.config.ts src/main/rate-limits/antigravity-usage-fetcher.test.ts src/main/rate-limits/gemini-usage-fetcher.test.ts src/main/rate-limits/gemini-usage-fetcher.fallback.test.ts src/main/rate-limits/service.test.ts(88 tests)pnpm run typecheck:nodeoxlint