Preserve selected Agent Host model for new Copilot CLI sessions in Agents window#316876
Open
Chulong-Li wants to merge 3 commits into
Open
Preserve selected Agent Host model for new Copilot CLI sessions in Agents window#316876Chulong-Li wants to merge 3 commits into
Chulong-Li wants to merge 3 commits into
Conversation
Preserve the current agent-host model selection when initializing new untitled sessions and keep cached session models in sync with summary updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a new session is created, eagerCreate() fires createSession() to pre-warm the backend before the first message is sent. The backend initialises its session summary with the default model (Claude Sonnet 4.6 Medium) because no model was dispatched at creation time. If the user had already selected a different model (e.g. GPT-5.5 XHigh) in the picker, that selection was stored locally on NewSession but never propagated to the backend until AgentHostSessionHandler._handleTurn() dispatched SessionModelChanged just before the first turn. This caused a brief visible flicker where the UI showed Claude Sonnet 4.6 Medium between the session start and the first-turn dispatch. Fix: store the pending ModelSelection on NewSession when setSelectedModelId is called. After eagerCreate() completes (createSession round-trip resolves, _subscription is set), dispatch SessionModelChanged immediately to align the backend summary with the user's selection. If setModel is called after eager create has already finished, dispatch right away. 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 model-selection race in the Agents window for Agent Host (Copilot CLI) sessions by ensuring the user-selected model is applied to new/untitled sessions early enough to avoid the backend briefly using its default model, and by keeping cached session model state in sync when summaries change.
Changes:
- Queue and flush model selection to the eagerly-created backend session once
createSession()completes (or immediately if already created). - Prefer the current picker selection over stored profile state when resolving the model for new/untitled sessions, while scoping picker state per Agent Host resource scheme.
- Update cached session model state when
SessionSummaryChangedincludeschanges.model(including explicit clears), with added test coverage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts | Queues/flushes model changes for eager session creation and updates cached model state on summary changes. |
| src/vs/sessions/contrib/providers/agentHost/browser/agentHostModelPicker.ts | Resolves model using current picker state before stored state for untitled sessions; scopes state by resource scheme and avoids redundant pushes. |
| src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts | Adds coverage for queued vs immediate model dispatch around eager create and for summary-driven cached model updates/clears. |
| src/vs/sessions/contrib/providers/agentHost/test/browser/agentHostModelPicker.test.ts | Adds coverage for preferring current picker model over stored model for new/untitled sessions. |
| // If the eager backend session has already been created, dispatch the | ||
| // model change immediately so the backend summary reflects the correct | ||
| // model before the first turn starts, preventing the transient flicker | ||
| // to the default model (Claude Sonnet 4.6 Medium). |
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 #316044
Summary
This fixes an Agent Host model-selection race where the model picker could show the intended model, such as GPT-5.5 XHigh or Claude Opus 4.7, while a new Copilot CLI session still briefly used or displayed the backend default model, Claude Sonnet 4.6 Medium.
The change ensures that new untitled Agent Host sessions receive the selected model before the first message is sent, and that eagerly-created backend sessions are updated with the selected model as soon as they are available. This keeps the picker, session cache, and backend session summary aligned during new session startup.
Root cause
The first-send path only includes
userSelectedModelIdand the corresponding model configuration when theNewSessionalready has a selected model.For new untitled Agent Host sessions, the picker could resolve and display a model from current picker state or stored profile state without pushing that model into the backing session before send. In that case, the first request was sent without
userSelectedModelId, allowing the backend to fall back to its default model.Cached session model state was also only updated from dedicated model-change actions. When a session summary update included
changes.model, the cachedmodelIdandmodelSelectioncould remain stale.There was one related startup flicker:
NewSession.eagerCreate()creates the backend session before the selected model is propagated to it. The backend can initially summarize the session with its default model, Claude Sonnet 4.6 Medium, before the later first-turnSessionModelChangedaction corrects it.Figure 1.1: The session automatically switches to Claude Sonnet 4.6 Medium even though GPT-5.5 XHigh was initially selected

Fix
SessionSummaryChangedincludeschanges.model, including explicit model clearing.SessionModelChangedonce eagercreateSession()completes, or immediately if the eager backend session already exists, preventing the transient Claude Sonnet 4.6 Medium flicker.Validation
Figure 2.1: Start a new Copilot CLI session with GPT-5.5 XHigh selected in the model picker



Figure 2.2: During processing, the UI continues to display the user-selected model instead of briefly falling back to Claude Sonnet 4.6 Medium
Figure 2.3: After completion, the session still displays the user-selected model rather than Claude Sonnet 4.6 Medium