Skip to content

fix(session): switch session when active child/grandchild's ancestor is deleted#376

Merged
sudo-tee merged 1 commit into
sudo-tee:mainfrom
hermandavid:main
May 19, 2026
Merged

fix(session): switch session when active child/grandchild's ancestor is deleted#376
sudo-tee merged 1 commit into
sudo-tee:mainfrom
hermandavid:main

Conversation

@hermandavid
Copy link
Copy Markdown
Contributor

Problem

When deleting a parent session from the session picker while switched into a child/grandchild subagent session, two bugs occurred:

  1. No session switch triggered — the deletion check only compared the active session ID directly against the deleted set, so deleting an ancestor while inside a child session was not detected.

  2. Agent mode stuck on subagent — when the "no remaining sessions" fallback created a new session, the agent mode was never reset. If the active session was running under a subagent (e.g. explore), the new session inherited that mode with no way to switch back.

Solution

  • Ancestor-aware deletion detection: a new _is_session_or_ancestor_deleted helper walks up the parentID chain to detect whether any ancestor of the active session is being deleted.

  • Agent mode reset: when no remaining sessions exist after deletion, state.model.clear() and agent_model.ensure_current_mode() are now called before creating the new session — matching the reset already present in switch_session.

Test coverage

  • Unit tests for _is_session_or_ancestor_deleted (direct, parent, grandparent, sibling, unrelated cases)
  • Integration tests verifying session switch on ancestor deletion and agent mode reset when all sessions are deleted

@hermandavid
Copy link
Copy Markdown
Contributor Author

Failing CI should be unrelated. There was a regression in nightly neovim that was fixed today.

@sudo-tee
Copy link
Copy Markdown
Owner

@hermandavid

Thanks for the fix.

@sudo-tee sudo-tee merged commit 1a40067 into sudo-tee:main May 19, 2026
8 of 15 checks passed
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