Repository navigation
fix(runtime): route HUB-owned SSH worktrees through owning runtime - #9994
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis 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)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 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 winUnhandled rejection risk:
getEditorFileOperationContextcan throw, but the autosave timer path doesn't catch it.
getEditorFileOperationContext(line 104) throwsOWNER_CHANGED_MESSAGEwhen 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 otherqueueSavecaller (handleSaveDirtyFiles,handleSaveAndClose,handleSaveFile) awaits inside its own try/catch, but the autosave timer at Line 221 doesvoid queueSave(file, draft, 'autosave')with no error handling. If ownership is stale when autosave fires, this becomes an unhandled promise rejection that recurs everyautoSaveDelayMsuntil 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 winScope the terminal close by pairing revision.
closeWebRuntimeTerminalis a destructive RPC path, but it callswindow.api.runtimeEnvironments.calldirectly withoutexpectedEnvironmentPairingRevision. 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 winReorder cleanup before the re-assertion in the write-failure catch.
assertCurrent()runs beforedeleteRuntimePath, so a stale-ownership race duringwriteRuntimeFileskips cleanup entirely and replaces the real write error with the ownership error, leaving an orphaned empty file atfilePath.🐛 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 winUnguarded
getEditorFileOperationContextcalls can throw uncaught. Both sites call the new throwinggetEditorFileOperationContext(which throwsOWNER_CHANGED_MESSAGEon 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 thegetEditorFileOperationContextcall in try/catch and route failures through the existingsetRenameError(...)path used by every other failure branch inhandleRenameConfirm.src/renderer/src/components/tab-bar/tab-create-entry-action.ts#L215-L243: wrap thegetEditorFileOperationContextcall in try/catch (or confirm and document thatopenTabBarEntry'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
activateTerminalTabno-ops entirely when ownership is unresolvable.Previously this function always activated the tab locally. Now, if
resolveTerminalWorktreeRoutereturns null (unresolvable ownership), the whole function returns before callings.setActiveTab/s.setActiveTabType. Local tab activation doesn't need remote ownership resolved — only theactivateWebRuntimeSessionTabsync 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 winReuse the shared
terminalMarkerCommand.
tests/e2e/helpers/nested-runtime-ssh-client-route.tsnow exportsterminalMarkerCommandwith the same logic. Importing it fromnested-runtime-ssh-terminal-creation.tswould 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 winExtract 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: replacecloseIntentPartitionKey+ theMap<string, Map<string, CloseIntent>>storage + theclearWebSessionCloseIntentsForOwnerprefix loop with a shared generic partition-map utility.src/renderer/src/runtime/web-session-focus-intent.ts#L14-L18: replacefocusIntentPartitionKey+pendingFocusByOwnerAndWorktree+clearWebSessionFocusIntentsForOwnerwith the same shared utility.src/renderer/src/runtime/web-session-reorder-intent.ts#L20-L26: replacereorderIntentPartitionKey+pendingReorderByOwnerAndWorktree+clearWebSessionReorderIntentsForOwnerwith the same shared utility.src/main/ipc/runtime-environment-revision-guard.ts (1)
9-11: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the effective pairing-revision fallback into one helper. The
pairingRevision ?? createdAtfallback 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 sharedresolveEnvironmentPairingRevision(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
📒 Files selected for processing (245)
config/scripts/run-nested-runtime-ssh-e2e.mjspackage.jsonsrc/main/index.tssrc/main/ipc/ephemeral-vm-runtime-handlers.tssrc/main/ipc/ephemeral-vm.test.tssrc/main/ipc/filesystem-import-ssh-directory.tssrc/main/ipc/filesystem-import-ssh-ops.test.tssrc/main/ipc/filesystem-import-ssh.test.tssrc/main/ipc/filesystem-import-ssh.tssrc/main/ipc/filesystem-mutations.test.tssrc/main/ipc/filesystem-mutations.tssrc/main/ipc/filesystem.test.tssrc/main/ipc/filesystem.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/ipc/runtime-environment-request-connections.tssrc/main/ipc/runtime-environment-revision-guard.test.tssrc/main/ipc/runtime-environment-revision-guard.tssrc/main/ipc/runtime-environment-tailscale-response.tssrc/main/ipc/runtime-environment-transport-generation.tssrc/main/ipc/runtime-environment-transport-routing.tssrc/main/ipc/runtime-environments.test.tssrc/main/ipc/runtime-environments.tssrc/main/ipc/ssh.test.tssrc/main/ipc/ssh.tssrc/main/persistence.test.tssrc/main/persistence.tssrc/main/providers/ssh-pty-notification-routing.tssrc/main/providers/ssh-pty-provider.test.tssrc/main/providers/ssh-pty-provider.tssrc/main/runtime/graph-sync-mobile-snapshot-gating.test.tssrc/main/runtime/orca-runtime-files.test.tssrc/main/runtime/orca-runtime-files.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/public-ssh-state.tssrc/main/runtime/rpc/methods/client-events.tssrc/main/runtime/rpc/methods/files.test.tssrc/main/runtime/rpc/methods/files.tssrc/main/runtime/rpc/methods/ssh.test.tssrc/main/runtime/rpc/methods/ssh.tssrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/runtime-rpc.test.tssrc/main/runtime/runtime-rpc.tssrc/main/ssh/ssh-connection-generation.test.tssrc/main/ssh/ssh-connection-generation.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/editor/CombinedDiffViewer.tsxsrc/renderer/src/components/editor/editor-autosave-conflict-flow.test.tssrc/renderer/src/components/editor/editor-autosave-controller-test-fixture.tssrc/renderer/src/components/editor/editor-autosave-controller.test.tssrc/renderer/src/components/editor/editor-autosave-controller.tssrc/renderer/src/components/editor/rich-markdown-image-insert.test.tssrc/renderer/src/components/editor/rich-markdown-image-insert.tssrc/renderer/src/components/editor/useUntitledFileRename.tssrc/renderer/src/components/native-chat/native-chat-attachment-upload.test.tssrc/renderer/src/components/native-chat/native-chat-attachment-upload.tssrc/renderer/src/components/native-chat/use-native-chat-composer-paste.test.tsxsrc/renderer/src/components/right-sidebar/FileExplorer.tsxsrc/renderer/src/components/right-sidebar/FileExplorerRow.tsxsrc/renderer/src/components/right-sidebar/file-explorer-delete-classification.tssrc/renderer/src/components/right-sidebar/file-explorer-operation-generation.test.tssrc/renderer/src/components/right-sidebar/file-explorer-operation-owner.tssrc/renderer/src/components/right-sidebar/file-explorer-runtime-owner-boundary.test.tssrc/renderer/src/components/right-sidebar/file-explorer-types.tssrc/renderer/src/components/right-sidebar/useFileDeletion.tssrc/renderer/src/components/right-sidebar/useFileDuplicate.tssrc/renderer/src/components/right-sidebar/useFileExplorerDragDrop.tssrc/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.tssrc/renderer/src/components/right-sidebar/useFileExplorerHandlers.tssrc/renderer/src/components/right-sidebar/useFileExplorerImport.tssrc/renderer/src/components/right-sidebar/useFileExplorerInlineInput.tssrc/renderer/src/components/right-sidebar/useFileExplorerTree.tssrc/renderer/src/components/right-sidebar/useFileExplorerWatch.test.tssrc/renderer/src/components/right-sidebar/useFileExplorerWatch.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.tssrc/renderer/src/components/settings/McpConfigSection.tsxsrc/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsxsrc/renderer/src/components/settings/RepositoryHostSetupsSection.tsxsrc/renderer/src/components/settings/RepositoryPane.tsxsrc/renderer/src/components/settings/Settings.tsxsrc/renderer/src/components/settings/settings-project-list.test.tssrc/renderer/src/components/settings/settings-project-list.tssrc/renderer/src/components/shared/kill-all-terminal-surfaces.test.tssrc/renderer/src/components/sidebar/WorktreeCard.ssh-reconnect-prompt.test.tsxsrc/renderer/src/components/sidebar/WorktreeCard.tsxsrc/renderer/src/components/tab-bar/TabBar.windows-shell-launch.test.tssrc/renderer/src/components/tab-bar/tab-create-entry-action.tssrc/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-query-reply-immediate.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-snapshot-escape-tail.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal-pane/terminal-drop-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-runtime-owner.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-runtime-owner.tssrc/renderer/src/components/terminal-pane/terminal-input-host-platform.test.tssrc/renderer/src/components/terminal-pane/terminal-input-host-platform.tssrc/renderer/src/components/terminal-pane/terminal-native-file-drop.tssrc/renderer/src/components/terminal-pane/unresolved-owner-pty-transport.tssrc/renderer/src/components/terminal/terminal-tab-actions-kill-all.test.tssrc/renderer/src/components/terminal/terminal-tab-actions.test.tssrc/renderer/src/components/terminal/terminal-tab-actions.tssrc/renderer/src/components/terminal/terminal-tab-bulk-actions.tssrc/renderer/src/components/terminal/terminal-tab-create.tssrc/renderer/src/hooks/runtime-client-events-sync.test.tssrc/renderer/src/hooks/runtime-client-events-sync.tssrc/renderer/src/hooks/useComposerState.tssrc/renderer/src/hooks/useGlobalFileDrop.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/lib/agent-hibernation-coordinator.test.tssrc/renderer/src/lib/create-untitled-markdown.test.tssrc/renderer/src/lib/create-untitled-markdown.tssrc/renderer/src/lib/e2e-config.tssrc/renderer/src/lib/editor-file-operation-owner.test.tssrc/renderer/src/lib/editor-file-operation-owner.tssrc/renderer/src/lib/ensure-hooks-confirmed.tssrc/renderer/src/lib/rename-file.tssrc/renderer/src/lib/runtime-session-mirror-owners.tssrc/renderer/src/lib/sidebar-worktree-activation.tssrc/renderer/src/lib/single-runtime-legacy-owner.tssrc/renderer/src/lib/ssh-mutation-expectation.test.tssrc/renderer/src/lib/ssh-mutation-expectation.tssrc/renderer/src/lib/terminal-worktree-route.tssrc/renderer/src/lib/workspace-runtime-host-ownership.tssrc/renderer/src/lib/workspace-session-host-persistence.test.tssrc/renderer/src/lib/workspace-session-host-persistence.tssrc/renderer/src/lib/worktree-activation-created-agent.test.tssrc/renderer/src/lib/worktree-activation-empty-remote.test.tssrc/renderer/src/lib/worktree-activation.test.tssrc/renderer/src/lib/worktree-operation-generation.tssrc/renderer/src/lib/worktree-operation-route.test.tssrc/renderer/src/lib/worktree-operation-route.tssrc/renderer/src/lib/worktree-runtime-owner-index.tssrc/renderer/src/lib/worktree-runtime-owner-state.tssrc/renderer/src/lib/worktree-runtime-owner.test.tssrc/renderer/src/lib/worktree-runtime-owner.tssrc/renderer/src/runtime/abortable-runtime-environment-call.tssrc/renderer/src/runtime/close-mirrored-editor-tab.test.tssrc/renderer/src/runtime/close-mirrored-editor-tab.tssrc/renderer/src/runtime/file-explorer-delete-owner-provenance.test.tssrc/renderer/src/runtime/mobile-markdown-bridge-test-harness.tssrc/renderer/src/runtime/mobile-markdown-bridge.test.tssrc/renderer/src/runtime/remote-host-file-delete-repro.test.tssrc/renderer/src/runtime/remote-runtime-terminal-frame-drop-resync.test.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer.tssrc/renderer/src/runtime/remote-server-parity.test.tssrc/renderer/src/runtime/runtime-client-events.test.tssrc/renderer/src/runtime/runtime-client-events.tssrc/renderer/src/runtime/runtime-environment-revision.tssrc/renderer/src/runtime/runtime-environment-ssh-state.test.tssrc/renderer/src/runtime/runtime-environment-ssh-state.tssrc/renderer/src/runtime/runtime-file-client.test.tssrc/renderer/src/runtime/runtime-file-client.tssrc/renderer/src/runtime/runtime-file-import-pairing-revision.test.tssrc/renderer/src/runtime/runtime-rpc-client-pairing-revision.test.tssrc/renderer/src/runtime/runtime-rpc-client.tssrc/renderer/src/runtime/runtime-rpc-environment-call.tssrc/renderer/src/runtime/runtime-rpc-result.tssrc/renderer/src/runtime/web-runtime-session.test.tssrc/renderer/src/runtime/web-runtime-session.tssrc/renderer/src/runtime/web-session-close-intent.test.tssrc/renderer/src/runtime/web-session-close-intent.tssrc/renderer/src/runtime/web-session-focus-intent.tssrc/renderer/src/runtime/web-session-intent-owner.test.tssrc/renderer/src/runtime/web-session-intent-owner.tssrc/renderer/src/runtime/web-session-reorder-intent.tssrc/renderer/src/runtime/web-session-tabs-sync.test.tssrc/renderer/src/runtime/web-session-tabs-sync.tssrc/renderer/src/store/slices/browser.test.tssrc/renderer/src/store/slices/cmd-j-create-actions.test.tssrc/renderer/src/store/slices/diffComments.test.tssrc/renderer/src/store/slices/editor.test.tssrc/renderer/src/store/slices/editor.tssrc/renderer/src/store/slices/purge-stale-runtime-host-ownership.test.tssrc/renderer/src/store/slices/repos-nested-ssh-projection.test.tssrc/renderer/src/store/slices/repos-project-host-lifecycle.test.tssrc/renderer/src/store/slices/repos.test.tssrc/renderer/src/store/slices/repos.tssrc/renderer/src/store/slices/runtime-environment-ssh.test.tssrc/renderer/src/store/slices/runtime-environment-ssh.tssrc/renderer/src/store/slices/runtime-status.test.tssrc/renderer/src/store/slices/runtime-status.tssrc/renderer/src/store/slices/ssh-target-cleanup.tssrc/renderer/src/store/slices/ssh.test.tssrc/renderer/src/store/slices/ssh.tssrc/renderer/src/store/slices/stale-runtime-host-rows.tssrc/renderer/src/store/slices/store-cascades.test.tssrc/renderer/src/store/slices/store-session-cascades.test.tssrc/renderer/src/store/slices/store-test-helpers.tssrc/renderer/src/store/slices/terminal-tab-retirement-store.test.tssrc/renderer/src/store/slices/terminal-tab-retirement.test.tssrc/renderer/src/store/slices/terminal-tab-retirement.tssrc/renderer/src/store/slices/terminals.tssrc/renderer/src/store/slices/ui.test.tssrc/renderer/src/store/slices/ui.tssrc/renderer/src/store/slices/worktrees.test.tssrc/renderer/src/store/slices/worktrees.tssrc/renderer/src/web/web-file-mutation-methods.test.tssrc/renderer/src/web/web-file-mutation-methods.tssrc/renderer/src/web/web-preload-api.test.tssrc/renderer/src/web/web-preload-api.tssrc/shared/file-mutation-ownership.tssrc/shared/protocol-version.tssrc/shared/remote-runtime-shared-control-connection.test.tssrc/shared/remote-runtime-shared-control-connection.tssrc/shared/remote-runtime-shared-control-reconnect.tssrc/shared/remote-runtime-shared-control-subscriptions.tssrc/shared/runtime-client-events.tssrc/shared/runtime-environment-store.test.tssrc/shared/runtime-environment-store.tssrc/shared/runtime-environments.tssrc/shared/runtime-types.tssrc/shared/ssh-types.tssrc/shared/types.tstests/e2e/fixtures/docker-ssh-relay/Dockerfiletests/e2e/global-setup.tstests/e2e/helpers/docker-ssh-relay-connection.tstests/e2e/helpers/docker-ssh-relay-image.tstests/e2e/helpers/docker-ssh-relay-processes.tstests/e2e/helpers/docker-ssh-relay-target.tstests/e2e/helpers/nested-runtime-proxy-jump-fixture.tstests/e2e/helpers/nested-runtime-proxy-jump-fixture.unit.test.tstests/e2e/helpers/nested-runtime-same-id-pairing.tstests/e2e/helpers/nested-runtime-ssh-client-route.tstests/e2e/helpers/nested-runtime-ssh-filesystem-route.tstests/e2e/helpers/nested-runtime-ssh-relay-lifecycle.tstests/e2e/helpers/nested-runtime-ssh-state.tstests/e2e/helpers/nested-runtime-ssh-terminal-creation.tstests/e2e/helpers/orca-app.tstests/e2e/helpers/orca-restart.tstests/e2e/helpers/paired-electron-client.tstests/e2e/helpers/paired-web-filesystem-route.tstests/e2e/helpers/terminal.tstests/e2e/nested-runtime-ssh-lifecycle.spec.tstests/e2e/nested-runtime-ssh-routing.spec.ts
…sted-ssh-runtime-routing
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/hooks/useComposerState.ts (1)
2409-2409: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUntranslated user-facing error string.
'Attachment upload host changed; retry the upload.'bypassestranslate(...), 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
📒 Files selected for processing (15)
package.jsonsrc/main/ipc/worktree-common-git-directory.tssrc/main/skills/skill-installation-topology.tssrc/renderer/src/components/terminal-pane/terminal-drop-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-native-file-drop.tssrc/renderer/src/components/terminal/terminal-tab-actions.test.tssrc/renderer/src/components/terminal/terminal-tab-bulk-actions.tssrc/renderer/src/hooks/composer-native-file-drop.test.tssrc/renderer/src/hooks/composer-native-file-drop.tssrc/renderer/src/hooks/useComposerState.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/lib/worktree-operation-generation.test.tssrc/renderer/src/lib/worktree-operation-generation.tssrc/renderer/src/store/slices/worktrees.test.tssrc/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
…sted-ssh-runtime-routing # Conflicts: # src/main/ipc/worktree-common-git-directory.ts # src/main/skills/skill-installation-topology.ts
…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]>
…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.
#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
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
…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]>
Summary
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)src/relay/agent-exec-handler.test.tsfrom duplicate inheritedGIT_CONFIG_*shell entriesThe unchanged
lint:switch-exhaustivenessbaseline failure remains atsrc/renderer/src/components/skills/skill-freshness-group.tsx:101for missingundefined | current | duplicatehandling.Closes #9276