Skip to content

fix(rate-limits): resolve Grok auth from configured WSL runtime - #13839

Open
euclodius wants to merge 3 commits into
stablyai:mainfrom
euclodius:fix/grok-wsl-runtime
Open

euclodius wants to merge 3 commits into
stablyai:mainfrom
euclodius:fix/grok-wsl-runtime

Conversation

@euclodius

@euclodius euclodius commented Aug 11, 2026 •

Copy link
Copy Markdown

Summary

  • Resolve Grok authentication from Orca's configured local account runtime.
  • Preserve host GROK_HOME; on Windows with a WSL runtime, resolve the selected or default distro home and read .grok/auth.json through its UNC path.
  • Use the same bounded asynchronous auth read for account status, full rate-limit refreshes, and Grok-only refreshes.
  • Refresh Grok after runtime changes and discard stale target results before credentials can be sent or attributed to the new target.

Fixes #13784

Screenshots

No visual change.

Testing

  • pnpm lint — not run project-wide; changed-code quality passed with 0 new native, type-aware, or React Doctor findings across 16 changed files.
  • pnpm typecheck — the affected Node TypeScript target passed with pnpm typecheck:node.
  • pnpm test — not run project-wide; 7 focused suites passed locally (123 tests). The resolver-failure follow-up additionally passed 3 affected suites (103 tests).
  • pnpm build — not run; this is a main-process behavior change with no renderer or bundle changes.
  • Added or updated high-quality tests for runtime selection, UNC auth paths, bounded async auth reads, target-change races, account status, refresh synchronization, and WSL resolver failure containment.

AI Review Report

The full runtime target → home resolution → auth read → account status/rate-limit refresh path was reviewed. The review checked selected/default WSL distro behavior, host fallback, stale-target races, account cross-attribution, resolver failures, abort/timeout handling, full versus Grok-only refreshes, and IPC status reuse. It found stale-target races and an uncontained WSL resolver rejection; both were fixed and covered by regression tests. The final independent code and security re-reviews found no remaining actionable blockers.

Cross-platform compatibility was checked explicitly: macOS and Linux remain on the host runtime and preserve GROK_HOME/~/.grok; Windows host behavior is unchanged; Windows WSL uses a normalized \\wsl.localhost\<distro>\...\.grok path. A real Windows Node + wsl.exe smoke against Ubuntu 24.04 resolved the WSL home and read a fresh auth session without printing token or account metadata.

Security Audit

The security review checked credential path selection, token exposure, error sanitization, filesystem timeouts, abort handling, shared-read behavior, and runtime-switch races. Grok tokens remain in the Electron main process and are not added to renderer state or logs. Resolver failures become a sanitized auth error rather than an unhandled rejection. Generation/target checks run before the Grok network request and again before applying results, preventing an old runtime credential from being sent or attributed after a target switch.

Notes

  • WSL home resolution is enabled only for Windows local-account runtime selection; SSH/remote behavior is unchanged.
  • Grok hook discovery is unrelated to quota authentication and is intentionally unchanged.
  • Real smoke result: {"runtime":"wsl","wslDistro":"Ubuntu-24.04","homeResolved":true,"authStatus":"ok","tokenFresh":true}.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 877f79e9-dbd1-4108-9a1f-6c55734abe7c

📥 Commits

Reviewing files that changed from the base of the PR and between cb42b60 and ad40489369cc67a988c8b98e4d959698c9e8492f.

📒 Files selected for processing (16)
  • src/main/grok-accounts/status.test.ts
  • src/main/grok-accounts/status.ts
  • src/main/grok/grok-runtime-home.test.ts
  • src/main/grok/grok-runtime-home.ts
  • src/main/index.ts
  • src/main/ipc/grok-accounts.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/rate-limits/account-runtime-target-sync.test.ts
  • src/main/rate-limits/account-runtime-target-sync.ts
  • src/main/rate-limits/grok-auth.test.ts
  • src/main/rate-limits/grok-auth.ts
  • src/main/rate-limits/grok-fetcher.test.ts
  • src/main/rate-limits/grok-fetcher.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
🚧 Files skipped from review as they are similar to previous changes (15)
  • src/main/rate-limits/grok-fetcher.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/rate-limits/grok-fetcher.test.ts
  • src/main/index.ts
  • src/main/grok-accounts/status.test.ts
  • src/main/ipc/grok-accounts.ts
  • src/main/rate-limits/grok-auth.test.ts
  • src/main/rate-limits/account-runtime-target-sync.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/account-runtime-target-sync.test.ts
  • src/main/grok-accounts/status.ts
  • src/main/rate-limits/service.ts
  • src/main/grok/grok-runtime-home.test.ts
  • src/main/rate-limits/grok-auth.ts

