Repository navigation
fix(worktrees): clear orphan cleanup on BusyBox WSL distros - #23296
Conversation
The WSL "is this path gone?" probe decided a path was missing by matching GNU coreutils' exact wording, `stat: cannot statx ...`. BusyBox writes `stat: can't stat ...`, so on an Alpine-style distro a successful orphaned worktree delete was still reported as a permanent failure, on every retry. Match only the trailing strerror text, which is POSIX and already pinned to English by the probe's LC_ALL=C. Permission failures still report failure.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe WSL missing-path matcher now recognizes Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No merge-blocking issue is identified; normal checks remain appropriate before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
ℹ️ No critical issues — one informational point on the description's reproduction trail below.
Reviewed changes
A focused portability fix for the WSL stat probe plus test coverage.
- Matcher narrowed to the portable tail —
isWslMissingPathErrornow testsWSL_MISSING_PATH_STDERR(/: (?:No such file or directory|Not a directory)\r?\n?$/) against stderr instead of requiring the GNU verb, still gated onexitCode === 1. BusyBox'scan't statand GNU'scannot statxboth convert to{ code: 'ENOENT' }. - Permission-denied behavior preserved — every other strerror reason still rethrows raw, so a delete that did not happen still surfaces as a failure.
- Tests — captured GNU/BusyBox stderr for the missing and permission-denied cases, an
LC_ALL=Cpin assertion, and a synthetic translated-failure case asserting the code errs toward failure.
ℹ️ The description's mechanism points at a check that already tolerated BusyBox
The post-delete isWorktreePathMissing check in cleanupLocalOrphanedWorktreeDirectory already passes on BusyBox before this change, because isMissingPathError (worktree-removal-safety.ts:286) falls back to a case-insensitive substring match on no such file or directory. The code-only consumer that actually regressed is isPrunableGitFileWorktree (isENOENT, which requires the literal ENOENT: prefix), and this change does fix it. Worth correcting the description's mechanism paragraph so the reproduction trail names the path the change repairs.
Technical details
# BusyBox ENOENT conversion gap
## Affected sites
- `src/main/worktree-prunable-git-file.ts:28` — `isENOENT(error)` only accepts `error.code === 'ENOENT'` or the literal `ENOENT: no such file or directory` message. A raw BusyBox `stat: can't stat '<path>': No such file or directory` rethrows instead of returning `null`, so `execute-worktree-removal.ts:148` throws rather than falling through to stale-registration recovery.
- `src/main/local-orphaned-worktree-cleanup.ts:36` — `isWorktreePathMissing` → `isMissingPathError` already matched the substring, so it was not the failing site.
## Required outcome
- None for the code: converting the probe failure to `{ code: 'ENOENT' }` before any consumer inspects it fixes all code-only consumers. This note is about PR-description accuracy only.ℹ️ Nitpicks
- The
isWorktreePathMissing(...)assertions added to the missing-path test (lines 236-238) already pass onmainfor the same substring-fallback reason, so they do not independently pin this fix — the siblingcode: 'ENOENT'assertion does. No change required; noting it so the coverage claim isn't overstated.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When Orca deletes a leftover worktree folder that lives inside a WSL Linux distro, it
double-checks afterwards that the folder is really gone. It did that check by reading the
wording of an error message. Not every Linux distro words it the same way. On the ones that
word it differently, Orca deleted the folder successfully and then still told the user the
cleanup had failed — every time they retried, forever. This makes the check read the part of
the message that every Linux distro words identically.
What Changed
Before: on a WSL distro built on BusyBox (Alpine and friends), removing an orphaned worktree
left the user with a permanent "could not clean up the worktree directory" error, even though
the directory had in fact been deleted. Retrying never helped. On Ubuntu and other
GNU-coreutils distros it worked fine, so the failure only showed up for a subset of users.
After: the cleanup finishes quietly on those distros, exactly as it already did on Ubuntu.
Mechanism: after deleting the directory, Orca asks the distro to
statthe path and inspectsthe failure to decide whether the path is genuinely absent (finish) or whether something else
went wrong (report a failure the user can retry). That decision was matching the whole error
message including the verb —
stat: cannot statx '<path>': No such file or directory— whichis GNU coreutils' phrasing. BusyBox says
stat: can't stat '<path>': No such file or directory,so nothing matched, the path was treated as still present, and a successful delete was reported
as a failure. The match now covers only the trailing reason, which is the standard C-library
text and identical across implementations. The probe already runs under
LC_ALL=C, so thattrailing text is pinned to English.
The behavior that distinguishes "gone" from "blocked" is unchanged: a
Permission deniedfailure still reports a failure rather than claiming success, on both userlands.
Why
This is a regression from #22409. That PR replaced a probe built from shell built-ins with a
statcall, for a good reason —[ -e "$path" ]answers false both when a path is absent andwhen a parent directory is unreadable, so the old probe could report a permission-blocked
directory as successfully deleted.
statpreserves the distinction. The cost it introduced wasa dependency on one implementation's message wording.
I considered going back to a message-free probe that emits a fixed token, which the brief for
this fix preferred. I did not, for one reason: the only way to tell "absent" from
"permission-blocked" using shell built-ins is to test whether each ancestor directory is
traversable. Doing that faithfully needs a loop over the path, and doing it partially
reintroduces exactly the false success #22409 removed — reporting a directory as deleted when
it was never touched. Trading a false failure for a false success is the wrong direction here,
and the loop is far more code than this bug justifies.
The remaining fragility after this change is translation, not implementation: a distro running
under a non-English locale would word the reason differently. The probe already forces
LC_ALL=Cto prevent that, and this PR adds a test that fails if that pin is ever removed,plus a test showing that if it ever were removed the code errs toward reporting a failure
rather than a false success.
Linked Issue
Fixes #
Visual Proof
N/A — no UI change. The user-visible difference is the absence of an error toast after a
worktree cleanup, on WSL distros only.
Testing
Automated (
src/main/local-worktree-filesystem.test.ts, 17 passing): the "missing path" and"unreadable path" cases are now run against the real stderr strings captured from live hosts
for both userlands, plus a test that the probe still pins
LC_ALL=C. The two BusyBox casesfail on
mainand pass with this change.src/main/worktree-removal-safety.test.tsandsrc/main/ipc/worktrees-removal-recovery.test.tsalso pass unchanged (81 tests total).Real hosts:
Linux, BusyBox v1.36.1 —
stat: can't stat '/nonexistent-xyz': No such file or directoryand
... : Not a directory, both exit 1.stat -c %F /tmp→directory, and file/symlinkreport
regular empty file/symbolic link, i.e. identical to GNU, so the error text wasthe only incompatibility.
Alpine 3.23.3 / BusyBox v1.37.0 (the userland an Alpine WSL distro actually ships) —
same two strings, same exit code, via Docker on the same host.
Windows 11 + WSL Ubuntu-24.04 (GNU coreutils) — ran the probe through a real
wsl.exeround trip for four cases (existing directory, missing path, path under a non-directory,
permission-denied path) and compared the old and new matchers on the actual captured stderr.
They agree on all four, confirming no change to the GNU path:
macOS:
pnpm tc:nodeandpnpm run check:code-quality:changedpass.Not reachable: a BusyBox-userland WSL distro. Installing one on the test machine was out of
scope, so the BusyBox evidence is a real BusyBox binary on Linux and a real Alpine image rather
than a real Alpine-under-WSL.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
macOS, Linux and plain Windows go through Node's
lstatand are untouched.WSL probe only.
with
stat:). It still requires the command to have exited 1, and the only thing that writesto that probe's stderr is
statitself, so there is no other producer whose output could bemistaken for a missing path. The consequence of a wrong match here is a cleanup reported as
complete; the permission-denied tests pin the case that matters.
same single
statcall as before.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)