Skip to content

fix(runtime): route HUB-owned SSH worktrees through owning runtime - #9994

Merged
OrcaWin merged 9 commits into
mainfrom
OrcaWin/issue-9276-nested-ssh-runtime-routing
Jul 23, 2026
Merged

OrcaWin merged 9 commits into
mainfrom
OrcaWin/issue-9276-nested-ssh-runtime-routing

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • route paired desktop and web operations through the runtime that owns the worktree, then let that HUB resolve its own SSH relay/session
  • separate runtime ownership from nested execution-host identity across graph projection, readiness, files, PTYs, terminal streams, reconnect, and persisted sessions
  • scope routing and generation fences by runtime, pairing, SSH connection, worktree, and terminal so multiple viewers and HUBs cannot cross-route
  • fail closed for missing or stale owners, including destructive filesystem mutations and disconnected SSH PTY write/resize; paired clients never need HUB SSH config, keys, ProxyJump state, or relay credentials
  • add a deterministic Docker OpenSSH three-node harness covering direct SSH and ProxyJump with Electron and browser clients

Architecture and compatibility

The route is explicit: paired client -> owning HUB runtime -> HUB-owned SSH relay -> SSH worktree.

Shared graph/RPC payloads publish only non-secret identity, capability, state, and generation metadata. SSH configuration and credentials stay on the HUB. Legacy local calls remain compatible, while mutations that require the nested route are capability-fenced and stale generations are rejected. Project readiness is attributed to the runtime that observed the connection. Stale relay daemon lifecycle remains a separately classified updater concern.

Validation

  • pnpm run test:e2e:nested-runtime-ssh: 5/5 passed after a clean rebuild (Electron, web, two paired desktops, two HUB isolation, direct SSH, ProxyJump, legacy capability fallback, same-ID re-pair, reconnect, HUB restart, terminal lifecycle, files, and mutations)
  • focused affected tests: 1,485/1,485 passed before final audit; final fail-closed regression set: 480 passed, 1 skipped
  • full test suite: 34,333 passed, 60 skipped; 2 unrelated failures remain in src/relay/agent-exec-handler.test.ts from duplicate inherited GIT_CONFIG_* shell entries
  • typecheck passed
  • oxlint passed with existing warnings only
  • reliability gates and max-lines ratchet passed
  • changed-file formatting passed
  • iterative routing/race, security/filesystem, and E2E proof reviews: clean

The unchanged lint:switch-exhaustiveness baseline failure remains at src/renderer/src/components/skills/skill-freshness-group.tsx:101 for missing undefined | current | duplicate handling.

Closes #9276

@coderabbitai

coderabbitai Bot commented Jul 22, 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
📝 Walkthrough

Walkthrough

This PR introduces nested runtime SSH support: SSH connection generation tracking, runtime environment pairing revisions, and file-mutation ownership capability checks that guard against stale or ambiguous execution-host targeting. Main-process IPC handlers, RPC methods, and PTY providers now validate SSH/host expectations before mutating files or PTYs, and invalidate transport/subscriptions on re-pairing. The renderer adds worktree operation route resolution, editor/file-explorer operation provenance guards, owner-scoped web-session intents (close/focus/reorder), and pairing-revision-aware runtime RPC/file-client calls. Terminal PTY transport and pane resolution now route through resolved execution hosts, including SSH pane recovery after HUB restarts. Store slices, preload contracts, and web preload APIs were updated to carry the new SSH/pairing metadata end-to-end. Extensive e2e infrastructure (Docker SSH relay, ProxyJump fixture, paired Electron/web clients, restart/re-pairing helpers) and new spec suites validate nested SSH routing across HUB restarts, re-pairing, and legacy transport paths.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description omits the required template sections for Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite it to match the repository template and add the missing screenshots, testing, review, security, and notes sections.
Out of Scope Changes check ⚠️ Warning A few utility-only changes, like the skills and git-directory type tweaks, appear unrelated to the SSH worktree routing objective. Split the unrelated utility changes in src/main/skills/skill-installation-topology.ts and src/main/ipc/worktree-common-git-directory.ts into a separate PR or justify them.
Docstring Coverage ⚠️ Warning Docstring coverage is 6.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: routing HUB-owned SSH worktrees through the owning runtime.
Linked Issues check ✅ Passed The PR addresses #9276 by routing paired clients through the owning HUB runtime and adding fail-closed SSH/worktree generation fences.

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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
src/renderer/src/components/editor/editor-autosave-controller.ts (1)

68-121: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Unhandled rejection risk: getEditorFileOperationContext can throw, but the autosave timer path doesn't catch it.

getEditorFileOperationContext (line 104) throws OWNER_CHANGED_MESSAGE when the execution-host route can't be resolved or an SSH route's connection generation is missing — a real scenario during SSH reconnects or worktree removal. Every other queueSave caller (handleSaveDirtyFiles, handleSaveAndClose, handleSaveFile) awaits inside its own try/catch, but the autosave timer at Line 221 does void queueSave(file, draft, 'autosave') with no error handling. If ownership is stale when autosave fires, this becomes an unhandled promise rejection that recurs every autoSaveDelayMs until the user edits again.

🛡️ Proposed fix
       const timerId = window.setTimeout(() => {
         autoSaveTimers.delete(file.id)
         autoSaveScheduledContent.delete(file.id)
-        void queueSave(file, draft, 'autosave')
+        void queueSave(file, draft, 'autosave').catch((error) => {
+          console.error('Autosave failed:', error)
+        })
       }, autoSaveDelayMs)

Also applies to: 218-222

src/renderer/src/runtime/web-runtime-session.ts (1)

1022-1052: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Scope the terminal close by pairing revision.

closeWebRuntimeTerminal is a destructive RPC path, but it calls window.api.runtimeEnvironments.call directly without expectedEnvironmentPairingRevision. If the workspace re-pairs after this runs, the RPC won’t carry the client-side pairing expectation and can proceed outside the captured session state.

🛡️ Proposed fix
   const remote = parseRemoteRuntimePtyId(ptyId)
   const environmentId = remote?.environmentId?.trim()
   if (!remote || !environmentId || !isWebRuntimeSessionActive(environmentId)) {
     return false
   }

   // Why: host owns the real pane graph; close the host terminal first so later snapshots can't resurrect the removed pane.
