Skip to content

fix: scope close-session grouping to one repo when worktree names collide - #1014

Open
SmolSmolStar wants to merge 2 commits into
web3dev1337:mainfrom
SmolSmolStar:fix/close-session-group-scoped-to-repo
Open

fix: scope close-session grouping to one repo when worktree names collide#1014
SmolSmolStar wants to merge 2 commits into
web3dev1337:mainfrom
SmolSmolStar:fix/close-session-group-scoped-to-repo

Conversation

@SmolSmolStar

Copy link
Copy Markdown
Contributor

Problem

Closing a terminal with the x close button (or destroy-session) expands to the worktree group so the agent + server terminals die together. getSessionGroupIds queried sessions by both the repo-scoped key (repo-work1) and the bare worktree id (work1).

In a mixed-repo workspace where several repos each have a work1 worktree (the default naming), the bare-key lookup matches every repo's work1 sessions. Clicking x on one terminal destroys every worktree's sessions in the workspace (only differently-named worktrees survive).

Reproduced live on 0.1.22: closing sandbox-work1-claude also destroyed the sessions of agent-workspace/work1, USDUC/work1 and Cat-Code-Academy/work1.

Fix

  • getSessionGroupIds: derive repo/worktree via parseWorktreeKey from the session id when the session record lacks them, and query only the repo-scoped key. The bare worktree id is used only when the repository is genuinely unknown (legacy single-repo ids like work1-claude).
  • getSessionIdsForWorktree is unchanged, so bare-token lookups from other call sites behave as before.

Tests

  • New regression cases in tests/unit/sessionManager.closeSession.test.js: repos sharing a worktree name stay scoped, with and without repositoryName on the session records; legacy pair grouping still works.
  • Full unit suite: 103 suites / 603 tests pass.
  • Pre-fix code run against the new scenario returns all 8 sessions across 4 repos; patched code returns exactly the clicked worktree's pair.

🤖 Generated with Claude Code

SmolSmolStar and others added 2 commits July 12, 2026 23:58
…lide

Closing a terminal expands to its worktree group so the agent and server
terminals live and die together. getSessionGroupIds looked sessions up by
BOTH the repo-scoped key (repo-work1) and the bare worktree id (work1).
In a mixed-repo workspace where several repos each have a work1 worktree,
the bare-key lookup matched every repo's work1 sessions — so clicking the
new x close button on one terminal killed every worktree in the workspace
(only differently-named worktrees like work4 survived).

- getSessionGroupIds: derive repo/worktree via parseWorktreeKey from the
  session id when the session record lacks them, and query only the
  repo-scoped key; the bare worktree id is used only when the repository
  is genuinely unknown (legacy single-repo ids like work1-claude).
- tests: regression cases for repos sharing a worktree name, with and
  without repositoryName on the session records.

Reproduced live: closing sandbox-work1-claude destroyed the sessions of
agent-workspace/work1, USDUC/work1 and Cat-Code-Academy/work1 as well.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…web3dev1337#1015

Cherry-picks the richer 4-repos-plus-work4 regression test from the sibling
PR web3dev1337#1015 so its coverage survives even though that PR's production change is
superseded by this one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@web3dev1337

Copy link
Copy Markdown
Owner

Reviewed as part of an open-PR sweep, side-by-side with sibling PR #1015 (both patch the same lines of getSessionGroupIds). Both were run through a behavioral harness against 4 scenarios: identical results everywhere except one adversarial edge (bare session id + populated repositoryName) where this PR stays correctly scoped and #1015's unconditional bare-prefix second key regresses. This PR also reuses parseWorktreeKey instead of duplicating parsing, and queries one key instead of two. Cherry-picked #1015's richer 4-repo regression test on top so its coverage isn't lost. Verdict: merge this one.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants