Skip to content

fix(ssh): decide remote-vs-local from the resolved execution host, not a raw field - #18294

Merged
nwparker merged 1 commit into
mainfrom
fix/repo-is-remote-resolved-host
Sep 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/repo-is-remote-resolved-host

Conversation

@nwparker

@nwparker nwparker commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​417 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​414
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29

The defect

repoIsRemote decided remote-vs-local from a raw repo.connectionId read. That field is one of four spellings of host ownership (Repo.connectionId, Repo.executionHostId, Worktree.hostId, and FolderWorkspace's pair), 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, which does not exist on a PATH served by the relay shim;
  • a row that declares itself local while a stale connectionId survives read as remote and lost the rename it needs on a Linux desktop.

Same host-blind class as #17909 / #17919; deliberately deferred out of #17919 because converting runtime-worktree-agent-startup.ts's detection probe alone would have left that file internally inconsistent — agent detection resolved on the host, launch shape still saying local.

Which question the predicate answers

The two questions #17909/#17919 settled are different, and repoIsRemote wants the first one — "which SSH target holds this row's files", i.e. getRepoSshConnectionId:

host holds the files this client may dial repoIsRemote
ssh:x x x true
runtime:env + nested SSH nested target null true — that machine reaches the files through its own relay shim
runtime:env, no nested target null null false — a full Orca install, not a shim
local + stale field null null false — a row contradicting itself

local and WSL stay false, as before.

Not every call site wanted that question

Three of the nine sites did not, and the honest answer was to stop calling the predicate there rather than to make it subtly wrong:

  • The four launch-scope sites in main already hold the resolved PTY route on TerminalWorkspaceLaunchScope.connectionId. scope.repo is documented display metadata (resolution.repo ?? getRepo(...)) and can be a row from a different host than the worktree names. 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 naming 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, and the renderer half of the shared resolver.
  • resolveAgentBackgroundLaunchHost derived the route, the trust write and the launch shape from three separate raw reads. One resolution now feeds all three.

No new resolver: everything goes through getRepoSshConnectionId / getConnectionIdFromState / the already-resolved scope connection.

Call-site table

# Site Question it needs Behavior change
1 runtime-worktree-agent-startup.ts buildWorktreeStartupForDraft detection probe (raw field) files-holder yes — ssh:*-only rows now probe the host; contradictory-local rows now probe this client
2 runtime-worktree-agent-startup.ts:72 launch shape files-holder yes — same two rows
3 runtime-worktree-agent-startup.ts:139 launch shape files-holder yes — same two rows
4 orca-runtime-create-agent-session.ts resolved PTY route yes — stops reading a possibly-foreign scope.repo
5 orca-runtime-resolve-worktree-removal-target.ts (resolveAgentTerminalCreateOptions) resolved PTY route yes — same
6 orca-runtime-get-agent-session-execution-namespace.ts resolved PTY route yes — same
7 orca-runtime-resolve-mobile-session-terminal-command.ts (both calls) resolved PTY route yes — same
8 runtime-target-selection.ts:152 files-holder yes via the widened predicate; selectedRepo is already host-resolved by resolveWorkspaceCreationTarget
9 launch-agent-in-new-tab.ts:108 files-holder, worktree-resolved yes — now follows the worktree's host instead of the first matching repo row

Every site changes for at least one row shape; ordinary ssh:<target> + matching connectionId rows and plain local rows are unaffected.

Tests

  • src/shared/agent-launch-remote.test.ts — both spellings on two different SSH hosts (m4air, openclaw), contradictory-local, runtime: with and without a nested SSH target.
  • src/main/runtime/runtime-worktree-agent-startup.test.ts — launched CLI name per host shape, plus detection routing to openclaw for an executionHostId-only row and to this client for a contradictory-local row.
  • src/renderer/src/lib/launch-agent-in-new-tab-host-resolution.test.ts — rival rows on two SSH hosts; the launch follows the worktree's host, including the runtime: + nested-SSH pair.
  • src/renderer/src/lib/agent-background-session-launch-host.test.ts — two SSH hosts routed distinctly, contradictory-local kept off the SSH route, runtime-nested kept remote.
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts — a locally-routed scope carrying an openclaw repo row now emits the local CLI name.

Out of scope (host-keyed dispatch, happening in parallel)

getAgentLaunchPlatformForRepo still reads repo.connectionId raw, so the platform half of a launch is still resolved off a row rather than a host. That is the host-keyed dispatch work, not a second copy of this fix; the predicate change does not depend on it.

…t a raw field

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

pullfrog Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Agent launch routing now uses resolved execution-host metadata. Runtime session and terminal flows derive remote status from the workspace connection ID. Startup detection and renderer launch-host resolution use getRepoSshConnectionId, including legacy, execution-host, local-stale, and nested SSH cases. Regression tests cover runtime commands, startup detection, background launch hosts, new-tab commands, and repoIsRemote.

Merge Risk: 🟡 Moderate · up to 76e16

Remote-versus-local routing now follows the resolved execution host, but two launch paths still choose the shell platform from potentially stale or foreign repository metadata. Cross-platform workspaces could therefore receive commands quoted for the wrong shell, causing failed or unsafe agent launches; this should be fixed or explicitly accepted before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the defect, implementation, scope, and tests in detail, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue with a Fixes reference, V… Reformat the description to include every required template section. Add the linked issue in the required Fixes #... format, provide Visual Proof or state N/A with a reason, document manual and automated testing with platforms tested, c…
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: remote-versus-local detection now uses the resolved execution host instead of a raw field.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the defect, implementation, scope, and tests in detail, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue with a Fixes reference, Visual Proof or N/A, Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the final Checklist.

Resolution

Reformat the description to include every required template section. Add the linked issue in the required Fixes #... format, provide Visual Proof or state N/A with a reason, document manual and automated testing with platforms tested, complete the applicable checkboxes, and address AI Disclosure, Review, Agent skill upstream boundary, and Notes.

  • 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: 571e7ac8-54bd-401a-8b50-5a1d3929f0db

📥 Commits

Reviewing files that changed from the base of the PR and between 36e139e and 76e1610.

📒 Files selected for processing (13)
  • src/main/runtime/orca-runtime-agent-session-operation.test.ts
  • src/main/runtime/orca-runtime-create-agent-session.ts
  • src/main/runtime/orca-runtime-get-agent-session-execution-namespace.ts
  • src/main/runtime/orca-runtime-resolve-mobile-session-terminal-command.ts
  • src/main/runtime/orca-runtime-resolve-worktree-removal-target.ts
  • src/main/runtime/runtime-worktree-agent-startup.test.ts
  • src/main/runtime/runtime-worktree-agent-startup.ts
  • src/renderer/src/lib/agent-background-session-launch-host.test.ts
  • src/renderer/src/lib/agent-background-session-launch-host.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-host-resolution.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/shared/agent-launch-remote.test.ts
  • src/shared/agent-launch-remote.ts

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

Comment on lines 51 to +53
platform: getAgentLaunchPlatformForRepo(
repo,
repo.connectionId ? undefined : getLocalProjectExecutionRuntimeContext(store, worktreeId)
sshConnectionId ? undefined : getLocalProjectExecutionRuntimeContext(store, worktreeId)

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use resolved host metadata for platform selection.

getAgentLaunchPlatformForRepo reads repo.connectionId. Both call sites pass raw repository metadata after resolving the worktree host. A local worktree with a stale or rival SSH row therefore bypasses local Windows runtime resolution and can use the wrong platform.

  • src/renderer/src/lib/agent-background-session-launch-host.ts#L51-L53: pass { connectionId: sshConnectionId, path: worktreePath ?? repo.path } to getAgentLaunchPlatformForRepo.
  • src/renderer/src/lib/launch-agent-in-new-tab.ts#L106-L110: pass the resolved connection ID and selected worktree path instead of the host-blind repository row.

Add Windows coverage for a local worktree with a stale or rival SSH row and a WSL runtime preference.

📍 Affects 2 files
  • src/renderer/src/lib/agent-background-session-launch-host.ts#L51-L53 (this comment)
  • src/renderer/src/lib/launch-agent-in-new-tab.ts#L106-L110

@nwparker
nwparker merged commit d084a2a into main Sep 3, 2026
28 of 29 checks passed
himichaelroberts added a commit to himichaelroberts/orca that referenced this pull request Sep 3, 2026
Conflict in runtime-worktree-agent-startup.test.ts: main added host-resolution
and draft-detection suites (stablyai#18294) while this branch rewrote the
markLocalWorktreeTrusted describe onto the consolidated dispatch. Took main's
file whole and re-applied only the dispatch change — the module mock now
provides applyLocalAgentTrustPreset delegating to the per-preset mocks, so
main's await and rejection tests keep asserting through markCodexProjectTrusted
unchanged, plus the claude and no-preset cases from this branch.
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.
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