Repository navigation
fix(worktree): ask the execution host whose home a remote delete would take - #19865
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a single commit that re-roots the worktree-removal home guard onto the execution host whose filesystem actually gets deleted.
WorktreeRemovalHomeAuthoritythreading — a new requiredhomeargument ({ kind: 'client' }vs{ kind: 'executionHost'; homePath }) on every guard entry point, soos.homedir()is reachable only through{ kind: 'client' }and a remote removal can no longer silently consult the wrong machine's home.- Path-shape detection expansion — POSIX, Windows drive/UNC
Usersprofiles (case-insensitive, drive letter fromparse().root), and WSL UNC aliases, moved intoworktree-removal-home-guard.tsso a Windows profile is dangerous regardless of which desktop is looking. - Host home sourced from existing deploy data —
getRemoteHomeDirectory()returnsremoteCliBridgeEnv.remoteHome(already read on the host viareadRemoteHomeCommand/normalizeRemoteHome), wired through asetWorktreeRemovalSshHostHomeResolversetter matching the existingsetSshActiveMultiplexerResolverpattern; no new RPC. - Call-site and test updates — IPC and runtime removal paths threaded with
CLIENT_REMOVAL_HOMEfor local removals and the resolved host home for SSH, backed by a shape table, the real removal entry point, and module-wiring tests.
The core logic is sound: resolveGuardHomePath only lets a home answer for paths in its own syntax (so a POSIX home can't be win32.resolved against a C:\… path), the containment check correctly distinguishes "removing the home" from "removing a worktree under it", and the WSL UNC branch deliberately routes Linux-shaped paths to POSIX rules. Tests assert exact verdicts rather than truthiness and pin the previously-uncovered SSH removal branch.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — one new commit since the prior review (a0be358).
- Import dedup — merges the two
../worktree-removal-execution-host-routeimports inorca-runtime-remove-managed-worktree.tsinto a single, alphabetized{ resolveWorktreeRemovalHome, resolveWorktreeRemovalRoute }block. Purely mechanical; no behavioral change.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
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:
📝 WalkthroughWalkthroughThe change adds explicit client and execution-host home authorities for worktree removal safety. It detects protected POSIX, Windows, and WSL home paths by path syntax and reported SSH host home. SSH relay sessions expose the remote home and register a resolver. Registered, unregistered, managed, local, and SSH removal flows pass the resolved authority into safety checks. Tests cover routing, path detection, host-home protection, and valid orphan cleanup. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟠 High · up to An SSH cleanup with an unresolved custom host home can recursively delete the remote user’s home directory and unrelated files; cleanup should fail closed before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
a0be358 to
4f145f6
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — one test-only commit (4f145f6) that closes the remaining mutation-testing survivors in the home guard.
- IPC call-site pin — a new
remove-unregistered-worktree-host-home.test.tsdrives the realremoveUnregisteredWorktreeover SSH and asserts it refuses the host's own home (never callingdeletePath) while still deleting a proven orphan beneath it; mutation testing had shown that substituting the client's home at this call site passed every other suite while a remote delete could still reach the host's home. - Guard regression cases — four additions to
worktree-removal-home-guard.test.tsplus the bare/Usersrow inworktree-removal-safety.test.ts: noos.homedir()fallback when the host reports nothing (spy assertshomediris untouched), the forward-slashC:/Users/bobformnormalizeRemoteHomestores for a Windows host, a foreign-syntax host home under POSIX ops (process.cwd()), and the bare/Usersshape.
Each new assertion is an exact verdict backed by a spy where a fallback must stay off, not a truthiness check — and all four targeted suites pass. The delta introduces no behavioral surface of its own.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
98efec6 to
bb5a35e
Compare
|
Folded this work onto #18341 (same three commits, rebased onto current |
…d take
`isDangerousWorktreeRemovalPath` read `os.homedir()` — the machine running
Orca — and then applied POSIX-only shape rules. SSH orphan cleanup feeds it
remote paths, so a Windows host profile (`C:\Users\bob`) was unrecognised from
a macOS/Linux desktop and the recursive delete lost its last guard, while a
coincidental client-home prefix could refuse a legitimate remote delete.
The removal route already resolves one execution host for the whole removal;
it now resolves one home authority the same way. `WorktreeRemovalHomeAuthority`
is `{ kind: 'client' }` or `{ kind: 'executionHost'; homePath }`, required at
every guard entry point, so the ambient read is unreachable from a remote
removal. The host's answer is the `$HOME` the SSH session already read on the
host during relay deploy — no new probe. Unresolved stays `null`, meaning
unknown, never "same as this client's".
Path-shape rules now cover Windows profiles (`C:\Users`, `C:\Users\<name>`,
any drive or UNC root, case-insensitively) and WSL UNC aliases, which front a
Linux filesystem and so take the POSIX shapes.
Fixes #18275
The focused code-quality plugins deny `import/no-duplicates`.
…me refusal Mutation testing found four survivors in the home guard: - Swapping the IPC unregistered-removal call site to the client's home passed every suite while the remote delete could reach the host's own home. Only the runtime call site was pinned. Add the mirror test for the IPC path. - Falling back to os.homedir() when the execution host reported nothing was indistinguishable from refusing; the client home never coincided with the probed path. Assert the fallback stays off with homedir pinned to the path. - Comparing an execution-host home across path syntaxes survived because no row exercised the win32 home under POSIX ops: path.resolve manufactures <cwd>/C:/Users/bob, which every ancestor of the cwd contains. - Dropping the bare /Users rule survived; add the row. Also cover the forward-slash C:/Users/bob form normalizeRemoteHome reports for a Windows host, which no existing row used.
bb5a35e to
1505500
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Fail closed when the SSH host home is unresolved. · src/main/worktree-removal-home-guard.ts:56-92
56-92: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winFail closed when the SSH host home is unresolved.
homePath: nullmakes/srv/homes/alicepassisHomeDirectoryRemovalPathbecause syntax-only checks do not recognize that home shape. With the orphan and force-removal preconditions met, the SSH path callsfsProvider.deletePath(worktreePath, true), whoserecursiveargument can delete the host home.if (home.kind === 'executionHost' && home.homePath === null) { return true }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 87fc8bc2-af3d-4bbf-b0ff-4270040f49e0
📒 Files selected for processing (4)
src/main/ipc/worktrees/removal/execute-worktree-removal.tssrc/main/runtime/orca-runtime-remove-managed-worktree.tssrc/main/runtime/runtime-registered-local-worktree-removal.tssrc/main/ssh/ssh-relay-session.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Rebasing onto main brings two gates this branch predates: typescript/consistent-type-assertions at assertionStyle: never, and the 300-line ceiling that the added home lookup pushed orca-runtime-remove-managed-worktree.ts past. The fixture casts carry per-site SAFETY rationales; the route's git-options-and-listing step moves into its own module, which also stops the local/SSH branch being spelled twice in one expression.
main enabled anti-slop/no-shape-in-symbol-names (#20785) after this branch was written. The predicate answers whether a path IS a home root, not whether it resembles one.
Review of the home guard found three ways it still let a delete proceed on evidence about the wrong machine, or on no evidence at all. `getPathOps` switches to win32 as soon as EITHER the worktree path or the repo path looks Windows-absolute, and `//nas/share/repo` does. A POSIX worktree path was then judged by Windows-only shape rules, which recognise `<root>\Users\<name>` and nothing else, so `/home/alice` — and any client home outside `\Users` — stopped matching and the last guard in front of a recursive delete went quiet. The home question involves the worktree path and a home, never the repo path, so the predicate now reads the path in its own syntax as well and refuses if either reading names a home. A union of refusals can only ever refuse more. An execution host that never reported its `$HOME` is `unverifiable`, and `unverifiable` does not authorise a delete. `isRemovalHomeAuthorityResolved` gates the two paths that recursively delete a directory — `canSafelyRemoveOrphanedWorktreeDirectory` and `canCleanupUnregisteredOrcaLeftoverDirectory` — because the orphan proof they accept, a `.git` file at the top of a directory, is also what a bare-repo dotfiles `$HOME` looks like, and there the guard is the only evidence there is. `git worktree remove` is deliberately not gated: the host's own Git registry already established that the path is a linked worktree of that repo, and a missing second opinion does not retract a first one. An empty `$HOME` is normalised to unanswered rather than read as a resolved home. The IPC entry point spelled its host two ways. The metadata prune, the archive-hook route and now the home authority came from `getRepoExecutionHostId(repo)`, while the `git worktree list` and every delete came from raw `repo.connectionId`. A row carrying only `executionHostId: 'ssh:<target>'` therefore listed a remote checkout on this client and deleted a same-named local path while the guards vouched for the remote one; the mirror row did the reverse (#11163, previously fixed on the runtime path only). Neither spelling is evidence about the other, so a row that carries two host names is refused before anything is listed or deleted. Both sides are spelled by `getRepoExecutionHostId`, so they can differ on content but never on normalisation. A `runtime:<env>` row refuses here for the same reason. It is not reachable through this handler today — the renderer sends environment targets to `worktree.rm`, and the host-qualified catalog refuses to list a runtime host — so that arm closes a door rather than changing a flow. Fixtures that register an SSH provider now report a host home, because a connected relay session always has one: `remoteCliBridgeEnv` is assigned before `registerSshGitProvider`, is never cleared, and providers are unregistered before the session leaves `activeSessions`. The wiring lives in its own module called from the harness rather than in `worktrees-test-module-mocks`, which `vi.mock` factories import: reaching the production route module from there pulls in `providers/ssh-git-dispatch` while it is being mocked, and the module runner deadlocks.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — one commit since the prior Pullfrog review (097ccec), 6a6727c "refuse a removal the execution host cannot vouch for", with the tests that pin it.
- Recursive deletes now fail closed —
canSafelyRemoveOrphanedWorktreeDirectoryandcanCleanupUnregisteredOrcaLeftoverDirectoryreturnfalseunlessisRemovalHomeAuthorityResolved(home), so an SSH host that never reported$HOMEleaves a proven-orphan directory in place rather than recursively deleting it;executionHostRemovalHome('')normalises an empty answer to unknown. This is exactly the failuregit worktree removedeliberately does not adopt, and the JSDoc explains why. - Home route keyed on the execution host id —
resolveWorktreeRemovalHomeForHost(hostId)replaces theconnectionId-keyed resolver, parsing theExecutionHostIdso anssh:<target>-only row asks the right host, whileruntime:and unparseable ids stay unknown instead of borrowing this client's home. - Repo-row host disambiguation (#11163) —
assertRemovalHostMatchesRepoRowrefuses a repo whoseexecutionHostIdandconnectionIdname different machines before any listing or delete, closing the "listed remote, deleted local" path. - Mixed-syntax path ops —
isHomeDirectoryRemovalPathre-reads the worktree path under its own syntax when the worktree/repo pair draggedgetPathOpsinto the other platform, so a POSIX home stays recognised when the repo path is//-rooted or Windows-shaped. The check is additive (OR), so it only widens protection. - Test coverage — new handler/disambiguation suite, unknown-host-home refusal at both the IPC and runtime entry points,
isRemovalHomeAuthorityResolved/empty-home cases, the mixed-syntax pair table, and a shared harness fixture that makes IPC SSH suites model a connected session's$HOME.
I verified the fail-closed gate is unreachable for a live session — remoteCliBridgeEnv is only assigned when remoteHome is truthy, validateRemoteHome throws on an invalid home, and a removal needs a registered provider — so the unverifiable refusal is a backstop, not a regression. I also confirmed the new repo-row assert cannot fire on a normal SSH row: target ids are ssh-<timestamp>-<base36> (no encode/decode variance) and renderer stamping uses toSshExecutionHostId(connectionId).
ℹ️ The PR now ships a separate #11163 fix under a #18275 description
The latest commit folds assertRemovalHostMatchesRepoRow into a PR whose description advertises only #18275. Both changes are sound and tested, but the disambiguation adds a new hard-refusal path with a blast radius independent of the home guard, and #11163 is not mentioned in the body. Worth a line in the description (and the changelog) so reviewers can treat the two as separately revertible.
Technical details
# The #11163 refusal is its own change
## Affected sites
- `src/main/ipc/worktrees/removal/execute-worktree-removal.ts:47-63` — `assertRemovalHostMatchesRepoRow` throws when `removalHostId !== getRepoExecutionHostId({ connectionId: repo.connectionId, executionHostId: null })`.
- PR body — "Fixes #18275"; no mention of #11163 or the new refusal.
## Required outcome
- No code change required if the bundling is intentional. The ask is a description/changelog line naming #11163 and the fact that a contradictorily-spelled repo row is now refused (worktree left in place) rather than deleted.
## Open questions for the human
- Is a `runtime:<env>` row with a nested SSH `connectionId` reachable through the desktop `worktrees:remove` IPC at all? If so, the new assert refuses it (runtime spelling vs `ssh:` connection id) — safe, but a distinct behaviour change from the #18275 guard. Runtime removals appear to route through `removeManagedWorktree`, so this is likely theoretical.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ed text `getRepoExecutionHostId` returns a row's `executionHostId` as stored, while the same row's `connectionId` is re-spelled through `toSshExecutionHostId`, which percent-encodes. A byte compare of the two would refuse a perfectly consistent row over a `%20`, so the two host ids are now compared after `parseExecutionHostId` has decoded the target id out of each. `runtime:<env>` and an unparseable id decode to no machine at all and match nothing, including each other — a runtime-owned row has a null `connectionId` and would otherwise read as local, which is a delete on this client.
There was a problem hiding this comment.
ℹ️ No critical issues — one comment-accuracy nit inline.
Reviewed changes — one commit since the prior Pullfrog review (6a6727c548): 865083bd63 "compare removal host names after decoding, not as stored text".
- Decoded host comparison —
assertRemovalHostMatchesRepoRownow comparesremovalHostName(hostId)(the parsedlocal/ssh:<targetId>) instead of the stored text, so a repo row whoseexecutionHostIdand re-encodedconnectionIddiffer only by a percent-escape is accepted rather than refused. This is the right direction: the two spellings name the same target id, and the route/provider lookups already key on it. - New handler tests — a
runtime:<env>row with a nullconnectionIdis refused before any listing or delete, and a%20-escaped-but-consistent SSH row is driven through the realworktrees:removehandler; the previous byte-compare would have refused the latter.
The comparison change is narrow and correct — target ids are what the route and guards actually key on, so normalising the escape spelling only removes a false refusal.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The type-aware audit rejects a `default` arm on a discriminated switch, so the host-kind switch names `runtime` and `undefined` outright — which also makes a host kind added later a compile error here rather than a silent fallthrough. The two test casts the changed-code gate flagged are gone: the leftover-cleanup meta is typed instead of asserted, and the unparseable-host-id case narrows to `ExecutionHostId` with the SAFETY rationale the gate asks for.
…ain compare The comparison refuses `runtime:<env>` because only the left operand can name no machine — `repoRowHostId` comes from `connectionId` and is always `local` or an `ssh:` id. That invariant was doing the work silently; an explicit null test in its place was a branch no input can reach, so the reason is written down instead.
I argued `git worktree remove --force` did not need the host's home answer, because the host's own Git registry had already established that the path is a linked worktree of that repo. That is true and it is not enough: `git worktree add` accepts a pre-existing empty directory, and that directory can afterwards be somebody's `$HOME` — a build account's home, a container's `HOME=/workspace`. Being a linked worktree proves provenance, not that the path is not a home, and the remove deletes the checkout either way. With the host's answer that case is already caught by containment. Without it only the path shapes remain, and a home at a non-standard location (`/var/home/<u>`, `/export/home/<u>`, `D:\\Profiles\\<u>`) has no shape to match. So `findRegisteredDeletableWorktree` now requires the answer as well, and every gate that authorises a delete is on the same rule. The fixture that models a connected relay session moves out of `ipc/` and is shared: four runtime specs register an SSH provider without one, and a live provider implies a reported home in production.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — one commit since the prior Pullfrog review (94a80e1d94): 13a306974f "gate the registered removal on the host home answer too".
- Registered removals now fail closed on an unknown host home —
findRegisteredDeletableWorktreerefuses unlessisRemovalHomeAuthorityResolved(home), sogit worktree removeno longer leans on the host's Git registry as proof that a path is not a$HOME. Every delete-authorising gate inworktree-removal-safety.tsis now on the same rule, and the JSDoc onisRemovalHomeAuthorityResolvedwas rewritten to say why the registry does not help (a linked worktree of a repo can afterwards be a build account's home or aHOME=/workspace). - SSH-home fixture moved and shared —
ipc/worktrees-test-ssh-host-home.tsrelocated tosrc/main/worktree-removal-test-ssh-host-home.tsand installed viabeforeEachin the four runtime specs that register an SSH provider but supplied no home answer;ipc/worktrees-test-harness.tsfollows the new path. - Test for the new gate — a
findRegisteredDeletableWorktreecase asserting the unanswered-home and matching-home refusals plus a non-matching-home delete, with exact-verdict assertions (not truthiness).
I checked the one thing that could make this a regression rather than a backstop: an SSH removal resolves its route only when a git provider is registered, and that provider is installed after establish() has read remoteHome into remoteCliBridgeEnv (validateRemoteHome throws otherwise) — so an unanswered home cannot co-exist with a usable SSH route. Local call sites pass CLIENT_REMOVAL_HOME. Focused suites pass: worktree-removal-*, the worktree IPC removal suites, and the full src/main/ipc run (3965 tests). The .spec.ts runtime specs are not collected by config/vitest.config.ts, so I also confirmed the fixture change is the only reason those four needed updating.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…d take (stablyai#19865) * fix(worktree): ask the execution host whose home a remote delete would take `isDangerousWorktreeRemovalPath` read `os.homedir()` — the machine running Orca — and then applied POSIX-only shape rules. SSH orphan cleanup feeds it remote paths, so a Windows host profile (`C:\Users\bob`) was unrecognised from a macOS/Linux desktop and the recursive delete lost its last guard, while a coincidental client-home prefix could refuse a legitimate remote delete. The removal route already resolves one execution host for the whole removal; it now resolves one home authority the same way. `WorktreeRemovalHomeAuthority` is `{ kind: 'client' }` or `{ kind: 'executionHost'; homePath }`, required at every guard entry point, so the ambient read is unreachable from a remote removal. The host's answer is the `$HOME` the SSH session already read on the host during relay deploy — no new probe. Unresolved stays `null`, meaning unknown, never "same as this client's". Path-shape rules now cover Windows profiles (`C:\Users`, `C:\Users\<name>`, any drive or UNC root, case-insensitively) and WSL UNC aliases, which front a Linux filesystem and so take the POSIX shapes. Fixes stablyai#18275 * fix(worktree): merge the duplicated removal-route import The focused code-quality plugins deny `import/no-duplicates`. * test(worktree): pin the IPC removal call site and the unknown-host-home refusal Mutation testing found four survivors in the home guard: - Swapping the IPC unregistered-removal call site to the client's home passed every suite while the remote delete could reach the host's own home. Only the runtime call site was pinned. Add the mirror test for the IPC path. - Falling back to os.homedir() when the execution host reported nothing was indistinguishable from refusing; the client home never coincided with the probed path. Assert the fallback stays off with homedir pinned to the path. - Comparing an execution-host home across path syntaxes survived because no row exercised the win32 home under POSIX ops: path.resolve manufactures <cwd>/C:/Users/bob, which every ancestor of the cwd contains. - Dropping the bare /Users rule survived; add the row. Also cover the forward-slash C:/Users/bob form normalizeRemoteHome reports for a Windows host, which no existing row used. * ci: re-run after an unrelated Electron probe startup timeout * fix(lint): clear the casting and max-lines gates on the home guard Rebasing onto main brings two gates this branch predates: typescript/consistent-type-assertions at assertionStyle: never, and the 300-line ceiling that the added home lookup pushed orca-runtime-remove-managed-worktree.ts past. The fixture casts carry per-site SAFETY rationales; the route's git-options-and-listing step moves into its own module, which also stops the local/SSH branch being spelled twice in one expression. * fix(lint): name the home predicate for what it matches main enabled anti-slop/no-shape-in-symbol-names (stablyai#20785) after this branch was written. The predicate answers whether a path IS a home root, not whether it resembles one. * fix(worktree): refuse a removal the execution host cannot vouch for Review of the home guard found three ways it still let a delete proceed on evidence about the wrong machine, or on no evidence at all. `getPathOps` switches to win32 as soon as EITHER the worktree path or the repo path looks Windows-absolute, and `//nas/share/repo` does. A POSIX worktree path was then judged by Windows-only shape rules, which recognise `<root>\Users\<name>` and nothing else, so `/home/alice` — and any client home outside `\Users` — stopped matching and the last guard in front of a recursive delete went quiet. The home question involves the worktree path and a home, never the repo path, so the predicate now reads the path in its own syntax as well and refuses if either reading names a home. A union of refusals can only ever refuse more. An execution host that never reported its `$HOME` is `unverifiable`, and `unverifiable` does not authorise a delete. `isRemovalHomeAuthorityResolved` gates the two paths that recursively delete a directory — `canSafelyRemoveOrphanedWorktreeDirectory` and `canCleanupUnregisteredOrcaLeftoverDirectory` — because the orphan proof they accept, a `.git` file at the top of a directory, is also what a bare-repo dotfiles `$HOME` looks like, and there the guard is the only evidence there is. `git worktree remove` is deliberately not gated: the host's own Git registry already established that the path is a linked worktree of that repo, and a missing second opinion does not retract a first one. An empty `$HOME` is normalised to unanswered rather than read as a resolved home. The IPC entry point spelled its host two ways. The metadata prune, the archive-hook route and now the home authority came from `getRepoExecutionHostId(repo)`, while the `git worktree list` and every delete came from raw `repo.connectionId`. A row carrying only `executionHostId: 'ssh:<target>'` therefore listed a remote checkout on this client and deleted a same-named local path while the guards vouched for the remote one; the mirror row did the reverse (stablyai#11163, previously fixed on the runtime path only). Neither spelling is evidence about the other, so a row that carries two host names is refused before anything is listed or deleted. Both sides are spelled by `getRepoExecutionHostId`, so they can differ on content but never on normalisation. A `runtime:<env>` row refuses here for the same reason. It is not reachable through this handler today — the renderer sends environment targets to `worktree.rm`, and the host-qualified catalog refuses to list a runtime host — so that arm closes a door rather than changing a flow. Fixtures that register an SSH provider now report a host home, because a connected relay session always has one: `remoteCliBridgeEnv` is assigned before `registerSshGitProvider`, is never cleared, and providers are unregistered before the session leaves `activeSessions`. The wiring lives in its own module called from the harness rather than in `worktrees-test-module-mocks`, which `vi.mock` factories import: reaching the production route module from there pulls in `providers/ssh-git-dispatch` while it is being mocked, and the module runner deadlocks. * fix(worktree): compare removal host names after decoding, not as stored text `getRepoExecutionHostId` returns a row's `executionHostId` as stored, while the same row's `connectionId` is re-spelled through `toSshExecutionHostId`, which percent-encodes. A byte compare of the two would refuse a perfectly consistent row over a `%20`, so the two host ids are now compared after `parseExecutionHostId` has decoded the target id out of each. `runtime:<env>` and an unparseable id decode to no machine at all and match nothing, including each other — a runtime-owned row has a null `connectionId` and would otherwise read as local, which is a delete on this client. * fix(lint): clear the static-analysis gates on the removal home authority The type-aware audit rejects a `default` arm on a discriminated switch, so the host-kind switch names `runtime` and `undefined` outright — which also makes a host kind added later a compile error here rather than a silent fallthrough. The two test casts the changed-code gate flagged are gone: the leftover-cleanup meta is typed instead of asserted, and the unparseable-host-id case narrows to `ExecutionHostId` with the SAFETY rationale the gate asks for. * docs(worktree): say why an unroutable removal host is refused by a plain compare The comparison refuses `runtime:<env>` because only the left operand can name no machine — `repoRowHostId` comes from `connectionId` and is always `local` or an `ssh:` id. That invariant was doing the work silently; an explicit null test in its place was a branch no input can reach, so the reason is written down instead. * fix(worktree): gate the registered removal on the host home answer too I argued `git worktree remove --force` did not need the host's home answer, because the host's own Git registry had already established that the path is a linked worktree of that repo. That is true and it is not enough: `git worktree add` accepts a pre-existing empty directory, and that directory can afterwards be somebody's `$HOME` — a build account's home, a container's `HOME=/workspace`. Being a linked worktree proves provenance, not that the path is not a home, and the remove deletes the checkout either way. With the host's answer that case is already caught by containment. Without it only the path shapes remain, and a home at a non-standard location (`/var/home/<u>`, `/export/home/<u>`, `D:\\Profiles\\<u>`) has no shape to match. So `findRegisteredDeletableWorktree` now requires the answer as well, and every gate that authorises a delete is on the same rule. The fixture that models a connected relay session moves out of `ipc/` and is shared: four runtime specs register an SSH provider without one, and a live provider implies a reported home in production.

Fixes #18275
ELI5
Before Orca recursively deletes a leftover worktree folder, it checks "wait, is
that somebody's home directory?" The check asked this computer — the one
running the Orca window — even when the folder lives on a remote SSH machine.
Two ways that goes wrong:
C:\Users\bobmatched none of thePOSIX rules (
/home/x,/Users/x), and your Mac home/Users/nwparkerhasnothing to say about it. The guard answered "safe to delete" for the host's
entire home directory.
/srv/homes/alice). Nothingprotected it, because only your home was ever consulted.
Now the guard is told whose home it is allowed to think about, and it can't
guess wrong because the type won't let you leave it out.
What changed
The removal route already resolves one execution host for the whole removal.
It now resolves one home authority the same way:
It is a required argument on every guard entry point
(
isDangerousWorktreeRemovalPath,canSafelyRemoveOrphanedWorktreeDirectory,findRegisteredDeletableWorktree,canCleanupUnregisteredOrcaLeftoverDirectory),so a remote removal cannot silently fall through to
os.homedir()— that readis reachable only via
{ kind: 'client' }, and only for paths written in thisplatform's syntax.
The host's answer is the
$HOMEthe SSH session already read on the hostduring relay deploy (
readRemoteHomeCommand→normalizeRemoteHome). No newprobe, no new RPC.
nullmeans unknown, never "same as this client's".Path-shape rules — which travel, because a Windows profile is a Windows profile
no matter which desktop is looking — now also cover:
C:\Users,C:\Users\<name>, any drive or UNC root, case-insensitively(drive letter comes from
parse().root, not a hardcodedC:)/Usersalongside the existing/home,/root,/home/<x>,/Users/<x>\\wsl.localhost\Ubuntu\home\alice), which front a Linuxfilesystem and so take the POSIX shapes rather than
<root>\UsersA linked worktree under a home (
/home/alice/wt/foo,C:\Users\bob\wt\foo)stays deletable — that direction is a regression too, and it is tested.
Repro
On this macOS client, against
origin/main@ 2bf298d:runtime-unregistered-worktree-removal.tsfeeds exactly these remote paths intothat guard on the SSH branch and then calls
fsProvider.deletePath(path, true).Tests
worktree-removal-home-guard.test.ts— the shape table (POSIX, Windows, WSLUNC) plus "whose home": the client home is not consulted for a foreign-syntax
path (asserted with a spy), is still consulted for a matching one, and a
host-reported non-standard home is honoured.
worktree-removal-safety.test.ts— the issue's table through the publicguard, and
canSafelyRemoveOrphanedWorktreeDirectoryrefusing the host's homewith a fully proven orphan
.git, i.e. in the state that otherwiseunlocks the recursive delete.
runtime-unregistered-worktree-removal-host-home.test.ts— the real removalentry point refuses the host home and never calls
deletePath, while stilldeleting a proven orphan beneath it.
ssh-active-relay-sessions.test.ts— pins the module-scope wiring, so theroute cannot quietly answer
homePath: nullforever.Mutation results (9/9 killed)
isDangerousWorktreeRemovalPathrefuses the Windows host's home directory from a POSIX clientand… even when the host reported nothingC:\Users…rowsos.homedir()answer for every syntax againnever lets the client homedir answer for a foreign-syntax pathprotects a non-standard home the execution host reported+ 2keeps a linked worktree under the execution host home deletable+ 2takes the home from the SSH host that will run the delete+ 2is wired into worktree removal, so an SSH delete asks the hostrefuses to recursively delete the host's own home directoryThe last one survived the first pass — nothing pinned the call site — which
is why
runtime-unregistered-worktree-removal-host-home.test.tsexists.Second mutation pass (review)
A second pass with different mutations found four more survivors, now killed:
remove-unregistered-worktree.tsuses the client home instead ofrepo.connectionIdipc/worktrees/removal/remove-unregistered-worktree-host-home.test.tsexecutionHostwithhomePath: nullfalls back toos.homedir()homedir()to the probed path, so the fallback and the refusal were indistinguishablenever lets an unknown execution-host home fall back to the client homedirpath.resolvemanufactures<cwd>/C:/Users/bob, which every ancestor of the cwd "contains"ignores an execution-host home written in the other platform s syntax/Usersrule/Usersrow at theisDangerousWorktreeRemovalPathlevel/Users under /opt/src -> dangerous=trueAlso added: the forward-slash
C:/Users/bobformnormalizeRemoteHomeactuallyreports for a Windows host (no existing row used it;
getPathOpsclassifies itas win32 and
win32.resolvenormalises it, so it already worked).Note
ipc/ssh-active-relay-sessions.tsis injected into the route module via asetter rather than imported by it, matching the existing
setSshActiveMultiplexerResolverpattern: importing the session table directlyruns its module-scope registration inside the ~30 suites that partially mock the
SSH registry, which fails them all.
Gates
pnpm tc,pnpm test src/main/runtime src/main/ipc …(11 395 passed),oxlint,pnpm run check:code-quality:changed,pnpm run check:max-lines-ratchet,pnpm format.Rebase record (2026-09-11)
Rebased onto
mainat5fa62feda7c264c6eda99ba4788ffebab9aae26c. No conflicts.98efec6118d5caf4733a54b2d79843c7df579fcfbb5a35e0f433cee25f1eae027fe177868bf6d8df#20051 stacks on this branch and was replayed onto the new head.
Rebased onto
main@231e805b1e1e49c765e96b9409f88e09d117346a(2026-09-15).bb5a35e0f433cee25f1eae027fe177868bf6d8df097ccecde0e3ecdadd06fbde2e8d0bc41fc5ba66Conflict in
src/main/ipc/worktrees/removal/execute-worktree-removal.tsresolved by takingmain's renamedremoveStaleLocalWorktreeRegistrationplus this PR'sresolveWorktreeRemovalHomeForConnectionimport. Two added commits satisfy gatesmainhas tightened since: the casting gate, and the 300-line ceiling that the added home lookup pushedorca-runtime-remove-managed-worktree.tspast (the route's git-options-and-listing step is now its own module). Verified withgit range-diff; prior CI results predate this rebase.