Repository navigation
fix(worktrees): route managed worktree removal by resolved execution host - #18529
Conversation
📝 WalkthroughWalkthroughWorktree removal now resolves a single execution-host route. Local and SSH routes select their own Git and filesystem operations. Runtime-only hosts are rejected. Cleanup receives the resolved host and connection data for metadata, directories, PTYs, watchers, history, and push targets. Folder-repository teardown now parses the removal host before SSH cleanup. New tests cover host isolation, unavailable hosts, runtime hosts, migrated metadata, and concurrent local and SSH removals. Merge Risk: 🟡 Moderate · up to Removing a runtime-hosted folder workspace can perform local teardown and delete its metadata rather than rejecting an unsupported route. This should be corrected before merge to preserve the intended host-isolation guarantees. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed technical context, scope, behavior changes, and verification results, but it does not follow the repository template. It omits the required Linked Issue, ELI5, Visual Proof or explicit N/A, Testing checklist, and several required checklist sections. Resolution Rewrite the description using every required template heading. Add a valid issue reference after ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 22bab719-4919-43cf-9895-23f4a23d5dae
📥 Commits
Reviewing files that changed from the base of the PR and between c79e1c0 and 56ae46570c0316bfee798746e749f5d60decba73.
📒 Files selected for processing (10)
src/main/runtime/orca-runtime-remove-managed-worktree.tssrc/main/runtime/orca-runtime-remove-orphan-or-folder-worktree.tssrc/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-03.spec.tssrc/main/runtime/orca-runtime-tests/worktree-removal-execution-host.spec.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/runtime-registered-remote-worktree-removal.tssrc/main/runtime/runtime-unregistered-worktree-removal.tssrc/main/runtime/runtime-worktree-filesystem.tssrc/main/worktree-removal-execution-host-route.test.tssrc/main/worktree-removal-execution-host-route.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| const folderHost = parseExecutionHostId(removalHostId) | ||
| const folderConnectionId = folderHost?.kind === 'ssh' ? folderHost.targetId : null |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- target outline ---'
ast-grep outline src/main/runtime/orca-runtime-remove-orphan-or-folder-worktree.ts
printf '%s\n' '--- target context ---'
sed -n '1,180p' src/main/runtime/orca-runtime-remove-orphan-or-folder-worktree.ts
printf '%s\n' '--- bound symbols and callers ---'
rg -n --glob '*.ts' 'parseExecutionHostId|ExecutionHostNotDispatchableError|teardownFolderWorkspacePtys|removeManagedWorktree|folderConnectionId' srcRepository: stablyai/orca
Length of output: 50369
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings
Length of output: 17127
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- execution-host parser ---'
sed -n '1,125p' src/shared/execution-host.ts
printf '%s\n' '--- dispatch error contract ---'
sed -n '55,175p' src/main/providers/execution-host-provider-dispatch.ts
printf '%s\n' '--- folder PTY teardown ---'
ast-grep outline src/main/runtime/folder-workspace-pty-teardown.ts
sed -n '1,220p' src/main/runtime/folder-workspace-pty-teardown.ts
printf '%s\n' '--- direct callers ---'
rg -n -C 12 --glob '*.ts' 'removeOrphanOrFolderWorktree' src/main
printf '%s\n' '--- removal route ---'
sed -n '1,120p' src/main/worktree-removal-execution-host-route.tsRepository: stablyai/orca
Length of output: 22083
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- managed removal control flow ---'
sed -n '1,125p' src/main/runtime/orca-runtime-remove-managed-worktree.ts
printf '%s\n' '--- route usage in managed removal ---'
rg -n -C 8 --glob '*.ts' 'resolveWorktreeRemovalRoute|getWorktreeRemovalConnectionId' src/main/runtime src/main
printf '%s\n' '--- folder-removal tests and helper tests ---'
fd -i '.*(remove.*worktree|folder.*teardown|orphan.*folder).*test.*' src/mainRepository: stablyai/orca
Length of output: 32439
Reject runtime: hosts before folder teardown.
removeManagedWorktree calls this folder branch before resolveWorktreeRemovalRoute. For a runtime host, folderConnectionId is null, so teardownFolderWorkspacePtys falls back to the local provider. It then removes the runtime workspace metadata. Throw ExecutionHostNotDispatchableError before teardown when folderHost.kind === 'runtime'.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the full PR: the removal-routing refactor, its two shared-signature downstream modules, the folder-teardown host resolution, and the new route module plus its two new test files.
- Unified removal host —
removeManagedWorktreenow resolves oneWorktreeRemovalRoute(local/ssh) from the host the metadata prune already used, so list, delete, and prune cannot disagree. - Ambiguous carrier removed —
removeRuntimeUnregisteredWorktreetakes arouteinstead ofprovider: SshGitProvider | null+fsProvider: IFilesystemProvider | null;removeRuntimeRegisteredRemoteWorktreetakes an explicitconnectionId; stale readers are now compile errors in the typed modules. - Host-keyed filesystem probe —
isRuntimeWorktreePathMissingtakeshostId: ExecutionHostIdand refusesruntime:hosts instead of statting locally. - Folder teardown routing —
removeOrphanOrFolderWorktreederives its connection from the resolved host rather than rawrepo.connectionId. - Route module + tests —
worktree-removal-execution-host-route.tsis a faithful narrowing of the shared dispatch (mirroringworkspace-cleanup-git-route/runtime-git-command-target); 7 end-to-end cases plus 6 unit cases, including the decisiveexecutionHostId-only row and the wrong-namespaceruntime:refusal.
The "refusing direction" holds: unreachable ssh: and runtime: hosts now throw instead of deleting a client-side path, the route is resolved after the orphan/folder early return, and legacy connectionId rows round-trip through toSshExecutionHostId→parseExecutionHostId unchanged. No wire or persistence change.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…host `removeManagedWorktree` resolved its host once — for the metadata prune (`cleanupHostId ?? getRepoExecutionHostId(repo)`) — and then read raw `repo.connectionId` for every step that touches the filesystem: the `git worktree list` deciding whether the path is registered, the provider handed to the unregistered-removal branch, the registered-remote-vs-local fork, and the PTY/history teardown. One function, two spellings. For a row naming its owner only as `executionHostId: 'ssh:<target>'` — the exact class #18296 names — the list ran on the client against a remote path, `removeRuntimeUnregisteredWorktree` was entered with `provider: null`, and the metadata was pruned under `ssh:<target>` while a same-named *local* directory was the one considered for deletion (#11163). #18358 made this reachable: it migrated the cleanup scan, so `executionHostId`-only rows now surface as removable candidates, but removal did not move with it. Routing is now one answer for the whole removal, taken from the host the prune already used, through #18296's host-keyed dispatch. The ambiguous `provider: SshGitProvider | null` carrier is deleted from the callees rather than supplemented, so every remaining reader is a compile error in the typed modules that do the destructive work (`runtime-unregistered-worktree-removal`, `runtime-registered-remote-worktree-removal`, `runtime-worktree-filesystem`). The orchestrator itself carries `@ts-nocheck` from its mechanical split, so that guarantee does not reach it — tests cover it instead. Every change is in the refusing direction; nothing became more aggressive: - an `ssh:` host with no registered provider throws instead of deleting a client-side path (`requireSshGitProvider` already threw for rows that spelled the same host as `connectionId`); - `runtime:<env>` throws rather than dialling a same-named target in this client's namespace, matching `workspace-cleanup-git-route` and `runtime-git-command-target`; - the folder-workspace teardown resolves its connection instead of reading the raw field, so a `runtime:` row stops dialling the wrong namespace. No wire or persistence change: `removeWorktreeMetadataAndHistory` already took the resolved host, and the removal RPC result shape is untouched.
56ae465 to
3005f30
Compare
|
Note on the red Those keys come from Everything else is green: all 8 test shards, typecheck, package, package (windows). |
…host (stablyai#18529) `removeManagedWorktree` resolved its host once — for the metadata prune (`cleanupHostId ?? getRepoExecutionHostId(repo)`) — and then read raw `repo.connectionId` for every step that touches the filesystem: the `git worktree list` deciding whether the path is registered, the provider handed to the unregistered-removal branch, the registered-remote-vs-local fork, and the PTY/history teardown. One function, two spellings. For a row naming its owner only as `executionHostId: 'ssh:<target>'` — the exact class stablyai#18296 names — the list ran on the client against a remote path, `removeRuntimeUnregisteredWorktree` was entered with `provider: null`, and the metadata was pruned under `ssh:<target>` while a same-named *local* directory was the one considered for deletion (stablyai#11163). stablyai#18358 made this reachable: it migrated the cleanup scan, so `executionHostId`-only rows now surface as removable candidates, but removal did not move with it. Routing is now one answer for the whole removal, taken from the host the prune already used, through stablyai#18296's host-keyed dispatch. The ambiguous `provider: SshGitProvider | null` carrier is deleted from the callees rather than supplemented, so every remaining reader is a compile error in the typed modules that do the destructive work (`runtime-unregistered-worktree-removal`, `runtime-registered-remote-worktree-removal`, `runtime-worktree-filesystem`). The orchestrator itself carries `@ts-nocheck` from its mechanical split, so that guarantee does not reach it — tests cover it instead. Every change is in the refusing direction; nothing became more aggressive: - an `ssh:` host with no registered provider throws instead of deleting a client-side path (`requireSshGitProvider` already threw for rows that spelled the same host as `connectionId`); - `runtime:<env>` throws rather than dialling a same-named target in this client's namespace, matching `workspace-cleanup-git-route` and `runtime-git-command-target`; - the folder-workspace teardown resolves its connection instead of reading the raw field, so a `runtime:` row stops dialling the wrong namespace. No wire or persistence change: `removeWorktreeMetadataAndHistory` already took the resolved host, and the removal RPC result shape is untouched.

The mix
removeManagedWorktreeresolved its host once — for the metadata prune, atorca-runtime-remove-managed-worktree.ts:69(cleanupHostId ?? getRepoExecutionHostId(repo)) — and then read rawrepo.connectionIdat:82,:84,:88,:148,:185,:199. One function, both spellings, which is worse than neither: half the flow fails loudly and half silently, leaving partial state.For a row naming its owner only as
executionHostId: 'ssh:<target>'(the exact class #18296 names, with noconnectionId):git worktree listran on the client, against a remote pathremoveRuntimeUnregisteredWorktreewas entered withprovider: null, so its directory branches statted and deleted heressh:<target>#18358 made this reachable. It migrated the cleanup scan, so
executionHostId-only rows now surface as removable candidates — but removal did not move with it. The scan finds them remotely and the removal acted locally.The fix
Routing is now one answer for the whole removal, taken from the host the prune already used, resolved through the existing layer (
getRepoExecutionHostId→ #18296'sresolveGitRouteForHost/resolveFilesystemRouteForHost). No new resolver:worktree-removal-execution-host-route.tsis a thin narrowing of the shared dispatch, the same shapeworkspace-cleanup-git-route.tstook in #18358.Following #18307/#18325, the ambiguous carrier is deleted rather than supplemented, so every remaining reader is a compile error:
runtime-unregistered-worktree-removalprovider: SshGitProvider | null+fsProvider: IFilesystemProvider | nullroute: WorktreeRemovalRouteruntime-registered-remote-worktree-removalconst connectionId = repo.connectionId!connectionId: stringparamruntime-worktree-filesystemisRuntimeWorktreePathMissing(repo, …)isRuntimeWorktreePathMissing(hostId, …)That guarantee is real in those three — none carries
@ts-nocheck. The orchestrator itself does (from its mechanical split fromOrcaRuntimeService), and removing it is out of reach here: 42 errors, almost allProperty 'removeWorktreeMetadataAndHistory' does not exist on typefrom the split class chain. Tests cover it instead.Nothing became more aggressive
Deleting a worktree on the wrong host is destructive, so every behavior change here is in the refusing direction:
ssh:host with no registered provider → throws.requireSshGitProvideralready threw for rows spelling the same host asconnectionId; the migrated spelling now gets the same answer instead of silently deleting a client-side path. Loss of contact is never evidence of locality (docs/reference/ssh-execution-boundary.md).runtime:<env>→ throwsExecutionHostNotDispatchableError. Its files live on that environment's own server and the SSH target on its repo row is that server's nested one, addressable only as(environmentId, targetId). Handing it to this client's SSH table wouldgit worktree removea same-named path on the wrong machine. Matchesworkspace-cleanup-git-routeandruntime-git-command-target.orca-runtime-remove-orphan-or-folder-worktree.ts) resolved its connection instead of readingrepo.connectionId?.trim(), so aruntime:row stops dialling this client's namespace.The route is resolved after the orphan/folder early return, exactly where
requireSshGitProvidersat, so no removal that previously reached that early return can now fail before it.Wire / persistence
No change.
removeWorktreeMetadataAndHistoryalready took the resolved host id, the removal RPC result shape is untouched, and nothing new is persisted or published — so nothing here reaches an old client (docs/reference/remote-wire-compatibility.mdRule 3).Tests
7 failed-first, 7 pass after (the 6 new end-to-end cases plus one rewritten incumbent), and 6 new unit cases on the route module itself (new module, so failed-first does not apply to those).
orca-runtime-tests/worktree-removal-execution-host.spec.ts:executionHostId: 'ssh:target-a'and noconnectionId, removed through the cleanup path: asserts list, existence probe and metadata prune all namessh:target-a, and thatlistWorktreesStrict/ localremoveWorktreeare never reachedssh:target-bnever touchestarget-a's providerssh:refuses with metadata intactruntime:without a nested SSH target refusesruntime:with a nested target that is dialable here refuses — the wrong-namespace caseworktree-removal-execution-host-route.test.tsadds unit coverage including two SSH hosts registered at once with distinct git and filesystem providers.Intended no-op:
worktree-removal-and-reconciliation-part-03.spec.ts'sdoes not coalesce concurrent same-id removals on different hostskept its name and property but swapped its second owner fromruntime:env-1(which asserted a localgit worktree removefor a runtime-hosted row — the bug) tossh:host-b. It now proves both non-coalescing and per-host routing.Residual, not fixed here
Selector resolution (
resolveWorktreeRemovalTarget→resolveWorktreeSelector) still lists through the raw field before removal begins. That is a read on the wrong namespace for aruntime:row — asserted and commented in the runtime test. It belongs to the selector-resolution flow, not this function, and wants its own migration.Verification
pnpm tccleanpnpm test src(whole tree)pnpm run check:code-quality:changed— 0 findingsnpx oxlint --deny-warningson all 8 changed files, exit 0, with a positive control (no-unused-varsfires) proving the rules actually ran