GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): recover worktree removal blocked by cached locations by Zhangyinglun · Pull Request #51281 · anomalyco/opencode

Conversation

@Zhangyinglun

@Zhangyinglun Zhangyinglun commented Sep 25, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #51172

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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 remove deletes the checkout and .git/worktrees/<id> but not the root. The row stays, and every retry fails with Worktree directory unavailable.

  • Worktree.remove still tries the strategy first. If that fails for a reason force wouldn't fix, it invalidates the cached local locations at or inside the worktree (the same thing debug.location.evict does; 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 plugin forceRequired) don't touch any location, and on Linux/macOS the first attempt succeeds, so nothing changes there.
  • The git strategy treats an empty directory as the leftover of a partial removal and deletes it, since a real checkout always has .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:

  • An active session's location is only detached by invalidation, so it can keep holding the directory until the session ends. I asked in the issue whether removal should reject or interrupt active sessions.
  • A locked file inside the worktree (for example an MCP server running from the worktree's .venv) still leaves a non-empty leftover.
  • A plugin removing the worktree it is loaded in is not handled.
  • The release-and-retry also runs for failures that releasing can't fix (for example a locked worktree). Happy to limit it to Windows if you prefer.

How did you verify your code works?

  • New tests in packages/core/test/worktree.test.ts, which fail before this change and pass after:

    • locations inside the worktree are released only after a failed first attempt, then the removal is retried;
    • a dirty git worktree and a plugin forceRequired refusal release nothing;
    • an empty leftover (outside and inside the repo) is cleared on retry;
    • a non-empty leftover is kept.

    bun run test test/worktree.test.ts in packages/core: 41 pass. location-layer, location-activity and git tests also pass.

  • On Windows 11 (git 2.55), I ran the issue's reproduction script against serve from this branch with a stub stdio MCP server. Before: DELETE /api/worktree → 400 Permission denied, an empty directory and the row are left, and the retry → 400 Worktree 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. Current v2 needs mcp.servers, otherwise no MCP server starts and the bug doesn't show.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Zhangyinglun
fix(core): recover worktree removal blocked by cached locations
6d0e476
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
@github-actions github-actions Bot added the needs:issue label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Zhangyinglun Zhangyinglun mentioned this pull request Sep 25, 2026
Windows: worktree remove fails half-way and leaves a stale row when the worktree's location has a local MCP server running #51172
Open
@opencode-agent opencode-agent Bot mentioned this pull request Oct 10, 2026
Worktree removal deletes unregistered directories #54260
Closed
@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:18
@github-actions github-actions Bot removed the needs:issue label Oct 10, 2026
@sogeisetsu

sogeisetsu commented Oct 15, 2026

Copy link
Copy Markdown

Adding a Windows data point in case it helps validate this on the real locking path (managed opencode v2.0.28, OpenChamber multi-run worktrees):

  • The blocker is the CWD handle alone: git worktree list was already clean (git worktree prune had run) and the directory was empty, yet the directory node stayed locked (Permission denied).
  • The holder was not a location-scoped local MCP server; it was orphaned MCP stdio children with CWD = the worktree (mcp-mail-server node + paddleocr_mcp python), parented by the opencode.exe server. Same class as Windows: worktree remove fails half-way and leaves a stale row when the worktree's location has a local MCP server running #51172, different holder.
  • Evicting the location (or killing exactly those children) released the directory immediately.

Any rough ETA for this landing on dev? Happy to re-test on Windows once it is in.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Zhangyinglun

Zhangyinglun commented Oct 18, 2026

Copy link
Copy Markdown
Author

Could a maintainer please check whether the CI workflows need approval? Both test and check show action_required, with no jobs started, so the required checks are still missing.

If approval is needed, could you please approve them to run? Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Zhangyinglun
fix(core): reconcile worktree removal with current dev
63ea64a
Merge current dev while preserving cached-location cleanup and retry behavior. Use the typed strategy ID and align the regression fixture with Instance.Error.

Validation: 81 related tests pass; core Bun and TypeScript checks pass; root bun run check passes.
@github-actions

github-actions Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Oct 25, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Oct 25, 2026
@github-actions github-actions Bot mentioned this pull request Oct 25, 2026
📊 AI CLI 工具社区动态日报 2026-10-26 litang9/big_model_radar#606
Open
@opencode-agent opencode-agent Bot mentioned this pull request Oct 26, 2026
worktree: delete fails on Windows and leaves unremovable ghost entry #59374
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Windows: worktree remove fails half-way and leaves a stale row when the worktree's location has a local MCP server running

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Zhangyinglun @sogeisetsu
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.