You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(orchestration): a host reconnect retries only sleepers that host owns, not a twin repo's - #49670
When an SSH host reconnects, Orca retries the wakes of sleeping agents on that host. If the same repo was added on two hosts, Orca could mistake host A's sleeping agents for host B's and redo their wake work every time B reconnected. Now a sleeping agent's own saved host decides first, and the repo is only consulted when the agent records nothing about its host.
Files
Added
Deleted
Net
Test
2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$143
$\color{#cf222e}{\Huge{\mathbf{−}}}$7
$\color{#1a7f37}{\Huge{\mathbf{+}}}$136
Prod
5
$\color{#1a7f37}{\Huge{\mathbf{+}}}$68
$\color{#cf222e}{\Huge{\mathbf{−}}}$10
$\color{#1a7f37}{\Huge{\mathbf{+}}}$58
What Changed
Follow-up to #49413. SleptPaneHost.on(host) decided a sleeper's host in this order: its saved partition matched, its saved SSH connection matched, otherwise the repo's first registration (getRepo). Two gaps:
A repo registered on hosts B then A (a twin) resolved to B, so every sleeper of that repo counted as on B, even ones whose partition or saved connection named A.
A folder workspace has no repo row, so it fell through to "unknown host, counts everywhere" even when its partition named another host.
Now ownership is resolved from the pane's own data before any repo fallback:
Partition is a known remote host (SSH or runtime, not the unresolved-owner sentinel): on this host when it is that host, or for an SSH edge when the pane's saved connection is that target. On a runtime edge, a pane whose runtime id rotated (its old partition no longer has the repo, the reconnecting runtime does) follows the repo, but only through a registration dialing the pane's saved nested SSH target, if any.
Otherwise a saved SSH connection names the owner: on this host when the host is that SSH target, or on a runtime edge whose own registration of the repo dials that same target.
Otherwise the local partition matches a local edge.
Only then the repo: on this host when any of its registrations is on it (a twin can't name one owner), off it when it is registered only on other real hosts, and on every host when it has no registration or only the unresolved-owner sentinel (true unknown owner, so no wake is stranded).
The store gains getRepoRegistrations(id), which returns that id's rows from the existing indexed repo lookup (no scan). Host ids still compare canonically, so runtime:wsl:x and runtime:wsl%3Ax match.
Why
The release review found that with 100 sleepers on host A and a twin repo first registered on B, a B reconnect did 200 synchronous Run-owner reads and 100 resume preparations (1,000 / 500 at 500 sleepers). A pane's partition and saved connection are its own record of where it runs; the repo row is shared across hosts and only a fallback.
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
slept-mailbox-wake.performance.test.ts › reconnecting host B reads no Run owner and prepares no resume for %i sleepers host A owns through a twin repo (100, 500): twin repo registered on B then A, sleepers named to A by partition (half) and by saved connection in the local partition (half). The store's getRepo names B first, as the old lookup saw it. A B edge does 0 Run reads and 0 new resume preparations; an A edge still retries them. On the previous code: 200 and 1,000 Run reads (fails).
slept-pane-host.test.ts:
a runtime pane follows its repo to the rotated runtime id only when the old id lost the repo (rotation, still-registered control, and a saved nested target that must match)
a pane whose partition or saved connection names host A is not on its twin repo host B (partition, saved connection, and a folder in A's partition: each is on A, not on B, a runtime or local; plus a runtime pane's nested SSH target, whether partitioned under the runtime or saved locally)
a pane with no known owner counts as on every host (positive control: no registration, or only the unresolved-owner sentinel)
matches a slept pane to its host however the saved host id is spelled (WSL alias control, now through the repo fallback)
Existing an unrelated host reconnect reads none of %i local sleepers' held mail or failed wakes moved from the getRepo stub to getRepoRegistrations, unchanged otherwise.
pnpm check:changed passes (format, lint, typecheck, unit tests, ratchets) on Linux.
Performance
Removes work: a reconnect of an unrelated host no longer reads Run owners or prepares resumes for another host's sleepers. The per-sleeper check is the same map lookups as before plus one iteration of a repo's registration host set (cached per id, usually 1-2 entries).
Risk
Level: Low
Riskiest part: a sleeper whose partition names a remote host but that actually runs elsewhere would no longer retry on the other host's edge. Partitions are written per host, and older builds that mixed hosts did so in the local partition, which still falls through to the saved connection and repo checks. Window reloads and pane edges still retry every sleeper.
Back out with a plain revert. No saved data changes.
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
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)
I stated the risk: what could break, for whom, and how to back it out
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)
Review was skipped as selected files did not have any reviewable changes.
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: 176cea2a-4f32-4029-9e23-fa6a3c23517e
Commits
Reviewing files that changed from the base of the PR and between 62d7def and 4d033fd.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Walkthrough
The change exposes repository registrations through persistence operations and the runtime store. Mailbox routing passes those registrations to SleptPaneHost, which uses them with partitions and saved connections to match panes to hosts. Tests cover matching cases, runtime ID rotation, unresolved ownership, and reconnect behavior for twin repositories.
Merge Risk: Minimal · previous review 62d7d
Reconnecting hosts no longer retry sleeping agents owned by another host that shares a repo registration. Unknown-owner cases still wake on every host, so no wake is stranded. The one open comment is a test-quality improvement, not a merge blocker.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a host reconnect should retry only the sleepers that host owns, not those of a twin repo on another host. It matches the ownership-resolution change in slept-pane-host…
Description check
The description follows the repository template closely. It has the ELI5, What Changed, Why, Testing, Performance, Risk, AI Disclosure section, and checklist. It explains the mechanism, the twin-repo …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: a host reconnect should retry only the sleepers that host owns, not those of a twin repo on another host. It matches the ownership-resolution change in slept-pane-host.ts and the fix described in the PR objectives. The title is long (92 characters) but specific and clear.
Full details: Description check
Explanation
The description follows the repository template closely. It has the ELI5, What Changed, Why, Testing, Performance, Risk, AI Disclosure section, and checklist. It explains the mechanism, the twin-repo gap, the performance regression numbers, the new getRepoRegistrations store method, and the risk with a revert path. The Linked Issue section cites a follow-up to #49413 rather than an actual issue number, which the template says outside contributors must provide. The Risk level is Low, and the template asks for it. The Visual Proof section is N/A with a reason. The manual-test checkbox is unchecked while the automated-test box is checked, which is acceptable. The AI Disclosure section is left as template text and should be filled in if an AI model was used.
Resolution
Optionally, link a real issue number under Linked Issue (currently only 'Follow-up to #49413' is given), and complete the AI Disclosure section if an AI model was used in this change.
Finishing Touches
Fix failing CI checks
Commit to this branch
Create a new PR
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.
Perf scan (head 59ed892a13f, base main at 3e227259249)
No findings. The change removes work.
Trigger: an SSH host connecting (retryOnHostConnect on sshStateChanged) calls retrySleptMailboxWakes(undefined, host). SleptPaneHost.on(host) then runs once for each failed wake and each tracked sleeper. It runs on Electron main, once per reconnect, not per keystroke or per status update.
Work per sleeper, before:getRepo(repoId) (an indexed lookup and a hydrated-row WeakMap read). A twin repo registered on another host first admitted another host's sleepers, so each one cost 2 synchronous Run-owner reads (SQLite) and 1 resume preparation. Measured: 200 reads and 100 preparations at 100 sleepers, 1,000 and 500 at 500.
Work per sleeper, after: map lookups, at most 3 canonical host-id parses, and one pass over the repo's registration host set. That set is cached per repo id in the existing repo lookup, rebuilt only when the repo collection is replaced, and usually holds 1-2 hosts. Measured: 0 Run reads and 0 preparations for the unrelated host, at 100 and at 500 sleepers.
Fleet price: 100+ sleeping agents, 750 worktrees and a dozen repos give ~100 × a constant number of in-memory operations per reconnect. That stays constant per sleeper at 10× fleet. There is no SQL, filesystem or subprocess work, and no publication.
Regression classes: hot-path rescans: the loop is over one repo's registration hosts (a bound of a few), not a collection the size of the fleet; disproved. Per-entity state outlives entity: registrationHostsFor is the lookup's existing cache, replaced along with it; no new map. Sync fs or SQLite on main: none added, and synchronous getRun reads are removed. New idle wakeups: none; no timer, poll, subscription or IPC is added.
Six questions:
Paid before the gate: the owner check now runs before any Run read; reviewed.
Ownership: no new owners; not applicable.
Thread: main, in-memory only; reviewed.
Growth: constant per sleeper; reviewed with N=100/500 counts.
Host: SSH and runtime ids compare canonically; WSL alias covered by a test.
Teardown: no resources retained.
Evidence:slept-mailbox-wake.performance.test.ts › reconnecting host B reads no Run owner and prepares no resume for %i sleepers host A owns through a twin repo (100, 500) fails on base with 200 and 1,000 getRun calls and passes here. pnpm check:changed passed on Linux.
Perf scan (head 0254a9184da, base main at 3e227259249)
No findings. The change removes work.
Trigger: an SSH host connecting (retryOnHostConnect on sshStateChanged) calls retrySleptMailboxWakes(undefined, host). SleptPaneHost.on(host) then runs once for each failed wake and each tracked sleeper. It runs on Electron main, once per reconnect, not per keystroke or per status update.
Work per sleeper, before:getRepo(repoId) (an indexed lookup and a hydrated-row WeakMap read). A twin repo registered on another host first admitted another host's sleepers, so each one cost 2 synchronous Run-owner reads (SQLite) and 1 resume preparation. Measured: 200 reads and 100 preparations at 100 sleepers, 1,000 and 500 at 500.
Work per sleeper, after: map lookups, at most 3 canonical host-id parses, and at most one pass over the repo's registration host set. That set is cached per repo id in the existing repo lookup, rebuilt only when the repo collection is replaced, and usually holds 1-2 hosts. Measured: 0 Run reads and 0 preparations for the unrelated host, at 100 and at 500 sleepers.
Fleet price: 100+ sleeping agents, 750 worktrees and a dozen repos give ~100 × a constant number of in-memory operations per reconnect. That stays constant per sleeper at 10× fleet. There is no SQL, filesystem or subprocess work, and no publication.
Regression classes: hot-path rescans: the loop is over one repo's registration hosts (a bound of a few), not a collection the size of the fleet; disproved. Per-entity state outlives entity: registrationHostsFor is the lookup's existing cache, replaced along with it; no new map. Sync fs or SQLite on main: none added, and synchronous getRun reads are removed. New idle wakeups: none; no timer, poll, subscription or IPC is added.
Six questions:
Paid before the gate: the owner check now runs before any Run read; reviewed.
Ownership: no new owners; not applicable.
Thread: main, in-memory only; reviewed.
Growth: constant per sleeper; reviewed with N=100/500 counts.
Host: SSH and runtime ids compare canonically; WSL alias covered by a test.
Teardown: no resources retained.
Evidence:slept-mailbox-wake.performance.test.ts › reconnecting host B reads no Run owner and prepares no resume for %i sleepers host A owns through a twin repo (100, 500) fails on base with 200 and 1,000 getRun calls and passes here. pnpm check:changed passed on Linux.
Perf scan (head 62d7def60c6, base main at 84bd7ed4198)
No findings. The change removes work.
Trigger: an SSH host connecting (retryOnHostConnect on sshStateChanged) calls retrySleptMailboxWakes(undefined, host). SleptPaneHost.on(host) then runs once for each failed wake and each tracked sleeper. It runs on Electron main, once per reconnect, not per keystroke or per status update.
Work per sleeper, before:getRepo(repoId) (an indexed lookup and a hydrated-row WeakMap read). A twin repo registered on another host first admitted another host's sleepers, so each one cost 2 synchronous Run-owner reads (SQLite) and 1 resume preparation. Measured: 200 reads and 100 preparations at 100 sleepers, 1,000 and 500 at 500.
Work per sleeper, after: a few map lookups and canonical host-id parses. A pane whose own partition decides returns before any repo read. Otherwise there is one indexed rowsFor(repoId) read of the existing repo lookup (rebuilt only when the repo collection is replaced) and a pass over that repo's registrations, usually 1-3 rows, each parsed once or twice. Measured: 0 Run reads and 0 preparations for the unrelated host, at 100 and at 500 sleepers.
Fleet price: 100+ sleeping agents, 750 worktrees and a dozen repos give ~100 × a constant number of in-memory operations per reconnect. That stays constant per sleeper at 10× fleet. There is no SQL, filesystem or subprocess work, and no publication.
Regression classes: hot-path rescans: the loop is over one repo's registration rows (a bound of a few), not a collection the size of the fleet; disproved. Per-entity state outlives entity: rowsFor reads the lookup's existing index; no new map. Sync fs or SQLite on main: none added, and synchronous getRun reads are removed. New idle wakeups: none; no timer, poll, subscription or IPC is added.
Six questions:
Paid before the gate: the owner check now runs before any Run read; reviewed.
Ownership: no new owners; not applicable.
Thread: main, in-memory only; reviewed.
Growth: constant per sleeper; reviewed with N=100/500 counts.
Host: SSH and runtime ids compare canonically; WSL alias covered by a test.
Teardown: no resources retained.
Evidence:slept-mailbox-wake.performance.test.ts › reconnecting host B reads no Run owner and prepares no resume for %i sleepers host A owns through a twin repo (100, 500) fails on base with 200 and 1,000 getRun calls and passes here. pnpm check:changed passed on Linux.
Reviews: fresh Claude and Codex reviews covered every behavioral commit. Over three fix rounds, findings on the runtime-edge paths were resolved: a saved SSH connection owns its pane, a nested runtime target is admitted only through that runtime's own registration, and a rotated runtime id is followed only when the old id lost the repo. The final round's incremental reviews have no open P0/P1/P2. Two documented trade-offs remain, both of which choose extra admission or the authorized strict match over a stranded wake.
Regression audit: a blinded Codex audit of the final increment says SAFE.
Perf: perf-scan verdict clean (comment above). The change only removes work.
Tests:pnpm check:changed passes on Linux (27 checks). The new twin-repo test fails on the base with 200 and 1,000 Run reads.
CI:mobile_web_bundle and orcad terminal smoke fail on the mobile web app eager-size budget, and main's head fails the same check at the same byte count. This PR touches no mobile code, and a separate fix on main is in progress.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Use fixed operation counts for each reconnect phase.
The test accepts any positive setup count and any positive owner-side increase. It can therefore pass when only one of the 100 or 500 owner-side sleepers is retried.
After setup, clear the operation counters. Assert zero Run reads and zero preparations for host B. Then assert the fixed expected preparation count for host A. Add an incident comment naming PR #49670.
As per coding guidelines, a performance contract “counts operations … against hardcoded values” and “names, in a comment, the incident it guards (PR number).”
Source: Coding guidelines
Review info
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: 607383b8-395d-4a6c-b20d-1577da07e514
Commits
Reviewing files that changed from the base of the PR and between 0254a91 and 62d7def.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When an SSH host reconnects, Orca retries the wakes of sleeping agents on that host. If the same repo was added on two hosts, Orca could mistake host A's sleeping agents for host B's and redo their wake work every time B reconnected. Now a sleeping agent's own saved host decides first, and the repo is only consulted when the agent records nothing about its host.
What Changed
Follow-up to #49413.
SleptPaneHost.on(host)decided a sleeper's host in this order: its saved partition matched, its saved SSH connection matched, otherwise the repo's first registration (getRepo). Two gaps:Now ownership is resolved from the pane's own data before any repo fallback:
The store gains
getRepoRegistrations(id), which returns that id's rows from the existing indexed repo lookup (no scan). Host ids still compare canonically, soruntime:wsl:xandruntime:wsl%3Axmatch.Why
The release review found that with 100 sleepers on host A and a twin repo first registered on B, a B reconnect did 200 synchronous Run-owner reads and 100 resume preparations (1,000 / 500 at 500 sleepers). A pane's partition and saved connection are its own record of where it runs; the repo row is shared across hosts and only a fallback.
Linked Issue
Follow-up to #49413 (release review finding).
Visual Proof
N/A: main-process bookkeeping with no UI change.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
slept-mailbox-wake.performance.test.ts›reconnecting host B reads no Run owner and prepares no resume for %i sleepers host A owns through a twin repo(100, 500): twin repo registered on B then A, sleepers named to A by partition (half) and by saved connection in the local partition (half). The store'sgetReponames B first, as the old lookup saw it. A B edge does 0 Run reads and 0 new resume preparations; an A edge still retries them. On the previous code: 200 and 1,000 Run reads (fails).slept-pane-host.test.ts:a runtime pane follows its repo to the rotated runtime id only when the old id lost the repo(rotation, still-registered control, and a saved nested target that must match)a pane whose partition or saved connection names host A is not on its twin repo host B(partition, saved connection, and a folder in A's partition: each is on A, not on B, a runtime or local; plus a runtime pane's nested SSH target, whether partitioned under the runtime or saved locally)a pane with no known owner counts as on every host(positive control: no registration, or only the unresolved-owner sentinel)matches a slept pane to its host however the saved host id is spelled(WSL alias control, now through the repo fallback)Existing
an unrelated host reconnect reads none of %i local sleepers' held mail or failed wakesmoved from thegetRepostub togetRepoRegistrations, unchanged otherwise.pnpm check:changedpasses (format, lint, typecheck, unit tests, ratchets) on Linux.Performance
Removes work: a reconnect of an unrelated host no longer reads Run owners or prepares resumes for another host's sleepers. The per-sleeper check is the same map lookups as before plus one iteration of a repo's registration host set (cached per id, usually 1-2 entries).
Risk
Level: Low
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)