Skip to content

fix(web): show usage and switch Claude/Codex accounts from the paired server - #25133

Closed
gustavobragac wants to merge 2 commits into
stablyai:mainfrom
gustavobragac:fix/web-usage-accounts
Closed

gustavobragac wants to merge 2 commits into
stablyai:mainfrom
gustavobragac:fix/web-usage-accounts

Conversation

@gustavobragac

@gustavobragac gustavobragac commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you use Orca from a web browser, the bottom bar never showed how much of your Claude or Codex quota you had used, and picking a different Claude account did nothing. The server always knew these numbers, but the web page never asked for them. Now the web page asks the server, shows the same usage bars as the desktop app, and account switches are applied on the server.

What Changed

Before: in the paired web client, the status bar had no usage bars, the Usage menu was empty, and the Claude/Codex account switcher listed nothing and switched nothing.

After: the web client shows the server's usage per provider, stays up to date as the server publishes changes, refreshes on demand, and lists and switches the server's Claude and Codex accounts.

Mechanism: the web client keeps activeRuntimeEnvironmentId as null, because it talks to its paired server directly. So the renderer reads usage and accounts through the "local" bridges, window.api.rateLimits, window.api.claudeAccounts and window.api.codexAccounts. On the web those bridges were stubs that returned empty state. This PR backs them with RPCs the server already exposes to paired clients:

Bridge Now calls
rateLimits.get accounts.list { refreshUsage: false } → snapshot.rateLimits
rateLimits.refresh, refresh*ForTarget, fetchInactive*Accounts accounts.list { refreshUsage: true } (also refreshes inactive accounts on the server)
rateLimits.onUpdate one shared accounts.subscribe stream, started with the first listener, stopped with the last, resubscribes 5s after the stream drops
claudeAccounts / codexAccounts list, select, remove accounts.list, accounts.selectClaude/selectCodex, accounts.removeClaude/removeCodex

These things stay as they were:

  • Adding and re-authenticating accounts need the server's own login flow, so they remain unavailable on the web.
  • Redeeming a Codex reset credit is still desktop-only.
  • setPollingInterval is still a no-op: the server owns its poll cadence.
  • A server whose snapshot has no rateLimits publishes nothing. The bars stay hidden instead of showing zeros.

Why

The data was already on the wire: these are the RPCs the mobile app uses for the same screens, they are allowlisted for paired clients, and they need no server or protocol change. Fixing it at the web bridge keeps every renderer reader untouched: status bar, usage roster, provider details, account switcher and Accounts pane. They keep reading window.api.*, which now returns the right data on the web. I considered routing the web client through the "remote runtime environment" code paths, which key off activeRuntimeEnvironmentId. On the web that id is intentionally null, so setting it would have changed unrelated behavior across the app.

Linked Issue

Fixes #25132

Visual Proof

Same server, same web client, before and after this change.

Before After
Before: empty status bar After: status bar with Claude and Codex usage
After: Usage menu
After: Claude details with account switcher

Testing

  • Built the web client (pnpm build:web), paired it with a real orca serve host (v1.4.216, Linux), and checked the status-bar usage, the Usage menu, the Claude details panel and the account switcher.

  • New src/renderer/src/web/web-preload-api-rate-limits.test.ts (7 tests) covers:

    • reading usage from the server
    • forcing a refresh, including the inactive-account fetch
    • falling back to an empty state when the server can't answer
    • forwarding streamed snapshots, ignoring snapshots with no rateLimits, and unsubscribing with the last listener
    • resubscribing after the stream closes
    • listing and switching Claude and Codex accounts

    6 of the 7 fail against the previous stubs.

  • pnpm typecheck, pnpm lint and the web client tests pass locally (Linux).

  • I also ran the full pnpm test locally. Every failure I saw either also fails on a clean main on this machine or passed when rerun. The ones I could diagnose come from the local environment: git diff.mnemonicPrefix, no zsh, network timeouts in the cross-version harness, and the shell environment. None of them touches the files changed here, so CI is the reference for the full suite.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Investigation, implementation and tests were done with Claude Code (Claude Opus 5.5). I reviewed the changes and tested them against my own server.

Review

Self-review summary:

  • Cross-platform: renderer-only TypeScript, no paths, shortcuts or OS APIs.
  • SSH/remote/local: only the web preload bridge changes, so the desktop app (local, SSH, remote runtimes) and the mobile app are unaffected. It uses existing RPCs, so it works with servers that already publish rateLimits in their accounts snapshot. Older servers that omit it show no bars, the same as before.
  • Agents/integrations: provider-neutral. It forwards the server's whole RateLimitState, so every provider the server tracks shows up.
  • Performance: one accounts.subscribe stream per tab, opened only while something listens, with a fixed 5s resubscribe delay. Refresh calls go only to accounts.list.
  • Security: no new RPCs or permissions. Account add/re-auth and reset-credit redemption stay disabled on the web.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Web client only. No server, protocol or desktop changes.

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). Full pnpm test is left to CI, see Testing.

🤖 Generated with Claude Code

The web client stubbed rateLimits, claudeAccounts and codexAccounts, so the
status-bar Usage menu stayed empty and account switching was a no-op. Back
them with the server accounts.list / accounts.subscribe / accounts.select*
RPCs.

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

Important

Three things to address before merge: the changed-code quality gate goes red on type assertions in this diff, switching Codex to "System default" on a WSL lane mutates the wrong lane, and the new usage stream dies permanently after a manual disconnect.

Reviewed changes

  • Web usage bridge — web-rate-limits-api.ts replaces the empty stubs with accounts.list({ refreshUsage }) reads and a shared accounts.subscribe stream, publishing snapshot.rateLimits to onUpdate listeners.
  • Web account bridge — web-agent-accounts-api.ts lists Claude/Codex accounts from the server snapshot and forwards select/remove to the matching accounts.* RPCs.
  • Tests — new web-preload-api-rate-limits.test.ts (7 cases) covering reads, refresh, fallback, streaming, resubscribe and selection.

The approach is sound and the tested read/stream paths behave as described; the findings below are the concrete fallout I could verify.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a7a02984-a599-41e8-a4c1-019c13c8cc3b
📥 Commits

Reviewing files that changed from the base of the PR and between 20dc6c7 and e23f9d5.

📒 Files selected for processing (4)
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/web/preload-api/web-agent-accounts-api.ts
  • src/renderer/src/web/preload-api/web-rate-limits-api.ts
  • src/renderer/src/web/web-preload-api-rate-limits.test.ts

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


📝 Walkthrough

Walkthrough

The web rate-limits API now reads usage snapshots from the paired server and publishes updates from its subscription. It retries failed subscriptions and stops them after the final listener unsubscribes. The Claude and Codex account APIs now list accounts from snapshots and use runtime RPCs for removal and selection. Successful selection triggers a rate-limit refresh. Tests cover these reads, updates, subscription behaviors, and account operations.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e23f9

The inspected usage-stream cleanup and account-removal update paths do not present a merge blocker. The PR is ready for normal merge checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to e23f9

The browser now performs account operations on its paired server. Inspected paths retain pairing checks, server-owned account mutations, and safeguards against switching the wrong runtime. No new authorization bypass was established, but concurrent recovery behavior and compatibility with older servers are not fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A holder of an authorized runtime pairing credential can affect the paired server's managed Claude and Codex accounts, including host and supported WSL selections. This is server-wide account authority, not isolation to one browser-selected account. The inspected base/head comparison indicates that this RPC authority predates the new browser bridge.

Trust Boundaries and Controls

  • observed — Account IDs and operation choices cross from the browser into privileged server account services through authenticated RPC. Dispatch rejects missing, invalid, or channel-mismatched device tokens, derives scope from the device registry, and denies non-allowlisted mobile-scope methods before invoking handlers.

