Skip to content

fix(rate-limits): read Antigravity usage from the WSL account runtime - #31741

Closed
sojiro-o wants to merge 1 commit into
stablyai:mainfrom
sojiro-o:sojiro-o/agy-usage-wsl
Closed

sojiro-o wants to merge 1 commit into
stablyai:mainfrom
sojiro-o:sojiro-o/agy-usage-wsl

Conversation

@sojiro-o

Copy link
Copy Markdown
Contributor

ELI5

If Antigravity is installed inside WSL, Orca now asks that WSL installation for quota. Previously, Windows Orca searched only Windows and reported that the CLI was missing.

What Changed

Pass the existing local account runtime target to each Antigravity usage fetch. On Windows with a WSL target, run the version and usage commands through the selected distribution's login shell using the shared WSL helpers. Resolve the guest executable, fence parsed output against startup banners, and set the probe environment inside the guest.

Keep the minimum version, timeouts, output limit, abort signal, sign-in classification, and process-wide model-turn latch. Reuse the background distro gate so polling cannot boot a stopped or unconfirmed distribution. Native execution, Claude/Codex fetchers, UI code, and translations remain unchanged.

Why

The Windows PATH cannot locate a CLI installed only in the Linux guest. Reusing the account policy keeps quota retrieval aligned with the selected runtime without another setting. Shared process and shell helpers preserve Orca's Windows launch protections and prevent login banners from satisfying a version check or appearing as quota output.

Linked Issue

Fixes #31740

Visual Proof

N/A — no UI change. Not launched locally; the change only decides which machine runs the existing quota probe, so the status bar shows the same Antigravity meter it already renders on macOS and Linux.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Executed on Linux in the WSL workspace:

  • ORCA_BACKGROUND_LAUNCH=1 nice -n 19 npx vitest run --config config/vitest.config.ts src/main/rate-limits --maxWorkers=1: 838 passed, 1 opt-in real-CLI test skipped.
  • ORCA_BACKGROUND_LAUNCH=1 nice -n 19 pnpm tc:node: passed, no type errors in 17,255 files.
  • Oxlint on all ten changed files: passed after fixing two initial test-style findings.
  • Commit hooks: oxlint, the React Doctor oxlint configuration, and formatting passed.
  • git diff --check: passed.

The WSL regression suite executes the actual generated POSIX scripts with isolated fake login-shell and CLI fixtures. It covers named/default distributions, guest-only PATH lookup, paths containing spaces, probe environment, startup noise, minimum version and failure guards, missing fences, sign-in errors, timeout handling, the model-turn latch, and stopped distributions. Native-platform routing and runtime changes between refreshes also have regression coverage.

Also ran the generated guest script against a real signed-in agy 1.4.3 in Ubuntu-26.04 (the part wsl.exe --exec hands to the distro): the version check returned 1.4.3 past the login-shell banner, and /usage returned the Gemini and Claude/GPT weekly and five-hour pools, parsed by the existing reader without spending a model turn.

Windows, macOS, SSH, mobile, and rendered UI were not manually tested. Full repository lint/typecheck/test/build remain for CI. Dependency setup logged an Electron archive extraction failure because unzip was unavailable; no Electron application was launched, and the requested checks completed successfully.

AI Disclosure

Written with OpenAI Codex (GPT-6-Astra) and Claude Code (Claude Opus 5.5). Reported by a Japanese-speaking user.

Review

Reviewed the runtime wiring, guest environment delivery, output capture, version guard, and native execution path. The service boundary test checks that runtime settings are read again on subsequent refreshes and remain independent of Codex account selection.

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

WSL routing is restricted to Windows. No settings schema, RPC contract, renderer state shape, or mobile protocol changes are introduced. Execution does not depend on a repository or worktree, so folder workspaces use the same account policy. Remote/native Linux execution keeps the native path. All launches use the existing process wrapper and quoted shell arguments.

Runtime setting changes apply on the next full fetch cycle. Existing Antigravity stale-result/cache behavior during an in-flight runtime switch is unchanged; target-specific cache invalidation is outside this fix.

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)
  • 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)

Not launched locally, and full lint/typecheck/test/build are left to CI.

Use the existing local account policy to run agy version and usage probes in the selected WSL distro. Reuse guarded process and shell helpers while preserving quota safety checks and native execution.
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The rate-limit service now passes Antigravity’s locally resolved runtime target to usage fetching. On Windows, the fetcher checks the selected WSL distribution and runs version and usage probes through WSL. It reports unavailable usage for a stopped distribution and an unavailable CLI when agy is missing inside WSL. Native command resolution remains in use for non-WSL targets. The changes add tests for runtime selection, WSL probe behavior, and native platform handling.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to d065c

