Skip to content

Add Grok usage status and managed accounts - #7901

Closed
bbingz wants to merge 5 commits into
stablyai:mainfrom
bbingz:fix/grok-usage-status
Closed

bbingz wants to merge 5 commits into
stablyai:mainfrom
bbingz:fix/grok-usage-status

Conversation

@bbingz

@bbingz bbingz commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add Grok usage status fetching with ACP auth support, stale-result protection, and managed GROK_HOME resolution.
  • Add managed Grok account add/select/reauth/remove flows with marker-validated isolated homes.
  • Wire Grok account selection through agent launch, PTY env injection, AI Vault discovery, settings UI, preload IPC, and localization.

Screenshots

No screenshots attached. The change adds a Settings account section and status/account wiring, but no PR evidence images are committed.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test - 2466 test files passed / 25777 tests passed / 3 files skipped / 31 tests skipped
  • pnpm build - not run
  • Added or updated high-quality tests that would catch regressions, including managed-home containment, marker repair, PTY env injection/scrubbing, rate-limit account races, AI Vault discovery, IPC validation, launch env guards, and Codex PTY fallback fetch isolation.

Additional targeted test run:

pnpm exec vitest run --config config/vitest.config.ts \
  src/shared/tui-agent-launch-defaults.test.ts \
  src/main/runtime/orca-runtime-grok-launch-env.test.ts \
  src/main/grok-accounts/managed-home.test.ts \
  src/main/grok-accounts/service.test.ts \
  src/main/rate-limits/service.test.ts \
  src/main/ai-vault/session-scanner.test.ts \
  src/main/ai-vault/session-scanner-grok-managed.test.ts \
  src/main/ipc/ai-vault.test.ts \
  src/main/ipc/grok-accounts.test.ts \
  src/main/ipc/register-core-handlers.test.ts \
  src/main/ipc/pty.test.ts \
  src/main/providers/local-pty-provider.test.ts \
  src/main/daemon/pty-subprocess.test.ts

Result: 13 test files / 449 tests passed.

AI Review Report

Reviewed in two passes with focus on cross-platform and account-isolation risks. Main findings addressed:

  • Windows path containment now rejects cross-drive and sibling-prefix paths instead of relying on path.relative.
  • Shared/renderer launch env no longer trusts settings-sourced managed Grok paths; main PTY spawn injects only marker/root-validated GROK_HOME and scrubs invalid renderer-provided values.
  • Reauth can repair missing markers only for the expected managed home and refuses symlink or out-of-root escapes.
  • WSL and remote launches avoid leaking host-local managed GROK_HOME; daemon and local PTY paths have explicit regression coverage.
  • Full pnpm test initially exposed existing Codex PTY fallback tests touching real backend fetch under fake timers; this PR now stubs that fetch and restores globals/timers so the full suite is deterministic locally.

Cross-platform review covered macOS, Linux, Windows, WSL path handling, PTY spawn env behavior, shell launch paths, IPC validation, and Electron main/preload boundaries touched by this PR.

Security Audit

Reviewed auth and filesystem boundaries for managed Grok accounts:

  • Managed homes require an Orca ownership marker matching the account id before use or deletion.
  • Recursive removal is constrained to marker-validated homes inside Orca managed storage.
  • Reauth marker repair refuses symlinks, non-directories, and realpaths outside the managed root.
  • Main-process PTY env is the trust boundary for managed GROK_HOME; renderer-provided values are overridden or removed when an active managed account is invalid.
  • IPC methods validate account ids before service calls; Grok login output is bounded and child processes use windowsHide.

No secrets are copied into settings; settings store account metadata and managed home paths, while credentials remain inside isolated Grok homes.

Notes

pnpm build was not run locally. Full unit test, typecheck, lint, and targeted regression suites passed on Node 24.18.0.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bf3bc52c-7b70-4459-90db-6e21d43eaaa1

📥 Commits

Reviewing files that changed from the base of the PR and between 8d74cce and 61bb1ff.

📒 Files selected for processing (1)
  • src/main/rate-limits/grok-acp-auth.ts

📝 Walkthrough

Walkthrough

This PR adds Grok managed-account support end to end. Main-process changes add managed-home creation and validation, Grok account state and IPC handlers, AI vault Grok session discovery, PTY and WSL GROK_HOME handling, Grok CLI-based rate-limit fetching, and startup PATH handling. Renderer changes add Grok account settings UI, status bar Grok usage display, and Grok-aware launch environment resolution across composer, worktree, resume, and background session flows. Shared types, preload APIs, default settings, and locale strings are extended accordingly.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR’s main change: Grok usage/status support plus managed Grok accounts.
Description check ✅ Passed The description follows the required template and covers summary, screenshots, testing, AI review, security audit, and notes.
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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/i18n/locales/en.json (1)

6838-6889: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Two Grok search keywords are missing from the accounts.search locale catalog.

accounts-search.ts calls translateSearchKeyword('auto.components.settings.accounts.search.c61b14be7c', 'grok') and translateSearchKeyword('auto.components.settings.accounts.search.a51c85f205', 'GROK_HOME'), but neither c61b14be7c nor a51c85f205 exists under this accounts.search namespace (the other 6 new Grok-related keywords — rate limit, status bar, quota, optional, reauthenticate, plus the title/description — are present). c61b14be7c does exist elsewhere in the file under settings.general.search, but that's a different namespace.

Functionally this degrades gracefully (i18next falls back to the English defaultValue, and English locale skips translate() entirely), so there's no runtime break, but it leaves the non-English catalog incomplete for these two keywords. Based on learnings, new auto-keyed strings should be added to en.json before running pnpm bootstrap:locale-catalog so they propagate to es/ja/ko/zh.

🌐 Proposed fix
       "d09fb5ca92": "Account Location",
+      "c61b14be7c": "grok",
+      "a51c85f205": "GROK_HOME",
       "733f9e2a93": "MiniMax Usage",

Source: Learnings

🧹 Nitpick comments (8)
src/main/daemon/pty-subprocess.ts (2)

715-745: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Grok WSL-home mapping duplicates the Codex block almost verbatim.

The Codex and Grok blocks (681-713 and 715-728) are structurally identical, and the post-chain scrub for Grok (741-745) is written as a separate top-level if instead of folding into the existing if (wsl.exe) {...} else if (...) {...} chain the way Codex's scrub does (line 734-739). The same duplication is repeated in local-pty-provider.ts. Extracting a shared applyWslManagedHomeEnv(env, { key, wslInfo, launchWslDistro, ... }) helper would remove this 4x copy-paste (2 accounts × 2 files) and make the launch-distro fix above land in one place instead of four.


677-728: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

isHostCodexHomeForWsl/isWslCodexHomeForHost are Codex-named but now shared with Grok.

These predicates (from src/main/pty/codex-home-wsl-env.ts) are generic Windows/WSL path detectors, reused here for GROK_HOME. The names still read as Codex-specific, which can mislead future readers into thinking they're Codex-only. Consider renaming to something account-agnostic (e.g. isHostStyleHomeForWsl) now that a second consumer exists.

src/main/ipc/pty.ts (1)

3924-3930: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

registerHeadlessPtyRuntime param style diverges from registerPtyHandlers's options bag.

getSelectedGrokHomePath is added here as a new positional parameter alongside store, whereas registerPtyHandlers groups the equivalent Grok option inside its options object (line 1266). Purely stylistic, but a future addition here will keep growing the positional parameter list.

src/main/rate-limits/grok-fetcher.test.ts (1)

195-363: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering the "no cached_token auth method" branch.

grok-acp-auth.ts's unavailable('Not signed in to Grok. Run \grok login`.', 'missing-credentials')path (wheninitializesucceeds butauthMethodslackscached_token) isn't exercised by this suite. The existing FakeGrokProcesscould easily be extended to return anauthMethods: []` initialize response for one test case.

src/main/rate-limits/service.ts (1)

418-428: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

refreshGrokForAccountChange forces a full fetchAll instead of a Grok-only cycle.

Unlike Codex/Claude account switches, which use dedicated fetchCodexOnly/fetchClaudeOnly cycles, switching the Grok account re-fetches every provider (Claude, Codex, Gemini, OpenCode Go, Kimi, MiniMax) via fetchAll({ force: true }). This causes unnecessary re-fetches/CLI calls for unrelated providers and momentary "fetching" flicker in their status, purely to refresh Grok's usage.

src/main/runtime/orca-runtime-grok-launch-env.test.ts (1)

9-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Regex-based source scan is a brittle proxy for real coverage.

This asserts textual presence of settings/isRemote/launchPlatform/hostPlatform substrings in matched call text rather than verifying actual resolved values — it would pass even if the wrong variable (one that merely contains e.g. "isRemote" in its name) were substituted, and could break on harmless reformatting. Not blocking given today's 5 call sites are simple and non-nested.

src/shared/tui-agent-launch-defaults.ts (1)

108-128: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Remove the dead Grok branch
src/shared/tui-agent-launch-defaults.ts: both paths return env, and the new hostPlatform/launchPlatform/isHostLocalLaunch plumbing plus options.settings are unused. Collapse this to a plain return env unless there’s a missing Grok-specific env change here.

src/renderer/src/components/settings/GrokAccountsSection.tsx (1)

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Widen return type per static analysis: use React.ReactNode instead of JSX.Element.

