Skip to content

chat: remember focused agent session's model as last-used - #323393

Merged
Don Jayamanne (DonJayamanne) merged 5 commits into
microsoft:mainfrom
DonJayamanne:agents/root-cause-analysis-fix-proposal
Jun 29, 2026
Merged

Don Jayamanne (DonJayamanne) merged 5 commits into
microsoft:mainfrom
DonJayamanne:agents/root-cause-analysis-fix-proposal

Conversation

@DonJayamanne

@DonJayamanne Don Jayamanne (DonJayamanne) commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

New chat editors for agent-host session types (e.g. Copilot Agent Host) default the model picker to Auto even when every open editor of that type is on a non-Auto model (e.g. Opus 4.8).

Follow-up to the #322792 fix. The per-agent last-used key chat.currentLanguageModel.<location>.<sessionType> is only written by setCurrentLanguageModel, i.e. on explicit user picks. Sessions restored to a model that already matches their saved state take the _syncFromModel keep path and never call it — so the visible Opus editors never record Opus. The key keeps the last explicit value (auto), and a fresh editor with no session state reads that and shows Auto.

Fix

Record the focused session's resolved model as the last-used model for its type, at the same focus chokepoint that already records the last-used agent (ChatWidgetService.recordLastUsedSessionType). Storage-key knowledge stays inside ChatInputPart via recordCurrentModelAsSessionTypeDefault().

Guarded to only write when:

  • the session type owns its own model pool,
  • the model is resolved and present in the pool (avoids transient auto during async load),
  • the session isn't local.

Tests

  • New shouldRecordSessionTypeDefaultModel pure function + 6 unit cases (record vs. local / no-pool / unresolved / not-in-pool / no-type).
  • typecheck-client and eslint clean.

Notes

  • Diagnostic [ModelPickerDbg] logging from the prior research is left as-is.

Fixes #322792

New chat editors for agent-host session types (e.g. Copilot Agent Host)
defaulted to "Auto" even when open editors used a non-Auto model. The
per-agent last-used key was only written on explicit picks, so restored
sessions that kept their model (the _syncFromModel `keep` path) never
recorded it; a fresh editor then read the stale "auto" value.

Record the focused session's resolved model into the same per-session-type
key on focus, so new editors restore it. Guarded to skip local sessions,
types without their own model pool, and unresolved/transient models during
async load. Adds shouldRecordSessionTypeDefaultModel + unit tests.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 29, 2026 04:35

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

This PR fixes model picker defaults for agent-host chat editors by ensuring the focused session’s resolved model is persisted as the last-used model for that session type, even when the model was restored implicitly (the “keep” path) rather than explicitly picked by the user.

Changes:

  • Add shouldRecordSessionTypeDefaultModel decision helper to gate when a focused session should update the per-session-type last-used model.
  • Record the focused widget’s current resolved model as the session-type default during the existing “record last used session type” focus chokepoint.
  • Add focused unit coverage for the new decision helper with multiple guard/skip cases.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/test/browser/widget/input/chatModelSelectionLogic.test.ts Adds unit tests for the new “should record default model” decision helper.
src/vs/workbench/contrib/chat/browser/widget/input/chatModelSelectionLogic.ts Introduces shouldRecordSessionTypeDefaultModel helper to ensure safe persistence conditions.
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts Adds recordCurrentModelAsSessionTypeDefault() to persist the focused session’s resolved model for its session type.
src/vs/workbench/contrib/chat/browser/widget/chatWidgetService.ts Hooks model-recording into the existing last-focused session type tracking.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Low

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

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.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Low

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

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.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Low

@DonJayamanne
Don Jayamanne (DonJayamanne) marked this pull request as ready for review June 29, 2026 05:14
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@DonJayamanne
Don Jayamanne (DonJayamanne) merged commit 81d97ff into microsoft:main Jun 29, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.128.0 milestone Jun 29, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model switches to Auto for AH in every new workspace

4 participants