Skip to content

fix: reset chat mode when switching to session with customAgentTarget#308010

Merged
DonJayamanne merged 3 commits intomainfrom
DonJayamanne/fix-chat-response-filter
Apr 7, 2026
Merged

fix: reset chat mode when switching to session with customAgentTarget#308010
DonJayamanne merged 3 commits intomainfrom
DonJayamanne/fix-chat-response-filter

Conversation

@DonJayamanne
Copy link
Copy Markdown
Contributor

Fixes #307118

When switching from Local to CLI, the Ask/Plan mode incorrectly persisted because the ModePickerActionItem captured customAgentTarget once 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, chatInputPart validated the selected model on session switch but never validated the mode.

This PR makes the mode picker dynamically evaluate the customAgentTarget each time the dropdown is opened, and adds a checkModeInSessionPool() method (analogous to the existing checkModelInSessionPool()) that resets invalid modes to Agent when switching to a session type with a customAgentTarget.

How to test:

  1. Open Copilot Chat, switch to "Local" provider
  2. Select Ask or Plan mode
  3. Switch to CLI provider
  4. Verify the mode resets to Agent and the dropdown only shows valid modes

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>
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

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 ModePickerActionItem choose its dropdown action provider dynamically based on the current customAgentTarget.
  • Add checkModeInSessionPool() to reset invalid modes to Agent when entering a session type with a customAgentTarget.
  • 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 before preselectModelFromSessionHistory(), but preselectModelFromSessionHistory() can change the mode (via modeInfo.modeInstructions.uri). If the last request in the new session references a mode that is invalid for the session’s customAgentTarget, the mode will be re-set after this validation and the UI can still end up in an invalid mode. Consider running checkModeInSessionPool() after preselectModelFromSessionHistory() (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

Comment thread src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts Outdated
DonJayamanne and others added 2 commits April 7, 2026 09:59
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>
@DonJayamanne DonJayamanne marked this pull request as ready for review April 7, 2026 02:22
@DonJayamanne DonJayamanne merged commit 1178013 into main Apr 7, 2026
19 checks passed
@DonJayamanne DonJayamanne deleted the DonJayamanne/fix-chat-response-filter branch April 7, 2026 03:29
@vs-code-engineering vs-code-engineering bot added this to the 1.116.0 milestone Apr 7, 2026
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.

Plan/Ask model agents visible in Copilot CLI

3 participants