JSX.Element excludes null, strings, numbers, and fragments, which limits future refactors of this component's return value.

♻️ Proposed fix
-import { useEffect, useState, type JSX } from 'react'
+import { useEffect, useState, type ReactNode } from 'react'
-export function GrokAccountsSection(): JSX.Element {
+export function GrokAccountsSection(): ReactNode {

Also applies to: 60-60

Source: Linters/SAST tools


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 80b20ed3-12d0-47ea-8e54-51fddb3e6494

📥 Commits

Reviewing files that changed from the base of the PR and between 2c20089 and ff9c193.

📒 Files selected for processing (77)
  • src/main/ai-vault/session-scanner-grok-managed.test.ts
  • src/main/ai-vault/session-scanner-source-discovery.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/grok-accounts/grok-auth-file.ts
  • src/main/grok-accounts/managed-home.test.ts
  • src/main/grok-accounts/managed-home.ts
  • src/main/grok-accounts/service.test.ts
  • src/main/grok-accounts/service.ts
  • src/main/index.ts
  • src/main/ipc/ai-vault.test.ts
  • src/main/ipc/ai-vault.ts
  • src/main/ipc/grok-accounts.test.ts
  • src/main/ipc/grok-accounts.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/rate-limits/grok-acp-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
  • src/main/runtime/orca-runtime-grok-launch-env.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/startup/configure-process.test.ts
  • src/main/startup/configure-process.ts
  • src/main/window/attach-main-window-services.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/floating-terminal/FloatingTerminalWindowControls.tsx
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/AgentsPane.tsx
  • src/renderer/src/components/settings/GrokAccountsSection.tsx
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.ts
  • src/renderer/src/components/settings/appearance-status-bar-usage-toggle-entries.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/status-bar-agent-gating.test.ts
  • src/renderer/src/components/status-bar/status-bar-agent-gating.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/tooltip.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.test.ts
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/hooks/useComposerState.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/ai-vault-resume-command.ts
  • src/renderer/src/lib/github-work-item-background-request.ts
  • src/renderer/src/lib/launch-agent-background-session.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-work-item-direct-agent.ts
  • src/renderer/src/lib/onboarding-folder-agent-startup.ts
  • src/renderer/src/lib/resume-sleeping-agent-session.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/store/slices/rate-limits.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/constants.ts
  • src/shared/rate-limit-types.test.ts
  • src/shared/rate-limit-types.ts
  • src/shared/status-bar-defaults.ts
  • src/shared/tui-agent-launch-defaults.test.ts
  • src/shared/tui-agent-launch-defaults.ts
  • src/shared/types.ts

Comment thread src/main/rate-limits/grok-fetcher.ts Resolved
- Guard auth.json read/parse so missing files return null
- Thread AbortSignal through Grok rate-limit fetch and ACP auth
- Pass isRemote:false for floating-terminal agent launch env

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

Run ID: 69cb7c12-43da-48a7-ae39-09cf764388e2

📥 Commits

Reviewing files that changed from the base of the PR and between a1cddd2 and 8d74cce.

📒 Files selected for processing (6)
  • src/main/grok-accounts/grok-auth-file.ts
  • src/main/rate-limits/grok-acp-auth.ts
  • src/main/rate-limits/grok-fetcher.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
  • src/renderer/src/components/floating-terminal/FloatingTerminalWindowControls.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/renderer/src/components/floating-terminal/FloatingTerminalWindowControls.tsx
  • src/main/grok-accounts/grok-auth-file.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/grok-fetcher.ts
  • src/main/rate-limits/service.ts

Comment thread src/main/rate-limits/grok-acp-auth.ts Resolved
@AmethystLiang
AmethystLiang self-requested a review July 9, 2026 09:48
@AmethystLiang

Copy link
Copy Markdown
Contributor

thx for the PR! it's a large PR so will take some time to review

@bbingz

bbingz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by replacement PR #7996 which combines Grok + Antigravity usage status (with #7878). Closing in favor of that stack.

@bbingz

bbingz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Closed in favor of #7996 (combined Antigravity + Grok usage status).

@bbingz bbingz closed this Jul 10, 2026
brennanb2025 pushed a commit to bbingz/orca that referenced this pull request Jul 10, 2026
Grok usage landed on main via stablyai#7869 (superseding this PR's stablyai#7901 lineage),
so this merge keeps main's Grok implementation everywhere the two stacks
overlapped and drops the PR-side Grok stack (managed accounts/GROK_HOME,
fetcher, launch/resume env, appearance catalog). The PR now carries only
the Antigravity usage surfaces.
@bbingz
bbingz deleted the fix/grok-usage-status branch August 1, 2026 00:47
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.

3 participants