Skip to content

fix(worktrees): route managed worktree removal by resolved execution host - #18529

Merged
nwparker merged 1 commit into
mainfrom
fix/worktree-removal-execution-host-route
Sep 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/worktree-removal-execution-host-route

Conversation

@nwparker

@nwparker nwparker commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​363 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​345
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110

The mix

removeManagedWorktree resolved its host once — for the metadata prune, at orca-runtime-remove-managed-worktree.ts:69 (cleanupHostId ?? getRepoExecutionHostId(repo)) — and then read raw repo.connectionId at :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 no connectionId):

  • git worktree list ran on the client, against a remote path
  • removeRuntimeUnregisteredWorktree was entered with provider: null, so its directory branches statted and deleted here
  • the metadata was pruned under ssh:<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's resolveGitRouteForHost / resolveFilesystemRouteForHost). No new resolver: worktree-removal-execution-host-route.ts is a thin narrowing of the shared dispatch, the same shape workspace-cleanup-git-route.ts took in #18358.

Following #18307/#18325, the ambiguous carrier is deleted rather than supplemented, so every remaining reader is a compile error:

module before after
runtime-unregistered-worktree-removal provider: SshGitProvider | null + fsProvider: IFilesystemProvider | null route: WorktreeRemovalRoute
runtime-registered-remote-worktree-removal const connectionId = repo.connectionId! connectionId: string param
runtime-worktree-filesystem isRuntimeWorktreePathMissing(repo, …) isRuntimeWorktreePathMissing(hostId, …)

That guarantee is real in those three — none carries @ts-nocheck. The orchestrator itself does (from its mechanical split from OrcaRuntimeService), and removing it is out of reach here: 42 errors, almost all Property 'removeWorktreeMetadataAndHistory' does not exist on type from 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. requireSshGitProvider already threw for rows spelling the same host as connectionId; 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> → throws ExecutionHostNotDispatchableError. 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 would git worktree remove a same-named path on the wrong machine. Matches workspace-cleanup-git-route and runtime-git-command-target.
  • folder-workspace teardown (orca-runtime-remove-orphan-or-folder-worktree.ts) resolved its connection instead of reading repo.connectionId?.trim(), so a runtime: row stops dialling this client's namespace.

The route is resolved after the orphan/folder early return, exactly where requireSshGitProvider sat, so no removal that previously reached that early return can now fail before it.

Wire / persistence

No change. removeWorktreeMetadataAndHistory already 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.md Rule 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:

  • the decisive case — a repo row carrying only executionHostId: 'ssh:target-a' and no connectionId, removed through the cleanup path: asserts list, existence probe and metadata prune all name ssh:target-a, and that listWorktreesStrict / local removeWorktree are never reached
  • the same row on the registered path
  • two distinct SSH hosts registered simultaneously — removal on ssh:target-b never touches target-a's provider
  • unreachable ssh: refuses with metadata intact
  • runtime: without a nested SSH target refuses
  • runtime: with a nested target that is dialable here refuses — the wrong-namespace case

worktree-removal-execution-host-route.test.ts adds 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's does not coalesce concurrent same-id removals on different hosts kept its name and property but swapped its second owner from runtime:env-1 (which asserted a local git worktree remove for a runtime-hosted row — the bug) to ssh: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 a runtime: 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 tc clean
  • pnpm test src (whole tree)
  • pnpm run check:code-quality:changed — 0 findings
  • npx oxlint --deny-warnings on all 8 changed files, exit 0, with a positive control (no-unused-vars fires) proving the rules actually ran
  • max-lines and ts-nocheck ratchets both OK, no new suppressions

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Worktree 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 3005f

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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… Rewrite the description using every required template heading. Add a valid issue reference after Fixes #, add an ELI5 summary, separate What Changed and Why sections, add a Visual Proof section with N/A and a reason if applicable, docum…
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: routing managed worktree removal by the resolved execution host.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description 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 Fixes #, add an ELI5 summary, separate What Changed and Why sections, add a Visual Proof section with N/A and a reason if applicable, document testing platforms and check the applicable testing items, complete AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 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.ts
  • src/main/runtime/orca-runtime-remove-orphan-or-folder-worktree.ts
  • src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-removal-execution-host.spec.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/runtime-registered-remote-worktree-removal.ts
  • src/main/runtime/runtime-unregistered-worktree-removal.ts
  • src/main/runtime/runtime-worktree-filesystem.ts
  • src/main/worktree-removal-execution-host-route.test.ts
  • src/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.

Comment on lines +97 to +98
const folderHost = parseExecutionHostId(removalHostId)
const folderConnectionId = folderHost?.kind === 'ssh' ? folderHost.targetId : null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 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' src

Repository: 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.ts

Repository: 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/main

Repository: 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'.

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

✅ 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 — removeManagedWorktree now resolves one WorktreeRemovalRoute (local / ssh) from the host the metadata prune already used, so list, delete, and prune cannot disagree.
  • Ambiguous carrier removed — removeRuntimeUnregisteredWorktree takes a route instead of provider: SshGitProvider | null + fsProvider: IFilesystemProvider | null; removeRuntimeRegisteredRemoteWorktree takes an explicit connectionId; stale readers are now compile errors in the typed modules.
  • Host-keyed filesystem probe — isRuntimeWorktreePathMissing takes hostId: ExecutionHostId and refuses runtime: hosts instead of statting locally.
  • Folder teardown routing — removeOrphanOrFolderWorktree derives its connection from the resolved host rather than raw repo.connectionId.
  • Route module + tests — worktree-removal-execution-host-route.ts is a faithful narrowing of the shared dispatch (mirroring workspace-cleanup-git-route/runtime-git-command-target); 7 end-to-end cases plus 6 unit cases, including the decisive executionHostId-only row and the wrong-namespace runtime: 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.

Pullfrog  | View workflow run | Using 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.
@nwparker
nwparker force-pushed the fix/worktree-removal-execution-host-route branch from 56ae465 to 3005f30 Compare September 3, 2026 22:36
@nwparker

nwparker commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Note on the red static analysis check — it is pre-existing drift on main, not from this PR.

src/renderer/src/i18n/en-runtime-required.json no longer covers en.json.
  components.onboarding.integrations.capabilities.browseIssues
  components.onboarding.integrations.capabilities.managePullRequests
  components.onboarding.integrations.capabilities.reviewStatus
  components.onboarding.integrations.capabilities.startWorkspaceFromIssue

Those keys come from c79e1c097b7 fix(i18n): localize remaining onboarding UI, which landed on main without regenerating the runtime-required catalog. Reproduced locally on a tree whose src/renderer/src/i18n/** is byte-identical to main — this branch touches no i18n file. It needs pnpm run sync:localization-runtime-catalog on main; deliberately not done here so the fix is not buried in an unrelated PR. verify is red only because it gates on static analysis.

Everything else is green: all 8 test shards, typecheck, package, package (windows).

@nwparker
nwparker merged commit 3c91404 into main Sep 3, 2026
26 of 28 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant