Skip to content

feat(claude-accounts): account pool picks the account with the most headroom for each new launch - #37572

Closed
nachumi-a2zoperations wants to merge 22 commits into
stablyai:mainfrom
A2Z-Operations:pr/claude-account-pool
Closed

nachumi-a2zoperations wants to merge 22 commits into
stablyai:mainfrom
A2Z-Operations:pr/claude-account-pool

Conversation

@nachumi-a2zoperations

Copy link
Copy Markdown

ELI5

With the pool on, each new Claude session Orca starts goes to the signed-in account with the most room, instead of always to the selected one. The selected account stays the status-bar account and the fallback. Off by default.

What Changed

  • Setting claudeAccountPool: 'off' | 'on' (default off). chooseClaudePoolAccount ranks signed-in accounts with a fresh reading, no failure hold, not hand-pinned; headroom = min over the 5-hour and weekly windows; candidates need ≥ 10 points; most headroom wins, tie → fewest assigned sessions → account order. Nobody ranks → selected account, marked fallback.
  • Decision sits in resolveRuntimeClaudeAuth, so new pane, worker terminal and mobile restore all get it; explicit --account and a remembered resume account win over the pool. A pooled launch sets CLAUDE_CONFIG_DIR to the chosen folder and records source: 'pool'.
  • Rebalancer: when the pool is on and the mover is on, panes on an over-line account are moved to the pool's choice (it is a session move, hence this PR sits on the mover).
  • Surface: Settings › Accounts › Claude "Start new sessions on the account with the most room" (hidden under two accounts); orca account pool --agent claude --on|--off; account list prints pool: on|off; pooled panes carry an account badge in the switcher.

Why

#37257. A coordinator dispatching ten workers in a minute put all ten on one account while others sat at 5%. Pairs with the auto-switch (which moves the pointer) and with #33193 (priority order fits as a tie-break).

Linked Issue

#37257, #8770, #7782, #33193. Stacked on the mover PR.

Visual Proof

account list showing sessions spread across accounts with source: pool.

Testing

Pool policy: headroom across windows, reset window = empty, tie-breaks, stale skip, all-stale fallback, pinned exclusion, 10-point floor, signed-out/held, null when nothing selected; launch: CLAUDE_CONFIG_DIR follows the choice, explicit/remembered win. Full check-changed on the gated sha 29/30 (unit = Mac-local). Manual: coordinator plus workers across seven accounts.

  • I manually tested these changes locally
  • Automated tests added/updated

@nachumi-a2zoperations
nachumi-a2zoperations force-pushed the pr/claude-account-pool branch 4 times, most recently from d7df158 to 2cc838e Compare November 6, 2026 12:47
The registry names the account a pane consumes. Automatic switching stays off until it is turned on, and a headless host keeps usage polled while it is on.
The polling switch takes the settings it actually reads. Tests stamp a fixed expiry and a stepping file mtime so the flaky-clock ratchet stays at its baseline.
The command is already in the account spec and the site reference. The root help is the list a user sees first.
The account commands read --on and --off as bare switches, but registering them as global boolean flags broke `orchestration worker-start --on <server>`, whose --on takes a value. The argument parser already treats a flag followed by another flag or by nothing as a switch, so the account commands keep working without the global entry.
The data-account snapshot helpers move beside the controller.
The proxy stays off unless claudeAuthProxy is true. Each launch gets a loopback slot URL in ANTHROPIC_BASE_URL unless the user set one; the pane registry records the slot and the account it bills. The session mover's proxy move strategy is not part of this change.
A launch and a quota poll each kept a slot the pane never used, so a headless status listed leftovers while account list showed sessions: 0. Forget, status, and the spawn merge now drop those slots, and a reattach into an empty registry records the live account without storing a slot the process did not receive.
… policy RPCs within the line limit.

The pane registry learns a launch at spawn commit, so the proxy slot and billed account of every live pane are known. The Claude policy RPC handlers and the data-account snapshots move beside the account controller, and the account CLI group gets its own module, so no file exceeds the lint budget. The two proxy tests that time a real idle timeout and a real stop() say so; the slot prune test runs on a fixed clock.
The 200 ms idle timer and the socket reset can land late when the full suite runs; the test still proves the idle cut happened after the budget.
…a loaded machine.

The ticks come every 40 ms; a 2 s idle budget still proves a writing stream is kept while a loaded suite cannot cut it by delaying one tick past 200 ms.
The default is ask, and a headless host treats ask as move. A quiet wait lets background work finish, and the hand-off note still lists jobs when the job script is absent. With the auth proxy on, a move retargets the pane's loopback slot instead of restarting Claude.
The hand-off calls the durable-job listing through Reflect.apply, and the stop handle starts unset through a helper. Both stay typed without a cast.
orcad and the CLI import the language detector, so the desktop entry binds the Electron read. Root help now lists auto-switch and session-mover, the account commands this branch ships.
anti-slop rejects Reflect.apply. The hand-off note checks the script export and calls it.
The session-mover command reads them as bare switches; the parser already treats a flag followed by another flag or by nothing as a switch, so no global boolean entry is needed.
Off unless claudeAccountPool is 'on'. An Orca-made Claude launch then starts on the signed-in account with the most room left, the pane registry records the pool pick, and the rebalancer moves a session whose account runs out ahead of the others. `orca account pool --on|--off`, `orca account moves`, the Settings row, the status-bar Pool badge with per-account session counts, and the tab chip come with it.
@nachumi-a2zoperations

Copy link
Copy Markdown
Author

Closing as part of the #37567 to #37573 stack: this account work now lives in a plugin built on the Orca plugin system. What the plugin needs from Orca is proposed in #43379 and #43389.

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.

1 participant