fix(core): recover worktree removal blocked by cached locations - #51281
Open
Zhangyinglun wants to merge 1 commit into
Open
Zhangyinglun wants to merge 1 commit into
Zhangyinglun wants to merge 1 commit into
Conversation
On Windows a cached location can keep a local MCP server running with the worktree as its cwd, so git deletes the checkout but not its root and every retry fails. Release the locations inside the worktree after a failure that force would not fix and retry once, and let the git strategy clear the empty leftover of a partial removal. Closes anomalyco#51172
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This branch has not been deployed
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.
Issue for this PR
Closes #51172
Type of change
What does this PR do?
On Windows, removing a worktree that has been used as a location fails halfway. A local MCP server started with the worktree as its cwd keeps the directory in use, so
git worktree removedeletes the checkout and.git/worktrees/<id>but not the root. The row stays, and every retry fails withWorktree directory unavailable.Worktree.removestill tries the strategy first. If that fails for a reasonforcewouldn't fix, it invalidates the cached local locations at or inside the worktree (the same thingdebug.location.evictdoes; closing an idle location stops its MCP servers) and retries once. If the retry also fails, the original error is returned and the retry error is logged. Refusals that need force (git or pluginforceRequired) don't touch any location, and on Linux/macOS the first attempt succeeds, so nothing changes there..git. Non-empty directories are left alone. This also lets a retry succeed once some other process that held the directory has exited.Known limits, same as before this change:
.venv) still leaves a non-empty leftover.How did you verify your code works?
New tests in
packages/core/test/worktree.test.ts, which fail before this change and pass after:forceRequiredrefusal release nothing;bun run test test/worktree.test.tsinpackages/core: 41 pass.location-layer,location-activityandgittests also pass.On Windows 11 (git 2.55), I ran the issue's reproduction script against
servefrom this branch with a stub stdio MCP server. Before:DELETE /api/worktree→ 400Permission denied, an empty directory and the row are left, and the retry → 400Worktree directory unavailable. After: 204, and the directory and row are gone. With an external process holding the directory, the first delete still reports git's error, and a retry after that process exits → 204.The script in the issue uses the old
mcp: { <name>: ... }config. Currentv2needsmcp.servers, otherwise no MCP server starts and the bug doesn't show.Screenshots / recordings
Not a UI change.
Checklist