On Windows with WSL, noise from a user's shell startup files could occasionally cause Antigravity usage failures to be reported as the wrong kind of error, such as a sign-in problem. Quota retrieval itself is unaffected. A one-line fix is available, so this can be merged with minor follow-up.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reading Antigravity usage from the selected WSL account runtime.
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, reason, linked issue, testing, platform scope, AI use, and checklist status. It also explains th…
Linked Issues check Passed The changes satisfy the coding requirements in #31740. RateLimitService now passes the resolved local account runtime target to Antigravity fetches. Windows WSL execution uses the selected distribut…
Out of Scope Changes check Passed The changes stay within #31740. The modified production files implement runtime-target wiring, WSL Antigravity command construction, fetch behavior, and service propagation. The added tests verify the…
Full details: Description check

Explanation

The description is complete and aligned with the template. It explains the user impact, implementation, reason, linked issue, testing, platform scope, AI use, and checklist status. It also explains that full repository checks remain for CI.

Full details: Linked Issues check

Explanation

The changes satisfy the coding requirements in #31740. RateLimitService now passes the resolved local account runtime target to Antigravity fetches. Windows WSL execution uses the selected distribution, login-shell PATH lookup, guest environment configuration, output fencing, and the existing background distribution gate. The version and usage probes retain minimum-version checks, deadlines, output limits, abort handling, sign-in classification, and model-turn protection. Native execution remains unchanged. Added tests cover explicit and automatic WSL targets, guest-only PATH lookup, stopped distributions, failure guards, and runtime changes between refreshes.

Full details: Out of Scope Changes check

Explanation

The changes stay within #31740. The modified production files implement runtime-target wiring, WSL Antigravity command construction, fetch behavior, and service propagation. The added tests verify these behaviors and preserve native-platform behavior. No unrelated UI, schema, RPC, renderer, translation, mobile, Claude, or Codex changes are reported.

  • 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

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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 912d2fe3-0880-40d9-87e6-1080ce3bf80a
📥 Commits

Reviewing files that changed from the base of the PR and between ad0bf9a and d065cc0.

📒 Files selected for processing: 10
  • src/main/provider-account-services.ts
  • src/main/rate-limits/antigravity-usage-command.ts
  • src/main/rate-limits/antigravity-usage-fetcher.test.ts
  • src/main/rate-limits/antigravity-usage-fetcher.ts
  • src/main/rate-limits/antigravity-usage-wsl.test.ts
  • src/main/rate-limits/service-antigravity-usage.test.ts
  • src/main/rate-limits/service/service-configuration.ts
  • src/main/rate-limits/service/service-full-cycle-preparation.ts
  • src/main/rate-limits/service/service-state.ts
  • src/main/rate-limits/service/service-types.ts

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

maxOutputBytes: ANTIGRAVITY_USAGE_MAX_OUTPUT_BYTES,
signal: options.signal
})
return wslCommand ? { ...result, stdout: wslCommand.readStdout(result.stdout) ?? '' } : result

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

Do not classify unfenced WSL stderr as CLI output.

For WSL probes, buildWslAntigravityCommand redirects agy stderr into the fenced stdout with 2>&1. As a result, result.stderr holds only output from outside the fence: login-shell startup files, the shell itself, and wsl.exe. The fenced stdout feeds the version parse and stdoutShowsModelTurn. The unchanged classifier at Line 219 still receives ${result.stdout}\n${result.stderr}. Startup noise from a user's profile can therefore drive the sign-in, rate-limit, or server classification. This breaks the startup-output fencing that the PR applies to every other read.

The fix is to clear stderr in the WSL branch of runProbe. The fenced stdout already contains the CLI's real stderr, so no CLI output is lost.

🛡️ Proposed fix
--- "a/src/main/rate-limits/antigravity-usage-fetcher.ts"
+++ "b/src/main/rate-limits/antigravity-usage-fetcher.ts"
@@ -162,7 +162,10 @@
       maxOutputBytes: ANTIGRAVITY_USAGE_MAX_OUTPUT_BYTES,
       signal: options.signal
     })
-    return wslCommand ? { ...result, stdout: wslCommand.readStdout(result.stdout) ?? '' } : result
+    // Why: agy stderr is merged into the fence; raw stderr is only login-shell/wsl.exe noise.
+    return wslCommand
+      ? { ...result, stdout: wslCommand.readStdout(result.stdout) ?? '', stderr: '' }
+      : result
   }
 
   // Recheck each read: the CLI can be replaced while Orca runs; unsupported reads spend quota.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return wslCommand ? { ...result, stdout: wslCommand.readStdout(result.stdout) ?? '' } : result
// Why: agy stderr is merged into the fence; raw stderr is only login-shell/wsl.exe noise.
return wslCommand
? { ...result, stdout: wslCommand.readStdout(result.stdout) ?? '', stderr: '' }
: result

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @sojiro-o for this fix and the WSL tests. #31542 covers the same Antigravity usage read through the WSL account runtime (and also re-syncs when the selected runtime changes), so we're going forward with that one and closing this as a duplicate. Much appreciated.

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.

Windows: Antigravity usage is unavailable when agy is installed only in WSL

2 participants