Skip to content

sidebar: Fix hang caused by archiving a thread from a worktree that was deleted from disk - #65202

Closed
mpyuglgwkxcmodyrpo wants to merge 1 commit into
zed-industries:mainfrom
mpyuglgwkxcmodyrpo:57957-archive-thread-on-deleted-worktree
Closed

mpyuglgwkxcmodyrpo wants to merge 1 commit into
zed-industries:mainfrom
mpyuglgwkxcmodyrpo:57957-archive-thread-on-deleted-worktree

Conversation

@mpyuglgwkxcmodyrpo

Copy link
Copy Markdown
Contributor

Summary

Closes #57957 and duplicate #64977.
Infinite task loop caused by attempting to open a worktree that was deleted from disk.

Root cause

The archive_thread task will schedule itself forever because should_load_closed_workspace_for_archive returns true for deleted linked worktrees because it only checks whether folder_paths != project_group_key.path_list(), but find_or_create_local_workspace silently falls back to the main project when those paths are missing on disk, so the opened workspace never matches the thread’s folder_paths and rebuild_contents keeps producing ThreadEntryWorkspace::Closed indefinitely causing another scheduling of archive_thread.

Notably this is not a problem on the "Thread History" sidebar panel because it does not try to open the workspace before archiving. This only affects the regular active (unarchived) threads sidebar.

Reproduction

I am finding that this problem mainly exists for External Agents, so if you are testing this here are the steps to reproduce:

  1. Start a new worktree
  2. Start and external agent thread in that worktree and send it a message so that it persists in the sidebar
  3. Switch back to the main worktree
  4. Use the UI to close (X icon) and then delete (trash can icon) the previously created worktree from the worktree dropdown in the top left
  5. Attempt to archive the thread created in the worktree from the threads view sidebar (NOT the threads history)
  6. Notice that the UI is now locked up

Fix

Check if the worktree exists before trying to open it, breaking the archive_thread task loop.

Testing

  • Manually verified that the problem exists before the patch in this PR and does not exist after the patch.
  • Created and ran unit test that hangs before the fix and succeeds after (test_archive_thread_from_deleted_linked_worktree_does_not_loop)
  • All 156 existing sidebar unit tests pass.

Self-review

  • I've reviewed my diff for quality, security, reliability, and performance.
  • [N/A] UI changes follow the checklist.
  • Tests cover the new or changed behavior.

Release Notes:

  • Fix hang caused by archiving a thread from a worktree that was deleted from disk

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Oct 5, 2026
@MrSubidubi MrSubidubi added the area:ai/multiagent sidebar aka Threads sidebar, aka Parallel Agents label Oct 5, 2026
@smitbarmase smitbarmase self-assigned this Oct 8, 2026

@smitbarmase smitbarmase left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down! Your regression test made this easy to verify, so I'm keeping it.

I'm going to close this because the new check runs fs.metadata on the local disk, even when the thread's worktree lives on an SSH remote. Those paths usually don't exist locally, so archiving a remote worktree thread would skip opening its workspace and never clean up the worktree.

find_or_create_workspace already checks whether the paths exist, on the right machine. The loop comes from archive_thread ignoring the workspace that open returns and starting over, so I'm fixing it there instead.

Getting to that fix took a fair bit of digging through the archive flow, and it turned up a related bug where the workspace opened for archiving stays in the sidebar as an extra project group. Both fixes touch the same code, so it's quicker for me to put them up together than to send this back with a long list of changes.

@smitbarmase smitbarmase closed this Oct 9, 2026
@mpyuglgwkxcmodyrpo

Copy link
Copy Markdown
Contributor Author

Thanks for the response and fix. I'll make sure to consider and test SSH remote sessions for future PRs. Can you link the fix/PR you mentioned so I can take a look and learn from it?

@smitbarmase

Copy link
Copy Markdown
Member

@mpyuglgwkxcmodyrpo here you go: #65578

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai/multiagent sidebar aka Threads sidebar, aka Parallel Agents cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't archive agent thread from deleted git worktree

3 participants