📝 Walkthrough

Walkthrough

Grok now selects a host or Windows WSL runtime and resolves its home directory. Authentication reads use asynchronous filesystem operations with caching, timeouts, abort signals, and explicit error states. Rate-limit service flows use resolved runtime homes and discard stale target results. Settings synchronization refreshes Grok when its runtime target changes. IPC account-status handlers use the shared rate-limit service. Tests cover runtime selection, authentication parsing, concurrency, retargeting, and status mapping.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: resolving Grok authentication from the configured WSL runtime.
Description check ✅ Passed The description covers the change, rationale, linked issue, testing, security, compatibility, and the absence of visual changes.
Linked Issues check ✅ Passed The implementation addresses issue #13784 by resolving WSL Grok homes, using UNC auth paths, sharing async reads, and refreshing after runtime changes.
Out of Scope Changes check ✅ Passed The changes remain focused on runtime-aware Grok authentication, status, rate-limit refreshes, race handling, and related regression tests.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

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

🧹 Nitpick comments (2)
src/main/rate-limits/service.test.ts (1)

344-386: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider covering the retry-exhaustion branch.

This test covers one retarget during resolution, so the second attempt succeeds. The getGrokAccountStatus loop also has an exhaustion branch that returns error: 'Grok runtime changed while reading account status'. That branch is user-visible and currently untested. Add a case where the target changes during both attempts.

src/main/rate-limits/account-runtime-target-sync.ts (1)

41-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Note the guard asymmetry for Grok.

Claude and Codex refresh only when the policy changed and the current service target differs. Grok refreshes on any policy change. The reason is that RateLimitState exposes claudeTarget and codexTarget but no grokTarget, so the second comparison is not available.

The result is a redundant forced Grok fetch when the policy changes but the effective target is already applied. setGrokFetchTarget returns early in that case, so no generation bump occurs and correctness is preserved.

If you want the same gating as the other providers, expose the Grok target on RateLimitState. Otherwise a one-line comment here would record why the guard differs.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c405dad-40b0-407b-80e4-3260f5e76460

📥 Commits

Reviewing files that changed from the base of the PR and between a0a654c and fad600fc5499628de707f023e2c4b58b3706bc91.

📒 Files selected for processing (16)
  • src/main/grok-accounts/status.test.ts
  • src/main/grok-accounts/status.ts
  • src/main/grok/grok-runtime-home.test.ts
  • src/main/grok/grok-runtime-home.ts
  • src/main/index.ts
  • src/main/ipc/grok-accounts.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/rate-limits/account-runtime-target-sync.test.ts
  • src/main/rate-limits/account-runtime-target-sync.ts
  • src/main/rate-limits/grok-auth.test.ts
  • src/main/rate-limits/grok-auth.ts
  • src/main/rate-limits/grok-fetcher.test.ts
  • src/main/rate-limits/grok-fetcher.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts

Comment thread src/main/rate-limits/service.ts Resolved
@euclodius
euclodius force-pushed the fix/grok-wsl-runtime branch 2 times, most recently from 8eb6fe2 to 0df7b53 Compare August 12, 2026 00:29
@AmethystLiang
AmethystLiang requested a review from OrcaWin August 12, 2026 17:03
@euclodius
euclodius force-pushed the fix/grok-wsl-runtime branch from 0df7b53 to 8d3849a Compare August 13, 2026 18:29
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@euclodius

Copy link
Copy Markdown
Author

Coordination note: #13276 adds managed Grok homes for new local host launches and touches some of the same account/IPC/service wiring. This PR remains narrower: it resolves the system-default Grok auth home from Orca's configured host/WSL runtime for Usage. It does not add managed-account billing attribution.

The two changes should be compatible, but whichever lands second may need a small rebase around grok-accounts, register-core-handlers, index.ts, and RateLimitService.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@euclodius
euclodius force-pushed the fix/grok-wsl-runtime branch from ad40489 to f7ca6cd Compare August 15, 2026 10:46
@euclodius
euclodius force-pushed the fix/grok-wsl-runtime branch from f7ca6cd to e45960f Compare August 17, 2026 09:49
@nwparker nwparker removed the P1 label Aug 19, 2026

This branch has not been deployed

No deployments
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.

[Bug]: Grok usage tracking ignores configured WSL account runtime

4 participants