Always remove linked worktree workspaces before archive cleanup#53672
Draft
Always remove linked worktree workspaces before archive cleanup#53672
Conversation
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.
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.
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.
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'sfolder_pathswas removed. This missed cases where the workspace's root paths diverged from the thread'sfolder_paths(e.g. after folders were added/removed from the workspace).Now we also scan
roots_to_archivefor any linked worktree workspaces that contain the worktree being archived and include them in the removal set. This ensures all editors are dropped, releasing theirEntity<Worktree>references (held throughFilestructs in buffers), sowait_for_worktree_releasecompletes andgit worktree removecan proceed.Release Notes: