Repository navigation
fix(ssh): resolve the worktree's execution host instead of guessing from one repo row - #17909
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 0b15240af8c96a178cc4c99d9d7e56aa39c52e0c and 5f2c4109f34772d3a6a722457f9dbafd9722faf1. 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change adds shared execution-host resolution and SSH target extraction helpers. Main-process launch resolution now selects the worktree’s execution host across repository rows and rejects ambiguous ownership. Renderer connection ownership uses the same host-aware rule. Runtime and renderer workspace-session paths apply explicit partition ownership modes. Tests cover host matching, ambiguity, SSH connection isolation, and partition mapping. Merge Risk: ⚪ Minimal · up to The PR makes execution-host routing explicit and refuses ambiguous ownership, preventing cross-host misrouting. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The changes satisfy [ Full details: Out of Scope Changes checkExplanation The shared resolver and renderer changes support [ Full details: Description checkExplanation The description provides a detailed ELI5 explanation, change summary, rationale, linked issues, scope limitations, regression risk, and extensive testing results. It does not reproduce every template heading or checklist item, and it omits the required Visual Proof section or an explicit N/A statement, but the core information is complete and relevant.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 0531ba66-ef31-4ee2-b33c-1c8d01107b68
📒 Files selected for processing (10)
src/main/runtime/orca-runtime-resolve-browser-network-execution-host-for-worktree.tssrc/main/runtime/runtime-workspace-session-controller.tssrc/main/runtime/worktree-launch-host-repo.test.tssrc/main/runtime/worktree-launch-host-repo.tssrc/renderer/src/lib/connection-context.test.tssrc/renderer/src/lib/connection-owner-resolution.tssrc/renderer/src/lib/workspace-session-host-persistence.tssrc/shared/execution-host.tssrc/shared/workspace-session-partition-owner.test.tssrc/shared/workspace-session-partition-owner.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the full 10-file diff: a cross-cutting fix that replaces host-blind repo.connectionId reads with execution-host resolution across the renderer connection resolver, the main-process terminal launch path, and the shared workspace-session partition owner.
- Host-aware SSH connection derivation — new
getRepoSshConnectionId/getSshTargetIdForExecutionHostinsrc/shared/execution-host.tsresolve the SSH target off the resolved host, so anssh:-onlyexecutionHostIdrow is no longer read as local and aruntime:-owned row can no longer hand out a client SSH connection. - Terminal launch routing —
resolveTerminalWorkspaceLaunchTargetnow routes throughresolveWorktreeLaunchHostand throwsworktree_execution_host_unresolvedwhen duplicate repo rows conflict, instead of spawning a remote PTY locally with the remote cwd. - Renderer connection resolver —
getConnectionIdFromStateresolves the worktree owner first, prefers a host-scoped repo row, and fails closed toundefinedon ambiguity. - Shared session partition owner —
workspaceSessionPartitionHostIdconsolidates the renderer (local-partition) and runtime (host-partition) owner maps into one function with byte-identical behavior on both sides.
The new tests use exact assertions and are meaningful where they claim fail-before coverage: the ambiguous-duplicate-rows case in connection-context.test.ts genuinely fails against the old last-wins map, and the runtime-worktree-no-client-SSH case in worktree-launch-host-repo.test.ts pins the security-relevant routing. The characterization tests in workspace-session-partition-owner.test.ts are labeled honestly rather than dressed up as regression tests. The consumer audit in the PR body holds up against spot-checks of file-explorer-operation-owner, useAgentDetectionTarget, terminal-pane-host-state, and terminal-tab-close: none turn the new undefined answer into a local action.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…time host getRepoSshConnectionId read only the resolved execution host, so a repo row owned by a runtime that reaches a nested SSH target (connectionId: ssh-*, executionHostId: runtime:*) resolved to no connection — answering 'local' for a remote worktree, the same defect #17909 fixed in the other direction.
There was a problem hiding this comment.
ℹ️ No critical issues — one scoping suggestion inline.
Reviewed changes
Reviewed the follow-up commit that re-opens nested-SSH resolution for runtime-owned rows.
- Nested-SSH fallback —
getRepoSshConnectionIdnow returnsrepo.connectionIdwhen the resolved host is notssh, so a runtime-owned row that reaches its repo over a nested SSH target (the target id lives only inconnectionId) no longer answerslocal.
ℹ️ Nitpicks
- The nested-runtime branch added here has no test coverage: no test file imports
getRepoSshConnectionId, andconnection-context.test.tsnever exercises theexecutionHostId: 'runtime:*'+connectionIdshape. A test pinning that row shape (and the local-row behavior below) would make the branch fail-before/pass-after real rather than incidental.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Review: HOLD. The main-side fix is real and the #11163 diagnosis is exact. Three things block it. 1. The renderer half still leaks between two SSH hosts — and this PR's own main-side sibling gets it rightRunnable probe against The second is a cross-host leak between two different SSH hosts. The main-side resolver in this same PR answers Two resolvers, one right and one wrong, for identical input — which is verbatim what the body says this PR removes ("Two resolvers, one host-aware, feeding one decision"). It reaches Not a regression — 2. Both bot findings are valid, confirmed, and unaddressed against the current headpullfrog, A row explicitly declaring itself local hands out an SSH connection — the raw-field-over-resolved-host read this PR exists to remove. This matters more now than when it was written, because #17919 wires this function into the worktree scan, the scan cache key, fingerprint capability, cache invalidation, and remote-repo dedupe. In that last one it makes CodeRabbit, Related: 3. The rebase is the dangerous kind
And the correct-looking resolution still leaks: that function does Tests don't encode the claimBoth new renderer tests use Duplication
Folder workspaces are unaffected — they take a separate, already ambiguity-aware path. (Residual seam in neither PR: its candidate classifier at Structural context for all of this is filed as #18110. |
2654842 to
2358260
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
ℹ️ No critical issues — two minor consistency notes inline.
Reviewed changes
Reviewed the three commits since the prior Pullfrog review: the shared execution-host rule extraction, the removal of the nested-SSH fallback, and the renderer/main unification.
- Extracted a single execution-host rule — new
resolveWorktreeExecutionHostinsrc/shared/worktree-execution-host-resolution.tsis now answered by both main'sresolveWorktreeLaunchHostand the renderer'sgetConnectionIdFromState, replacing two independent re-derivations that disagreed. - Dropped the nested-SSH fallback —
getRepoSshConnectionIdnow composesgetSshTargetIdForExecutionHost(getRepoExecutionHostId(repo)), so alocal/runtime:*row hands out no SSH connection regardless of a survivingconnectionId(resolving the prior scoping note). - Pinned the composition with tests —
execution-host.test.tsnow importsgetRepoSshConnectionIdand exercises theexecutionHostId: 'runtime:*'+connectionIdrow shape, and a newworktree-execution-host-resolution.test.tscovers cross-host routing, two-spelling agreement, and ambiguity.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| /** | ||
| * How a caller finds repo rows. Main scans the store array; the renderer answers from a | ||
| * WeakMap-memoized index because owner resolution runs inside retained selectors. That is a | ||
| * performance difference, not a different rule. |
There was a problem hiding this comment.
This isn't only a performance difference — the two byId implementations disagree about ambiguity. createRepoRowExecutionHostLookup.byId treats two rows that name the same host in different spellings (connectionId: 'm4air' vs executionHostId: 'ssh:m4air') as agreement — the new treats the two spellings of one host as agreement test pins that — but the renderer's byId (resolveIndexedRepoOwner → repoOwnerIdentity) compares the raw connectionId/executionHostId fields and returns ambiguous for the same pair. Same worktree state: main resolves and launches, the renderer fails closed to undefined.
Technical details
# Unify the two lookups' ambiguity rule (or stop claiming they are one rule)
## Affected sites
- src/shared/worktree-execution-host-resolution.ts:92-94 — `byId` compares `Set(getRepoExecutionHostId(...))`, so two spellings of one host agree
- src/renderer/src/lib/worktree-runtime-owner-index.ts:120-143 — `repoOwnerIdentity` compares `[executionHostId ?? null, connectionId?.trim() || null]`, so the same two rows are `ambiguous`
## Required outcome
- Both sides render the same verdict for duplicate repo rows, or the module doc acknowledges the divergence explicitly.
## Suggested approach
- Base `repoOwnerIdentity` on `getRepoExecutionHostId` (optionally plus connectionId only for legacy rows) so the two spellings of one host are agreement, matching the array-backed lookup and the new test.| throw new Error('worktree_execution_host_unresolved') | ||
| } | ||
| // Metadata only (display name, hook settings); the routing decision is `resolution.connectionId`. | ||
| const repo = resolution.repo ?? this.store?.getRepo(worktree.repoId) ?? null |
There was a problem hiding this comment.
repo is not purely metadata: triggerTerminalSpawnPushTargetMaterialization reads repo.connectionId to pick SSH-vs-local materialization of the fork-PR remote. When resolution.repo is null (a worktree that names a host with no matching row — a state the new tests assert), this falls back to the host-blind getRepo, so materialization can dial a different host's connection than resolution.connectionId.
Technical details
# Feed the materialization path the resolved connection, not a host-blind fallback row
## Affected sites
- src/main/runtime/orca-runtime-resolve-browser-network-execution-host-for-worktree.ts:137 — `repo` falls back to `getRepo(worktree.repoId)` when `resolution.repo` is null
- src/main/runtime/runtime-terminal-spawn-push-target-materialization.ts:27 — reads `repo?.connectionId` and routes `materializeOverSsh` vs local off it
## Required outcome
- Push-target remote materialization routes to the same host the terminal spawn uses (`resolution.connectionId`), not an arbitrary sibling row's `connectionId`.
## Suggested approach
- Pass `resolution.connectionId` (or derive the materialization connection from it) rather than relying on `repo.connectionId`; the "Metadata only" comment should not claim `repo` is never used for routing while this call site consumes `repo.connectionId`.0b15240 to
5f2c410
Compare
…tion Three issues in one defect class: a resolver reads one spelling of one arbitrarily chosen row instead of resolving the worktree's execution host, so something local answers a question about a remote. returned that row's connectionId. With duplicate repo rows for one repo id it could pair a runtime owner with a client-owned SSH connection. It now resolves through the same ambiguity-aware index getRuntimeEnvironmentIdForWorktree uses, prefers the repo row for the host the worktree names, and derives the connection from the resolved host. Conflicting rows return `undefined` (this module's documented "cannot determine the host"), never `null`. `store.getRepo(worktree.repoId)?.connectionId ?? null`. `getRepo` is host-blind and the same repo id can exist on local, SSH and runtime hosts, so a remote worktree could spawn its PTY on the client with the remote cwd. resolveWorktreeLaunchHost picks the row for the worktree's host and reads the connection off that host; conflicting rows are unresolved, not local. session-partition owner maps that contradict each other. Both now compute through one shared function whose argument records the divergence. No behaviour change on either side: converging needs a read-both migration, since both partitions hold real data written by shipping builds.
…time host getRepoSshConnectionId read only the resolved execution host, so a repo row owned by a runtime that reaches a nested SSH target (connectionId: ssh-*, executionHostId: runtime:*) resolved to no connection — answering 'local' for a remote worktree, the same defect #17909 fixed in the other direction.
…ne rule The renderer resolver leaked between two different SSH hosts: a worktree on `ssh:m4air` whose only indexed repo row belonged to `openclaw` answered 'openclaw', because the host-scoped lookup missing fell through to an id-only one. Main's resolver, in the same change, answered 'm4air' — two resolvers, one right and one wrong, on identical input. Both sides now adapt one shared rule (`worktree-execution-host-resolution.ts`): the worktree's own host outranks every repo row, and a row on a different host is never evidence about this one. The renderer's WeakMap index becomes the memoizing adapter it always was; `resolveWorktreeLaunchHost` becomes main's mapping of unresolved onto its throw. Settles the rule the change previously answered two ways. `getRepoSshConnectionId` and `getSshTargetIdForExecutionHost` disagreed for a runtime host carrying a nested `connectionId`; they now compose, so the execution host is the single authority. On a `runtime:*` row that field is a paired HUB's private SSH target, spread through by `repoWithFetchedOwner` and unaddressable from this client — the project-first successor of the row nulls it for exactly that reason. That also fixes the `kind !== 'ssh'` fallback, which fired for `local`: a row declaring itself local handed out an SSH connection.
5f2c410 to
05bc9aa
Compare
There was a problem hiding this comment.
ℹ️ No new issues in this delta.
Reviewed changes
Reviewed the three commits since the prior Pullfrog review: the re-scoping of nested-SSH resolution to runtime hosts, the split of "filesystem-holding target" from "client-dialable route", and the main-side PTY adapter now deriving its connection from the resolved host.
- Re-scoped
getRepoSshConnectionIdtoruntimeonly — a runtime host's nested SSH target (normalizeHostPart(repo.connectionId)) is returned again, while alocalhost still yieldsnull, so the earlierlocal-leaks-a-stale-connection bug stays closed while the renderer can once more read a nested-SSH workspace as non-local. - Split the shared
connectionIdfrom the dialable route —resolveWorktreeExecutionHost'sconnectionIdis now documented as the target whose filesystem holds the workspace (possibly un-dialable), andgetSshTargetIdForExecutionHost(hostId)is the client-dialable answer; the main PTY adapter uses only the latter, so aruntime:host can no longer hand the PTY its nested target. - Pinned the split at three levels —
execution-host.test.ts, the shared rule's tests, and the renderer's connection-context tests each assert the nested-runtime, stale-local, and cross-host cases with exact values rather than truthiness.
Prior review notes remain tracked and unchanged by this delta.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…host (#17919) * fix(host-routing): resolve the execution host before reading a connection Three issues in one defect class: a resolver reads one spelling of one arbitrarily chosen row instead of resolving the worktree's execution host, so something local answers a question about a remote. returned that row's connectionId. With duplicate repo rows for one repo id it could pair a runtime owner with a client-owned SSH connection. It now resolves through the same ambiguity-aware index getRuntimeEnvironmentIdForWorktree uses, prefers the repo row for the host the worktree names, and derives the connection from the resolved host. Conflicting rows return `undefined` (this module's documented "cannot determine the host"), never `null`. `store.getRepo(worktree.repoId)?.connectionId ?? null`. `getRepo` is host-blind and the same repo id can exist on local, SSH and runtime hosts, so a remote worktree could spawn its PTY on the client with the remote cwd. resolveWorktreeLaunchHost picks the row for the worktree's host and reads the connection off that host; conflicting rows are unresolved, not local. session-partition owner maps that contradict each other. Both now compute through one shared function whose argument records the divergence. No behaviour change on either side: converging needs a read-both migration, since both partitions hold real data written by shipping builds. * fix(host-routing): keep nested SSH connections resolvable under a runtime host getRepoSshConnectionId read only the resolved execution host, so a repo row owned by a runtime that reaches a nested SSH target (connectionId: ssh-*, executionHostId: runtime:*) resolved to no connection — answering 'local' for a remote worktree, the same defect #17909 fixed in the other direction. * fix(host-routing): resolve both sides of the execution host through one rule The renderer resolver leaked between two different SSH hosts: a worktree on `ssh:m4air` whose only indexed repo row belonged to `openclaw` answered 'openclaw', because the host-scoped lookup missing fell through to an id-only one. Main's resolver, in the same change, answered 'm4air' — two resolvers, one right and one wrong, on identical input. Both sides now adapt one shared rule (`worktree-execution-host-resolution.ts`): the worktree's own host outranks every repo row, and a row on a different host is never evidence about this one. The renderer's WeakMap index becomes the memoizing adapter it always was; `resolveWorktreeLaunchHost` becomes main's mapping of unresolved onto its throw. Settles the rule the change previously answered two ways. `getRepoSshConnectionId` and `getSshTargetIdForExecutionHost` disagreed for a runtime host carrying a nested `connectionId`; they now compose, so the execution host is the single authority. On a `runtime:*` row that field is a paired HUB's private SSH target, spread through by `repoWithFetchedOwner` and unaddressable from this client — the project-first successor of the row nulls it for exactly that reason. That also fixes the `kind !== 'ssh'` fallback, which fired for `local`: a row declaring itself local handed out an SSH connection. * fix(ssh): resolve the execution host in the worktree scan and managed create The worktree scan and createManagedWorktree both picked remote-vs-local from repo.connectionId, so a row stamped only executionHostId: 'ssh:*' was scanned and created on the client against a remote path. The folder branch returns before the check, so its agent-trust write landed locally too. Refs #11163 * fix(ssh): stop over-rejecting and refusing SSH hosts the process owns runtimeRepoMatchesExecutionHost rejected an unstamped SSH repo against its own ssh:<connectionId>, so repo-add/clone dedupe could register a second row for a path the host already owns. assertHostIsSupported made the CLI/runtime RPC refuse --host ssh:* while the same process's IPC handler routed it correctly; setupExistingFolder now shares that registration. Clone still refuses, because nothing in this process clones onto an SSH host. Refs #11163 * test(ssh): retarget the SSH host-setup guard spec at the substitution it prevents setupProjectExistingFolder now registers the remote path through the same addRemoteRepoFromPath the desktop IPC uses, so it fails on the host's terms (connection not registered) rather than a categorical refusal. The local clone/probe side effects it exists to catch are still asserted absent. Refs #11163 * fix(cli): require an absolute path when setting a project up on an SSH host Routing --host ssh:* to the remote registration made relative paths newly reachable there, and they were resolved against the client cwd — registering a path that names the wrong machine. Refs #11163 * fix(repos): read the SSH registry directly so the runtime stays Node-bootable Routing runtime project setup through addRemoteRepoFromPath dragged ipc/ssh -- and its 25-module electron graph -- into the runtime bundle. ssh-target-registry already exists for exactly this; ipc/ssh only re-exports it. * fix(ssh): close the agent-launch and session-export host-blind twins Three sites left on the legacy spelling, all the same shape as the ones this branch already fixed: - `launchAgentTerminal` did `getRepo(worktree.repoId)` then wrote agent trust with that row's `connectionId`. Host-blind, so a repo id carried by two SSH hosts wrote a remote path into the *client's* Codex/Cursor/Copilot config and the agent on the host never saw the trust. Every sibling call site already passes the resolved `workspace.connectionId`; this was the last that did not. - `targetForWorktree` (workspace-session export) fell back to the same host-blind read, so a session could be published to a machine that never owned the worktree. Unresolvable ownership now exports to nobody. - `addRemoteRepoFromPath` minted `connectionId`-only rows while being the routing path this branch adds, so it kept creating rows in exactly the spelling the branch works around. It now stamps `toSshExecutionHostId(connectionId)` at creation; `reassignSshTargetId` already migrates both spellings, so target rename stays correct. Tests cover two *different* SSH hosts throughout — the case none of the earlier duplicate-row tests had, all of which were local-vs-ssh or runtime-vs-ssh.
…connectionId (#18307) `RuntimeGitTarget` carried `connectionId?: string` and no host id, so `undefined` spelled three different answers at once — "runtime: host", "unresolved", and "genuinely local". Its sole resolver read `store.getRepo(worktree.repoId)?.connectionId` and never looked at `worktree.hostId`, which outranks every repo row, so one arbitrarily chosen row decided the execution host for 36 downstream dispatches. The target now carries `executionHostId: ExecutionHostId` (never null, never optional), resolved through the shared rule that landed with #17909/#17919 and dispatched through the host-keyed routes from #18296. Dispatch sites call `requireRuntimeGitProvider`, where `null` means exactly one thing: the host is `local` and the command runs here as free functions. Four answers that used to collapse into one: - `ssh:x` with a rival row on `ssh:y` — routes to x. Previously the first row won, which is the reproduced cross-host leak. - `local` with a surviving `connectionId` — a row contradicting itself; no SSH connection is handed out. - `runtime:<env>` — throws `ExecutionHostNotDispatchableError`. Its repo row's connection names a target in the *server's* namespace; dialling it here reaches a same-named target on this client. - rival rows disagreeing with no worktree host — `worktree_execution_host_unresolved`, matching the launch path rather than guessing a row. An unreachable SSH host still throws `SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE`; loss of contact is never evidence of locality (docs/reference/ssh-execution-boundary.md). `resolveWorktreeLaunchHost` keeps its exact signature and now delegates to `resolveWorktreeHostRouting`, the same resolution answering "which host is this on" rather than "what may this client dial" — the git target needs the first question because `local` and `runtime:` are two different non-SSH answers. No wire change: `RuntimeGitTarget` is main-process internal, and the SSH and local model-discovery host keys are byte-identical to before. `RuntimeFileTarget` has the same defect in ~30 filesystem dispatches and is deliberately left for a follow-up.
…rom one repo row (stablyai#17909) * fix(host-routing): resolve the execution host before reading a connection Three issues in one defect class: a resolver reads one spelling of one arbitrarily chosen row instead of resolving the worktree's execution host, so something local answers a question about a remote. returned that row's connectionId. With duplicate repo rows for one repo id it could pair a runtime owner with a client-owned SSH connection. It now resolves through the same ambiguity-aware index getRuntimeEnvironmentIdForWorktree uses, prefers the repo row for the host the worktree names, and derives the connection from the resolved host. Conflicting rows return `undefined` (this module's documented "cannot determine the host"), never `null`. `store.getRepo(worktree.repoId)?.connectionId ?? null`. `getRepo` is host-blind and the same repo id can exist on local, SSH and runtime hosts, so a remote worktree could spawn its PTY on the client with the remote cwd. resolveWorktreeLaunchHost picks the row for the worktree's host and reads the connection off that host; conflicting rows are unresolved, not local. session-partition owner maps that contradict each other. Both now compute through one shared function whose argument records the divergence. No behaviour change on either side: converging needs a read-both migration, since both partitions hold real data written by shipping builds. * fix(host-routing): keep nested SSH connections resolvable under a runtime host getRepoSshConnectionId read only the resolved execution host, so a repo row owned by a runtime that reaches a nested SSH target (connectionId: ssh-*, executionHostId: runtime:*) resolved to no connection — answering 'local' for a remote worktree, the same defect stablyai#17909 fixed in the other direction. * fix(host-routing): resolve both sides of the execution host through one rule The renderer resolver leaked between two different SSH hosts: a worktree on `ssh:m4air` whose only indexed repo row belonged to `openclaw` answered 'openclaw', because the host-scoped lookup missing fell through to an id-only one. Main's resolver, in the same change, answered 'm4air' — two resolvers, one right and one wrong, on identical input. Both sides now adapt one shared rule (`worktree-execution-host-resolution.ts`): the worktree's own host outranks every repo row, and a row on a different host is never evidence about this one. The renderer's WeakMap index becomes the memoizing adapter it always was; `resolveWorktreeLaunchHost` becomes main's mapping of unresolved onto its throw. Settles the rule the change previously answered two ways. `getRepoSshConnectionId` and `getSshTargetIdForExecutionHost` disagreed for a runtime host carrying a nested `connectionId`; they now compose, so the execution host is the single authority. On a `runtime:*` row that field is a paired HUB's private SSH target, spread through by `repoWithFetchedOwner` and unaddressable from this client — the project-first successor of the row nulls it for exactly that reason. That also fixes the `kind !== 'ssh'` fallback, which fired for `local`: a row declaring itself local handed out an SSH connection.
…host (stablyai#17919) * fix(host-routing): resolve the execution host before reading a connection Three issues in one defect class: a resolver reads one spelling of one arbitrarily chosen row instead of resolving the worktree's execution host, so something local answers a question about a remote. returned that row's connectionId. With duplicate repo rows for one repo id it could pair a runtime owner with a client-owned SSH connection. It now resolves through the same ambiguity-aware index getRuntimeEnvironmentIdForWorktree uses, prefers the repo row for the host the worktree names, and derives the connection from the resolved host. Conflicting rows return `undefined` (this module's documented "cannot determine the host"), never `null`. `store.getRepo(worktree.repoId)?.connectionId ?? null`. `getRepo` is host-blind and the same repo id can exist on local, SSH and runtime hosts, so a remote worktree could spawn its PTY on the client with the remote cwd. resolveWorktreeLaunchHost picks the row for the worktree's host and reads the connection off that host; conflicting rows are unresolved, not local. session-partition owner maps that contradict each other. Both now compute through one shared function whose argument records the divergence. No behaviour change on either side: converging needs a read-both migration, since both partitions hold real data written by shipping builds. * fix(host-routing): keep nested SSH connections resolvable under a runtime host getRepoSshConnectionId read only the resolved execution host, so a repo row owned by a runtime that reaches a nested SSH target (connectionId: ssh-*, executionHostId: runtime:*) resolved to no connection — answering 'local' for a remote worktree, the same defect stablyai#17909 fixed in the other direction. * fix(host-routing): resolve both sides of the execution host through one rule The renderer resolver leaked between two different SSH hosts: a worktree on `ssh:m4air` whose only indexed repo row belonged to `openclaw` answered 'openclaw', because the host-scoped lookup missing fell through to an id-only one. Main's resolver, in the same change, answered 'm4air' — two resolvers, one right and one wrong, on identical input. Both sides now adapt one shared rule (`worktree-execution-host-resolution.ts`): the worktree's own host outranks every repo row, and a row on a different host is never evidence about this one. The renderer's WeakMap index becomes the memoizing adapter it always was; `resolveWorktreeLaunchHost` becomes main's mapping of unresolved onto its throw. Settles the rule the change previously answered two ways. `getRepoSshConnectionId` and `getSshTargetIdForExecutionHost` disagreed for a runtime host carrying a nested `connectionId`; they now compose, so the execution host is the single authority. On a `runtime:*` row that field is a paired HUB's private SSH target, spread through by `repoWithFetchedOwner` and unaddressable from this client — the project-first successor of the row nulls it for exactly that reason. That also fixes the `kind !== 'ssh'` fallback, which fired for `local`: a row declaring itself local handed out an SSH connection. * fix(ssh): resolve the execution host in the worktree scan and managed create The worktree scan and createManagedWorktree both picked remote-vs-local from repo.connectionId, so a row stamped only executionHostId: 'ssh:*' was scanned and created on the client against a remote path. The folder branch returns before the check, so its agent-trust write landed locally too. Refs stablyai#11163 * fix(ssh): stop over-rejecting and refusing SSH hosts the process owns runtimeRepoMatchesExecutionHost rejected an unstamped SSH repo against its own ssh:<connectionId>, so repo-add/clone dedupe could register a second row for a path the host already owns. assertHostIsSupported made the CLI/runtime RPC refuse --host ssh:* while the same process's IPC handler routed it correctly; setupExistingFolder now shares that registration. Clone still refuses, because nothing in this process clones onto an SSH host. Refs stablyai#11163 * test(ssh): retarget the SSH host-setup guard spec at the substitution it prevents setupProjectExistingFolder now registers the remote path through the same addRemoteRepoFromPath the desktop IPC uses, so it fails on the host's terms (connection not registered) rather than a categorical refusal. The local clone/probe side effects it exists to catch are still asserted absent. Refs stablyai#11163 * fix(cli): require an absolute path when setting a project up on an SSH host Routing --host ssh:* to the remote registration made relative paths newly reachable there, and they were resolved against the client cwd — registering a path that names the wrong machine. Refs stablyai#11163 * fix(repos): read the SSH registry directly so the runtime stays Node-bootable Routing runtime project setup through addRemoteRepoFromPath dragged ipc/ssh -- and its 25-module electron graph -- into the runtime bundle. ssh-target-registry already exists for exactly this; ipc/ssh only re-exports it. * fix(ssh): close the agent-launch and session-export host-blind twins Three sites left on the legacy spelling, all the same shape as the ones this branch already fixed: - `launchAgentTerminal` did `getRepo(worktree.repoId)` then wrote agent trust with that row's `connectionId`. Host-blind, so a repo id carried by two SSH hosts wrote a remote path into the *client's* Codex/Cursor/Copilot config and the agent on the host never saw the trust. Every sibling call site already passes the resolved `workspace.connectionId`; this was the last that did not. - `targetForWorktree` (workspace-session export) fell back to the same host-blind read, so a session could be published to a machine that never owned the worktree. Unresolvable ownership now exports to nobody. - `addRemoteRepoFromPath` minted `connectionId`-only rows while being the routing path this branch adds, so it kept creating rows in exactly the spelling the branch works around. It now stamps `toSshExecutionHostId(connectionId)` at creation; `reassignSshTargetId` already migrates both spellings, so target rename stays correct. Tests cover two *different* SSH hosts throughout — the case none of the earlier duplicate-row tests had, all of which were local-vs-ssh or runtime-vs-ssh.
…connectionId (stablyai#18307) `RuntimeGitTarget` carried `connectionId?: string` and no host id, so `undefined` spelled three different answers at once — "runtime: host", "unresolved", and "genuinely local". Its sole resolver read `store.getRepo(worktree.repoId)?.connectionId` and never looked at `worktree.hostId`, which outranks every repo row, so one arbitrarily chosen row decided the execution host for 36 downstream dispatches. The target now carries `executionHostId: ExecutionHostId` (never null, never optional), resolved through the shared rule that landed with stablyai#17909/stablyai#17919 and dispatched through the host-keyed routes from stablyai#18296. Dispatch sites call `requireRuntimeGitProvider`, where `null` means exactly one thing: the host is `local` and the command runs here as free functions. Four answers that used to collapse into one: - `ssh:x` with a rival row on `ssh:y` — routes to x. Previously the first row won, which is the reproduced cross-host leak. - `local` with a surviving `connectionId` — a row contradicting itself; no SSH connection is handed out. - `runtime:<env>` — throws `ExecutionHostNotDispatchableError`. Its repo row's connection names a target in the *server's* namespace; dialling it here reaches a same-named target on this client. - rival rows disagreeing with no worktree host — `worktree_execution_host_unresolved`, matching the launch path rather than guessing a row. An unreachable SSH host still throws `SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE`; loss of contact is never evidence of locality (docs/reference/ssh-execution-boundary.md). `resolveWorktreeLaunchHost` keeps its exact signature and now delegates to `resolveWorktreeHostRouting`, the same resolution answering "which host is this on" rather than "what may this client dial" — the git target needs the first question because `local` and `runtime:` are two different non-SSH answers. No wire change: `RuntimeGitTarget` is main-process internal, and the SSH and local model-discovery host keys are byte-identical to before. `RuntimeFileTarget` has the same defect in ~30 filesystem dispatches and is deliberately left for a follow-up.

The shared defect
All three issues are one shape: a resolver reads one spelling of one arbitrarily-chosen row instead of resolving the worktree's execution host. The seam already exists —
getRepoExecutionHostId/getWorktreeExecutionHostIdinsrc/shared/execution-host.ts— and each path bypasses it for rawrepo.connectionIdplus a host-blind lookup by id.Two facts make that unsafe, and the codebase already documents both:
Repo.executionHostIdpermits`ssh:${string}`, andgetRepoExecutionHostIdtreats it as authoritative overconnectionId.project-host-operations.ts:207is a first-winsrepos.find(r => r.id === id)— and ten lines below,setResolvedRepoGitUsernamerefuses that exact lookup: "the same id can exist on several execution hosts, and an id-only lookup would write one host's username onto a sibling host's row." The renderer had the identical hazard.#17799 — fixed at the seam
getConnectionIdFromStateresolved through last-wins maps and returnedrepo.connectionId ?? null, while its siblinggetRuntimeEnvironmentIdForWorktreeused the ambiguity-awareresolveIndexedWorktreeOwner/resolveIndexedRepoOwner. Two resolvers, one host-aware, feeding one decision.It now resolves the worktree first, prefers
findIndexedRepoOwnerForHostso the connection comes off the same host record the runtime owner came from, and derives the connection via a newgetRepoSshConnectionIdrather than reading.connectionId— so aruntime:-owned row can no longer hand out a client SSH connection, and anssh:-only row is no longer read as local.On the "
nullmeans local" trap: no new state was introduced.undefinedwas already this module's documented "cannot determine the host" —isWorktreeConnectionResolvedexists purely to test for it, added for #6648, the same failure mode. Every non-test consumer was audited; the table is in the commit. Summary:file-explorer-operation-owner→unresolved, blocks destructive ops;useAgentDetectionTarget→ skip;isNativeChatTranscriptLocalReadable→ false; the file-preview family all compare=== nullsoundefinednever takes the local branch. The single coercion (use-tab-bar-runtime-model:136) is display-only, deciding which Windows shells to offer. No consumer turnsundefinedinto "run it locally" — nothing here can reach a teardown RPC the way #14004 did.Two tests: the ambiguous case refuses, and duplicate rows that agree still resolve — so the fix isn't just "refuse more".
#11163 — partly fixed; the PTY-routing seam
resolveTerminalWorkspaceLaunchTargetdidthis.store?.getRepo(worktree.repoId)thenconnectionId: repo?.connectionId ?? null— and thatconnectionIdis the routing key handed straight toptyController.spawn.getRepois host-blind, so a remote worktree whose repo id also has a local row gets the local row,connectionIdreadsnull, and the PTY spawns on the client with the remote cwd — producingDaemonProtocolError: Working directory "…" does not exist, exactly the reported error. It ignoredworktree.hostIdentirely.The damning part: 98 lines above, in the same class,
resolveBrowserNetworkExecutionHostForWorktreeanswers the identical question correctly withgetWorktreeExecutionHostId(worktree, repo). The seam existed; the terminal path bypassed it.New
worktree-launch-host-repo.tsselects the row for the host the worktree names and returnsambiguouswhen rows conflict; the launch scope throwsworktree_execution_host_unresolvedrather than falling back to local.Honest note on the test: it is a unit test of the new resolver, so it "fails before" only trivially. An end-to-end
createTerminaltest was attempted and abandoned, and the reason is itself a finding — the worktree scan is host-blind on the same field, so anexecutionHostId:'ssh:*'-only repo never resolves a remote worktree at all, and duplicate-id rows fail selector resolution before reaching the launch scope. That needs the scan seam fixed first.Residual host-blind sites found and deliberately not fixed (each needs its own change): the worktree scan (
orca-runtime-refresh-repo-worktree-scan.ts:95,101); managed-worktree create (:90, and noteisFolderReporeturns before that check, so a folder repo on an SSH host takes the local path);getRepoitself (fixing it would fix ~100 downstream readers but is a store-contract change);runtimeRepoMatchesExecutionHostover-rejecting an unstamped SSH repo against its own host; andassertHostIsSupportedrefusing--host ssh:*from the CLI while the same process routes it correctly via IPC.Verdict: partly fixed, not closable.
#12723 — contained, not converged
Confirmed in both directions: the renderer collapses
ssh:*tolocal;runtime-workspace-session-controller.ts:47returnsssh:<targetId>verbatim. Same worktree, two durable homes, both written by the shipping build.Not converged, deliberately: flipping either resolver orphans whichever store it stops reading, and a safe migration needs a read-both transition generalizing
workspaceSessionPartitionIdsForHost— larger than this task and not something to land half-done next to session state.Instead: one shared owner map,
workspaceSessionPartitionHostId(hostId, sshOwnership), with the renderer passing'local-partition'and the runtime'host-partition'. Behaviour on both sides is byte-identical (33 existing tests unchanged and passing). The divergence is now one argument in one documented place, and the comment records the decision: converge onhost-partition, because Orca Remote already partitions asruntime:*, so collapsing SSH deepens the fork while partitioning it moves toward one model. Flipping becomes a one-line change plus the migration.Its test is characterization, not fail-before/pass-after — stated plainly rather than dressed up.
Verification
orca-runtime.test.tspnpm tc:node/pnpm tc:webcheck:code-quality:changedOne flake seen in a run that raced
oxfmt --writeover 22k files (worktree-removal-and-reconciliation.spec.ts:289); clean on re-run and in isolation, and that path is untouched here.Fixes #17799
Refs #11163, #12723
ELI5
Orca sometimes acted on the wrong machine. When two projects shared an id — one local, one on an SSH host — a lookup grabbed whichever row it saw first, so a remote terminal could launch locally with a remote path and fail with a confusing 'directory does not exist'.
User-facing regression risk
Update — the renderer half was still wrong, and is now fixed
Rebased onto current
main. Review found the PR's central claim false for the renderer:getConnectionIdFromStatepreferredfindIndexedRepoOwnerForHost, but when that missed it fellthrough to an id-only lookup and answered with whatever host that row named. So a pane on
ssh:m4airwas offered "Reconnect openclaw" (terminal-pane-host-state.ts:28) and thefile-drop/paste paths read off
openclaw. The main-side resolver in this same PR answered'm4air'— two resolvers, one right and one wrong, on identical input, which is verbatim what thisPR said it removes.
mainis equally wrong, so it is not a regression, but the claim did not hold.One resolver, two adapters
New
src/shared/worktree-execution-host-resolution.tsholds the rule; both sides adapt to it:resolveWorktreeLaunchHostis now the array adapter plus itsunresolved→ throw mapping;The intersection is the discriminator plus
connectionId: string | null. The repo row rides alongas display metadata and is still fallback-patched at the main call site.
The nested-SSH rule — corrected after review
An earlier revision of this PR made
getRepoSshConnectionIdcompose withgetSshTargetIdForExecutionHost, on the premise that the two "contradicted" each other for aruntime host carrying a nested
connectionId. That premise was wrong, and review caught it.They are not two answers to one question; they are two questions:
getRepoSshConnectionId(repo)getSshTargetIdForExecutionHost(hostId)nullCollapsing them broke
terminal-pane-host-state.test.ts— the one red lane — and the failure wasreal, not a stale expectation:
selectRuntimeAwareSshStatus(state, environmentId, targetId)looks upsshStateByEnvironment.get(environmentId).connectionStates.get(targetId).The
(environmentId, ssh host)pair is expressible and is expressed — the renderer recoversthe environment from the worktree and pairs it with the target. Nulling the target half removed a
nested-SSH pane's way back to its session.
nativeChatTranscriptIsLocalReadableflippedfalse → true.isNativeChatTranscriptLocalReadabletreatsnullas "this client can read it", and ~14 callsites gate transcript reads on it. That is the exact failure class this sweep exists to remove —
a client inferring something only the host can know.
The rule now distinguishes the two non-SSH hosts, because they are not alike:
localhas no SSH namespace to nest in, so a survivingconnectionIdis a row contradictingitself — the shape main's own
resolveRepoOwnershipEvidencecallscontradictory. This is thepullfrog finding, and it is fixed: a row declaring itself local hands out no SSH connection.
runtime:<env>is a different machine with its own SSH targets, and a nested one appearsonly in this field. It is kept.
project-host-routing.ts:73nulling the field is not counter-evidence: it stops a paired clienttreating that id as client-local configuration, which is the routing question — and the routing
answer is still
null. Main's launch adapter now derives its PTY route fromhostId, never fromthe row, so the two consumers get opposite answers from one resolution by design.
The cross-host leak fix is unaffected and is the part that stands: a row on a different host
is never evidence about this one. A row on the worktree's own host still is — that is where the
nested target legitimately lives.
Confirmed bot findings, both fixed
execution-host.ts:184— the fallback fired forkind !== 'ssh', which includeslocal:getRepoSshConnectionId({executionHostId:'local', connectionId:'openclaw'})returned'openclaw'. A row declaring itself local handed out an SSH connection. Fixed narrowly:localyields no connection, while a runtime host keeps its nested one.
connection-owner-resolution.ts:93— the id-only fallback after host resolution;the severe variant is the cross-host leak above.
Tests
No test in either PR used two different SSH hosts — every duplicate case was local-vs-ssh or
runtime-vs-ssh, which is exactly why the leak survived. Added at three levels (shared rule, main
adapter, renderer). Both renderer tests also used
worktreesByRepo: {}, so a PR titled "resolve theworktree's execution host" had no renderer test where a worktree carried a
hostId; the new onesdo.
pnpm tcsrctree (main+renderer+shared+cli+preload)terminal-pane-host-state.test.tscheck:code-quality:changeden.jsonvsmain