Repository navigation
Fix un-removable SSH ghost worktrees after host remove/re-add - #7753
Conversation
When a user removed a broken SSH host and re-added it, old grey worktrees stayed pinned to the dead target id and could not be deleted: worktrees:remove threw at requireSshGitProvider before any cleanup ran. Two root causes, both fixed: - Re-add never re-associated orphaned workspaces. Removing a target now records an identity tombstone; adding/importing a target with matching identity (configHost alias, else host+user+port) re-points orphaned repos/worktrees onto the new id (reassignSshTargetId), so workspaces reattach to the live host. - Removal had no local-only escape hatch. New worktrees:forgetLocal IPC handler clears Orca records without touching the SSH provider; new host-scoped removeProjectForHost/repos:removeForHost avoids over-deleting a repo id shared across hosts. UX: per-workspace delete on a disconnected/ghost SSH host offers Reconnect & Delete / Remove from Orca / Cancel; host removal accounts for its workspaces. Review fixes: skip the SSH-forget interception on paired web/mobile clients (they have no SSH host state and would misroute to an unavailable local path); thread an explicit hostId through removeProject so host removal targets the SSH row not the focused host; the re-adoption tuple fallback no longer matches across two distinct config aliases sharing an endpoint; host removal aborts and reports failure instead of removing the target when a workspace fails to clear. Co-authored-by: Orca <[email protected]>
|
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:
📝 WalkthroughWalkthroughChangesThis PR adds host-scoped repo removal and SSH workspace forget flows across main, preload, and renderer code. Persistence now tracks removed SSH target tombstones, supports host-specific repo pruning, and can reassign orphaned records when an SSH target is re-added. Renderer store and dialogs add host-aware removal, local-only worktree forgetting, and SSH-specific resolution paths. IPC and preload expose the new channels, and tests cover the new persistence, IPC, and renderer behavior. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 8
🧹 Nitpick comments (5)
src/renderer/src/components/sidebar/ssh-host-remove-workspaces.ts (1)
1-61: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy liftMissing test coverage for this critical failure-aggregation path.
Unlike
ssh-host-remove-resolution.ts, this file has no accompanying test. Given its role in deciding whether an SSH target is safe to remove (based onfailedIds), a regression here directly risks reintroducing ghost repos/worktrees. Consider adding unit tests covering: successful clear in both modes, a failingremoveWorktree, and a failingremoveProject.src/renderer/src/components/sidebar/HostRemoveDialog.tsx (2)
91-147: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRedundant
setBusy(null)before earlyreturn.Lines 111-113 explicitly clear
busybefore returning on the failure path, but thefinallyblock (lines 142-146) also runs on that same path and clears it again. The early call is dead weight; thefinallyalready guarantees cleanup.♻️ Proposed simplification
if (failedIds.length > 0) { - if (mountedRef.current) { - setBusy(null) - } toast.error(
91-98: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
modeandbusyKeyare always identical at every call site.
runSshRemovaltakes bothmodeandbusyKeyas separate parameters, but every caller (lines 232, 245, 256) passes the same value for both. Consider derivingbusyKeyfrommodeinside the function to remove the duplicated argument.Also applies to: 227-260
src/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsx (1)
148-148: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueArbitrary font size bypasses design tokens.
text-[11px]is a custom bracket value not on the standard Tailwind text scale (closest token istext-xs). As per path instructions, UI work undersrc/renderer/src/**/*.{ts,tsx,css}should "use the design tokens... instead of inventing new colors, font sizes, or shadow tiers when existing documented values cover the need."🎨 Proposed fix
- <p className="text-[11px] leading-snug text-muted-foreground">{forgetDescription}</p> + <p className="text-xs leading-snug text-muted-foreground">{forgetDescription}</p>Source: Coding guidelines
src/main/ssh/ssh-connection-store.ts (1)
34-43: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFragile shared-state pattern for surfacing
lastReadoptedRepoCount.Exposing the last operation's result via a mutable instance field that the IPC layer reads-then-resets works today because both
addTargetandimportFromSshConfig(and their IPC handlers) are fully synchronous, but it's an implicit contract that would silently break if either becomesasyncor gains anawaitbefore the notify call. Consider returning the count alongside the result (e.g.{ target, readoptedCount }) instead of a side-channel field.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a43a4572-f5a1-4ebb-bce9-7499283880fd
📒 Files selected for processing (29)
src/main/ipc/repos.tssrc/main/ipc/ssh.tssrc/main/ipc/worktrees.test.tssrc/main/ipc/worktrees.tssrc/main/persistence.test.tssrc/main/persistence.tssrc/main/ssh/ssh-connection-store.test.tssrc/main/ssh/ssh-connection-store.tssrc/main/ssh/ssh-target-readoption.test.tssrc/main/ssh/ssh-target-readoption.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsxsrc/renderer/src/components/sidebar/HostRemoveDialog.tsxsrc/renderer/src/components/sidebar/delete-worktree-flow.tssrc/renderer/src/components/sidebar/index.tsxsrc/renderer/src/components/sidebar/ssh-host-remove-resolution.test.tssrc/renderer/src/components/sidebar/ssh-host-remove-resolution.tssrc/renderer/src/components/sidebar/ssh-host-remove-workspaces.tssrc/renderer/src/components/sidebar/ssh-workspace-forget-resolution.test.tssrc/renderer/src/components/sidebar/ssh-workspace-forget-resolution.tssrc/renderer/src/store/slices/repos-host-identity-routing.test.tssrc/renderer/src/store/slices/repos.tssrc/renderer/src/store/slices/ui.tssrc/renderer/src/store/slices/worktree-helpers.tssrc/renderer/src/store/slices/worktrees.tssrc/renderer/src/web/web-preload-api.tssrc/shared/ssh-types.tssrc/shared/types.ts
Explain the orphaned state in the user's terms ('no longer connected to a
live host') and name the host, so it's clear why the workspace can only be
removed from Orca. Fold the 'remote untouched' reassurance into that copy and
drop the now-redundant secondary line on the ghost path.
Co-authored-by: Orca <[email protected]>
E2E testing surfaced a renderer bug: after re-adoption re-points a repo from the old (removed) SSH target id to a re-added one, the renderer's per-host repo merge preserved the stale row on the dead id (it looks like 'another host'). A terminal pane bound to that ghost row then failed with 'SSH target not found'. Prune a repo row when it targets an SSH connection that is no longer a known target AND the same repo id also exists on a live host (the re-adoption sibling). A lone project-only ghost — repo id only on the dead host, no live sibling — is deliberately kept so it can still be surfaced and forgotten. Runtime-owned SSH rows are never pruned. Co-authored-by: Orca <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/renderer/src/store/slices/repos.ts (1)
2577-2589: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftDerive the runtime target from
ownerHostId— still unresolved.
ownerReponow honorsoptions?.hostIdviafindRepoForHost, buttargetstill comes fromsettingsForRepoOwner(get(), projectId), which ignores the explicit host. When duplicate repo IDs exist across hosts, this can routerepo.rmto the focused runtime instead of the intended one, deleting the wrong remote row. PassownerHostIdinto target selection (e.g.,getProjectSetupRuntimeTarget(ownerHostId)) or derive the target fromownerRepodirectly.This was previously flagged and remains unaddressed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 45420952-72f8-4ec2-96f6-00678fa2674e
📒 Files selected for processing (3)
src/renderer/src/store/slices/repos.tssrc/renderer/src/store/slices/superseded-ssh-repo-rows.test.tssrc/renderer/src/store/slices/superseded-ssh-repo-rows.ts
E2E: a workspace pinned to a removed SSH target showed the reconnect overlay
with a 'Connect' button that always failed ('SSH target not found'), because
the overlay decided its action purely from connection status and had no notion
of the target being gone.
When the target is no longer a known SSH target, show an 'SSH host removed'
state with a 'Remove workspace' action (routing through the normal delete flow
-> forget dialog) instead of a dead Connect button. Runtime-owned targets are
unaffected.
Co-authored-by: Orca <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.tsx (1)
151-162: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value"Remove workspace" button uses neutral
outlinestyling for a destructive action.The button triggers
runWorktreeDelete, which ultimately deletes the workspace record. Consider using a destructive variant (if one exists in the design system) to visually distinguish this from the benign "Connect" action it replaces, consistent with how other destructive actions are styled elsewhere in the app.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 44c3bc46-1a01-4434-bab2-8752bd147739
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.test.tsxsrc/renderer/src/components/terminal-pane/TerminalSshReconnectOverlay.tsx
The terminal PTY auto-reattach path called ssh:connect for the workspace's connectionId even after the target was removed, failing with 'SSH target not found' and surfacing a red 'please file an issue' banner for what is an expected user action. Skip reattach when the connectionId is no longer a known SSH target (a real, populated target map that omits it). The 'SSH host removed' overlay already gives the user a clear state and a remove action. Runtime-owned targets and not-yet-hydrated label maps are exempt. Co-authored-by: Orca <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0bf29ca8-8c07-49c5-951f-5c093e50c205
📒 Files selected for processing (1)
src/renderer/src/components/terminal-pane/pty-connection.ts
The sidebar host menu routed removal through the workspace-aware HostRemoveDialog, but the SSH settings pane used a plain confirm that silently orphaned the host's workspaces. Route the settings-pane remove through the same HostRemoveDialog when the target still owns workspaces (falling back to the plain confirm otherwise), so both entry points offer the same delete/keep choice. Also dedupe repo/worktree ids in resolveSshHostRemoval so a transient duplicate store row can't inflate the workspace count or double-remove a worktree. Co-authored-by: Orca <[email protected]>
…dvanced The host-removal dialog crammed three buttons in a row and made 'Delete host & workspaces' the primary red action, signalling destruction as the default. Redesign: the default primary is now just 'Remove host' (keeps workspaces, reversible). Deleting/forgetting the host's workspaces moves behind an Advanced disclosure (matching the create-workspace modal) as an opt-in checkbox with a 'cannot be undone' warning; ticking it re-labels the primary to the destructive variant. Clean two-button footer (Cancel + primary). Co-authored-by: Orca <[email protected]>
Replace the bordered-card + checkbox with the same borderless ghost 'Advanced' header + grid-rows collapse + toggle switch used by the New Workspace composer, so the disclosure looks consistent with the rest of the app. Switch turns red (destructive) when the workspace-deletion opt-in is enabled. Co-authored-by: Orca <[email protected]>
Make the workspace-deletion toggle use the neutral foreground color (not red), and always label the confirm button 'Remove host' regardless of the toggle state instead of switching to a longer conditional label. Co-authored-by: Orca <[email protected]>
Deleting a workspace on a connected SSH host always removed the remote git worktree, with no way to just declutter Orca while keeping the remote. Route connected-SSH deletes to a new dialog whose default is 'Remove from Orca' only (keeps the remote worktree/branch), with a gated 'Also delete on the remote' toggle to opt into the destructive remote removal. The second toggle is disabled until 'Remove from Orca' is on, and Delete is disabled if neither would do anything. Reuses the provider-free forgetLocal for the keep-remote path and the normal removal for the delete-remote path. Co-authored-by: Orca <[email protected]>
… choice" This reverts commit 67bd6ae.
'Also delete these N workspaces on the remote' read awkwardly; use the host label — 'Also delete these N workspaces on «host»' — consistent with the rest of the dialog. Co-authored-by: Orca <[email protected]>
The re-adoption tombstones already store each removed target's label, but the renderer had no access to it, so ghost-host UI fell back to the raw ssh-<ts>-<rand> id. Expose removed-target labels via ssh:listRemovedTargetLabels, hydrate a removedSshTargetLabels store map, and use it as a fallback in: - the terminal 'SSH host removed' overlay - the forget-workspace dialog - the Remove Project dialog, which now says an SSH project's files stay on the named host and can be recovered by re-adding it (instead of the misleading 'still on your disk'). Co-authored-by: Orca <[email protected]>
- Re-adoption tuple bypass (Major): treat configHost === host as no alias, so a manual add (which defaults configHost to host) can't reattach workspaces to a different account/port on the same host. Falls back to host+user+port. +tests. - persistence.reassignSshTargetId (Major): persist worktree-meta-only re-points (repoCount === 0) by tracking metaChanged; keep host-setup sync repo-gated. +test. - clearSshHostWorkspaces (Major): removeProject swallows its errors, so verify the host's repo row is actually gone and mark it failed if it lingers. - removeProject target (Major): derive the runtime target from the resolved owner host (getProjectSetupRuntimeTarget) instead of settingsForRepoOwner, so an explicit hostId routes repo.rm to the right host, not the focused one. +test update. - superseded test name: 'keeps' -> 'drops' to match the assertion. - Document why the ghost/disconnected forget path skips the lineage-children warning (forget-local is metadata-only, per-worktree; descendants stay independently forgettable, not orphaned). Co-authored-by: Orca <[email protected]>
removeProject now derives the runtime target via settingsForRepoOwner (threaded with the explicit hostId) instead of getProjectSetupRuntimeTarget. settingsForRepoOwner already pins runtime owners to their env and clears the focused runtime for SSH/local owners, so an explicit SSH host removal still routes local while focused-runtime repos route their repo.rm RPC. The prior change ignored the focused runtime env for repos with no explicit executionHostId, breaking three runtime-routing tests. Add an SSH-explicit-host removeProject regression test. Co-authored-by: Orca <[email protected]>
Registers 21 translation keys referenced by ForgetSshWorkspaceDialog, HostRemoveDialog, RemoveFolderDialog, and TerminalSshReconnectOverlay (added in stablyai#7753) that were never synced into en.json, and repairs key parity across all locale catalogs. Mechanical output of `pnpm run sync:localization-catalog`; fixes the currently failing verify:localization-catalog lint step on main.
…ai#7753) Co-authored-by: Orca <[email protected]>
Problem
A user removed an SSH host that had broken, re-added it, and was left with grey "ghost" worktrees they couldn't delete. Deleting them failed with "Remote connection dropped. Click Reconnect on the SSH target before retrying" or
spawning git ENOENT, becauseworktrees:removethrows atrequireSshGitProviderbefore any cleanup runs when the target/provider is gone.Root causes (two, both fixed)
ssh-${Date.now()}-…); removing a target deleted the target row but left every repo/worktree pinned to the dead id, and re-adding minted a new id with nothing linking the old workspaces to it. Association is purely by exact id, so the old workspaces became un-removable project-only ghost hosts.store.removeProject, repo-id-only) could over-delete a repo id shared across hosts.What this does
Re-adoption (the primary fix). Removing a target now records an identity tombstone (
{ oldTargetId, configHost, host, port, username }). Adding or importing a target whose identity matches (configHost alias first, then host+user+port) re-points orphaned repos/worktrees onto the new id (reassignSshTargetId), so workspaces reattach to the reconnected host. Tombstones are capped/deduped; runtime-owned (ephemeral-VM) targets are excluded. Matching is strict: two distinct config aliases sharing one endpoint do not steal each other's workspaces.Forget escape hatch. New provider-free
worktrees:forgetLocalIPC handler clears Orca's records (metadata, history, transient state, PTYs) without touching the SSH provider — so a ghost workspace can always be removed. New host-scopedremoveProjectForHost/repos:removeForHostremove only the intended host's repo row when an id is shared across hosts (local / SSH / re-added target), avoiding cross-host data loss.UX.
Adversarial review — findings fixed in this PR
A four-lens adversarial review (correctness, contract/persistence, remoting/parity, scenario) surfaced issues that are fixed here:
sshTargetLabels), routing deletes to a local-only path that's unavailable there → SSH workspaces became undeletable on web/mobile. Now the SSH-forget interception is skipped on paired web clients; they keep their normalworktree.rmRPC path.removeProject(id), which resolves by focused host — for a duplicate id it deleted the wrong (local) project and left the SSH ghost. Now an explicithostIdis threaded through so it targets the SSH row.Persistence / backcompat
New
removedSshTargetTombstones?field is optional with??guards on every access; old state files load cleanly and new files round-trip. IPC channels registered + removed, preload + web-shim + type surface all updated.Tests
New/updated coverage:
worktrees:forgetLocalnever touches the SSH provider (even with no provider registered); host-scopedremoveProjectForHost/reassignSshTargetId; re-adoption matching incl. the different-alias/same-endpoint case; per-workspace + host-remove resolution helpers; explicit-hostIdproject removal targets the right host. Full affected suites green; typecheck, oxlint, max-lines ratchet, and localization coverage all pass.Not committed: PR evidence images (none).
Made with Orca 🐋