fix: reset chat mode when switching to session with customAgentTarget#308010
Merged
DonJayamanne merged 3 commits intomainfrom Apr 7, 2026
Merged
fix: reset chat mode when switching to session with customAgentTarget#308010DonJayamanne merged 3 commits intomainfrom
DonJayamanne merged 3 commits intomainfrom
Conversation
Fixes #307118 When switching from Local to CLI, Ask/Plan modes persisted because: 1. ModePickerActionItem captured customAgentTarget once at construction, so the dropdown kept showing Local's modes even after switching to CLI. 2. chatInputPart validated the model on session switch but not the mode. Now the mode picker dynamically evaluates the target on each dropdown open, and a new checkModeInSessionPool() resets invalid modes to Agent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an issue where chat mode (Ask/Plan/custom agents) could incorrectly persist when switching to a session type that uses customAgentTarget (e.g. Local → CLI), by making the mode picker target-aware at open time and adding mode validation on session/provider changes.
Changes:
- Make
ModePickerActionItemchoose its dropdown action provider dynamically based on the currentcustomAgentTarget. - Add
checkModeInSessionPool()to reset invalid modes to Agent when entering a session type with acustomAgentTarget. - Invoke mode validation on session type/provider changes alongside existing model validation.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/browser/widget/input/modePickerActionItem.ts | Dynamically selects the action provider at dropdown open time so mode lists reflect the current customAgentTarget. |
| src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts | Adds and wires checkModeInSessionPool() to reset invalid modes when switching session/provider context. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts:1963
checkModeInSessionPool()runs beforepreselectModelFromSessionHistory(), butpreselectModelFromSessionHistory()can change the mode (viamodeInfo.modeInstructions.uri). If the last request in the new session references a mode that is invalid for the session’scustomAgentTarget, the mode will be re-set after this validation and the UI can still end up in an invalid mode. Consider runningcheckModeInSessionPool()afterpreselectModelFromSessionHistory()(or re-validating immediately after setting the mode there).
const newSessionType = this.getCurrentSessionType();
if (e.currentSessionResource && newSessionType !== this._currentSessionType) {
this._currentSessionType = newSessionType;
this.initSelectedModel();
this.checkModelInSessionPool();
this.checkModeInSessionPool();
}
// For contributed sessions with history, pre-select the model
// from the last request so the user resumes with the same model.
this.preselectModelFromSessionHistory();
- Files reviewed: 2/2 changed files
- Comments generated: 2
Pass newSessionType directly from the onDidChangeActiveSessionProvider handler instead of deriving it from the session resource, which may not yet reflect the newly selected provider. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Make the mode picker evaluate the custom agent target each time the dropdown is opened instead of capturing it once at construction time. This ensures the correct modes are shown after switching session types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
justschen
approved these changes
Apr 7, 2026
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 #307118
When switching from Local to CLI, the Ask/Plan mode incorrectly persisted because the
ModePickerActionItemcapturedcustomAgentTargetonce at construction time and used it to statically select the action provider for the dropdown. Since the widget isn't recreated on session switch, the dropdown kept showing Local's full mode list (Ask/Edit/Agent) even in CLI. Additionally,chatInputPartvalidated the selected model on session switch but never validated the mode.This PR makes the mode picker dynamically evaluate the
customAgentTargeteach time the dropdown is opened, and adds acheckModeInSessionPool()method (analogous to the existingcheckModelInSessionPool()) that resets invalid modes to Agent when switching to a session type with acustomAgentTarget.How to test: