Skip to content

fix: multi-agent sessions survive group deletion on restart#174

Merged
PureWeen merged 2 commits intomainfrom
fix/delete-group-orphaned-sessions
Feb 22, 2026
Merged

fix: multi-agent sessions survive group deletion on restart#174
PureWeen merged 2 commits intomainfrom
fix/delete-group-orphaned-sessions

Conversation

@PureWeen
Copy link
Owner

Problem

Deleting a multi-agent group (e.g., Code Review Team) left orphaned sessions in active-sessions.json. On app restart, those sessions reappeared without their group.

Root Cause

DeleteGroup marks sessions as IsHidden and calls CloseSessionAsync in a fire-and-forget Task.Run. If the app restarts before CloseSessionAsync completes:

  1. Session IDs weren't in _closedSessionIds
  2. SaveActiveSessionsToDisk's merge logic re-added them from the existing file

Fix

In DeleteGroup, immediately:

  • Add session IDs to _closedSessionIds (prevents merge re-adding)
  • Call SaveActiveSessionsToDisk() (persists the exclusion before restart)

8-line change in CopilotService.Organization.cs.

Tests (5 new, 1126 total passing)

  • Merge-level: proves sessions survive without closedIds, excluded with closedIds
  • Integration: verifies IsHidden set on real sessions after DeleteGroup
  • Integration: verifies _closedSessionIds populated with deleted session IDs

PureWeen and others added 2 commits February 21, 2026 23:24
DeleteGroup marks sessions as IsHidden and fires CloseSessionAsync in a
Task.Run, but if the app restarts before CloseSessionAsync completes,
the sessions reappear because:
1. Their IDs aren't in _closedSessionIds
2. SaveActiveSessionsToDisk uses merge logic that re-adds entries from
   the existing file unless they're in the closed set

Fix: In DeleteGroup, immediately add session IDs to _closedSessionIds
and call SaveActiveSessionsToDisk() before the fire-and-forget close.

Added 5 tests:
- 2 merge-level tests proving sessions survive/excluded based on closedIds
- 2 integration tests verifying IsHidden on real sessions
- 1 integration test verifying _closedSessionIds is populated

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…stence

Addresses code review finding that Demo mode skips SaveActiveSessionsToDisk,
leaving the critical save call untested. This test simulates the snapshot+merge
pipeline directly, verifying that sessions from a deleted group are excluded
via _closedSessionIds while surviving sessions are preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PureWeen PureWeen merged commit f20a7b6 into main Feb 22, 2026
@PureWeen PureWeen deleted the fix/delete-group-orphaned-sessions branch February 22, 2026 13:47
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