Repository navigation
chat: don't throw when closing an editor group or window with a chat view - #350681
Merged
Sandeep Somavarapu (sandy081) merged 5 commits intoNov 27, 2026
Merged
Sandeep Somavarapu (sandy081) merged 5 commits into
Sandeep Somavarapu (sandy081) merged 5 commits into
Conversation
A view's content can still create instances while it is disposed, such as a chat input reacting to its text being reset. Disposing the view's scoped instantiation service first made that throw. The service is now disposed last. Co-authored-by: Copilot <[email protected]>
Clearing a chat input reparses it, and the widget created a new request parser through its instantiation service on every parse. When a whole editor group or auxiliary window closes, the group's scoped instantiation service disposes its children before the editor panes, so the New Session prompt options clearing their generated prompt on dispose threw "InstantiationService has been disposed". The widget now creates its parser once, in its constructor. The view editor pane registers the view's instantiation service right after creating it, in an outer store that disposes the view first. Co-authored-by: Copilot <[email protected]>
Closing a group or window disposes the widget's instantiation service before the New Session prompt options clear the generated prompt (#342683); parsing the cleared input must not throw, and the draft saved on close stays empty. Co-authored-by: Copilot <[email protected]>
… closes Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the chat teardown and editor disposal changes.
No open issues 🎉
What changed in this PR
This PR prevents “InstantiationService has been disposed” errors when closing or reloading a chat host, while preserving the generated-prompt cleanup introduced by #342683.
Changes:
- Reuses one
ChatRequestParserper chat widget, avoiding instance creation during teardown. - Disposes editor views before their scoped instantiation services on individual editor close.
- Adds regression coverage for teardown parsing, generated-prompt clearing, and view disposal order.
| File | Description |
|---|---|
src/vs/workbench/services/editor/test/browser/viewEditor.test.ts |
Checks disposal order for active and hidden views. |
src/vs/workbench/contrib/sessions/test/browser/chat/newSessionPromptOptions.test.ts |
Verifies closing prompt options clears the generated draft. |
src/vs/workbench/contrib/chat/test/browser/widget/chatWidget.test.ts |
Covers parsing after the instantiation service is disposed. |
src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts |
Creates and reuses a widget-owned request parser. |
src/vs/workbench/browser/parts/editor/viewEditorPane.ts |
Orders view cleanup before service disposal and handles setup failures. |
Review effort: Balanced
… now creates once Co-authored-by: Copilot <[email protected]>
Sandeep Somavarapu (sandy081)
marked this pull request as ready for review
November 27, 2026 12:42
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 27, 2026
Ulugbek Abdullaev (ulugbekna)
approved these changes
Nov 27, 2026
Sandeep Somavarapu (sandy081)
deleted the
sandy081/agents/infra-view-editor-dispose
branch
November 27, 2026 13:09
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 "InstantiationService has been disposed" when an editor group or window with a chat view closes, or on reload.
What happened. When the New Session prompt options are disposed, they deliberately clear their generated prompt (#342683), so an unedited generated prompt isn't kept as a draft. Clearing the input makes the chat widget parse it again, and the widget created a new
ChatRequestParserthrough its instantiation service on every parse. An editor group registers its scoped instantiation service before its editor panes, andInstantiationService.disposedisposes its children first. So when a whole group or window closed, the view's instantiation service was already disposed by the time the input cleared, and parsing threw.Changes
ChatWidgetcreates its request parser once, in its constructor. Parsing no longer goes through the instantiation service, for every chat host and every close path. The deliberate clearing from Unify new session and active session composer #342683 is unchanged, so drafts behave as before.ViewEditorPanedisposes a view before the view's instantiation service. It registers the service as soon as it's created, in an outer store, with the view's things in an inner store that's disposed first.Tests
chatWidget.test.ts: parsing the cleared input after the widget's instantiation service is disposed (closing a group or window) doesn't throw. Fails without the fix with "InstantiationService has been disposed".newSessionPromptOptions.test.ts: closing the prompt options still clears the generated prompt, so the draft saved on close is empty (Unify new session and active session composer #342683).viewEditor.test.ts: the view is disposed before its instantiation service, on close and while hidden.Validation
./scripts/test.sh --runGlob "vs/workbench/{services/editor/test/browser,test/browser,contrib/chat/test/browser/widget,contrib/sessions/test/browser/chat}/**/*.test.js": 6549 passing, 1 failing:ChatListWidget"falls back to a full refresh when the request or the transcript changes", which also fails on main without this changepnpm run typecheck-client: passedpnpm run valid-layers-check: passedpnpm run oxlint <changed files>: passedWritten by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)