Skip to content

fix(agent-manager): select nearest session after worktree deletion - #13714

Merged
marius-kilocode merged 2 commits into
mainfrom
fix-worktree-session-selection
Sep 3, 2026
Merged

marius-kilocode merged 2 commits into
mainfrom
fix-worktree-session-selection

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Deleting the selected worktree can leave Agent Manager on “No sessions open” while another worktree still has a session. The legacy sidebar can select an empty neighbor. The multi-project sidebar does not select a replacement at all.

Why This Change Was Made

Choose the nearest worktree with a managed session in the current project's sidebar order. Prefer the worktree below when distances are equal. Skip empty, stale, or unavailable worktrees and include collapsed sections, expanding the selected section when needed. Use the existing worktree-scoped tab restoration so the replacement session belongs to the selected worktree.

User Impact

  • Continue in a nearby worktree's session after deletion or stale-worktree removal.
  • Keep the current session selected when deleting an inactive worktree.
  • Fall back to Local if no eligible worktrees remain. Do not switch projects or create a session automatically.

Evidence

Reproduced both failure paths in an isolated VS Code self-test workspace before the fix. Verified the rebuilt extension through the real sidebar controls, with assertions for both the expected worktree ID and session ID:

  • Skip an empty neighbor and open the remaining session.
  • Select the remaining session in multi-project mode.
  • Preserve selection when deleting an inactive worktree.
  • Expand a collapsed section and select its session.
  • Select Local after deleting the final worktree.

137 focused navigation, project-state, selection, and architecture tests pass. The full extension unit suite also passes: 4,652 passed, 1 skipped, 0 failed. Extension compile, lint, typecheck, Knip, and the Kilo change-marker guard pass. The UI test used disposable empty sessions without model calls. Screenshots are cropped to exclude account and model information.

Before: a worktree with a session remains, but no session tab is open.

Agent Manager shows No sessions open even though the remaining worktree has one session

After: the surviving worktree is selected, its collapsed section is expanded, and its session tab is restored.

Agent Manager selects the surviving worktree and opens its session tab

@marius-kilocode
marius-kilocode merged commit 0083235 into main Sep 3, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the fix-worktree-session-selection branch September 3, 2026 08:44
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