Skip to content

fix(ssh): resolve the worktree's execution host instead of guessing from one repo row - #17909

Merged
nwparker merged 3 commits into
mainfrom
fix/execution-host-resolution
Sep 2, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/execution-host-resolution

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​474 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​474
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​275 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​266

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 / getWorktreeExecutionHostId in src/shared/execution-host.ts — and each path bypasses it for raw repo.connectionId plus a host-blind lookup by id.

Two facts make that unsafe, and the codebase already documents both:

  1. SSH ownership has two spellings. Repo.executionHostId permits `ssh:${string}`, and getRepoExecutionHostId treats it as authoritative over connectionId.
  2. One repo id can name several rows on different hosts. project-host-operations.ts:207 is a first-wins repos.find(r => r.id === id) — and ten lines below, setResolvedRepoGitUsername refuses 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

getConnectionIdFromState resolved through last-wins maps and returned repo.connectionId ?? null, while its sibling getRuntimeEnvironmentIdForWorktree used the ambiguity-aware resolveIndexedWorktreeOwner / resolveIndexedRepoOwner. Two resolvers, one host-aware, feeding one decision.

It now resolves the worktree first, prefers findIndexedRepoOwnerForHost so the connection comes off the same host record the runtime owner came from, and derives the connection via a new getRepoSshConnectionId rather than reading .connectionId — so a runtime:-owned row can no longer hand out a client SSH connection, and an ssh:-only row is no longer read as local.

On the "null means local" trap: no new state was introduced. undefined was already this module's documented "cannot determine the host" — isWorktreeConnectionResolved exists 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 === null so undefined never takes the local branch. The single coercion (use-tab-bar-runtime-model:136) is display-only, deciding which Windows shells to offer. No consumer turns undefined into "run it locally" — nothing here can reach a teardown RPC the way #14004 did.

BEFORE  AssertionError: expected 'ssh-client' to be undefined
AFTER   Tests  20 passed (20)

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

resolveTerminalWorkspaceLaunchTarget did this.store?.getRepo(worktree.repoId) then connectionId: repo?.connectionId ?? null — and that connectionId is the routing key handed straight to ptyController.spawn. getRepo is host-blind, so a remote worktree whose repo id also has a local row gets the local row, connectionId reads null, and the PTY spawns on the client with the remote cwd — producing DaemonProtocolError: Working directory "…" does not exist, exactly the reported error. It ignored worktree.hostId entirely.

The damning part: 98 lines above, in the same class, resolveBrowserNetworkExecutionHostForWorktree answers the identical question correctly with getWorktreeExecutionHostId(worktree, repo). The seam existed; the terminal path bypassed it.

New worktree-launch-host-repo.ts selects the row for the host the worktree names and returns ambiguous when rows conflict; the launch scope throws worktree_execution_host_unresolved rather 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 createTerminal test was attempted and abandoned, and the reason is itself a finding — the worktree scan is host-blind on the same field, so an executionHostId:'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 note isFolderRepo returns before that check, so a folder repo on an SSH host takes the local path); getRepo itself (fixing it would fix ~100 downstream readers but is a store-contract change); runtimeRepoMatchesExecutionHost over-rejecting an unstamped SSH repo against its own host; and assertHostIsSupported refusing --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:* to local; runtime-workspace-session-controller.ts:47 returns ssh:<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 on host-partition, because Orca Remote already partitions as runtime:*, 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

Check Result
orca-runtime.test.ts 1220 passed, twice isolated
All 6 changed/new test files 1281 passed | 1 skipped
pnpm tc:node / pnpm tc:web exit 0
check:code-quality:changed passed

One flake seen in a run that raced oxfmt --write over 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:

BEFORE  hostId 'ssh:m4air',    sole repo row {connectionId:'openclaw'}  ->  'openclaw'
        hostId 'runtime:awin', sole repo row {connectionId:'openclaw'}  ->  'openclaw'
AFTER   'm4air'  /  null

