Skip to content

agent_ui: Keep threads pinned to their git worktree group#60776

Open
ivanbanov wants to merge 1 commit into
zed-industries:mainfrom
ivanbanov:fix-thread-worktree-regrouping
Open

agent_ui: Keep threads pinned to their git worktree group#60776
ivanbanov wants to merge 1 commit into
zed-industries:mainfrom
ivanbanov:fix-thread-worktree-regrouping

Conversation

@ivanbanov

@ivanbanov ivanbanov commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Closes #60553

With git worktrees nested inside the repository, a thread's worktree group in the Agent panel could change while navigating the file tree. Two causes:

  • The computed main worktree path for a linked worktree falls back to the folder path whenever git state is unavailable (e.g. during scanning), and stored thread metadata was rewritten from that freshly-computed state on every worktree event and thread update, so a resolved association (main-repo / worktree) could regress and the thread jumped to another group.
  • WorktreePaths::add_path accumulated a duplicate pair for the same folder when its main path was re-resolved, corrupting the group key.

Fix:

  • WorktreePaths::add_path replaces a stale same-folder pair and never downgrades a resolved pair to the unresolved fallback.
  • New WorktreePaths::preserving_resolved_main_paths keeps previously-resolved main paths when merging freshly-computed paths into stored thread/terminal metadata.
  • AgentPanel only rewrites stored thread paths for threads that were tracking the project's previous path set, so threads associated with a different worktree keep their association.

Covered by a regression test (fails without the fix), an end-to-end test with the nested-worktree layout from the issue, and unit tests for the new WorktreePaths semantics.

Verified manually on a repo with <repo>/.worktrees/<name> worktrees — threads now stay pinned to their worktree while navigating:

threads pinned to their worktrees

Release Notes:

  • Fixed agent threads being re-grouped under the wrong git worktree in the Agent panel when using worktrees nested inside the repository (#60553).

🤖 Generated with Claude Code

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 10, 2026
A thread's Agent-panel grouping is derived from its stored worktree
paths, which were rewritten from freshly-computed project state on every
worktree event and thread update. For git worktrees nested inside the
repository, the computed main worktree path falls back to the folder
path whenever git state is unavailable (e.g. while a worktree is being
scanned), so a thread's resolved association with its main repository
could regress and the thread would jump to a different worktree group.

- WorktreePaths::add_path now replaces a stale pair when a folder's main
  path is resolved, instead of accumulating duplicate folder entries,
  and refuses to downgrade a resolved pair to the unresolved fallback.
- WorktreePaths::preserving_resolved_main_paths keeps previously
  resolved main paths when merging freshly-computed paths into stored
  thread/terminal metadata.
- AgentPanel only rewrites stored thread paths for threads that were
  tracking the project's previous path set, so threads associated with
  a different worktree keep their association.

Fixes zed-industries#60553

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ivanbanov ivanbanov force-pushed the fix-thread-worktree-regrouping branch from a94bd4d to adb0e5c Compare July 10, 2026 20:22
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent panel: thread reassigned to the wrong git-worktree group when navigating the file tree (nested worktrees)

1 participant