Skip to content

Don't reclassify an emptied chat session as never-used - #333629

Open
Ahmed Mahdy (abmahdy) wants to merge 3 commits into
microsoft:mainfrom
abmahdy:fix/empty-session-hidden-from-history
Open

Don't reclassify an emptied chat session as never-used#333629
Ahmed Mahdy (abmahdy) wants to merge 3 commits into
microsoft:mainfrom
abmahdy:fix/empty-session-hidden-from-history

Conversation

@abmahdy

Copy link
Copy Markdown
Contributor

Fixes #333623

A local chat session whose requests are all removed — restoring the checkpoint on the first request, for example — keeps its title and full transcript on disk but disappears from the Chat Sessions list for good. Before it goes it also flickers in and out.

Why

Two paths decide session-list membership and they disagree about empty sessions.

getHistorySessionItems skips sessions that are currently loaded, and excludes empty ones:

.filter(entry => !this._sessionModels.has(LocalChatSessionUri.forSession(entry.sessionId))
    && entry.initialLocation === ChatAgentLocation.Chat
    && !entry.isEmpty)

shouldBeInHistory, which covers the loaded models, applies no emptiness filter at all:

return !entry.isImported && !entry.isDeleted
    && !!LocalChatSessionUri.parseLocalSessionId(entry.sessionResource)
    && entry.initialLocation === ChatAgentLocation.Chat;

So the same session is visible while its model is in memory and hidden once it is evicted — the flicker — and permanently gone after the last eviction.

isEmpty itself is written correctly from the live model (getSessionMetadataSync), so this is not a stale index. The problem is that "has no requests right now" is conflated with "was never used", and only the latter is what the filter is for.

The fix

Once a session has held requests, keep isEmpty: false. Sessions that never had any are still reported as empty and stay out of the list, so never-used "New Chat" entries remain hidden exactly as before.

The guard is applied at every site that writes an index entry — writeSession, writeSessionMetadataOnly, and the synchronous shutdown flush updateAndFlushIndexSync — so a shutdown flush can't undo it.

Tests

Two tests in chatSessionStore.test.ts:

  • storeSessions marks a session with no requests as empty — pins the existing behaviour so the guard can't over-apply and start listing never-used sessions.
  • storeSessions keeps a session non-empty after all of its requests are removed — the regression.

MockChatModel.getRequests() returned a hard-coded [] while the class already carried a requests field; it now returns that field, which is what makes request counts expressible in tests.

Negative control: with the guard disabled, the regression test fails with true !== false while the companion test still passes.

Validation

  • npm run typecheck-client — no errors in contrib/chat. (21 pre-existing errors remain in platform/agentHost, all from a stale local @github/copilot-sdk; untouched by this change.)
  • Full test-node suite: 15059 passing. The whole ChatSessionStore suite is green. The one failure is Request Service > Kerberos lookup, an environment artifact on a corporate network, unrelated to this change.

`isEmpty` keeps never-used sessions out of the history list, which filters on it
in `getHistorySessionItems`. Removing every request from a session that did have
them - restoring the checkpoint on the first request, for example - flipped the
stored entry back to `isEmpty: true`, so the session was filtered out of history
permanently even though its title and full transcript were still on disk.

Before that final eviction it also flickered: the live-model path
(`shouldBeInHistory`) applies no emptiness filter, while the history path skips
sessions that are currently loaded, so the same session was listed while its
model was in memory and gone once it was evicted.

Keep `isEmpty` false once a session has held requests. Sessions that never had
any are still reported empty and stay out of the list.

Fixes microsoft#333623

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7544f2e8-0346-4710-91b2-4abf34955191
Copilot AI balanced review requested due to automatic review settings August 31, 2026 19:32

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

Preserves previously used chat sessions in history after all requests are removed.

Changes:

  • Retains non-empty metadata across all index-write paths.
  • Updates mocks and adds regression coverage for emptied sessions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
chatSessionStore.ts Preserves prior non-empty state.
chatSessionStore.test.ts Tests empty-session classification.
mockChatModel.ts Exposes configurable mock requests.
Suppressed comments (1)

src/vs/workbench/contrib/chat/common/model/chatSessionStore.ts:906

  • isEmpty is optional on legacy index entries, so this falsy check treats an unknown value as proof that the session was previously used. When such an entry is next written with zero requests, it is forced to false and can be surfaced as a used session. Preserve only an explicitly recorded false value.
	if (next.isEmpty && previous && !previous.isEmpty) {

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/workbench/contrib/chat/common/model/chatSessionStore.ts
Comment thread src/vs/workbench/contrib/chat/common/model/chatSessionStore.ts
Comment thread src/vs/workbench/contrib/chat/test/common/model/chatSessionStore.test.ts Outdated

@karelyvalenzuela879-lang karelyvalenzuela879-lang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

abmahdy:fix/empty-session-hidden-from-history

Addressed inline review comment ids: 3897745274,3897745343,3897745401
The macOS/Browser job failed on 9 CSS/layout assertions in
vs/sessions/contrib/chat/test/browser/chatView.test, a suite this PR does
not touch. Linux/Browser and Windows/Browser both passed on the same commit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7544f2e8-0346-4710-91b2-4abf34955191
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.

Chat session emptied by checkpoint restore becomes permanently unreachable and flickers in the sessions list

4 participants