-  void window.api.runtimeEnvironments
-    .call({
-      selector: environmentId,
-      method: 'terminal.close',
-      params: {
-        terminal: remote.handle
-      },
-      timeoutMs: 15_000
-    })
+  void captureRuntimeEnvironmentCall(environmentId)({
+      method: 'terminal.close',
+      params: {
+        terminal: remote.handle
+      },
+      timeoutMs: 15_000
+    })
     .then((response) => {
src/renderer/src/lib/create-untitled-markdown.ts (1)

93-112: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reorder cleanup before the re-assertion in the write-failure catch.

assertCurrent() runs before deleteRuntimePath, so a stale-ownership race during writeRuntimeFile skips cleanup entirely and replaces the real write error with the ownership error, leaving an orphaned empty file at filePath.

🐛 Proposed fix: always attempt cleanup before re-checking ownership
         } catch (error) {
-          assertCurrent()
           await deleteRuntimePath(context, filePath).catch(() => undefined)
+          assertCurrent()
           throw error
         }
src/renderer/src/components/editor/useUntitledFileRename.ts (1)

40-58: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Unguarded getEditorFileOperationContext calls can throw uncaught. Both sites call the new throwing getEditorFileOperationContext (which throws OWNER_CHANGED_MESSAGE on ambiguous/stale ownership per the upstream contract) without a local try/catch, so a resolution failure propagates as an unhandled rejection instead of a user-facing error.

  • src/renderer/src/components/editor/useUntitledFileRename.ts#L40-L58: wrap the getEditorFileOperationContext call in try/catch and route failures through the existing setRenameError(...) path used by every other failure branch in handleRenameConfirm.
  • src/renderer/src/components/tab-bar/tab-create-entry-action.ts#L215-L243: wrap the getEditorFileOperationContext call in try/catch (or confirm and document that openTabBarEntry's caller already catches and surfaces the rejection) so the failure mode matches the rest of this cohort's fail-closed error handling.
src/renderer/src/components/terminal/terminal-tab-actions.ts (1)

230-252: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

activateTerminalTab no-ops entirely when ownership is unresolvable.

Previously this function always activated the tab locally. Now, if resolveTerminalWorktreeRoute returns null (unresolvable ownership), the whole function returns before calling s.setActiveTab/s.setActiveTabType. Local tab activation doesn't need remote ownership resolved — only the activateWebRuntimeSessionTab sync call does. Consider always performing the local activation and only gating the remote sync call on a resolved route.

🛠️ Proposed fix: keep local activation independent of remote route resolution
 export function activateTerminalTab(tabId: string): void {
   const s = useAppStore.getState()
   const owningWorktreeId =
     Object.entries(s.tabsByWorktree).find(([, worktreeTabs]) =>
       worktreeTabs.some((tab) => tab.id === tabId)
     )?.[0] ?? null
   const worktreeRoute = resolveTerminalWorktreeRoute(s, owningWorktreeId)
-  if (!worktreeRoute) {
-    return
-  }
-  const runtimeEnvironmentId = worktreeRoute.runtimeEnvironmentId
-  if (owningWorktreeId && isWebRuntimeSessionActive(runtimeEnvironmentId)) {
+  const runtimeEnvironmentId = worktreeRoute?.runtimeEnvironmentId ?? null
+  if (owningWorktreeId && worktreeRoute && isWebRuntimeSessionActive(runtimeEnvironmentId)) {
     // Why: activation needs to update the host's active tab as well as the
     // local optimistic state, otherwise the next host snapshot snaps back.
     void activateWebRuntimeSessionTab({
       worktreeId: owningWorktreeId,
       tabId,
       environmentId: runtimeEnvironmentId
     })
   }
   s.setActiveTab(tabId)
   s.setActiveTabType('terminal')
 }
🧹 Nitpick comments (3)
tests/e2e/helpers/nested-runtime-ssh-terminal-creation.ts (1)

5-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the shared terminalMarkerCommand.

tests/e2e/helpers/nested-runtime-ssh-client-route.ts now exports terminalMarkerCommand with the same logic. Importing it from nested-runtime-ssh-terminal-creation.ts would create a circular dependency, so move the helper to a shared helper module or pass it through the pairing client helper API instead of keeping a private duplicate in this file.

src/renderer/src/runtime/web-session-close-intent.ts (1)

9-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the owner+worktree partition-map pattern shared by close/focus/reorder intent modules. All three modules independently implement the identical ${webSessionIntentOwnerKey(owner)}\0${worktreeId} key scheme and identical prefix-scan "clear for owner" loop; the only difference is the stored payload type.

  • src/renderer/src/runtime/web-session-close-intent.ts#L9-L13: replace closeIntentPartitionKey + the Map<string, Map<string, CloseIntent>> storage + the clearWebSessionCloseIntentsForOwner prefix loop with a shared generic partition-map utility.
  • src/renderer/src/runtime/web-session-focus-intent.ts#L14-L18: replace focusIntentPartitionKey + pendingFocusByOwnerAndWorktree + clearWebSessionFocusIntentsForOwner with the same shared utility.
  • src/renderer/src/runtime/web-session-reorder-intent.ts#L20-L26: replace reorderIntentPartitionKey + pendingReorderByOwnerAndWorktree + clearWebSessionReorderIntentsForOwner with the same shared utility.
src/main/ipc/runtime-environment-revision-guard.ts (1)

9-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the effective pairing-revision fallback into one helper. The pairingRevision ?? createdAt fallback that defines the pairing fence is duplicated across three sites; centralizing it prevents a future edit from silently diverging the guard in one path.

  • src/main/ipc/runtime-environment-revision-guard.ts#L9-L11: add and use a shared resolveEnvironmentPairingRevision(environment) helper here for the comparison.
  • src/main/ipc/runtime-environments.ts#L179-L179: replace the inline fallback in the upfront subscribe check with the shared helper.
  • src/main/ipc/runtime-environments.ts#L245-L245: replace the inline fallback in the post-subscribe re-check with the shared helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 207c07b9-0d90-49d8-859d-e8e1c16e57a4

📥 Commits

Reviewing files that changed from the base of the PR and between 034aeb1 and 2ccc97a.

📒 Files selected for processing (245)
  • config/scripts/run-nested-runtime-ssh-e2e.mjs
  • package.json
  • src/main/index.ts
  • src/main/ipc/ephemeral-vm-runtime-handlers.ts
  • src/main/ipc/ephemeral-vm.test.ts
  • src/main/ipc/filesystem-import-ssh-directory.ts
  • src/main/ipc/filesystem-import-ssh-ops.test.ts
  • src/main/ipc/filesystem-import-ssh.test.ts
  • src/main/ipc/filesystem-import-ssh.ts
  • src/main/ipc/filesystem-mutations.test.ts
  • src/main/ipc/filesystem-mutations.ts
  • src/main/ipc/filesystem.test.ts
  • src/main/ipc/filesystem.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/runtime-environment-request-connections.ts
  • src/main/ipc/runtime-environment-revision-guard.test.ts
  • src/main/ipc/runtime-environment-revision-guard.ts
  • src/main/ipc/runtime-environment-tailscale-response.ts
  • src/main/ipc/runtime-environment-transport-generation.ts
  • src/main/ipc/runtime-environment-transport-routing.ts
  • src/main/ipc/runtime-environments.test.ts
  • src/main/ipc/runtime-environments.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/providers/ssh-pty-notification-routing.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/runtime/graph-sync-mobile-snapshot-gating.test.ts
  • src/main/runtime/orca-runtime-files.test.ts
  • src/main/runtime/orca-runtime-files.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/public-ssh-state.ts
  • src/main/runtime/rpc/methods/client-events.ts
  • src/main/runtime/rpc/methods/files.test.ts
  • src/main/runtime/rpc/methods/files.ts
  • src/main/runtime/rpc/methods/ssh.test.ts
  • src/main/runtime/rpc/methods/ssh.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/main/ssh/ssh-connection-generation.test.ts
  • src/main/ssh/ssh-connection-generation.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/editor/CombinedDiffViewer.tsx
  • src/renderer/src/components/editor/editor-autosave-conflict-flow.test.ts
  • src/renderer/src/components/editor/editor-autosave-controller-test-fixture.ts
  • src/renderer/src/components/editor/editor-autosave-controller.test.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/rich-markdown-image-insert.test.ts
  • src/renderer/src/components/editor/rich-markdown-image-insert.ts
  • src/renderer/src/components/editor/useUntitledFileRename.ts
  • src/renderer/src/components/native-chat/native-chat-attachment-upload.test.ts
  • src/renderer/src/components/native-chat/native-chat-attachment-upload.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-paste.test.tsx
  • src/renderer/src/components/right-sidebar/FileExplorer.tsx
  • src/renderer/src/components/right-sidebar/FileExplorerRow.tsx
  • src/renderer/src/components/right-sidebar/file-explorer-delete-classification.ts
  • src/renderer/src/components/right-sidebar/file-explorer-operation-generation.test.ts
  • src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts
  • src/renderer/src/components/right-sidebar/file-explorer-runtime-owner-boundary.test.ts
  • src/renderer/src/components/right-sidebar/file-explorer-types.ts
  • src/renderer/src/components/right-sidebar/useFileDeletion.ts
  • src/renderer/src/components/right-sidebar/useFileDuplicate.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerDragDrop.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerHandlers.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerImport.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerInlineInput.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerTree.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerWatch.test.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerWatch.ts
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.ts
  • src/renderer/src/components/settings/McpConfigSection.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.tsx
  • src/renderer/src/components/settings/RepositoryPane.tsx
  • src/renderer/src/components/settings/Settings.tsx
  • src/renderer/src/components/settings/settings-project-list.test.ts
  • src/renderer/src/components/settings/settings-project-list.ts
  • src/renderer/src/components/shared/kill-all-terminal-surfaces.test.ts
  • src/renderer/src/components/sidebar/WorktreeCard.ssh-reconnect-prompt.test.tsx
  • src/renderer/src/components/sidebar/WorktreeCard.tsx
  • src/renderer/src/components/tab-bar/TabBar.windows-shell-launch.test.ts
  • src/renderer/src/components/tab-bar/tab-create-entry-action.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-query-reply-immediate.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-snapshot-escape-tail.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/components/terminal-pane/terminal-drop-handler.test.ts
  • src/renderer/src/components/terminal-pane/terminal-drop-runtime-owner.test.ts
  • src/renderer/src/components/terminal-pane/terminal-drop-runtime-owner.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.test.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.ts
  • src/renderer/src/components/terminal-pane/terminal-native-file-drop.ts
  • src/renderer/src/components/terminal-pane/unresolved-owner-pty-transport.ts
  • src/renderer/src/components/terminal/terminal-tab-actions-kill-all.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.ts
  • src/renderer/src/components/terminal/terminal-tab-bulk-actions.ts
  • src/renderer/src/components/terminal/terminal-tab-create.ts
  • src/renderer/src/hooks/runtime-client-events-sync.test.ts
  • src/renderer/src/hooks/runtime-client-events-sync.ts
  • src/renderer/src/hooks/useComposerState.ts
  • src/renderer/src/hooks/useGlobalFileDrop.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/agent-hibernation-coordinator.test.ts
  • src/renderer/src/lib/create-untitled-markdown.test.ts
  • src/renderer/src/lib/create-untitled-markdown.ts
  • src/renderer/src/lib/e2e-config.ts
  • src/renderer/src/lib/editor-file-operation-owner.test.ts
  • src/renderer/src/lib/editor-file-operation-owner.ts
  • src/renderer/src/lib/ensure-hooks-confirmed.ts
  • src/renderer/src/lib/rename-file.ts
  • src/renderer/src/lib/runtime-session-mirror-owners.ts
  • src/renderer/src/lib/sidebar-worktree-activation.ts
  • src/renderer/src/lib/single-runtime-legacy-owner.ts
  • src/renderer/src/lib/ssh-mutation-expectation.test.ts
  • src/renderer/src/lib/ssh-mutation-expectation.ts
  • src/renderer/src/lib/terminal-worktree-route.ts
  • src/renderer/src/lib/workspace-runtime-host-ownership.ts
  • src/renderer/src/lib/workspace-session-host-persistence.test.ts
  • src/renderer/src/lib/workspace-session-host-persistence.ts
  • src/renderer/src/lib/worktree-activation-created-agent.test.ts
  • src/renderer/src/lib/worktree-activation-empty-remote.test.ts
  • src/renderer/src/lib/worktree-activation.test.ts
  • src/renderer/src/lib/worktree-operation-generation.ts
  • src/renderer/src/lib/worktree-operation-route.test.ts
  • src/renderer/src/lib/worktree-operation-route.ts
  • src/renderer/src/lib/worktree-runtime-owner-index.ts
  • src/renderer/src/lib/worktree-runtime-owner-state.ts
  • src/renderer/src/lib/worktree-runtime-owner.test.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/runtime/abortable-runtime-environment-call.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/runtime/file-explorer-delete-owner-provenance.test.ts
  • src/renderer/src/runtime/mobile-markdown-bridge-test-harness.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.test.ts
  • src/renderer/src/runtime/remote-host-file-delete-repro.test.ts
  • src/renderer/src/runtime/remote-runtime-terminal-frame-drop-resync.test.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts
  • src/renderer/src/runtime/remote-server-parity.test.ts
  • src/renderer/src/runtime/runtime-client-events.test.ts
  • src/renderer/src/runtime/runtime-client-events.ts
  • src/renderer/src/runtime/runtime-environment-revision.ts
  • src/renderer/src/runtime/runtime-environment-ssh-state.test.ts
  • src/renderer/src/runtime/runtime-environment-ssh-state.ts
  • src/renderer/src/runtime/runtime-file-client.test.ts
  • src/renderer/src/runtime/runtime-file-client.ts
  • src/renderer/src/runtime/runtime-file-import-pairing-revision.test.ts
  • src/renderer/src/runtime/runtime-rpc-client-pairing-revision.test.ts
  • src/renderer/src/runtime/runtime-rpc-client.ts
  • src/renderer/src/runtime/runtime-rpc-environment-call.ts
  • src/renderer/src/runtime/runtime-rpc-result.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-close-intent.test.ts
  • src/renderer/src/runtime/web-session-close-intent.ts
  • src/renderer/src/runtime/web-session-focus-intent.ts
  • src/renderer/src/runtime/web-session-intent-owner.test.ts
  • src/renderer/src/runtime/web-session-intent-owner.ts
  • src/renderer/src/runtime/web-session-reorder-intent.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/slices/browser.test.ts
  • src/renderer/src/store/slices/cmd-j-create-actions.test.ts
  • src/renderer/src/store/slices/diffComments.test.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
  • src/renderer/src/store/slices/purge-stale-runtime-host-ownership.test.ts
  • src/renderer/src/store/slices/repos-nested-ssh-projection.test.ts
  • src/renderer/src/store/slices/repos-project-host-lifecycle.test.ts
  • src/renderer/src/store/slices/repos.test.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/runtime-environment-ssh.test.ts
  • src/renderer/src/store/slices/runtime-environment-ssh.ts
  • src/renderer/src/store/slices/runtime-status.test.ts
  • src/renderer/src/store/slices/runtime-status.ts
  • src/renderer/src/store/slices/ssh-target-cleanup.ts
  • src/renderer/src/store/slices/ssh.test.ts
  • src/renderer/src/store/slices/ssh.ts
  • src/renderer/src/store/slices/stale-runtime-host-rows.ts
  • src/renderer/src/store/slices/store-cascades.test.ts
  • src/renderer/src/store/slices/store-session-cascades.test.ts
  • src/renderer/src/store/slices/store-test-helpers.ts
  • src/renderer/src/store/slices/terminal-tab-retirement-store.test.ts
  • src/renderer/src/store/slices/terminal-tab-retirement.test.ts
  • src/renderer/src/store/slices/terminal-tab-retirement.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/renderer/src/web/web-file-mutation-methods.test.ts
  • src/renderer/src/web/web-file-mutation-methods.ts
  • src/renderer/src/web/web-preload-api.test.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/file-mutation-ownership.ts
  • src/shared/protocol-version.ts
  • src/shared/remote-runtime-shared-control-connection.test.ts
  • src/shared/remote-runtime-shared-control-connection.ts
  • src/shared/remote-runtime-shared-control-reconnect.ts
  • src/shared/remote-runtime-shared-control-subscriptions.ts
  • src/shared/runtime-client-events.ts
  • src/shared/runtime-environment-store.test.ts
  • src/shared/runtime-environment-store.ts
  • src/shared/runtime-environments.ts
  • src/shared/runtime-types.ts
  • src/shared/ssh-types.ts
  • src/shared/types.ts
  • tests/e2e/fixtures/docker-ssh-relay/Dockerfile
  • tests/e2e/global-setup.ts
  • tests/e2e/helpers/docker-ssh-relay-connection.ts
  • tests/e2e/helpers/docker-ssh-relay-image.ts
  • tests/e2e/helpers/docker-ssh-relay-processes.ts
  • tests/e2e/helpers/docker-ssh-relay-target.ts
  • tests/e2e/helpers/nested-runtime-proxy-jump-fixture.ts
  • tests/e2e/helpers/nested-runtime-proxy-jump-fixture.unit.test.ts
  • tests/e2e/helpers/nested-runtime-same-id-pairing.ts
  • tests/e2e/helpers/nested-runtime-ssh-client-route.ts
  • tests/e2e/helpers/nested-runtime-ssh-filesystem-route.ts
  • tests/e2e/helpers/nested-runtime-ssh-relay-lifecycle.ts
  • tests/e2e/helpers/nested-runtime-ssh-state.ts
  • tests/e2e/helpers/nested-runtime-ssh-terminal-creation.ts
  • tests/e2e/helpers/orca-app.ts
  • tests/e2e/helpers/orca-restart.ts
  • tests/e2e/helpers/paired-electron-client.ts
  • tests/e2e/helpers/paired-web-filesystem-route.ts
  • tests/e2e/helpers/terminal.ts
  • tests/e2e/nested-runtime-ssh-lifecycle.spec.ts
  • tests/e2e/nested-runtime-ssh-routing.spec.ts

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

🧹 Nitpick comments (1)
src/renderer/src/hooks/useComposerState.ts (1)

2409-2409: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Untranslated user-facing error string.

'Attachment upload host changed; retry the upload.' bypasses translate(...), unlike the sibling error messages in this same function (e.g. Lines 2378-2380, 2429-2431).

🌐 Proposed fix
-              throw new Error('Attachment upload host changed; retry the upload.')
+              throw new Error(
+                translate(
+                  'auto.hooks.useComposerState.attachmentUploadHostChanged',
+                  'Attachment upload host changed; retry the upload.'
+                )
+              )

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3406e850-3038-4449-9f35-dd361a1f8166

📥 Commits

Reviewing files that changed from the base of the PR and between 15bc47c and 2648d10.

📒 Files selected for processing (15)
  • package.json
  • src/main/ipc/worktree-common-git-directory.ts
  • src/main/skills/skill-installation-topology.ts
  • src/renderer/src/components/terminal-pane/terminal-drop-handler.test.ts
  • src/renderer/src/components/terminal-pane/terminal-native-file-drop.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.test.ts
  • src/renderer/src/components/terminal/terminal-tab-bulk-actions.ts
  • src/renderer/src/hooks/composer-native-file-drop.test.ts
  • src/renderer/src/hooks/composer-native-file-drop.ts
  • src/renderer/src/hooks/useComposerState.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/worktree-operation-generation.test.ts
  • src/renderer/src/lib/worktree-operation-generation.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • package.json
  • src/renderer/src/components/terminal/terminal-tab-bulk-actions.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/worktree-operation-generation.ts
  • src/renderer/src/components/terminal-pane/terminal-drop-handler.test.ts
  • src/renderer/src/components/terminal-pane/terminal-native-file-drop.ts
  • src/renderer/src/store/slices/worktrees.ts

OrcaWin added 2 commits July 22, 2026 18:00
…sted-ssh-runtime-routing

# Conflicts:
#	src/main/ipc/worktree-common-git-directory.ts
#	src/main/skills/skill-installation-topology.ts
@OrcaWin
OrcaWin merged commit 41751dd into main Jul 23, 2026
19 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/issue-9276-nested-ssh-runtime-routing branch July 23, 2026 01:25
nwparker added a commit that referenced this pull request Jul 23, 2026
…ad of failing them closed (#10151)

Inline setup/onboarding terminals (skill installs, feature tips) and the floating terminal use host-agnostic synthetic worktree ids with no worktree/repo row. Since #9994, connectPanePty gated their transport on resolveWorktreeOperationRouteResult, which fails closed ('missing') for unknown ids — so the Orca CLI skill Update button, every other inline setup terminal, and the floating terminal showed "Workspace identity is ambiguous across hosts" instead of running.

Route them through the shared resolveTerminalWorktreeRoute (which already exempts the floating terminal and folder workspaces), and add the missing ephemeral-setup exemption so setup terminals follow the single active runtime (remote skill installs land there) or run locally when none is focused. Genuinely unknown/stale repo-backed worktrees still fail closed, preserving #9994.

Adds terminal-worktree-route unit tests and connectPanePty regression tests (proven to fail without the fix).

Co-authored-by: Orca <[email protected]>
svc-orca Bot pushed a commit to LesleyMurfin/orca that referenced this pull request Sep 7, 2026
…ners (stablyai#16733)

Two cases in src/renderer/src/lib/worktree-operation-route.test.ts assert the
behaviour stablyai#16733 reports as the bug, so they have to move:

  - :158 'fails a paired-client ownerless stale publication closed instead of
    routing it locally'
  - :171 'fails ownerless rows closed until the saved-runtime catalog is hydrated'

Both arrived with stablyai#9994 (41751dd, route HUB-owned SSH worktrees through their
owning runtime), whose stated goal was to fail closed for missing or stale
owners. That goal is right and is kept. The premise being rebutted is narrower:
neither fixture describes a missing or stale owner. Each carries a present repo
row that is merely unstamped -- repos: [{ id: 'repo-1' }] -- and three places in
this codebase already read exactly that row as locally owned:

  - shared/execution-host.ts getRepoExecutionHostId returns LOCAL_EXECUTION_HOST_ID
  - main/ipc/worktrees/listing/worktree-host-ownership.ts resolveRepoOwnershipEvidence
    falls back to LOCAL_EXECUTION_HOST_ID, and the listing and removal paths trust it
  - shared/repo-types.ts documents executionHostId as the field runtime-host repos
    need precisely because they otherwise look identical to local repos

attribute. It swept in the legacy-local case because at the time nothing in this
resolver consulted the repo index for an unstamped row.

So each case is re-aimed at the state it was actually defending, and neither is
deleted -- the fail-closed coverage is not reduced, it is pointed at a real
missing owner:

  - the first becomes 'fails a paired-client publication closed when no repo row
    can own it': same runtime state, repos: []. A worktree row alone is not host
    evidence, so this still returns missing, before and after the fix.
  - the second becomes 'fails ownerless rows closed mid-hydration while a saved
    runtime could own them': an active runtime with an ambiguous saved catalog
    during hydration. This returns missing from the active-runtime branch and is
    untouched by the fix. It is worded to stay distinct from the neighbouring
    case at :185, which already covers focus-is-not-ownership with an empty
    catalog, rather than duplicating it.

The states these two cases vacate are re-asserted with their corrected expected
result in the stablyai#16733 block added by the previous commit. Suite unchanged at
7 failed | 52 passed (59): the rewrites pass, the 7 reds are still the 7 states
the fix must convert.
nwparker pushed a commit that referenced this pull request Sep 15, 2026
#16841 still fails closed (#16829)

* test(worktrees): cover local worktree owner routing with saved runtimes (#16733)

A local git worktree whose rows carry no host stamp fails every owner-routed
operation closed as soon as any runtime environment is saved, however unrelated.
resolveWorktreeOperationRouteResult establishes positive identity from the
worktree/repo catalogs, then discards it: with no runtime active the only exit is
the legacy-local gate, which demands an empty saved-runtime list. One saved
environment makes that false and the call returns { kind: 'missing' }.

These tests state the contract before the fix, so the claim that the fix is
purely additive can be checked rather than asserted. Committed red on purpose.

Observed at 5631aa0 (vitest run, both files):

  Tests  7 failed | 52 passed (59)

The 7 failing are exactly the states that must become local, plus their two
consumers:

  - an unrelated runtime is saved (the reported bug)
  - several unrelated runtimes are saved
  - the repo is known before its worktree row is listed
  - the saved-runtime catalog has not hydrated
  - an unrelated runtime was removed
  - resolveTerminalWorktreeRoute on such a worktree (the gate in front of the
    "Terminal creation is unavailable" reply)
  - the folder/worktree parity state: identical store, folder local, worktree
    missing

The other 52 pass now and must keep passing: connection-owned and
runtime-stamped repos never route local, a stamped worktree row still outranks
its repo, contradictory repo rows stay ambiguous, an ambiguous or hydrating
runtime focus still fails closed, and a genuinely unknown id still fails closed.
That set is the additive-only guarantee.

* test(worktrees): re-aim two fail-closed cases at genuinely missing owners (#16733)

Two cases in src/renderer/src/lib/worktree-operation-route.test.ts assert the
behaviour #16733 reports as the bug, so they have to move:

  - :158 'fails a paired-client ownerless stale publication closed instead of
    routing it locally'
  - :171 'fails ownerless rows closed until the saved-runtime catalog is hydrated'

Both arrived with #9994 (41751dd, route HUB-owned SSH worktrees through their
owning runtime), whose stated goal was to fail closed for missing or stale
owners. That goal is right and is kept. The premise being rebutted is narrower:
neither fixture describes a missing or stale owner. Each carries a present repo
row that is merely unstamped -- repos: [{ id: 'repo-1' }] -- and three places in
this codebase already read exactly that row as locally owned:

  - shared/execution-host.ts getRepoExecutionHostId returns LOCAL_EXECUTION_HOST_ID
  - main/ipc/worktrees/listing/worktree-host-ownership.ts resolveRepoOwnershipEvidence
    falls back to LOCAL_EXECUTION_HOST_ID, and the listing and removal paths trust it
  - shared/repo-types.ts documents executionHostId as the field runtime-host repos
    need precisely because they otherwise look identical to local repos

attribute. It swept in the legacy-local case because at the time nothing in this
resolver consulted the repo index for an unstamped row.

So each case is re-aimed at the state it was actually defending, and neither is
deleted -- the fail-closed coverage is not reduced, it is pointed at a real
missing owner:

  - the first becomes 'fails a paired-client publication closed when no repo row
    can own it': same runtime state, repos: []. A worktree row alone is not host
    evidence, so this still returns missing, before and after the fix.
  - the second becomes 'fails ownerless rows closed mid-hydration while a saved
    runtime could own them': an active runtime with an ambiguous saved catalog
    during hydration. This returns missing from the active-runtime branch and is
    untouched by the fix. It is worded to stay distinct from the neighbouring
    case at :185, which already covers focus-is-not-ownership with an empty
    catalog, rather than duplicating it.

The states these two cases vacate are re-asserted with their corrected expected
result in the #16733 block added by the previous commit. Suite unchanged at
7 failed | 52 passed (59): the rewrites pass, the 7 reds are still the 7 states
the fix must convert.

* fix(worktrees): keep unstamped local worktrees routable when runtimes are saved (#16733)

resolveWorktreeOperationRouteResult establishes positive identity from the
worktree and repo catalogs, then discards it. With no runtime active the only
exit is the legacy-local gate, which requires an empty saved-runtime list, so one
saved runtime environment -- connected or not, related or not -- made it false
and the call returned { kind: 'missing' }. Every owner-routed operation on a
genuinely local git worktree then failed closed, and because
resolveTerminalWorktreeRoute is the sole gate in front of
terminal-request-ipc-bridge.ts, the user saw "Terminal creation is unavailable
because the worktree owner could not be resolved".

Folder workspaces hit the same gate and were carved out in #10251/#10269, whose
comment in this file states the principle and names this exact failure mode: a
found record is positive identity evidence, and the worktree legacy hydration
gates "would fail local folders closed whenever unrelated runtimes exist". Git
worktrees never got the equivalent. This adds it, in the same shape and the same
function.

The rule is not new. An unstamped repo row is read as locally owned by
getRepoExecutionHostId, by main's resolveRepoOwnershipEvidence, and by
Repo.executionHostId's own documentation; and the repo write path
(repoWithFetchedOwner) stamps runtime: and ssh: owners at fetch time, so an
unstamped row is a legacy row that predates owner projection -- local by
construction. The router now consults that evidence instead of contradicting it.
The sidebar already rendered these worktrees as Local; this removes the
disagreement rather than adding a heuristic.

Four properties this change holds to:

1. The branch sits after the active-runtime block, so an unambiguous active
   runtime still wins (routes runtime:<id>, not local) and an ambiguous or
   mid-hydration focus still returns missing. That ordering is structural, not
   incidental.
2. mayBeLegacyLocal is left byte-identical (verified: both 7-line hunks hash to
   f0ed1b4287c646cb). The new branch does take over the two states where a local
   repo row exists and no runtime is saved, but returns the identical local
   route, so no input changes its answer -- only which branch produced it.
3. The helper returns null on anything but unanimous local, so the branch can
   only ever convert missing into local. It never returns ambiguous: a
   contradiction between repo rows is already decided upstream by
   resolveExplicitWorktreeOperationRouteResult, and answering it here would be a
   second, divergent authority.
4. It reads neither runtimeEnvironmentCatalogHydrated nor
   removedRuntimeEnvironmentIds. That is sound rather than merely convenient,
   because it consults host evidence rather than runtime-environment inference: a
   runtime-owned repo row is stamped runtime:<id> at fetch time, so neither an
   unhydrated runtime catalog nor a removed environment can turn an unstamped row
   into a remote one.

Control only reaches this point after the explicit catalog resolver returned
missing, which means every worktree row and every repo row for this id is
unstamped -- any stamped row routes ssh: or runtime: earlier, and two disagreeing
rows return ambiguous earlier. There is no remote-owned state left here to leak.

Out of scope, deliberately: who wins when a runtime is focused (#11512), and
back-filling Worktree.hostId at creation time, which is a persistence migration
over worktreeMeta and does nothing for the users already carrying unstamped rows.

The 7 cases red in the two preceding commits now pass; the 52 that guard the
fail-closed contract are unchanged.

  Test Files  2 passed (2)
       Tests  59 passed (59)

* test(worktrees): defer repo-row-only routing to #16841's fail-closed rule (#16733)

Upstream #16841 (merged d347595) landed its own fix for #16733 and drew the
positive-identity line one notch tighter than this branch did: its
'does not treat a repo row alone as positive local identity' case asserts that a
worktree id no row has ever listed stays `missing`, even when the repo row for
its repoId is local.

This branch's 'routes a known local repo before its worktree row has been listed'
asserted the opposite result for that identical state, so the two cannot both
hold. Main's rule is the safer reading — a repo row is repo identity, not
worktree identity — so the reconciled code gates
resolveUnstampedLocalWorktreeRoute on hasKnownWorktree and this case is dropped
rather than re-pinned. Every state that actually reproduces #16733 keeps a
worktree row (listed or detected), so the reported bug and both extra
fail-closed edge cases this branch fixes are unaffected.

* refactor(worktrees): drop the unreachable disagreement loop in resolveUnstampedLocalWorktreeRoute

resolveWorktreeOperationRouteResult only calls resolveUnstampedLocalWorktreeRoute after
resolveExplicitWorktreeOperationRouteResult has already returned 'missing' for this repoId.
That function (worktree-operation-catalog-route.ts) indexes every repo row carrying a
non-empty executionHostId or connectionId and resolves/ambiguous-es on any of them, so by
construction every row resolveUnstampedLocalWorktreeRoute ever sees is unstamped -- and
getRepoExecutionHostId's own fallback (shared/execution-host.ts) always resolves an unstamped
row to local. The per-row disagreement check could never actually return null; it was dead
defensive code describing a state the caller's short-circuit already rules out. Reduced to
an existence check with identical behavior (verified: same 66/66 tests, same mutation-proof
property -- reverting only this file still fails exactly the same 6 tests it did before).
Also harmonized a same-function 'local' string literal to the LOCAL_EXECUTION_HOST_ID constant
already in use one branch above it, and dropped a dangling getWorktreeExecutionHostId doc
reference the shipped code never actually calls.

* docs(routing): document the undocumented worktree operation route helpers
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
stablyai#16841 still fails closed (stablyai#16829)

* test(worktrees): cover local worktree owner routing with saved runtimes (stablyai#16733)

A local git worktree whose rows carry no host stamp fails every owner-routed
operation closed as soon as any runtime environment is saved, however unrelated.
resolveWorktreeOperationRouteResult establishes positive identity from the
worktree/repo catalogs, then discards it: with no runtime active the only exit is
the legacy-local gate, which demands an empty saved-runtime list. One saved
environment makes that false and the call returns { kind: 'missing' }.

These tests state the contract before the fix, so the claim that the fix is
purely additive can be checked rather than asserted. Committed red on purpose.

Observed at 5631aa0 (vitest run, both files):

  Tests  7 failed | 52 passed (59)

The 7 failing are exactly the states that must become local, plus their two
consumers:

  - an unrelated runtime is saved (the reported bug)
  - several unrelated runtimes are saved
  - the repo is known before its worktree row is listed
  - the saved-runtime catalog has not hydrated
  - an unrelated runtime was removed
  - resolveTerminalWorktreeRoute on such a worktree (the gate in front of the
    "Terminal creation is unavailable" reply)
  - the folder/worktree parity state: identical store, folder local, worktree
    missing

The other 52 pass now and must keep passing: connection-owned and
runtime-stamped repos never route local, a stamped worktree row still outranks
its repo, contradictory repo rows stay ambiguous, an ambiguous or hydrating
runtime focus still fails closed, and a genuinely unknown id still fails closed.
That set is the additive-only guarantee.

* test(worktrees): re-aim two fail-closed cases at genuinely missing owners (stablyai#16733)

Two cases in src/renderer/src/lib/worktree-operation-route.test.ts assert the
behaviour stablyai#16733 reports as the bug, so they have to move:

  - :158 'fails a paired-client ownerless stale publication closed instead of
    routing it locally'
  - :171 'fails ownerless rows closed until the saved-runtime catalog is hydrated'

Both arrived with stablyai#9994 (41751dd, route HUB-owned SSH worktrees through their
owning runtime), whose stated goal was to fail closed for missing or stale
owners. That goal is right and is kept. The premise being rebutted is narrower:
neither fixture describes a missing or stale owner. Each carries a present repo
row that is merely unstamped -- repos: [{ id: 'repo-1' }] -- and three places in
this codebase already read exactly that row as locally owned:

  - shared/execution-host.ts getRepoExecutionHostId returns LOCAL_EXECUTION_HOST_ID
  - main/ipc/worktrees/listing/worktree-host-ownership.ts resolveRepoOwnershipEvidence
    falls back to LOCAL_EXECUTION_HOST_ID, and the listing and removal paths trust it
  - shared/repo-types.ts documents executionHostId as the field runtime-host repos
    need precisely because they otherwise look identical to local repos

attribute. It swept in the legacy-local case because at the time nothing in this
resolver consulted the repo index for an unstamped row.

So each case is re-aimed at the state it was actually defending, and neither is
deleted -- the fail-closed coverage is not reduced, it is pointed at a real
missing owner:

  - the first becomes 'fails a paired-client publication closed when no repo row
    can own it': same runtime state, repos: []. A worktree row alone is not host
    evidence, so this still returns missing, before and after the fix.
  - the second becomes 'fails ownerless rows closed mid-hydration while a saved
    runtime could own them': an active runtime with an ambiguous saved catalog
    during hydration. This returns missing from the active-runtime branch and is
    untouched by the fix. It is worded to stay distinct from the neighbouring
    case at :185, which already covers focus-is-not-ownership with an empty
    catalog, rather than duplicating it.

The states these two cases vacate are re-asserted with their corrected expected
result in the stablyai#16733 block added by the previous commit. Suite unchanged at
7 failed | 52 passed (59): the rewrites pass, the 7 reds are still the 7 states
the fix must convert.

* fix(worktrees): keep unstamped local worktrees routable when runtimes are saved (stablyai#16733)

resolveWorktreeOperationRouteResult establishes positive identity from the
worktree and repo catalogs, then discards it. With no runtime active the only
exit is the legacy-local gate, which requires an empty saved-runtime list, so one
saved runtime environment -- connected or not, related or not -- made it false
and the call returned { kind: 'missing' }. Every owner-routed operation on a
genuinely local git worktree then failed closed, and because
resolveTerminalWorktreeRoute is the sole gate in front of
terminal-request-ipc-bridge.ts, the user saw "Terminal creation is unavailable
because the worktree owner could not be resolved".

Folder workspaces hit the same gate and were carved out in stablyai#10251/stablyai#10269, whose
comment in this file states the principle and names this exact failure mode: a
found record is positive identity evidence, and the worktree legacy hydration
gates "would fail local folders closed whenever unrelated runtimes exist". Git
worktrees never got the equivalent. This adds it, in the same shape and the same
function.

The rule is not new. An unstamped repo row is read as locally owned by
getRepoExecutionHostId, by main's resolveRepoOwnershipEvidence, and by
Repo.executionHostId's own documentation; and the repo write path
(repoWithFetchedOwner) stamps runtime: and ssh: owners at fetch time, so an
unstamped row is a legacy row that predates owner projection -- local by
construction. The router now consults that evidence instead of contradicting it.
The sidebar already rendered these worktrees as Local; this removes the
disagreement rather than adding a heuristic.

Four properties this change holds to:

1. The branch sits after the active-runtime block, so an unambiguous active
   runtime still wins (routes runtime:<id>, not local) and an ambiguous or
   mid-hydration focus still returns missing. That ordering is structural, not
   incidental.
2. mayBeLegacyLocal is left byte-identical (verified: both 7-line hunks hash to
   f0ed1b4287c646cb). The new branch does take over the two states where a local
   repo row exists and no runtime is saved, but returns the identical local
   route, so no input changes its answer -- only which branch produced it.
3. The helper returns null on anything but unanimous local, so the branch can
   only ever convert missing into local. It never returns ambiguous: a
   contradiction between repo rows is already decided upstream by
   resolveExplicitWorktreeOperationRouteResult, and answering it here would be a
   second, divergent authority.
4. It reads neither runtimeEnvironmentCatalogHydrated nor
   removedRuntimeEnvironmentIds. That is sound rather than merely convenient,
   because it consults host evidence rather than runtime-environment inference: a
   runtime-owned repo row is stamped runtime:<id> at fetch time, so neither an
   unhydrated runtime catalog nor a removed environment can turn an unstamped row
   into a remote one.

Control only reaches this point after the explicit catalog resolver returned
missing, which means every worktree row and every repo row for this id is
unstamped -- any stamped row routes ssh: or runtime: earlier, and two disagreeing
rows return ambiguous earlier. There is no remote-owned state left here to leak.

Out of scope, deliberately: who wins when a runtime is focused (stablyai#11512), and
back-filling Worktree.hostId at creation time, which is a persistence migration
over worktreeMeta and does nothing for the users already carrying unstamped rows.

The 7 cases red in the two preceding commits now pass; the 52 that guard the
fail-closed contract are unchanged.

  Test Files  2 passed (2)
       Tests  59 passed (59)

* test(worktrees): defer repo-row-only routing to stablyai#16841's fail-closed rule (stablyai#16733)

Upstream stablyai#16841 (merged d347595) landed its own fix for stablyai#16733 and drew the
positive-identity line one notch tighter than this branch did: its
'does not treat a repo row alone as positive local identity' case asserts that a
worktree id no row has ever listed stays `missing`, even when the repo row for
its repoId is local.

This branch's 'routes a known local repo before its worktree row has been listed'
asserted the opposite result for that identical state, so the two cannot both
hold. Main's rule is the safer reading — a repo row is repo identity, not
worktree identity — so the reconciled code gates
resolveUnstampedLocalWorktreeRoute on hasKnownWorktree and this case is dropped
rather than re-pinned. Every state that actually reproduces stablyai#16733 keeps a
worktree row (listed or detected), so the reported bug and both extra
fail-closed edge cases this branch fixes are unaffected.

* refactor(worktrees): drop the unreachable disagreement loop in resolveUnstampedLocalWorktreeRoute

resolveWorktreeOperationRouteResult only calls resolveUnstampedLocalWorktreeRoute after
resolveExplicitWorktreeOperationRouteResult has already returned 'missing' for this repoId.
That function (worktree-operation-catalog-route.ts) indexes every repo row carrying a
non-empty executionHostId or connectionId and resolves/ambiguous-es on any of them, so by
construction every row resolveUnstampedLocalWorktreeRoute ever sees is unstamped -- and
getRepoExecutionHostId's own fallback (shared/execution-host.ts) always resolves an unstamped
row to local. The per-row disagreement check could never actually return null; it was dead
defensive code describing a state the caller's short-circuit already rules out. Reduced to
an existence check with identical behavior (verified: same 66/66 tests, same mutation-proof
property -- reverting only this file still fails exactly the same 6 tests it did before).
Also harmonized a same-function 'local' string literal to the LOCAL_EXECUTION_HOST_ID constant
already in use one branch above it, and dropped a dangling getWorktreeExecutionHostId doc
reference the shipped code never actually calls.

* docs(routing): document the undocumented worktree operation route helpers
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ad of failing them closed (stablyai#10151)

Inline setup/onboarding terminals (skill installs, feature tips) and the floating terminal use host-agnostic synthetic worktree ids with no worktree/repo row. Since stablyai#9994, connectPanePty gated their transport on resolveWorktreeOperationRouteResult, which fails closed ('missing') for unknown ids — so the Orca CLI skill Update button, every other inline setup terminal, and the floating terminal showed "Workspace identity is ambiguous across hosts" instead of running.

Route them through the shared resolveTerminalWorktreeRoute (which already exempts the floating terminal and folder workspaces), and add the missing ephemeral-setup exemption so setup terminals follow the single active runtime (remote skill installs land there) or run locally when none is focused. Genuinely unknown/stale repo-backed worktrees still fail closed, preserving stablyai#9994.

Adds terminal-worktree-route unit tests and connectPanePty regression tests (proven to fail without the fix).

Co-authored-by: Orca <[email protected]>
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.

[Bug] Possible bug: a paired desktop client can't see a remote runtime's SSH-hosted worktrees (the web UI

1 participant