Repository navigation
fix(worktrees): keep failed orphan cleanup retryable - #22409
Conversation
Based on the report and proposal by @SiinXu. Co-authored-by: SiinXu <[email protected]>
|
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 (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe WSL filesystem probe now uses Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No concrete issue blocks merging after normal checks. The change is intended to keep failed orphan cleanup retryable rather than discard its registration. 🚥 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.
Important
The runtime removal path now keeps a failed orphan cleanup retryable, but the equivalent local-desktop removal path still drops the retry handle. The desktop renderer routes local deletes through window.api.worktrees.remove → removeRegisteredLocalWorktree, which was not updated, so the linked issue's local-desktop surface keeps the old behavior.
Reviewed changes
- Runtime orphan cleanup is now retryable —
cleanupOrphanedDirectoryreports whether the path is gone, andremoveRuntimeRegisteredLocalWorktreethrowsORPHANED_WORKTREE_DIRECTORY_MESSAGEbeforegit worktree prune, push-target cleanup, or metadata removal when it is not. The watcher gate'sfinish(false)still restores watchers. - WSL stat no longer conflates denial with absence — the shell
[ -f/-d ]probe (which exited2for an unreadable path) is replaced byLC_ALL=C stat -c %F; only the statNo such file or directory/Not a directorystderr maps toENOENT, and permission failures propagate.%Fkinds are mapped back tosymlink/file/directory, elseother. - Coverage — WSL permission-vs-missing classification,
isWorktreePathMissingonEACCES, and both runtime retention paths (unproven directory, and a proven directory whose removal fails) plus a retry.
⚠️ The local desktop removal path still drops the retry handle
removeRegisteredLocalWorktree (src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts:159) mirrors the pre-fix runtime logic: after an orphan cleanup that can silently leave the directory in place, it calls git worktree prune, removeWorktreeMetadataAndTransientState and returns success. Since dispatch-worktree-removal.ts:34 sends local deletes over window.api.worktrees.remove, this is the transport the UI uses, so a failed local orphan cleanup still removes the row and the retry handle. The linked report is a macOS local-desktop one, and the renderer already knows how to offer force-delete on ORPHANED_WORKTREE_DIRECTORY_MESSAGE (store-worktree-removal-cascade.test.ts:623), which this path never throws.
Technical details
# Apply the same missing-path gate to the desktop local-removal path
## Affected sites
- `src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts:159-211` — orphan branch prunes registration and removes metadata unconditionally after `removeLocalWorktreePath(...).catch(() => {})`.
- `src/main/runtime/runtime-registered-local-worktree-removal.ts:164-223` — the fixed twin, for reference.
## Required outcome
- The desktop path should throw `ORPHANED_WORKTREE_DIRECTORY_MESSAGE` and leave metadata (and Git registration) intact whenever the orphan directory is not absent after the cleanup attempt, matching the runtime path.
## Suggested approach (optional)
- `cleanupOrphanedDirectory` already exists in the runtime module; consider lifting the shared "cleanup, then prove absence" helper so both entry points use one implementation instead of a third copy.
## Open questions for the human
- Is the local desktop path intentionally out of scope here (e.g. the local case is blocked earlier by PTY proof), or should this land too / in a follow-up?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Addressed the desktop IPC path in 8d3d89f. Runtime and desktop removal now share cleanupLocalOrphanedWorktreeDirectory, which proves execution-host path absence before either caller prunes registration or removes metadata. Two desktop regressions fail before the fix and pass after; they cover refused proof, failed recursive removal, watcher restoration, retained metadata and successful retry. The combined 1,381 focused tests (one skipped), Node typecheck and changed-code quality pass. |
|
@coderabbitai review |
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Extracted one shared orphan-cleanup helper —
cleanupLocalOrphanedWorktreeDirectorynow owns the "prove it is a safe orphan, delete if proven, then throwORPHANED_WORKTREE_DIRECTORY_MESSAGEif the path still exists" sequence. - Fixed the desktop registered-removal path —
removeRegisteredLocalWorktreeroutes its orphan branch through that helper, so a failed cleanup now throws beforegit worktree prune, push-target cleanup, and metadata removal, and the watcher gate restores watchers viafinish(false). The renderer already maps this message to theorphan-directoryforce reason (src/shared/worktree/removal.ts:136). - Removed the runtime path's private copy —
runtime-registered-local-worktree-removal.tsnow calls the same helper, keeping the two entry points in lockstep. - Added desktop regression coverage — a new
it.eachcovers both the unproven-directory and removal-failure retention cases plus a successful retry; verified these two cases fail if the helper's throw is removed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
A workspace stays in Orca when its folder could not safely be removed, so you can retry cleanup.
What Changed
Both runtime and desktop IPC removal reuse one cleanup helper that confirms that the execution-host path is absent before pruning registration and removing metadata. WSL uses a C-locale stat probe so permission failures cannot masquerade as absence.
Why
Reuse the existing directory proof and missing-path check. Silently forgetting a folder after a refused or failed removal loses the only retry handle. PTY-stop policy is unchanged.
Linked Issue
Related to #21954. Reported by @SiinXu. This covers orphan cleanup metadata ordering; broader leftover-process force cleanup and #22161 are not assessed.
Visual Proof
N/A — backend cleanup and filesystem error classification only; no renderer change. Disposable fixture and failure tests establish retained metadata and retry behavior.
Testing
1,381 focused filesystem, safety, desktop IPC and runtime tests pass; one skipped. Two new desktop regression cases fail before the shared absence gate and pass afterward, including a successful retry. Node typecheck and changed-code quality pass. Native execution was macOS only; WSL uses controlled tests, with no native Windows/Linux/WSL/live SSH claim.
ORCA_BACKGROUND_LAUNCH=1AI Disclosure
Review
Reviewed cleanup ordering, execution-host routing, failed stat/removal and watcher restoration. Addressed Pullfrog’s desktop-path finding by sharing the same cleanup and absence-proof function between desktop IPC and runtime removal. The existing stat-to-remove race is not redesigned.
Agent skill upstream boundary
Notes
No full application build, full lint, or full suite is claimed; CI covers broader validation.
Checklist