Repository navigation
fix(agent-manager): select nearest session after worktree deletion - #13714
Merged
Merged
Conversation
marius-kilocode
enabled auto-merge
September 3, 2026 08:04
WebReflection
approved these changes
Sep 3, 2026
This was referenced Sep 6, 2026
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.
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
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:
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.
After: the surviving worktree is selected, its collapsed section is expanded, and its session tab is restored.