Skip to content

Fix deleting forked session showing wrong confirmation dialog#313205

Merged
sandy081 merged 1 commit intomainfrom
sandy081/fix-delete-forked-session
Apr 29, 2026
Merged

Fix deleting forked session showing wrong confirmation dialog#313205
sandy081 merged 1 commit intomainfrom
sandy081/fix-delete-forked-session

Conversation

@sandy081
Copy link
Copy Markdown
Member

When clicking X on a sub-session tab, deleteChat checks chatIds.length <= 1 before finding the specific chat by URI. If the grouping cache doesn't include the forked chat (e.g. due to stale sessionParentId metadata), _getChatIdsInGroup returns only the main chat. The chatIds.length <= 1 check then falls through to deleteSession, which shows "delete this session?" and deletes the entire session including the worktree.

Fix: Find the specific chat by URI first, then check if it's the last chat. Only fall through to deleteSession if the chat IS found AND it's the last one. If the chat isn't in the current grouping result, return early instead of accidentally deleting the whole session.

Fixes #313148

When clicking X on a sub-session tab, deleteChat checks chatIds.length
before finding the specific chat by URI. If the grouping cache doesn't
include the forked chat (e.g. due to stale sessionParentId metadata),
_getChatIdsInGroup returns only the main chat. The chatIds.length <= 1
check then falls through to deleteSession, which shows 'delete this
session?' and deletes the entire session including the worktree.

Fix: find the specific chat by URI first. Only fall through to
deleteSession if the chat IS found in the group AND it's the last one.

Fixes #313148

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 11:39
@sandy081 sandy081 enabled auto-merge (squash) April 29, 2026 11:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an edge case in the Agents sessions UI where deleting a forked (sub-)chat tab could incorrectly fall through to deleting the entire session (including its worktree) when the multi-chat grouping cache is stale.

Changes:

  • Reorders deleteChat logic to resolve the specific chat by URI before deciding whether it’s the last chat in the group.
  • Prevents accidental full-session deletion by returning early when the target chat isn’t found in the current grouping result.
Show a summary per file
File Description
src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts Makes deleteChat identify the chat-by-URI before applying the “last chat => delete session” fallback, avoiding unintended session/worktree deletion under stale grouping.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines 1468 to 1478
@@ -1478,6 +1477,11 @@ export class CopilotChatSessionsProvider extends Disposable implements ISessions
return;
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regression fix in deleteChat (returning early when the chat URI isn’t found in the current group) isn’t covered by tests. Given the severity of the original bug (accidentally deleting the whole session/worktree), please add a unit test that calls deleteChat(mainSessionId, forkChatUri) where the fork isn’t grouped under the main session (e.g. due to missing/stale sessionParentId) and asserts that deleteSession is not triggered (model sessions remain unchanged).

Copilot uses AI. Check for mistakes.
@sandy081 sandy081 merged commit a654c50 into main Apr 29, 2026
30 checks passed
@sandy081 sandy081 deleted the sandy081/fix-delete-forked-session branch April 29, 2026 12:53
@vs-code-engineering vs-code-engineering Bot added this to the 1.119.0 milestone Apr 29, 2026
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.

Deleting forked session deleted my worktree

3 participants