Skip to content

fix(worktree): recognise the Windows profile through WSL's drvfs view - #20051

Merged
nwparker merged 2 commits into
mainfrom
nwparker/worktree-home-guard-path-authority
Sep 21, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/worktree-home-guard-path-authority

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

Note

Rebased onto main 2026-09-18, and cut from two commits to one.

This was stacked on #19865, which has since squash-merged. The first of its two
commits — "let the worktree path alone decide whose home it is" — landed
inside that squash
, solved a different way: isHomeDirectoryRemovalPath now
re-reads the worktree path under its own path ops and refuses if either
reading names a home. Measured on main: all five of that commit's assertions
already pass, so it is dropped rather than re-applied. Only the second commit
remains.

old head a43dc36b187 (4 files, +70/−10)
new head 2ca2b008fcd (2 files, +29/−2)

The defect

/mnt/<letter> under a WSL UNC alias is the distro's drvfs mount of a Windows
volume
, so \\wsl.localhost\Ubuntu\mnt\c\Users\bob is C:\Users\bob wearing a
Linux spelling.

The guard's Windows-profile rule excludes every WSL UNC path by design — those
aliases normally front a Linux filesystem — and the POSIX home shapes never match
a /mnt/... tail. So that path falls through both rules and reads back as an
ordinary deletable directory, in front of a recursive delete.

Still reproducible on main at 7063c2cbdd3:

isDangerousWorktreeRemovalPath('\\wsl.localhost\Ubuntu\mnt\c\Users\bob', ...) -> false
isDangerousWorktreeRemovalPath('\\wsl$\Ubuntu\mnt\c\Users', ...)             -> false

The spelling is producible by the product, not hypothetical:
resolveWslRepoWorktreeBasePath maps a /mnt/c/... worktree base against a WSL
repo into exactly this UNC form, and getWslFilesystemBoundaryDistro already
treats it as the drvfs crossing.

The fix

A drvfs tail now takes the Windows profile rule on its drive form, via the
existing toWindowsWslDrivePath. Scoped to the UNC branch, where
parseWslUncPath has already proven the path is a WSL alias — a plain Linux
host's /mnt/c/... is untouched.

The lowercase-only /mnt match is deliberate: /MNT is an ordinary
case-sensitive Linux directory, never the automount.

Why this shape and not the alternatives

Widening the POSIX home shapes to include /mnt/<letter>/Users/<name> was the
other option. It is wrong in both directions: it would fire on a plain Linux box
where /mnt/c/Users/bob is just a directory somebody made, and it would still
miss every other Windows-profile shape the drive form already handles
(\\server\share\Users\bob, non-C: volumes). Translating to the drive form and
reusing the one Windows rule keeps a single answer to "is this a Windows
profile".

Verification

  • worktree-removal-home-guard + worktree-removal-safety — 81 passed on the
    rebased tree.
  • Typecheck config/tsconfig.node.json — clean.
  • pnpm run check:code-quality:changed — passed, 0 findings.
  • Teeth proven by reverting the production hunk against the new test rows: the
    two -> true rows fail by name, the two -> false rows (/MNT, and a real
    worktree under the profile) stay green.

@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

  • Home guard re-derives ops from worktreePath alone — isHomeDirectoryRemovalPath now takes (worktreePath, home) and computes getPathOps(worktreePath) internally, so a POSIX worktree path paired with a WSL UNC repo spelling no longer falls under win32 ops and silences every POSIX home shape.
  • drvfs Windows-profile recognition — isLikelyWslDistroHomeDirectory routes a /mnt/<letter> tail through toWindowsWslDrivePath and applies the Windows Users rule, protecting \\wsl.localhost\Ubuntu\mnt\c\Users\bob while leaving /MNT and nested subdirectories deletable.
  • Tests now exercise the real entry point — the guard's unit helper calls isHomeDirectoryRemovalPath directly (dropping the single-arg paraphrase), and four mutation-proven mixed-pair rows plus a drvfs table and a "linked WSL worktree stays deletable" case were added.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the fix/remote-worktree-home-delete-guard branch from 98efec6 to bb5a35e Compare September 11, 2026 08:18
@nwparker
nwparker force-pushed the nwparker/worktree-home-guard-path-authority branch from 0ec10eb to a43dc36 Compare September 11, 2026 08:25
@nwparker
nwparker force-pushed the fix/remote-worktree-home-delete-guard branch from bb5a35e to 1505500 Compare September 15, 2026 09:33
@nwparker
nwparker deleted the branch main September 17, 2026 05:24
@nwparker nwparker closed this Sep 17, 2026
@nwparker nwparker reopened this Sep 17, 2026
@nwparker
nwparker changed the base branch from fix/remote-worktree-home-delete-guard to main September 17, 2026 05:25
@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e01edb06-71d1-4802-b09f-d5e01d3a70fb

📥 Commits

Reviewing files that changed from the base of the PR and between 0e3b71f and a43dc36.

