Skip to content

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

Open
SmolSmolStar wants to merge 1 commit 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 1 commit 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

…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>
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.

1 participant