Show new local chat sessions in list without manual refresh#320306
Draft
roblourens wants to merge 2 commits into
Draft
Show new local chat sessions in list without manual refresh#320306roblourens wants to merge 2 commits into
roblourens wants to merge 2 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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.tryUpdateLiveSessionItemto 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 -> truetransition, 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 initialrefresh()correctly excludes it (a session only becomes listable once ithasRequests).Adding a session to the list could only happen via
refresh(). The per-model change listenertryUpdateLiveSessionItemcould only update items already present in_items— it returned early withif (!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:refresh()then the session was added.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
tryUpdateLiveSessionItemnow builds the item from the current model state usingtoChatSessionItem(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 viaisEqual. The session now appears the moment its first request is sent, independent of refresh timing.Tests
setHasRequestshelper to simulate the no-requests to has-requests transition.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)