Skip to content

Show new local chat sessions in list without manual refresh#320306

Draft
roblourens wants to merge 2 commits into
mainfrom
roblou/local-session-list-race
Draft

Show new local chat sessions in list without manual refresh#320306
roblourens wants to merge 2 commits into
mainfrom
roblou/local-session-list-race

Conversation

@roblourens
Copy link
Copy Markdown
Member

@roblourens roblourens commented Jun 7, 2026

Fixes #306169

Problem

When starting a session in the VS Code editor window (the "local" harness), the new session often didn't appear in the Chat Sessions list until the Refresh button was clicked.

Root cause

The list is driven by LocalAgentsSessionsController. A brand-new local session has no requests when its chat model is created, so the initial refresh() correctly excludes it (a session only becomes listable once it hasRequests).

Adding a session to the list could only happen via refresh(). The per-model change listener tryUpdateLiveSessionItem could only update items already present in _items — it returned early with if (!existing) return;, so it could never add a newly-qualifying session.

This made the outcome an event-ordering race between refresh() reading live items and the model's first-request event:

  • If the first request was observed by refresh() then the session was added.
  • If the request landed after refresh() read the items, the only follow-up event (the model change listener) bailed for the not-yet-listed session, so it stayed invisible until a manual refresh.

That timing dependence is why it worked sometimes. In the common flow where the chat model is created empty when the view opens and the request is sent later, refresh() always loses the race, so it consistently failed.

Fix

tryUpdateLiveSessionItem now builds the item from the current model state using toChatSessionItem (the same qualification rules as the full refresh) and adds it when the model becomes listable, regardless of whether an item already existed — while still deduping unchanged items via isEqual. The session now appears the moment its first request is sent, independent of refresh timing.

Tests

  • Added a regression test ("should add a new session once it gains its first request (without manual refresh)") and extended the mock model with a setHasRequests helper to simulate the no-requests to has-requests transition.
  • Updated the pre-existing "model progress changes" event count from 3 to 2: the session is now added via the model-change path, so the later refresh() dedupes instead of firing a separate add event.

All 22 tests in the suite pass; type-check and full client compile are clean.

Note: a user reported the same symptom for the agent-host harness, but that path goes through a different provider and couldn't be reproduced — this change specifically addresses the reproducible local-harness case.

(Written by Copilot)

A brand-new local session has no requests when its chat model is created,
so the initial refresh() correctly excludes it. When the first request was
sent, the per-model change listener (tryUpdateLiveSessionItem) bailed out
early because the session was not yet in _items, so it was never added until
something triggered a full refresh. This was effectively an event-ordering
race between refresh() reading live items and the model's first-request
event.

Build the item from the current model state and add it when it becomes
listable, regardless of whether an item already existed, while still
deduping unchanged items. Update the affected event-count assertion and add
a regression test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

This PR fixes a race in the local chat sessions provider where newly-created local sessions (initially empty) could fail to appear in the Chat Sessions list until a manual refresh. It updates the live model-change path to add sessions as soon as they become “listable” (i.e., once they have their first request), and adds a regression test to lock in the behavior.

Changes:

  • Update LocalAgentsSessionsController.tryUpdateLiveSessionItem to build/qualify a session item from the current model state and add it even if it wasn’t previously present.
  • Add a regression test for the “first request makes session appear without refresh” scenario.
  • Extend the mock chat model used in tests to simulate a hasRequests: false -> true transition, and adjust an existing event-count assertion.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/agentSessions/localAgentSessionsController.ts Enables live session-item creation on model changes so newly-qualifying local sessions appear without manual refresh.
src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts Adds coverage for the regression and extends the mock model to simulate hasRequests transitions.

Copilot's findings

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

- Gate tryUpdateLiveSessionItem on model.hasRequests before building the
  full detail, avoiding the expensive diff-stats computation in
  chatModelToChatDetail on every model change for non-listable models.
- Fire a correctly-shaped IChatAddRequestEvent (with request payload) from
  the test mock's setHasRequests helper, only when a request is added.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Local chat sessions do not appear until I click refresh

2 participants