Skip to content

Always remove linked worktree workspaces before archive cleanup#53672

Draft
rtfeldman wants to merge 3 commits intomainfrom
fix-archive-worktree-workspace-removal
Draft

Always remove linked worktree workspaces before archive cleanup#53672
rtfeldman wants to merge 3 commits intomainfrom
fix-archive-worktree-workspace-removal

Conversation

@rtfeldman
Copy link
Copy Markdown
Contributor

When archiving a thread's last reference to a linked worktree, the worktree workspace must be removed from the MultiWorkspace before the background cleanup task runs git worktree remove. Previously, only the workspace found via exact PathList match on the thread's folder_paths was removed. This missed cases where the workspace's root paths diverged from the thread's folder_paths (e.g. after folders were added/removed from the workspace).

Now we also scan roots_to_archive for any linked worktree workspaces that contain the worktree being archived and include them in the removal set. This ensures all editors are dropped, releasing their Entity<Worktree> references (held through File structs in buffers), so wait_for_worktree_release completes and git worktree remove can proceed.

Release Notes:

  • Fixed linked worktree directories sometimes not being cleaned up from disk when archiving a thread.

When archiving a thread's last reference to a linked worktree, the
worktree workspace must be removed from the MultiWorkspace before
the background cleanup task runs git worktree remove. Previously,
only the workspace_to_remove (found via exact PathList match on the
thread's folder_paths) was removed. This missed cases where the
workspace's root paths diverged from the thread's folder_paths
(e.g. after folders were added/removed from the workspace).

Now we also scan roots_to_archive for any linked worktree workspaces
that contain the worktree being archived and include them in the
removal set. This ensures all editors are dropped, releasing their
Entity<Worktree> references (held through File structs in buffers),
so wait_for_worktree_release completes and git worktree remove can
proceed.
Tests the scenario where a thread's folder_paths don't exactly match
any workspace's root paths (e.g. after a folder was added to the
workspace post-creation). In this case, workspace_to_remove is None
because workspace_for_paths can't find an exact match, but the linked
worktree workspace still has the worktree loaded with open editors
holding Entity<Worktree> references.

Without the fix, the archive cleanup task's wait_for_worktree_release
hangs forever because the workspace's editors prevent the worktree
entity from being released, and the worktree directory is never
cleaned up from disk.
@rtfeldman rtfeldman self-assigned this Apr 11, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 11, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Apr 11, 2026
The open_abs_path call panics on Windows because the path gets
backslashes which can't be parsed as a URI in the LSP layer.
The core test scenario (workspace removal when paths diverge)
doesn't require an open editor, so remove that step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant