Skip to content

feat(chat): enhance model selection logic and session handling - #324843

Merged
Don Jayamanne (DonJayamanne) merged 3 commits into
mainfrom
don/wide-road-runner-refactor
Jul 7, 2026
Merged

Don Jayamanne (DonJayamanne) merged 3 commits into
mainfrom
don/wide-road-runner-refactor

Conversation

@DonJayamanne

@DonJayamanne Don Jayamanne (DonJayamanne) commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor
  • Implemented functions to manage model selection persistence and validation during session switches:

    • shouldDropAgnosticDraftModel: Determines if a draft model should be dropped based on session type compatibility.
    • shouldPersistModelSelection: Checks if a model selection should be persisted based on user actions and session state.
    • shouldSuppressModelPersistenceOnSessionSwitch: Suppresses model persistence during session switches for empty own-pool sessions.
    • shouldRestorePerTypeModelOnSessionSwitch: Restores the persisted model for fresh untitled own-pool sessions.
    • shouldWaitForSessionModel: Decides whether to wait for a session's remembered model to load before applying a default.
  • Enhanced ChatService to backfill missing picker selections from previously saved states during session restoration, ensuring user selections are honored.

  • Added comprehensive tests for new logic and regression scenarios to prevent model selection issues during session transitions.

Fixes #322792

- Implemented functions to manage model selection persistence and validation during session switches:
  - `shouldDropAgnosticDraftModel`: Determines if a draft model should be dropped based on session type compatibility.
  - `shouldPersistModelSelection`: Checks if a model selection should be persisted based on user actions and session state.
  - `shouldSuppressModelPersistenceOnSessionSwitch`: Suppresses model persistence during session switches for empty own-pool sessions.
  - `shouldRestorePerTypeModelOnSessionSwitch`: Restores the persisted model for fresh untitled own-pool sessions.
  - `shouldWaitForSessionModel`: Decides whether to wait for a session's remembered model to load before applying a default.

- Enhanced `ChatService` to backfill missing picker selections from previously saved states during session restoration, ensuring user selections are honored.

- Added comprehensive tests for new logic and regression scenarios to prevent model selection issues during session transitions.
@DonJayamanne
Don Jayamanne (DonJayamanne) force-pushed the don/wide-road-runner-refactor branch from 10359a3 to 5473206 Compare July 7, 2026 23:00
@DonJayamanne
Don Jayamanne (DonJayamanne) changed the base branch from don/wide-roadrunner to main July 7, 2026 23:01
Copilot AI review requested due to automatic review settings July 7, 2026 23:27

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 a set of related model-selection bugs in agent-host chat sessions where switching to (or restoring) a session would revert the picker to the pool default (e.g. Auto/Haiku) instead of the remembered per-harness model, and could corrupt the persisted per-session-type storage key. It also fixes a "custom agent picker flips to a stale agent after send" bug in the mode synchronizer. The approach extracts the decision logic into small, unit-tested pure functions in chatModelSelectionLogic.ts, and rewires chatInputPart.ts to suppress storage writes during a session switch while restoring/waiting for the correct model.

Changes:

  • Adds pure predicates (shouldDropAgnosticDraftModel, shouldPersistModelSelection, shouldSuppressModelPersistenceOnSessionSwitch, shouldRestorePerTypeModelOnSessionSwitch, shouldWaitForSessionModel) and threads them through ChatInputPart, replacing the removed _getRememberedSessionTypeModel seeding with a session-switch guard + a cold-restore wait (_waitForSessionModel) and late custom-mode re-apply (_restorePersistedCustomModeIfAvailable).
  • Refactors the large onDidChangeViewModel handler into named helpers (handleViewModelChange and friends) and adds backfillRestoredPickerState in ChatService to recover dropped picker selections at cold restore.
  • Restricts AgentHostModeSynchronizer to only seed the shared per-scheme agent into untitled sessions via isUntitledChatSession.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/widget/input/chatModelSelectionLogic.ts Adds five exported pure decision helpers governing draft-model dropping, persistence suppression, per-type restore, and cold-restore waiting.
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts Wires session-switch decisions, adds authoritative-wait guarding of persistence, _waitForSessionModel, _restorePersistedCustomModeIfAvailable, and extracts the view-model-change handler into helpers.
src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts Adds backfillRestoredPickerState to recover model/mode from saved state during remote session restore.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostModeSynchronizer.ts Guards the shared per-scheme agent seed to untitled sessions only.
src/vs/workbench/contrib/chat/test/browser/widget/input/chatModelSelectionLogic.test.ts Adds predicate tests and a storage-write "ledger" simulation of the session-switch sequence, including a negative control.
src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts Adds tests for backfillRestoredPickerState.
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostModeSynchronizer.test.ts Adds untitled/established coverage for the new seed guard.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Medium

@DonJayamanne
Don Jayamanne (DonJayamanne) marked this pull request as ready for review July 7, 2026 23:49
@DonJayamanne
Don Jayamanne (DonJayamanne) enabled auto-merge (squash) July 7, 2026 23:49
@DonJayamanne
Don Jayamanne (DonJayamanne) merged commit 8fa554d into main Jul 7, 2026
30 checks passed
@DonJayamanne
Don Jayamanne (DonJayamanne) deleted the don/wide-road-runner-refactor branch July 7, 2026 23:56
@vs-code-engineering vs-code-engineering Bot added this to the 1.129.0 milestone Jul 7, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 22, 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

3 participants