fix: closing one worktree closes every repo's same-numbered worktree#1015
Open
SmolSmolStar wants to merge 1 commit into
Open
fix: closing one worktree closes every repo's same-numbered worktree#1015SmolSmolStar wants to merge 1 commit into
SmolSmolStar wants to merge 1 commit into
Conversation
… worktree
In a mixed-repo workspace, closing a single worktree's terminal (the close-process
button) could close every OTHER repo's worktree that shared the same number — e.g.
clicking close on sandbox/work1 also closed agent-workspace/work1, USDUC/work1 and
Cat-Code-Academy/work1, leaving only the one repo on a different number (work4).
Root cause: SessionManager.getSessionGroupIds looked up the group by two keys —
the repo-scoped `${repo}-${worktree}` AND the bare worktree number (`work1`). The
bare number is not repo-scoped (parseWorktreeKey only treats `<repo>-work<N>` as
scoped), so getSessionIdsForWorktree matched every repo's work1 in the workspace.
The existing tests only covered cross-WORKSPACE scoping (handled by the workspace
filter), so the same-workspace/different-repo collision slipped through.
Fix: only ever key on repo-scoped identifiers — the composed `${repo}-${worktree}`
key and the session id's own repo-scoped prefix (e.g. `sandbox-work1`). Never the
bare worktree number.
Adds a regression test seeding several repos that share `work1` (plus one `work4`)
in one workspace and asserting getSessionGroupIds('sandbox-work1-claude') returns
only sandbox's own sessions. Verified it fails on the old code (returns 4 extra
sessions) and passes with the fix; full suite green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
In a mixed-repo workspace, closing a single worktree's terminal (the close-process
×button) can close every other repo's worktree that shares the same number. Reproduced in the wild: clicking close onsandbox/work1also closedagent-workspace/work1,USDUC/work1, andCat-Code-Academy/work1, leaving onlyTest-game/work4(the one worktree on a different number).Root cause
SessionManager.getSessionGroupIdsbuilds its close-list from two keys:composedKeyis repo-scoped (sandbox-work1, correct), butparsedWorktreeIdis the bare worktree number (work1).parseWorktreeKeyonly treats<repo>-work<N>as repo-scoped, so a barework1lookup ingetSessionIdsForWorktreematches every repo'swork1in the workspace.The existing tests only covered cross-workspace scoping (already handled by the workspace filter), so this same-workspace / different-repo collision slipped through. It's the same class of hazard the repo's own docs call out for
remove-worktree(bare worktree ids nuke all repos).Fix
Only ever key on repo-scoped identifiers:
${repositoryName}-${worktreeId}key, andsandbox-work1).Never the bare worktree number.
Test plan
work1(plus onework4) in a single workspace and assertsgetSessionGroupIds('sandbox-work1-claude')returns only sandbox's own sessions.sessionManager.closeSessionsuite green (9/9),node --checkclean.🤖 Generated with Claude Code