Skip to content

feat(mobile): account switcher and rate-limit usage on mobile - #1467

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/mobile-account-switcher
May 5, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/mobile-account-switcher

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1438.

Bridges the desktop's ClaudeAccountService / CodexAccountService / RateLimitService through new accounts.* RPC methods on the mobile WebSocket transport so the companion app can view live rate-limit usage and switch active Claude/Codex accounts per host. Interactive add / re-auth stays desktop-only since they require browser-based PTY login.

Backend

  • New ACCOUNT_METHODS RPC manifest exposing accounts.list / selectClaude / selectCodex / removeClaude / removeCodex / subscribe / unsubscribe.
  • OrcaRuntimeService gains setAccountServices(), getAccountsSnapshot(), select*Account(), remove*Account(), onAccountsChanged(), and refreshAccountsForMobile() (the last one drives rateLimits.refresh() + fetchInactive*AccountsOnOpen() so usage data is populated when a mobile screen first connects).
  • RateLimitService gains an onStateChange() listener API used to fan out live snapshots to subscribed mobile clients.

Multi-socket reconnect fix

Two parallel sockets from the same device (e.g. host page + accounts page) used to clobber each other: OrcaRuntimeRpcServer.onConnectionClose looked up the E2EE channel by deviceToken and the first match won, so closing one screen could destroy the channel the other screen was still using and the device would get stuck reconnecting. Fixed by:

  • WebSocketTransport.onConnectionClose now passes (clientId, ws, hasOtherConnections).
  • Runtime uses exact e2eeChannels.get(ws) and skips runtime.onClientDisconnected() when other sockets exist for the same deviceToken.

Mobile

  • New per-host accounts screen at /h/[hostId]/accounts with Claude + Codex sections, system-default rows, tap-to-switch, streaming accounts.subscribe + pull-to-refresh.
  • Usage bars match the desktop StatusBar convention (% remaining, not % used) with inverted color thresholds: green >=30%, amber <=30%, red <=10%.
  • Fixed-width trailing slot keeps usage-bar widths identical regardless of selection state.
  • Real Claude / OpenAI SVG icons extracted to a shared AgentIcons module.

Home redesign

New Active accounts section between Resume and Quick Actions on the home page. Shows one card per connected host that has at least one account configured, with the active Claude/Codex emails and live 5h / 7d bars. Tap routes to the per-host accounts screen.

Verification

  • pnpm exec tsc --noEmit (mobile) — clean
  • pnpm lint (mobile) — clean
  • pnpm typecheck (root) — clean

Made with Orca 🐋

Jinwoo-H and others added 2 commits May 5, 2026 17:31
Bridge desktop ClaudeAccountService/CodexAccountService/RateLimitService
through new accounts.* RPC methods so the mobile companion can view live
rate-limit usage and switch active Claude/Codex accounts per host.

- Backend: new ACCOUNT_METHODS RPC manifest (list/select/remove/subscribe);
  RateLimitService.onStateChange() listener and OrcaRuntimeService account
  bridge with refreshAccountsForMobile() to repopulate inactive-account
  usage on first mobile open
- Multi-socket fix: ws-transport passes (clientId, ws, hasOtherConnections)
  to onConnectionClose; runtime uses exact ws->channel match and skips
  per-client teardown when other sockets share the same deviceToken, so
  closing one mobile screen no longer destroys the channel another screen
  is using
- Mobile: per-host accounts screen at /h/[hostId]/accounts with Claude +
  Codex sections, % remaining 5h/7d usage bars (matching desktop StatusBar
  semantics), tap-to-switch, streaming subscribe + pull-to-refresh
- Home: new 'Active accounts' section after Resume showing one card per
  connected host with at least one account, with the same usage bars
- Shared AccountUsage module and real Claude / OpenAI SVG icons extracted
  to AgentIcons

Co-authored-by: Orca <[email protected]>
…pshot

Addresses code-review findings and home-screen UX feedback on top of
the initial mobile account-switcher PR.

Subscription correctness (server)
- Eliminate Date.now() subscriptionId collision in accounts.subscribe
  and notifications.subscribe by replacing with a per-process counter
  scoped to a stable per-WebSocket connectionId. Two near-simultaneous
  subscribes from different mobile screens can no longer evict each
  other through registerSubscriptionCleanup's existing-key path.
- Plumb connectionId through RpcContext + RpcDispatcher.dispatchStreaming
  so every streaming handler can scope its cleanup by socket.
- Track subscriptionsByConnection on OrcaRuntimeService and add
  cleanupSubscriptionsForConnection(); the WebSocket transport's
  on-close hook now sweeps every subscription registered for the
  closing socket regardless of hasOtherConnections, so listeners no
  longer leak across reconnects (RateLimitService.stateListeners,
  notificationListeners).

Home screen
- Add 'Account usage' section (renamed from 'Active accounts') after
  Resume showing one card per host with at least one Claude/Codex
  managed account, using shared UsageBar.
- Drop redundant 'Claude'/'Codex' label rows since the icon already
  identifies the provider; promote the email to the primary line.
- Compact Quick Actions to a horizontal icon+label row to save
  vertical space.
- Persist worktreeInfo + accountsByHost to AsyncStorage in a debounced
  home-snapshot cache; cold-start hydrates immediately so Resume and
  Account-usage cards no longer flash empty for ~1s while the WS
  reconnects.
- Render Resume + Account-usage memos from cached data regardless of
  current connection state (previous gating on hostStates === 'connected'
  caused the cards to vanish during reconnects).
- Don't clobber worktreeInfo[hostId] with a zeroed record on transient
  worktree.ps failures; only seed an empty record when no prior entry
  exists. Fixes the host card briefly flipping to '0 worktrees' and
  the Resume card disappearing during reconnects.

Co-authored-by: Orca <[email protected]>
@Jinwoo-H
Jinwoo-H merged commit f938ff1 into main May 5, 2026
3 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/mobile-account-switcher branch May 5, 2026 23:09
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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.

[Mobile-Beta-Feedback]: see and change accounts in mobile

1 participant