getConnectionIdFromState preferred findIndexedRepoOwnerForHost, but when that missed it fell
through to an id-only lookup and answered with whatever host that row named. So a pane on
ssh:m4air was offered "Reconnect openclaw" (terminal-pane-host-state.ts:28) and the
file-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 this
PR said it removes. main is 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.ts holds the rule; both sides adapt to it:

  • main's resolveWorktreeLaunchHost is now the array adapter plus its unresolved → throw mapping;
  • the renderer passes its WeakMap index in as the lookup — the memoizing adapter it always was.

The intersection is the discriminator plus connectionId: string | null. The repo row rides along
as 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 getRepoSshConnectionId compose with
getSshTargetIdForExecutionHost, on the premise that the two "contradicted" each other for a
runtime 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:

question runtime host with a nested target
getRepoSshConnectionId(repo) which SSH target holds this row's files? the nested target
getSshTargetIdForExecutionHost(hostId) which connection may this client dial? null

Collapsing them broke terminal-pane-host-state.test.ts — the one red lane — and the failure was
real, not a stale expectation:

  • The reconnect affordance disappeared. selectRuntimeAwareSshStatus(state, environmentId, targetId) looks up sshStateByEnvironment.get(environmentId).connectionStates.get(targetId).
    The (environmentId, ssh host) pair is expressible and is expressed — the renderer recovers
    the 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.
  • Worse: nativeChatTranscriptIsLocalReadable flipped false → true.
    isNativeChatTranscriptLocalReadable treats null as "this client can read it", and ~14 call
    sites 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:

  • local has no SSH namespace to nest in, so a surviving connectionId is a row contradicting
    itself — the shape main's own resolveRepoOwnershipEvidence calls contradictory. This is the
    pullfrog 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 appears
    only in this field. It is kept.

project-host-routing.ts:73 nulling the field is not counter-evidence: it stops a paired client
treating 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 from hostId, never from
the 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

  • pullfrog, execution-host.ts:184 — the fallback fired for kind !== 'ssh', which includes
    local: getRepoSshConnectionId({executionHostId:'local', connectionId:'openclaw'}) returned
    'openclaw'. A row declaring itself local handed out an SSH connection. Fixed narrowly: local
    yields no connection, while a runtime host keeps its nested one.
  • CodeRabbit, 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 the
worktree's execution host" had no renderer test where a worktree carried a hostId; the new ones
do.

Check Result
pnpm tc exit 0
whole src tree (main+renderer+shared+cli+preload) 67499 passed | 267 skipped
previously-red terminal-pane-host-state.test.ts passing
check:code-quality:changed 0 new findings
en.json vs main byte-identical (no drift from the rebase)

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: f08384e3-67a9-4f13-a04b-31d46226d4a6

📥 Commits

Reviewing files that changed from the base of the PR and between 0b15240af8c96a178cc4c99d9d7e56aa39c52e0c and 5f2c4109f34772d3a6a722457f9dbafd9722faf1.

