Skip to content

Chats follow an account switch for worker results too - #37126

Merged
brennanb2025 merged 10 commits into
mainfrom
brennanb2025/sta-13191-account-switch-audit
Nov 2, 2026
Merged

brennanb2025 merged 10 commits into
mainfrom
brennanb2025/sta-13191-account-switch-audit

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​369 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2093 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1724
Prod 42 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​308 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1465 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1157

Problem

Since #30955, a coordinator chat that has started any worker ignores a Claude account switch. Every message the user types keeps running on the old account until every worker it started has finished and every result has been read. That can take hours, and a worker stuck open holds the chat on the old account forever. A user who switched because the old account hit its usage limit, or to separate work and personal use, keeps getting answers from the account they left.

Two smaller problems sit in the same code:

  • When the old account had been removed, a worker result that arrived later recreated the removed account's folder and ran on it, or failed with "not signed in".
  • Every options read, model-list read and send for a Claude chat on an Orca-managed account read the account's state file synchronously on the main thread.

What changes for users

After switching Claude accounts, a coordinator chat's next message, and any worker result that arrives later, run on the newly selected account. A reply already running finishes on the account it started on. A chat whose own background tasks are still running keeps its current process until they finish, as before. A removed account's folder is never recreated. The account check that runs before every chat read and send no longer reads the account's state file in a way that blocks the main thread, and chats checking at the same time share one read. Starting a new Claude process (the first message, after the chat was closed, or after a restart) can still read that file in a blocking way while preparing the launch, as before.

Codex chats are unchanged: they stay on the account they were started with.

How

  • One launch account: every Claude launch prepares the current selection (prepareClaudeLaunchAccount). This removes Open chats move to the account you switch to, before their next message #30955's per-account result tracking: the parent-work query, the native response index, its queued and usage-limit carve-outs, the input account recipe on the startup attempt, and the read-only journal restore that existed only to feed it.
  • Removing it also removes the only path that prepared a saved account by id, so nothing can recreate a removed account's folder.
  • Cleanup of state that existed only for that tracking:
    • A journal index that only it queried is dropped on open.
    • Two change-feed fields only it read are removed.
  • The record still saves the account each launch actually ran on (acquiredAccount), which Session History shows. Nothing reads it to choose an account any more.
  • The existing rule that a running reply, the agent's own background work or an assigned worker's open dispatch keeps the live process is unchanged. It decides when a process may be replaced, never which account the next launch uses.
  • The account check before chat reads and sends routes through an async twin of the router's routing read (claudeRoutedHomeAsync). It shares the same login cache, and chats reading at the same time share one read of the state file. Preparing a new Claude process (first message, after the chat was closed, or after a restart) can still read the file synchronously, as before, and terminal launches keep the sync read.

Differences from the common pattern

  • Worker result after a switch: the common pattern queues it as a normal message with no account of its own, so it runs on the current selection. Same here.
  • Removed account with a result still to come: the common pattern acknowledges and drops the result. Here the result runs on the selected account. Intended: a worker's result is not silently lost, and older chats with no usable known account already go to the selected account (10-27 ruling).
  • Conversation whose history exists only under the old account: when history wasn't shared into the new account (data folder on another drive, or conflicting entries kept aside), the result notice is refused with the existing "history is in another account" message and the result stays unread. Switching back alone doesn't deliver it: once the chat can run again (for example after switching back), it is delivered when the user next sends a message in that chat, or after a restart. This applies to ordinary messages already. Temporary: tracked in STA-13329.
  • Saved record of the account a launch ran on: kept for Session History only. Intended: it chooses nothing.

Tests

  • New, on the real-RPC fixture with production report and mailbox delivery, the real account router and the real Claude launch resolution (only the Claude process and its transcripts are scripted):
    • A coordinator on A starts a worker, then the user switches to B. The worker's result arrives before any other message, replaces the idle process and is answered on B; the next message stays on that process.
    • With the process gone (a cold start reads only saved state, as after a restart), a result launches on B and the saved receipt moves from A to B.
    • A worker result and a message from the user, on the same inputs, launch the same account with the same outcome: the old account was removed (runs on the selection, its folder is not recreated); the selected account is signed out (refused as not signed in); history only under the old account (refused, the result stays unread and is delivered after a later message runs on the old account); System default selected.
  • Account state reads: the existing performance test now also starts 10 and 100 reads at once and checks one read of the state file per version of the file.
  • Deleted the test files that covered only the removed tracking.
  • The touched test files pass locally; CI runs the full suite.

Tracked in STA-13191.

…sends

Chat option reads, model-list reads and every send resolved the selected
Claude account through the router's synchronous state-file read. Route them
through an async twin that shares the same login cache. A relaunch for a
removed account no longer prepares (and recreates) its folder.
A coordinator chat that had started any worker kept answering every
message on the account it used before a switch, until every worker it
started finished and every result was read. Every new turn, including a
worker's result, now launches on the selected account. A reply already
running finishes where it started, and a chat whose own background work
is still running keeps its process until that work ends.

This removes the per-account result tracking that held the old account
(the parent-work query, the response index and its queued and
usage-limit carve-outs, the input account recipe on the startup attempt,
and the read-only journal restore that only fed it), plus the journal
index and change-feed fields only it read. A relaunch can no longer
prepare, and so recreate, a removed account's folder. The record still
saves the account each launch actually ran on, for Session History.
@brennanb2025
brennanb2025 marked this pull request as ready for review November 1, 2026 21:45
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 86f850ce-fbd1-43d6-a6ba-059a5dcab303
Commits

Reviewing files that changed from the base of the PR and between 1fb7995 and a712597.

Files selected for processing: 63
  • src/main/claude-accounts/claude-account-folder.ts
  • src/main/claude-accounts/claude-launch-routing.test.ts
  • src/main/claude-accounts/claude-profile-routed-home.ts
  • src/main/claude-accounts/claude-profile-router.test.ts
  • src/main/claude-accounts/claude-profile-router.ts
  • src/main/claude/claude-launch-account.ts
  • src/main/claude/structured/launch/claude-structured-acquisition-launch.ts
  • src/main/claude/structured/launch/claude-structured-launch-account-routing.test.ts
  • src/main/claude/structured/launch/claude-structured-launch-home.ts
  • src/main/claude/structured/launch/claude-structured-launch-resolution.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-prewarm.test.ts
  • src/main/native-chat/agent-session-journal/journal-database-schema.ts
  • src/main/native-chat/agent-session-journal/journal-database.ts
  • src/main/native-chat/agent-session-journal/journal-read-row.ts
  • src/main/native-chat/agent-session-wire/agent-session-history-batches.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-account-recovery.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-account-switch-workers.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-acquisition.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-account.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-orchestration.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-catalog-reads.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-account-routing.test-support.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-conversation-reads.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-delivery.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-types.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-native-responses.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-outgrown-child.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-queued-native-responses.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-read-restore.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-read-restore.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-account-perf.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-account-queue.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-account.test-support.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-account.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-account.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-auth.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-callers-perf.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-callers.test-support.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-cancellation.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-catalog.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-cold.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-nested.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-persisted.test-support.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-recipient.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-routes.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-receiving-sql.test-support.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-startup-attempt-contract.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-startup-attempt.ts
  • src/main/runtime/agent-session-acquired-account.test.ts
  • src/main/runtime/agent-session-record-lineage.ts
  • src/main/runtime/agent-session/records/agent-session-record-store.ts
  • src/main/runtime/orchestration/structured-parent-account-work.ts
  • src/main/runtime/session-tabs/structured-session-account-home-perf.test.ts
  • src/main/runtime/structured-agent-account-home.ts
  • src/main/runtime/structured-agent-launch-composition.test-support.ts
  • src/main/runtime/structured-agent-launch-composition.ts
  • src/main/runtime/structured-agent-runtime-metadata.ts
  • src/main/runtime/structured-agent-session-host-assembly.ts
  • src/main/runtime/structured-agent-session-runtime-contract.ts
  • src/main/runtime/structured-native-work-readers.ts
  • src/main/runtime/workspaces/workspace-process-listing.ts
  • Autofix · 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

@brennanb2025

brennanb2025 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Review loop status: done on the head

The problem. Since #30955, a coordinator Claude chat that had started any Orca worker ignored a Claude account switch: every message, and every worker result, kept running on the old account until all of its workers had finished and every result had been read. That could be hours, or forever for a stuck worker. Users who switched because the old account hit its usage limit kept getting answers from the account they left. Two smaller problems sat in the same code: a worker result arriving after the old account was removed recreated that account's folder (or failed with "not signed in"), and every chat read and send read the account's state file synchronously on the main thread.

