Skip to content

Preserve selected Agent Host model for new Copilot CLI sessions in Agents window#316876

Open
Chulong-Li wants to merge 3 commits into
microsoft:mainfrom
Chulong-Li:fix/316044-agent-host-model-selection-minimal
Open

Preserve selected Agent Host model for new Copilot CLI sessions in Agents window#316876
Chulong-Li wants to merge 3 commits into
microsoft:mainfrom
Chulong-Li:fix/316044-agent-host-model-selection-minimal

Conversation

@Chulong-Li
Copy link
Copy Markdown
Member

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 userSelectedModelId and the corresponding model configuration when the NewSession already 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 cached modelId and modelSelection could 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-turn SessionModelChanged action corrects it.

Figure 1.1: The session automatically switches to Claude Sonnet 4.6 Medium even though GPT-5.5 XHigh was initially selected
image

Fix

  • Applies the resolved picker model to new untitled Agent Host sessions before first send.
  • Uses the current picker selection before falling back to the stored profile model for new untitled sessions.
  • Avoids changing sessions that already have an explicit model.
  • Keeps picker state scoped to the Agent Host resource scheme.
  • Updates cached session model state when SessionSummaryChanged includes changes.model, including explicit model clearing.
  • Queues the selected model while eager backend session creation is in flight.
  • Dispatches SessionModelChanged once eager createSession() 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
image


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
image


Figure 2.3: After completion, the session still displays the user-selected model rather than Claude Sonnet 4.6 Medium
image

Chulong Li (M365) and others added 3 commits May 17, 2026 19:40
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>
Copilot AI review requested due to automatic review settings May 17, 2026 13:56
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 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 SessionSummaryChanged includes changes.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).
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.

Model Selection Resets in Agents UX

3 participants