Fix chat session disposal error by implementing move behavior instead of duplicate opening #265038
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 #264680 - Chat breaks when closing window with chat session
Problem
When opening a chat session in a new window via "Open in New Window", both the original window and new window maintain references to the same chat session. When the auxiliary window is closed, its
InstantiationServicegets disposed, but the original window's chat view still has references to services from the disposed window, causing an "InstantiationService has been disposed" error.This occurs because the current implementation creates multiple instances that share the same underlying session data and services:
OpenChatSessionInNewWindowActioncreates new editor instances but doesn't close the originalOpenChatSessionInSidebarActionloads sessions without closing editor instancesOpenChatSessionInNewEditorGroupActionduplicates sessions instead of moving themSolution
Implement "move" behavior instead of "open in multiple places" to eliminate shared service references between windows.
Key Changes
Added Helper Methods
findAndCloseExistingSessionInstances(): Centralized method to close all existing instances of a session and preserve view statecloseEditorsBySessionId(): Safely closes all chat editors with matching session ID, extracting view state from active editorsclearWidgetBySessionId(): Clears chat widgets using properclear()andwaitForReady()patternModified Actions to Use Move Behavior
All three chat session actions now:
OpenChatSessionInNewWindowAction: Closes original instances before opening in auxiliary window
OpenChatSessionInSidebarAction: Closes existing editor instances before loading in sidebar
OpenChatSessionInNewEditorGroupAction: Clears original instances before opening in new editor group
Technical Implementation
The implementation follows existing patterns from
chatMoveActions.tsand ensures:Validation
Added comprehensive test suite in
chatSessionActions.test.tsthat verifies:Result
This eliminates the disposal error by ensuring no shared service references exist between windows. When a user:
The chat panel will remain clear after closing the auxiliary window since the session was moved rather than duplicated, preventing any disposal-related errors.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
electronjs.orgnode-gyp(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Created from VS Code via the GitHub Pull Request extension.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.