Skip to content

fix(chat): route mode switches to the originating pane when widgets share a session (#275200)#310970

Open
maruthang wants to merge 2 commits into
microsoft:mainfrom
maruthang:fix/issue-275200-mode-switch-wrong-pane
Open

fix(chat): route mode switches to the originating pane when widgets share a session (#275200)#310970
maruthang wants to merge 2 commits into
microsoft:mainfrom
maruthang:fix/issue-275200-mode-switch-wrong-pane

Conversation

@maruthang

Copy link
Copy Markdown
Contributor

What — When two chat widgets share a session (e.g. a chat-view pane and a chat-editor pane after "Move Chat to Editor Area"), changing the mode in one no longer silently flips the mode in the other.

WhyToggleChatModeAction resolved the target widget via getWidgetBySessionResource(...), which returns the first match. With two widgets on the same session, the mode change always landed on whichever registered first — not the one whose picker was clicked (#275200).

How — Each ChatInputPart has a unique inputUri, and IChatWidgetService.getWidgetByInputUri already disambiguates by it. Threaded inputUri through IModePickerDelegateModePickerActionItem.runIToggleChatModeArgs so the action can resolve the exact widget. The existing sessionResource path is preserved as a fallback for older callers.

Test plan — Two new unit tests in chatExecuteActions.test.ts: (1) with two widgets sharing a session, a toggle dispatched with inputUri targets widget B not widget A; (2) without inputUri, the existing sessionResource resolution still works. Manual: open a chat session, "Move Chat to Editor Area", pick a different mode in the editor's picker — the panel mode should stay unchanged.

Fixes #275200

Copilot AI review requested due to automatic review settings July 6, 2026 07:51

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 chat mode-routing bug (#275200): when two chat widgets share a session (e.g. a chat-view pane and a chat-editor pane after "Move Chat to Editor Area"), changing the mode in one widget's picker incorrectly changed the mode of the first-registered widget. The fix threads the hosting widget's unique inputUri from the picker delegate into the ToggleAgentModeActionId command args so the action resolves the exact widget via getWidgetByInputUri, preserving the sessionResource path as a fallback for older callers.

Changes:

  • Added an optional inputUri to IToggleChatModeArgs and reordered ToggleChatModeAction resolution to prefer input URI, then session resource, then editing-session context.
  • Added inputUri to IModePickerDelegate, wired it through ModePickerActionItem.run, and supplied it from ChatInputPart.
  • Added two unit tests covering the multi-widget disambiguation and the sessionResource back-compat fallback.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.ts Adds inputUri to IToggleChatModeArgs and prefers input-URI resolution with session-resource/editing-context fallbacks.
src/vs/workbench/contrib/chat/browser/widget/input/modePickerActionItem.ts Adds optional inputUri to the delegate and forwards it in the ToggleAgentModeActionId command call.
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts Supplies the widget's unique inputUri to the mode picker delegate.
src/vs/workbench/contrib/chat/test/browser/actions/chatExecuteActions.test.ts Adds a ToggleChatModeAction suite verifying inputUri-based targeting and sessionResource fallback.

@justschen

Copy link
Copy Markdown
Collaborator

thanks! will give this a look!

@justschen justschen added this to the 1.129.0 milestone Jul 6, 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.

switch modes with multiple chat windows

3 participants