Skip to content

fix(ssh): route four host-blind seams through the resolved execution host - #17919

Merged
nwparker merged 9 commits into
mainfrom
fix/host-blind-seams-11163
Sep 2, 2026
Merged

nwparker merged 9 commits into
mainfrom
fix/host-blind-seams-11163

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​818 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​814
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​84

Stacked on #17909. Review that first; retarget to main once it merges.

Closes four of the five residual host-blind sites #17909 identified and left. The unifying rule throughout: resolve the execution host via getRepoExecutionHostId / getWorktreeExecutionHostId, never the raw connectionId field — SSH ownership has two spellings, and code reading only one is wrong for half the rows.

Site 1 — the worktree scan (this is the one that mattered)

orca-runtime-refresh-repo-worktree-scan.ts keyed on repo.connectionId, so a repo stamped executionHostId: 'ssh:*' without a connectionId never resolved a remote worktree at all. Its caller mattered as much as the sites #17909 listed: an ssh:*-only row was also getting a local project runtime and a local:default scan cache key — so the scan never re-ran when the SSH provider generation changed — and a failed remote scan was cached as authoritative.

This unblocked the end-to-end proof #17909 attempted and abandoned:

BEFORE  × scans an executionHostId-only SSH repo over its SSH provider, not on the client
          expected "vi.fn()" to be called with [ 'remote-1' ]; Number of calls: 0
        × routes the PTY of an executionHostId-only SSH worktree to its host
          Error: selector_not_found
            at OrcaRuntimeService.resolveWorktreeSelector ...:105
        Tests  2 failed | 1 passed (3)
AFTER   Tests  3 passed (3)

That selector_not_found is exactly the blocker #17909 described. A third case (legacy connectionId-only) proves the fix is not just "route everything remotely".

Site 2 — managed-worktree create, and the isFolderRepo question

:90 now branches on the resolved SSH connection. The remote pipeline reads repo.connectionId! at a dozen depths, so rather than teach each one the second spelling, the row is normalised once at the branch.

On isFolderRepo returning before the check — it is a real bug, but narrower than it looks. The create itself is host-agnostic: a folder workspace is a registration, not a filesystem operation, and its terminals route through the resolver #17909 fixed. The actual leak is one line — markTrusted was hard-wired to markLocalWorkspaceTrustedForAgent, so a folder repo on an SSH host wrote Codex/Cursor/Copilot trust into the client's config keyed by a remote path. The remote agent never sees the trust; the client gets a bogus entry.

BEFORE  × creates on the SSH host for a repo stamped executionHostId only
          Error: local_worktree_create_ran_for_remote_repo
        × marks a folder workspace trusted on its SSH host, not on the client
        Tests  2 failed | 2 passed (4)
AFTER   Tests  4 passed (4)

Site 3 — runtimeRepoMatchesExecutionHost

A row naming a host in either spelling now matches only that host, while a genuinely host-less legacy row stays adoptable — the documented case the old shape existed to protect.

BEFORE  × matches an unstamped SSH repo against its own host — expected false to be true
AFTER   Tests  7 passed (7)

Site 4 — assertHostIsSupported, split, and the split is the finding

The two operations behind that one guard are not the same:

  • setupExistingFolder now routes ssh:* through addRemoteRepoFromPath — the exact function the desktop IPC handler in the same process already uses.
  • setupClone still refuses, with an accurate message. There is no remote clone anywhere in this process: cloneRepo runs git clone on the client and there is no projectHostSetups:clone IPC handler at all. Accepting ssh:* would have registered the client's copy as the host's repo. The old message was wrong for both — false for existing-folder, misleading for clone.

Two consequences handled rather than left:

  1. An existing spec pinned the old wording; retargeted at what it actually protects (spawnSpy not called, repos empty), which still holds.
  2. A regression this PR introduced and closed: making --host ssh:* reachable made relative CLI paths newly reachable there, and resolveRepoPathArgument only guards when the client is remote — so --host ssh:x --path ./orca sent the client's cwd as the remote path. Guarded, with its own fail-before test showing that literal value.