Resilience and Maintainability Implications

  • observed — Account mutation serialization remains server-owned. Claude transitions attempt settings restoration and credential rematerialization on failure. Codex removal performs managed-home removal and cache eviction before returning, while reset-ledger cleanup is best-effort and quota refresh is asynchronous. These existing paths are not evidence of crash-atomic recovery.
  • observed — Inspected environment replacement closes the previous runtime client and its child subscription clients. Transport closure clears subscription registrations; account snapshot routing then has no registered callback to receive later frames. This is counterevidence against the proposed ordinary post-close cross-server snapshot delivery path.

Hardening Proposals

  • proposed — Consider explicit environment-generation checks for queued account calls and snapshot publication across pairing replacement. This would make ownership guarantees easier to verify across request/stream interleavings; it is defense in depth, not a verified authorization bypass.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.26% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. (1 skipped: 1… 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 summarizes the main change: the web client shows usage and switches Claude/Codex accounts through the paired server.
Description check ✅ Passed The description follows the template and explains the user impact, implementation, rationale, linked issue, visual proof, testing, and compatibility considerations. It also discloses the full test-sui…
Linked Issues check ✅ Passed [#25132] web-rate-limits-api.ts reads usage from accounts.list, streams updates from accounts.subscribe, and refreshes server usage. web-agent-accounts-api.ts lists and selects Claude and Code…
Out of Scope Changes check ✅ Passed The changes support the linked issue. The WSL selection safeguards, locale string, account removal RPCs, and focused tests support correct server-backed account behavior. No unrelated changes appear i…
Full details: Docstring Coverage

Explanation

Docstring coverage is 5.26% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
  • Autopilot · 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.

- Route a WSL Codex selection through accounts.selectCodexForTarget so a
  system-default switch clears that lane, not the host lane.
- Refuse a WSL Claude system-default switch on the web: no targeted RPC
  exists and the server would read it as the host lane.
- Start the accounts.subscribe stream inside the promise chain so a manually
  disconnected server cannot leave it stuck until reload.
- Replace type assertions with checked narrowing.

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

Reviewed changes

Reviewed only the new commit e23f9d5 since the prior pullfrog review. It resolves every earlier finding and adds regression coverage for each.

  • WSL Codex lane switching — codexAccounts.select now forwards runtime/wslDistro and routes runtime === 'wsl' to accounts.selectCodexForTarget, so switching a WSL lane to "System default" no longer clears the host lane.
  • WSL Claude refusal — claudeAccounts.select rejects a null selection on a WSL lane with a translated error, since no targeted Claude select RPC exists; a concrete account id still reaches the server, which infers the account's own lane.
  • Usage stream recovery — startStream now resolves the client inside the promise chain with .catch/.finally, so a manually disconnected server resets streamStarting and a later reconnect resubscribes instead of leaving the stream dead.
  • Test hardening — the type assertions the changed-code gate flagged are replaced with type guards and a RuntimeRpcFailure helper, plus tests for WSL Codex targeting, the Claude WSL refusal, and stream reopening after a disconnect.

Verified locally: check:code-quality:changed reports 0 new findings versus 20dc6c74f5, the 10 tests in web-preload-api-rate-limits.test.ts pass, and typecheck:web plus the localization extraction/coverage checks pass.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

OrcaWin added a commit that referenced this pull request Oct 10, 2026
…7135)

The web client's usage and Claude/Codex account bridges were stubs, so the
status-bar usage bars never appeared and switching accounts did nothing.
Back them with the server's existing accounts.list / accounts.subscribe
snapshot (which already carries rate limits) and its select/remove RPCs.
Adding or re-signing accounts now fails with a reason instead of silently
returning an empty roster.

Harvests the approach and tests from #25133 by @gustavobragac.

Co-authored-by: m4air <[email protected]>
Co-authored-by: gustavobragac <[email protected]>
@OrcaWin

OrcaWin commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @gustavobragac! This approach and most of its tests landed in #27135 (credited as co-author), with a few additions: the last usage is kept when a refresh fails, refreshes made at the same time share one request, and add/sign-in-again are refused with a reason. Closing as superseded.

@OrcaWin OrcaWin closed this Oct 10, 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.

[Bug]: Web client shows no usage and can't switch Claude/Codex accounts

2 participants