📒 Files selected for processing (17)
  • src/main/ipc/ssh-active-relay-sessions.test.ts
  • src/main/ipc/ssh-active-relay-sessions.ts
  • src/main/ipc/worktrees/removal/execute-worktree-removal.ts
  • src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts
  • src/main/ipc/worktrees/removal/remove-unregistered-worktree-host-home.test.ts
  • src/main/ipc/worktrees/removal/remove-unregistered-worktree.ts
  • src/main/runtime/orca-runtime-remove-managed-worktree.ts
  • src/main/runtime/runtime-registered-local-worktree-removal.ts
  • src/main/runtime/runtime-unregistered-worktree-removal-host-home.test.ts
  • src/main/runtime/runtime-unregistered-worktree-removal.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/worktree-removal-execution-host-route.test.ts
  • src/main/worktree-removal-execution-host-route.ts
  • src/main/worktree-removal-home-guard.test.ts
  • src/main/worktree-removal-home-guard.ts
  • src/main/worktree-removal-safety.test.ts
  • src/main/worktree-removal-safety.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds explicit client and execution-host home authorities for worktree removal. It adds POSIX, Windows, and WSL path checks and updates removal safety APIs to receive the authority. SSH routes resolve the remote home from active relay sessions. Registered, unregistered, managed, and local removal flows pass the resolved authority into safety checks and cleanup. New tests cover route resolution, path semantics, host-home rejection, and orphan child removal.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to a43dc

Worktree deletion safety checks now compare paths against the home directory of the machine that will actually perform the delete, including remote SSH hosts and Windows profiles reached through WSL. Behavior for existing local deletions is unchanged, protections are strengthened for remote removals, and new tests cover the mixed path formats, so no merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the defect, fix, rationale, and verification, but it does not follow the required template. It omits the required Linked Issue format, Visual Proof or N/A statement, testing c… Add all required template sections. Include a valid issue reference using the required "Fixes #..." format, state "N/A" with a reason for Visual Proof, document manual and automated testing with tested platforms, complete the AI Disclosure …
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: recognizing Windows profiles through WSL drvfs paths.
Full details: Description check

Explanation

The description explains the defect, fix, rationale, and verification, but it does not follow the required template. It omits the required Linked Issue format, Visual Proof or N/A statement, testing checkboxes and platform details, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist sections.

Resolution

Add all required template sections. Include a valid issue reference using the required "Fixes #..." format, state "N/A" with a reason for Visual Proof, document manual and automated testing with tested platforms, complete the AI Disclosure and Agent skill boundary sections, address the Notes items, and complete the Checklist.

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch nwparker/worktree-home-guard-path-authority

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

`/mnt/<letter>` under a WSL UNC alias is the distro's drvfs mount of a Windows
volume, so `\\wsl.localhost\Ubuntu\mnt\c\Users\bob` is `C:\Users\bob` wearing a
Linux spelling. The Windows-profile rule excludes every WSL UNC path by design
(the aliases normally front a Linux filesystem) and the POSIX shapes never match
a `/mnt/...` tail, so that path fell through both and read back as deletable.

The spelling is producible by the product: `resolveWslRepoWorktreeBasePath` maps a
`/mnt/c/...` worktree base against a WSL repo into exactly this UNC form, and
`getWslFilesystemBoundaryDistro` already treats it as the drvfs crossing.

A drvfs tail now takes the Windows rule on its drive form, via the existing
`toWindowsWslDrivePath`. Scoped to the UNC branch, where `parseWslUncPath` has
proven the path is a WSL alias — a plain Linux host's `/mnt/c/...` is untouched.
The lowercase-only `/mnt` match is deliberate: `/MNT` is an ordinary
case-sensitive Linux directory, never the automount.
@nwparker
nwparker force-pushed the nwparker/worktree-home-guard-path-authority branch from a43dc36 to 2ca2b00 Compare September 19, 2026 06:50
@nwparker nwparker changed the title fix(worktree): let the worktree path alone decide whose home it is fix(worktree): recognise the Windows profile through WSL's drvfs view Sep 19, 2026
… WSL UNC alias

`\\wsl.localhost\Ubuntu\mnt\c` is the whole C: volume and `\\wsl.localhost\Ubuntu\mnt`
holds every drvfs volume. Neither is caught by the root check in
`isDangerousWorktreeRemovalPath` (their win32 root is the distro share) nor by the
Windows-profile rule on the drive form (`C:\` is not `C:\Users`), so both read as
deletable. Measured on a Windows 11 host with WSL2: `rm -rf` inside the distro on the
`/mnt/c` spelling deletes on the Windows drive.

@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

  • Refused the drvfs volume root — in the WSL UNC drvfs branch, a resolved drive path equal to its own win32 root (/mnt/c → C:\, any volume) is now treated as dangerous, so \\wsl.localhost\Ubuntu\mnt\c no longer reads as an ordinary deletable directory. The comment correctly explains why the outer root check cannot catch it: the UNC spelling's win32 root is the distro share.
  • Refused the automount parent — when the tail does not translate to a drive, linuxPath === '/mnt' is refused, since the automount holds every volume and therefore every profile. /MNT stays an ordinary case-sensitive directory.
  • Tests extended with teeth — four rows added (volume root, trailing slash, /mnt, and a nested /mnt/c/src/repo that must stay deletable). I verified the three → true rows fail when the 4a7a835 production hunk is reverted; the → false rows stay green.

I ran worktree-removal-home-guard + worktree-removal-safety — 85 passed. No open threads from the prior review.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit b2fe56d into main Sep 21, 2026
56 of 58 checks passed
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