Also fixed the mirror-image blindness in addRemoteRepoFromPath's dedupe, since the runtime now routes through it.

Site 5 — getRepo(id): handed off with data, not attempted

Of the 45 non-test .getRepo( call sites:

  • 30 host-deciding — the row picks an SSH vs local git/filesystem provider, a PTY route, a WSL distro, a trust write, or a worktree create target. Worst: orca-runtime-persist-headless-terminal-title.ts:168 (every runtime git exec) and :189; register-worktree-create-handlers.ts:40; register-worktree-catalog-handlers.ts:170.
  • 3 destructive — worktree-removal-repo-owner.ts:36, folder-repo-git-upgrade.ts:121, first-work-folder-rename.ts:42 (irreversible moveWorktree).
  • 5 metadata-only, 7 existence checks — safe.

That is a store-contract change needing a host argument or an ambiguity refusal threaded through 33 real decision sites, several destructive. Doing it alongside four other fixes would make all five unreviewable. Two host-safe patterns already exist to migrate onto: resolveWorktreeLaunchHost, and the getRepoExecutionHostId-filtered getRepos() used correctly at base-ref-query-handlers.ts:198-203 and two other sites. Suggested order: the destructive three first (cheap to fail closed), then the git/filesystem target resolvers, then the rest.

Verification

Check Result
4 new/changed test files 18 passed
src/main/runtime + ipc + persistence 965 files, 10380 passed | 21 skipped
src/cli 107 files, 1019 passed
orca-runtime.test.ts 1220 passed | 1 skipped
pnpm tc:node, pnpm tc:cli exit 0
check:code-quality:changed 0 new findings across 24 files

Is #11163 closable?

Not yet — but the gap is now one named thing instead of five. Sites 1-4 have fail-before/pass-after tests, and site 1 is closed provably. What remains is site 5, plus one residual worth naming: runtime-worktree-agent-startup.ts:60 still branches agent detection on raw repo.connectionId — same shape, and it belongs with the site-5 sweep rather than bolted on here.

Refs #11163


Update — retitled, rebased, and two more twins closed

Retitled. The old title, "close the remaining host-blind seams behind #11163", was not what this
does. Measured on src/main + src/renderer, non-test, raw repo.connectionId / repo?.connectionId
reads: 532 on main, 519 after both PRs — 13 converted, ~2%. The body already admitted this
("Not yet — but the gap is now one named thing instead of five"); the title now says it too.

Rebased onto current main and onto the reworked #17909. en.json verified byte-identical to
main (the rebase-loss check, since a stale branch copy silently dropping keys is how three reverts
happened in this sweep).

Inherited from #17909: one shared resolver

getRepoSshConnectionId no longer fires for a local host, which fixes the pullfrog finding
this PR depended on. That matters here specifically: this PR wires that function into the scan, its
cache key, fingerprint capability, cache invalidation, and the remote-repo dedupe — and the old
kind !== 'ssh' fallback made setup-existing-folder --host ssh:develop falsely dedupe onto a
local row. Covered by a test.

The fix is narrow on purpose. An earlier revision also dropped the field for a runtime: host;
review caught that as a regression (it removed a nested-SSH pane's reconnect affordance and made a
remote transcript read as locally readable), so a runtime host keeps its nested target. The
distinction matters to this PR's own uses: fingerprintCapable wants the ownership answer — a
runtime-hosted row is not locally fingerprintable — which is what it now gets.

Two named twins, now closed rather than listed

addRemoteRepoFromPath no longer mints legacy-only rows

It created repos with connectionId and no executionHostId, so this PR's new routing path kept
minting rows in exactly the spelling the PR works around. It now stamps
toSshExecutionHostId(connectionId) at creation. Safe for target rename: reassignSshTargetId
already migrates both spellings (ssh-target-reassignment.ts:70-80).

Tests

Every duplicate-row case in this PR was local-vs-ssh or runtime-vs-ssh. Added two different SSH
hosts
throughout — including a dedupe case where two hosts hold the same path, the mirror image of
the id-only lookup this PR removes.

Check Result
pnpm tc exit 0
src/main + renderer/src/lib + shared + cli 43327 passed | 268 skipped
requested scope (ssh/runtime/persistence/ipc/lib/shared/cli) 25321 passed | 110 skipped
check:code-quality:changed 0 new findings across 34 files

Two failures seen only under the full 4300-file parallel run (ssh-remote-commands.test.ts 30s
timeout; a daemon scrollback spec) pass in isolation and touch untouched timing paths.

Still open

Site 5 (getRepo(id) itself, ~30 host-deciding call sites, 3 destructive) is unchanged and still
the named gap, with the same suggested order. runtime-worktree-agent-startup.ts:60 also still
branches agent detection on raw repo.connectionId.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Worktree scan and cache routing — orca-runtime-refresh-repo-worktree-scan.ts, orca-runtime-list-known-resolved-worktrees-for-explicit-target.ts, and invalidateSshWorktreeScanCacheInternal now resolve sshConnectionId via getRepoSshConnectionId, so an executionHostId: 'ssh:*'-only repo scans over its SSH provider, gets an ssh:<target>:<generation> cache key instead of local:default, and invalidates when the provider generation changes.
  • Managed worktree create — orca-runtime-create-managed-worktree.ts resolves the host once; folder workspaces route agent trust to the owning host, and git workspaces normalize { ...repo, connectionId: sshConnectionId } before the remote-create pipeline.
  • Project host setup — runtime-project-host-setup-controller.ts splits the blanket SSH refusal so setup-existing-folder routes ssh:* through the desktop IPC handler's own addRemoteRepoFromPath while setupClone still refuses with an accurate message.
  • Dedupe and host matching — addRemoteRepoFromPath and runtimeRepoMatchesExecutionHost compare on the resolved execution host, so either spelling of SSH ownership dedupes/matches correctly while a genuinely host-less legacy row stays adoptable.
  • CLI path guard — setup-existing-folder treats an ssh:* host as off-client for relative --path resolution, rejecting relative paths instead of resolving them against the client cwd.

The fail-before/pass-after tests exercise both spellings (connectionId-only and executionHostId-only) and pin the PTY routing, scan provider, and trust targets; the assertions are exact rather than loose.

ℹ️ Nitpicks

  • The comment above getRequiredHostId in src/cli/handlers/project.ts:71-73 still says the runtime rejects every ssh: host "for those operations" — after this PR that is only true of setup-clone; setup-existing-folder now routes ssh:* to the remote registration. Worth a one-line touch-up so the rationale matches the split.
  • runtime-project-host-setup-controller.test.ts names its local-registration test "local and runtime hosts" but only exercises hostId: 'local'; adding a runtime:<env> case would make the title honest.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (ca0fa60), the delta is a two-file import swap that closes the Node-bootability regression the PR itself introduced:

  • Direct SSH registry import — remote-home-path.ts and remote-repo-registration.ts now import getActiveMultiplexer from ssh-target-registry instead of the ipc/ssh barrel, so the runtime path through addRemoteRepoFromPath no longer pulls ipcMain / BrowserWindow (and the wider Electron graph) into the Node-bootable runtime bundle. ipc/ssh.ts:23 re-exports the same function from that registry, so the swap is behavior-preserving on the desktop side.
  • Electron-free transitive graph confirmed — the two files' other imports (ssh-git-dispatch, repo-icon-autodetect) and ssh-target-registry itself import no Electron runtime modules, so the seam is fully closed rather than partially.

The targeted suites still pass (38/38 across runtime-project-host-setup-controller.test.ts and repos-remote.test.ts).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the fix/execution-host-resolution branch from 2654842 to 2358260 Compare September 2, 2026 22:28
@nwparker
nwparker force-pushed the fix/host-blind-seams-11163 branch from f0deb06 to 8619642 Compare September 2, 2026 22:50
@nwparker nwparker changed the title fix(ssh): close the remaining host-blind seams behind #11163 fix(ssh): route four host-blind seams through the resolved execution host Sep 2, 2026
@nwparker
nwparker force-pushed the fix/execution-host-resolution branch from 2358260 to 0b15240 Compare September 2, 2026 22:54
@nwparker
nwparker force-pushed the fix/host-blind-seams-11163 branch from 8619642 to 14577e3 Compare September 2, 2026 22:56
@nwparker
nwparker force-pushed the fix/execution-host-resolution branch from 0b15240 to 5f2c410 Compare September 2, 2026 22:57
@nwparker
nwparker force-pushed the fix/host-blind-seams-11163 branch 2 times, most recently from 5ac7c85 to 680e21d Compare September 2, 2026 23:01

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (f0deb06), the delta is one commit closing the three remaining host-blind twins — launchAgentTerminal, workspace-session export, and remote-repo registration:

  • Agent-launch trust write — launchAgentTerminal now resolves the launch host via resolveWorktreeLaunchHost (the main-side adapter over resolveWorktreeExecutionHost) and writes agent trust with the resolved connectionId, throwing worktree_execution_host_unresolved on ambiguous rows instead of the host-blind getRepo(id)?.connectionId.
  • Session export routing — remote-workspace.ts targetForWorktree routes through resolveWorktreeExecutionHost + createRepoRowExecutionHostLookup, so a session exports to nobody on unresolved ownership rather than the host-blind getRepo(id)?.connectionId.
  • Unified spelling at creation — addRemoteRepoFromPath now stamps executionHostId: toSshExecutionHostId(connectionId) and dedupes on getRepoSshConnectionId, so the runtime's SSH registration path no longer mints connectionId-only rows or misses executionHostId-only duplicates.

The new suites (agent-terminal-launch-trust-host.test.ts, remote-repo-registration.test.ts) and the getRepos projections in the remote-workspace mocks exercise the previously-uncovered two-distinct-SSH-host case with exact assertions rather than loose ones; all 22 tests across the four touched suites pass.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (8619642), the delta is a rebase onto the reworked #17909 base plus a retitle, not a code change to this PR's own surface:

  • Shared resolver inherited, not re-derived — worktree-execution-host-resolution.ts, worktree-launch-host-repo.ts (now a thin adapter over it), the renderer connection-owner-resolution.ts change, and the getRepoSshConnectionId composition (getSshTargetIdForExecutionHost(getRepoExecutionHostId(repo))) all moved into the base branch, so they no longer appear in this PR's diff. The PR's own 21 files are byte-identical to the previously reviewed version (same per-file diff hashes).
  • getRepoSshConnectionId composition — the base now makes the execution host authoritative, so a local/runtime:* row no longer hands out a stale connectionId. This is the exact behavior the PR's new remote-repo-registration.test.ts case (does not dedupe onto a local row that carries a stale connection id) depends on, and it resolves the pullfrog finding this PR wired in.
  • Comment reword — launchAgentTerminal's rationale comment was reworded; no behavior change.

The touched suites still pass (26/26 across the five changed/resolved test files).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…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.
@nwparker
nwparker force-pushed the fix/execution-host-resolution branch from 5f2c410 to 05bc9aa Compare September 2, 2026 23:20
… 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
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
… 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
…H 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
…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.
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.
@nwparker
nwparker force-pushed the fix/host-blind-seams-11163 branch from 680e21d to 36f6ce6 Compare September 2, 2026 23:39
@nwparker
nwparker changed the base branch from fix/execution-host-resolution to main September 2, 2026 23:41

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review (680e21d), the delta is a force-pushed rebase that re-sequences and retitles the six commits without changing the PR's runtime surface:

  • Re-sequenced commits, identical content — the commits now read cbdaeebf7 (worktree scan + managed create) → a9c58bba9 (host-setup split) → 69a502d01 (guard-spec retarget) → f7fb1a64f (CLI absolute-path guard) → bb72699f8 (SSH-registry import swap) → 36f6ce64 (agent-launch + session-export twins). Each maps one-to-one onto a previously reviewed change; the PR's own 21 files are content-identical to the last reviewed version.
  • Shared resolver stays in the base — resolveWorktreeExecutionHost, getRepoSshConnectionId, and workspaceSessionPartitionHostId continue to live in fix/execution-host-resolution (#17909) rather than this PR.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 7c94d12 into main Sep 2, 2026
37 checks passed
nwparker added a commit that referenced this pull request Sep 3, 2026
…t a raw field (#18294)

`repoIsRemote` read `repo.connectionId` directly. That is one of four spellings
of host ownership, so the predicate was wrong in both directions: a row carrying
only `executionHostId: 'ssh:<target>'` read as local and got the Linux-only
`orca-ide` rename it cannot resolve through the relay shim, while a row that
declares itself `local` with a stale `connectionId` read as remote and lost the
rename it needs on a Linux desktop.

The predicate now resolves the host first and asks "does an SSH target hold this
row's files" via `getRepoSshConnectionId`. That keeps a `runtime:` host's nested
SSH target remote (that machine reaches the files through its own relay shim)
while a runtime with no nested target - a full Orca install - stays local, as do
WSL and local.

Its call sites did not all want that question:

- The four launch-scope sites in main already hold the resolved PTY route on
  `TerminalWorkspaceLaunchScope.connectionId`. `scope.repo` is documented display
  metadata and can be a row from a different host than the worktree names, so
  they now read the route they will actually spawn on. A launch shape that
  disagrees with its own route is the bug, not a second predicate.
- `launchAgentInNewTab` picked its repo row with a host-blind
  `store.repos.find`, so a worktree that names its own host could be shaped by
  another host's row. It now resolves through `getConnectionIdFromState`, the
  same rule the file already used for transcript readability.
- `resolveAgentBackgroundLaunchHost` derived the route, the trust write and the
  launch shape from three reads of the raw field; one resolution now feeds all
  three.

Also converts the raw `repo.connectionId` agent-detection probe eight lines above
`buildWorktreeStartupForDraft`'s launch shape, which #17919 deferred precisely
because converting it alone would have left that file internally inconsistent.

Tests cover two distinct SSH hosts (a single-host fixture passes even when the
answer comes off the wrong row, which is how the `ssh:m4air` -> openclaw leak
survived review) and a `runtime:` host carrying a nested SSH target.
nwparker added a commit that referenced this pull request Sep 3, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…t a raw field (stablyai#18294)

`repoIsRemote` read `repo.connectionId` directly. That is one of four spellings
of host ownership, so the predicate was wrong in both directions: a row carrying
only `executionHostId: 'ssh:<target>'` read as local and got the Linux-only
`orca-ide` rename it cannot resolve through the relay shim, while a row that
declares itself `local` with a stale `connectionId` read as remote and lost the
rename it needs on a Linux desktop.

The predicate now resolves the host first and asks "does an SSH target hold this
row's files" via `getRepoSshConnectionId`. That keeps a `runtime:` host's nested
SSH target remote (that machine reaches the files through its own relay shim)
while a runtime with no nested target - a full Orca install - stays local, as do
WSL and local.

Its call sites did not all want that question:

- The four launch-scope sites in main already hold the resolved PTY route on
  `TerminalWorkspaceLaunchScope.connectionId`. `scope.repo` is documented display
  metadata and can be a row from a different host than the worktree names, so
  they now read the route they will actually spawn on. A launch shape that
  disagrees with its own route is the bug, not a second predicate.
- `launchAgentInNewTab` picked its repo row with a host-blind
  `store.repos.find`, so a worktree that names its own host could be shaped by
  another host's row. It now resolves through `getConnectionIdFromState`, the
  same rule the file already used for transcript readability.
- `resolveAgentBackgroundLaunchHost` derived the route, the trust write and the
  launch shape from three reads of the raw field; one resolution now feeds all
  three.

Also converts the raw `repo.connectionId` agent-detection probe eight lines above
`buildWorktreeStartupForDraft`'s launch shape, which stablyai#17919 deferred precisely
because converting it alone would have left that file internally inconsistent.

Tests cover two distinct SSH hosts (a single-host fixture passes even when the
answer comes off the wrong row, which is how the `ssh:m4air` -> openclaw leak
survived review) and a `runtime:` host carrying a nested SSH target.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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