📒 Files selected for processing (1)
  • src/renderer/src/lib/connection-owner-resolution.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The 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 5f2c4

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)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The shared resolver and renderer changes support [#17799], but the PR also changes terminal PTY routing and workspace-session partition ownership. Those changes address referenced issues #11163 and #1… Split the terminal-routing and session-partition changes into separately linked pull requests, or link #11163 and #12723 and explicitly define those changes as part of this pull request's approved scope.
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy [#17799]. They resolve connections using the worktree execution host and matching repository row, reject ambiguous ownership, prevent client SSH connections from being forwarded to…
Title check ✅ Passed The title clearly and concisely describes the primary change: resolving a worktree's execution host instead of selecting an arbitrary repository row.
Description check ✅ Passed 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 …
Full details: Linked Issues check

Explanation

The changes satisfy [#17799]. They resolve connections using the worktree execution host and matching repository row, reject ambiguous ownership, prevent client SSH connections from being forwarded to runtime hosts, and add coverage for duplicate and host-specific rows.

Full details: Out of Scope Changes check

Explanation

The shared resolver and renderer changes support [#17799], but the PR also changes terminal PTY routing and workspace-session partition ownership. Those changes address referenced issues #11163 and #12723, which are not directly linked in the provided issue context.

Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 0531ba66-ef31-4ee2-b33c-1c8d01107b68

📥 Commits

Reviewing files that changed from the base of the PR and between a573c57 and 0f2959e.

📒 Files selected for processing (10)
  • src/main/runtime/orca-runtime-resolve-browser-network-execution-host-for-worktree.ts
  • src/main/runtime/runtime-workspace-session-controller.ts
  • src/main/runtime/worktree-launch-host-repo.test.ts
  • src/main/runtime/worktree-launch-host-repo.ts
  • src/renderer/src/lib/connection-context.test.ts
  • src/renderer/src/lib/connection-owner-resolution.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/shared/execution-host.ts
  • src/shared/workspace-session-partition-owner.test.ts
  • src/shared/workspace-session-partition-owner.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@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

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 / getSshTargetIdForExecutionHost in src/shared/execution-host.ts resolve the SSH target off the resolved host, so an ssh:-only executionHostId row is no longer read as local and a runtime:-owned row can no longer hand out a client SSH connection.
  • Terminal launch routing — resolveTerminalWorkspaceLaunchTarget now routes through resolveWorktreeLaunchHost and throws worktree_execution_host_unresolved when duplicate repo rows conflict, instead of spawning a remote PTY locally with the remote cwd.
  • Renderer connection resolver — getConnectionIdFromState resolves the worktree owner first, prefers a host-scoped repo row, and fails closed to undefined on ambiguity.
  • Shared session partition owner — workspaceSessionPartitionHostId consolidates 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.

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

nwparker added a commit that referenced this pull request Sep 1, 2026
…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 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 — getRepoSshConnectionId now returns repo.connectionId when the resolved host is not ssh, so a runtime-owned row that reaches its repo over a nested SSH target (the target id lives only in connectionId) no longer answers local.

ℹ️ Nitpicks

  • The nested-runtime branch added here has no test coverage: no test file imports getRepoSshConnectionId, and connection-context.test.ts never exercises the executionHostId: 'runtime:*' + connectionId shape. A test pinning that row shape (and the local-row behavior below) would make the branch fail-before/pass-after real rather than incidental.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/shared/execution-host.ts Resolved
@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

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 right

Runnable probe against getConnectionIdFromState:

worktree hostId 'runtime:awin', sole repo row {connectionId:'openclaw'}  ->  'openclaw'
worktree hostId 'ssh:m4air',    sole repo row {connectionId:'openclaw'}  ->  'openclaw'

The second is a cross-host leak between two different SSH hosts. The main-side resolver in this same PR answers 'm4air' correctly, because it derives the connection from the worktree's own host.

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 terminal-pane-host-state.ts:28 (offers "Reconnect openclaw" on an m4air pane) and the file-drop/paste paths that read files off the resolved connection.

Not a regression — main is equally wrong — but the central claim is false for the renderer half.

2. Both bot findings are valid, confirmed, and unaddressed against the current head

pullfrog, execution-host.ts:184 — the fallback fires for kind !== 'ssh', which includes local:

getRepoSshConnectionId({ executionHostId: 'local', connectionId: 'openclaw' })  ->  'openclaw'

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 setup-existing-folder --host ssh:develop falsely dedupe onto a local row.

CodeRabbit, connection-owner-resolution.ts:93 — the id-only fallback after host resolution; the severe variant is finding 1 above.

Related: getRepoSshConnectionId and getSshTargetIdForExecutionHost are both new here, both labelled as fixing #11163, and return opposite answers for a runtime host carrying a nested SSH connectionId — with the contradiction locked in by worktree-launch-host-repo.test.ts:27-31.

3. The rebase is the dangerous kind

orca-runtime-resolve-browser-network-execution-host-for-worktree.ts: #17922 (b4ba3e97ff2, merged after this PR opened) inserted triggerTerminalSpawnPushTargetMaterialization(...) into the exact hunk this PR rewrites. Resolving to the child's side silently reverts #17922.

And the correct-looking resolution still leaks: that function does const connectionId = repo?.connectionId ?? undefined and runs git remote add/fetch on that basis. This PR hands it resolution.repo, which by its own test (worktree-launch-host-repo.test.ts:31) can be a mismatched-host row. Post-rebase the PTY goes to one host and the git materialization to another, in a single spawn. It must take resolution.connectionId, not repo.

Tests don't encode the claim

Both new renderer tests use worktreesByRepo: {} — a PR titled "resolve the worktree's execution host" has no renderer test where a worktree carries a hostId. And no test anywhere uses two different SSH hosts; every duplicate case is local-vs-ssh or runtime-vs-ssh, which is why finding 1 survived.

Duplication

  • workspaceSessionPartitionHostId(x, 'host-partition') is an exact duplicate of workspaceSessionOwnerPartitionForHost (session-owner-removal.ts:57-61) — no input separates them. That function has one caller, so moving it to src/shared/ was cheap.
  • resolveWorktreeLaunchHost re-derives the "worktree.hostId outranks the repo fallback" precedence that getWorktreeExecutionHostId (execution-host.ts:169) already implements, without importing it.
  • An ambiguity-aware host resolver already exists in shared code: resolveFolderWorkspaceHost (src/shared/folder-workspace-execution-host.ts:95) handles both spellings and returns ambiguous.

Folder workspaces are unaffected — they take a separate, already ambiguity-aware path. (Residual seam in neither PR: its candidate classifier at folder-workspace-execution-host.ts:58-72 reads raw repo.connectionId.)

Structural context for all of this is filed as #18110.

@nwparker
nwparker force-pushed the fix/execution-host-resolution branch from 2654842 to 2358260 Compare September 2, 2026 22:28
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.

@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 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 resolveWorktreeExecutionHost in src/shared/worktree-execution-host-resolution.ts is now answered by both main's resolveWorktreeLaunchHost and the renderer's getConnectionIdFromState, replacing two independent re-derivations that disagreed.
  • Dropped the nested-SSH fallback — getRepoSshConnectionId now composes getSshTargetIdForExecutionHost(getRepoExecutionHostId(repo)), so a local/runtime:* row hands out no SSH connection regardless of a surviving connectionId (resolving the prior scoping note).
  • Pinned the composition with tests — execution-host.test.ts now imports getRepoSshConnectionId and exercises the executionHostId: 'runtime:*' + connectionId row shape, and a new worktree-execution-host-resolution.test.ts covers cross-host routing, two-spelling agreement, and ambiguity.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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.

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.

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

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.

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

@nwparker
nwparker force-pushed the fix/execution-host-resolution branch 2 times, most recently from 0b15240 to 5f2c410 Compare September 2, 2026 22:57
…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.
@nwparker
nwparker force-pushed the fix/execution-host-resolution branch from 5f2c410 to 05bc9aa Compare September 2, 2026 23:20

@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 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 getRepoSshConnectionId to runtime only — a runtime host's nested SSH target (normalizeHostPart(repo.connectionId)) is returned again, while a local host still yields null, so the earlier local-leaks-a-stale-connection bug stays closed while the renderer can once more read a nested-SSH workspace as non-local.
  • Split the shared connectionId from the dialable route — resolveWorktreeExecutionHost's connectionId is now documented as the target whose filesystem holds the workspace (possibly un-dialable), and getSshTargetIdForExecutionHost(hostId) is the client-dialable answer; the main PTY adapter uses only the latter, so a runtime: 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.

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

@nwparker
nwparker merged commit c61ca56 into main Sep 2, 2026
28 checks passed
nwparker added a commit that referenced this pull request Sep 2, 2026
…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.
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
…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.
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
…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.

Host-blind connectionId resolution can hand a client-owned SSH connection to a runtime (duplicate repo rows)

1 participant