Skip to content

sessions: persist closed chats across session switch#323429

Merged
sandy081 merged 1 commit into
mainfrom
agents/preserve-closed-chats-state
Jun 29, 2026
Merged

sessions: persist closed chats across session switch#323429
sandy081 merged 1 commit into
mainfrom
agents/preserve-closed-chats-state

Conversation

@sandy081

Copy link
Copy Markdown
Member

What

Closed (hidden) chats in the Agents window reappeared in the tab strip when you closed a chat, switched the visible session to another session, and switched back. This persists the closed-chat state so closed tabs stay hidden across session switches (and reloads), with only one session visible at a time.

Why

Closed-chat state lived in the VisibleSession wrapper's in-memory set and was only written to storage at save time (onWillSaveState) for visible sessions. Switching the session out of the grid disposes its wrapper before any flush, and reopening rebuilt it from stale state — so the closed set was lost. A first attempt persisted the set reactively from the closedChats observable, but that derivation is closedURIs intersected with loadedChats, so it depended on chats being loaded and on autorun timing, and still failed when a session's chats were re-resolving on switch-back.

How

  • Maintain the closed-chat set deterministically in SessionsService.closeChat/openChat via _setChatClosedState — add the chat URI on close, remove on reopen. Independent of loaded chats / autorun timing.
  • Save-time snapshot prefers the explicitly maintained set over the loaded-chats-only closedChats, so a not-yet-loaded session does not drop it.
  • Added a "closed chats persistence" test suite (incl. close-the-middle-of-three-chats repro). These fail without the fix.
  • Updated SESSIONS.md.

Validated: tsgo typecheck, eslint, layers check, and the new tests pass; tests fail without the fix.

Closed (hidden) chats reappeared when switching the visible session away
and back, because the closed-chat set was only snapshotted at save time
and the session's wrapper (and its in-memory closed set) is disposed on
switch. Persist the set deterministically in closeChat/openChat instead
of deriving it reactively from closedChats (which intersects with loaded
chats), so it survives switches and reloads regardless of load timing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 08:52
@sandy081 sandy081 self-assigned this Jun 29, 2026
@sandy081 sandy081 added the release-cherry-pick Automated cherry-pick between release and main branches label Jun 29, 2026
@sandy081 sandy081 enabled auto-merge (squash) June 29, 2026 08:52
@sandy081 sandy081 added ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch and removed release-cherry-pick Automated cherry-pick between release and main branches labels Jun 29, 2026
@sandy081 sandy081 added this to the 1.127.0 milestone Jun 29, 2026
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsService.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

@vs-code-engineering

Copy link
Copy Markdown
Contributor

This PR will be automatically cherry-picked to release/1.127 when merged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a state-loss bug in the Agents window where closed (hidden) chats could reappear after switching away from a session and back, by persisting the closed-chat set in SessionsService so it survives VisibleSession wrapper disposal and restores correctly on reopen (and across reloads when the session is persisted).

Changes:

  • Persist closed/open chat state deterministically on closeChat/openChat via _setChatClosedState, independent of loaded chats / autorun timing.
  • Adjust save-time session-state snapshotting to prefer the explicitly maintained closed-chat set.
  • Add a dedicated “closed chats persistence” test suite covering the repro (including closing the middle of three chats) and update SESSIONS.md documentation.
Show a summary per file
File Description
src/vs/sessions/services/sessions/browser/sessionsService.ts Persist closed-chat URIs into _sessionStates on close/open and prefer that set when snapshotting state for storage.
src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts Adds regression tests proving closed chats remain closed across session switches and reopen operations.
src/vs/sessions/SESSIONS.md Documents how per-session closed-chat state is maintained and why it must be updated synchronously on close/open.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Low

@sandy081 sandy081 merged commit 6005263 into main Jun 29, 2026
30 checks passed
@sandy081 sandy081 deleted the agents/preserve-closed-chats-state branch June 29, 2026 09:07
@vs-code-engineering vs-code-engineering Bot added release-cherry-pick Automated cherry-pick between release and main branches and removed ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch labels Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-cherry-pick Automated cherry-pick between release and main branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants