fix: retry worktree removal on Windows when transient locks delay deletion#25
Open
jeremylasne92-hue wants to merge 2 commits into
Open
fix: retry worktree removal on Windows when transient locks delay deletion#25jeremylasne92-hue wants to merge 2 commits into
jeremylasne92-hue wants to merge 2 commits into
Conversation
…etion Sourced agents (npm, watchers) often hold short-lived locks on files inside node_modules right after exit; the first 'git worktree remove' then fails with 'Directory not empty' even though the lock clears in a second or two. Retry up to 3 times with a 1s backoff on MSYS/MinGW/Cygwin shells, leaving Linux/macOS behavior unchanged.
Field-tested 3x sleep 1 was insufficient for npm-loaded worktrees on Windows. Locks on node_modules native binaries (esbuild, vitest, .dll) can persist 5-8 seconds after process exit. Bump retry budget to 10s total, then fall back to rm -rf + git worktree prune if git still refuses to delete.
Author
|
Field-tested on a real DANTE IA worktree (Node monorepo with vitest+esbuild). The initial 3x sleep 1 budget (3s total) was insufficient in practice — locks on
This now succeeds reliably end-to-end on Windows for a 1.8 GB |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24
Problem
On Windows (Git Bash / MSYS),
cmux rmfails withDirectory not emptywhen the worktree contains a populatednode_modules/. Background processes (npm watchers, esbuild, vitest) hold short-lived file handles insidenode_modulesafter exit;git worktree removeruns its cleanup while a handle is still open → fails. The lock clears within ~1 second but cmux gives up immediately.Fix
Retry
git worktree removeup to 3 times with a 1-second backoff when running on MSYS/MinGW/Cygwin (uname -smatchesMINGW*|MSYS*|CYGWIN*). Linux and macOS behavior is unchanged — they fall through to the original failure path with the existing error message.Verification
On Windows Git Bash (MSYS2/MINGW64, bash 5.2.37, git 2.52.0.windows.1):
On Linux (no
cygpath/MSYS detected): thecaseblock is skipped entirely; the function behaves exactly as before. Existing error message and--forcehint still trigger when the first attempt fails.Scope
_cmux_rmCLAUDE.md)