Skip to content

fix(worktrees): clear orphan cleanup on BusyBox WSL distros - #23296

Merged
nwparker merged 1 commit into
mainfrom
nwparker/busybox-stat-detect
Sep 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/busybox-stat-detect

Conversation

@nwparker

@nwparker nwparker commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​51 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3

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 stat the path and inspects
the 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 — which
is 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 that
trailing text is pinned to English.

The behavior that distinguishes "gone" from "blocked" is unchanged: a Permission denied
failure 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
stat call, for a good reason — [ -e "$path" ] answers false both when a path is absent and
when a parent directory is unreadable, so the old probe could report a permission-blocked
directory as successfully deleted. stat preserves the distinction. The cost it introduced was
a 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=C to 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 cases
fail on main and pass with this change. src/main/worktree-removal-safety.test.ts and
src/main/ipc/worktrees-removal-recovery.test.ts also pass unchanged (81 tests total).

Real hosts:

  • Linux, BusyBox v1.36.1 — stat: can't stat '/nonexistent-xyz': No such file or directory
    and ... : Not a directory, both exit 1. stat -c %F /tmp → directory, and file/symlink
    report regular empty file / symbolic link, i.e. identical to GNU, so the error text was
    the 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.exe
    round 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:

    GNU existing dir       exit=0 stdout=[directory] stderr=[] OLDregex=false NEWregex=false
    GNU missing            exit=1 stderr=[stat: cannot statx '/nonexistent-xyz': No such file or directory] OLDregex=true  NEWregex=true
    GNU not-a-directory    exit=1 stderr=[stat: cannot statx '/etc/hostname/nope': Not a directory]         OLDregex=true  NEWregex=true
    GNU permission denied  exit=1 stderr=[stat: cannot statx '<tmp>/locked/inner': Permission denied]       OLDregex=false NEWregex=false
    
  • macOS: pnpm tc:node and pnpm run check:code-quality:changed pass.

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.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Cross-platform: the changed code only runs on a Windows host with a WSL distro selected.
    macOS, Linux and plain Windows go through Node's lstat and are untouched.
  • SSH / remote: unaffected. Remote hosts have their own filesystem path; this is the local
    WSL probe only.
  • Security: the matcher is looser than before (it no longer requires the message to start
    with stat:). It still requires the command to have exited 1, and the only thing that writes
    to that probe's stderr is stat itself, so there is no other producer whose output could be
    mistaken 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.
  • Backwards compatibility / performance / mobile: no wire, storage or UI surface touched;
    same single stat call as before.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 67cc4048-ea20-482d-9b55-7e7fb461610f

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb1ade and 95c47d5.

📒 Files selected for processing (2)
  • src/main/local-worktree-filesystem.test.ts
  • src/main/local-worktree-filesystem.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The WSL missing-path matcher now recognizes No such file or directory and Not a directory stderr suffixes when the command exits with code 1. Tests cover GNU and BusyBox error formats, permission-denied and translated errors, and the LC_ALL=C setting for WSL stat probes.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 95c47

No merge-blocking issue is identified; normal checks remain appropriate before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix for orphaned worktree cleanup on BusyBox-based WSL distributions and matches the main change.
Description check ✅ Passed The description is detailed and covers the required explanation, change, rationale, testing, compatibility, and checklist sections. The Linked Issue field remains empty after “Fixes #”, but the rest o…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@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 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 — isWslMissingPathError now tests WSL_MISSING_PATH_STDERR (/: (?:No such file or directory|Not a directory)\r?\n?$/) against stderr instead of requiring the GNU verb, still gated on exitCode === 1. BusyBox's can't stat and GNU's cannot statx both 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=C pin 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 on main for the same substring-fallback reason, so they do not independently pin this fix — the sibling code: 'ENOENT' assertion does. No change required; noting it so the coverage claim isn't overstated.

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

@nwparker
nwparker merged commit a2325bb into main Sep 27, 2026
41 checks passed
@nwparker
nwparker deleted the nwparker/busybox-stat-detect branch September 27, 2026 03:43
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