What changes for users. After a Claude account switch, a coordinator chat's next message and any worker result that arrives later run on the newly selected account, also after quitting and reopening Orca. A reply already running finishes where it started. A removed account's folder is never recreated. The account check before chat reads and sends no longer blocks the main thread on the state file, and chats checking at once share one read. Codex chats are unchanged.

Fixed during review

  • Many chats reading the account at once each read and parsed the same state file; they now share one in-flight read, with a performance test at 10 and 100 concurrent reads.
  • The new tests scripted the account decision, so they would have passed with the old behavior; they now go through the real account router and launch resolution, and one table checks a worker result and a typed message get the same account and outcome (removed account, signed-out account, history only under the old account, System default).
  • The "history only under the old account" limitation is now tracked in STA-13329 (STA-11300 only covers a custom Claude folder), and the description says how a refused result gets delivered.
  • Main was merged before final QA. Read who each agent works with: its manager, workers and peers #34890 now uses a worker-custody parameter this PR had removed, so that file is left as main has it.

Deferred (P3, none worse for users than main)

  • The cache keeps a "signed out" result after a one-off read failure until the state file changes, and an older background read can briefly replace a newer one for the System default summary. Both are the same on main.
  • Account-state reads still happen synchronously once per naming and when preparing a new Claude process, as before.
  • A nested coordinator that is itself a worker with an open assignment stays on its live process until that assignment settles. This is the existing rule for when a process may be replaced.
  • There's no dedicated test that dropping the old journal index on open keeps existing records; generic open tests and the restart QA cover it.

Verified

  • Review: round 1 (correctness, every consumer, architecture challenger), repair checks, merge checks, and a fresh comparison with the common pattern. Six differences, all labelled in the description. No open P0, P1 or P2.
  • QA, one real run on M4Air on db4dd1f with real Claude and Codex CLIs, two managed Claude accounts A and B:
    • Claude coordinator on A starts a Codex worker, then the user switches to B. The next message runs on B while the worker is still open, and the worker's result wakes the chat on B. Session History shows the B account.
    • Restart: quit with the worker running, relaunch, switch to B without opening the chat. The result wakes the chat on B in the same Claude session, and the next message keeps its context.
    • Codex coordinator: an ordinary message while the worker runs, the result wake, and the same after a restart. Codex stays on its account throughout.
    • Main at c18c358 with the same steps: the message and the result both stay on A while B shows Active.
  • Since QA (QA ran on db4dd1f; review and CI on a712597):
    • 8a90771 changes only a test, adapting it to a dependency main renamed.
    • 7967528 and a712597 merge main. They carry main's fix for its own lint and Source Control test failures; the only conflict was a test file this PR also deletes from.
    • 6189295 merges two imports from the same module in workspace-process-listing.ts that the main merge had duplicated (a lint error), and tidies one test. It changes no behavior and touches none of the QA'd flows. CI lint and typecheck plus the account-home performance test cover it.
  • CI is green on a712597.

Not verified

  • Windows, WSL and SSH weren't run: Claude native chats run locally, and the change is host-only.
  • QA's first restart attempt was void: the rig's stop also killed Orca's terminal daemon, which a user's quit leaves running. The rerun kept the daemon, as a real quit does.
  • Outside this PR: when a worker's terminal dies across a restart, its coordinator isn't told the worker was abandoned. That's the same on main.

For Brennan's review

Branch Main
Next message after switching to B, worker still open (screenshot removed: contained real product data) (screenshot removed: contained real product data)
Worker result wakes the chat (screenshot removed: contained real product data) (screenshot removed: contained real product data)
Result after quitting and reopening (screenshot removed: contained real product data)
Codex result after restart (screenshot removed: contained real product data)
Session History account (screenshot removed: contained real product data)

Where judgment matters:

  1. claude-launch-account.ts:7-28: every Claude launch now takes the current selection; the saved account only feeds Session History.
  2. structured-agent-session-host-delivery.ts:140-142: whether a live process is replaced compares it with the selected account, and the existing work gate decides when.
  3. claude-account-folder.ts:115-140: the shared in-flight read of the state file.

Pending with Brennan (Decision 8): whether a worker's result should instead stay on the account that started the worker. This PR is built as "follow the switch".

@brennanb2025
brennanb2025 merged commit ef32c76 into main Nov 2, 2026
51 checks passed
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