Skip to content

chat: fix crash on disposed widget in scopedTools derived (#309547)#309588

Merged
roblourens merged 1 commit intomainfrom
agents/lengthy-owl
Apr 13, 2026
Merged

chat: fix crash on disposed widget in scopedTools derived (#309547)#309588
roblourens merged 1 commit intomainfrom
agents/lengthy-owl

Conversation

@roblourens
Copy link
Copy Markdown
Member

Fix #309547

The derived observable created in getModeRequestOptions() outlives the ChatWidget — it's returned in request options and kept alive by the session. When an MCP server uninstall triggers tool deletion from an observable set, the derived recomputes. By then, the widget is disposed, so this.input is undefined (the backing MutableDisposable was cleared), and accessing .currentModeObs crashes with:

Cannot read properties of undefined (reading 'currentModeObs')

Fix: Add a this._store.isDisposed guard at the top of the derived callback. When the widget is disposed, it returns the last known tools snapshot instead of trying to read from the destroyed input part.

(Written by Copilot)

The derived observable created in getModeRequestOptions() outlives the
ChatWidget. When MCP tool changes trigger a recompute after the widget
is disposed, this.input is undefined (MutableDisposable cleared),
crashing on .currentModeObs. Add a disposal guard to return the last
snapshot instead. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 13, 2026 19:10
@roblourens roblourens enabled auto-merge (squash) April 13, 2026 19:10
@github-actions
Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 91311400 Current: 1a7b1946

Changed (1)

chat/aiCustomizations/aiCustomizationManagementEditor/PromptsTabScrolled/Dark
Before After
before after

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 a crash in ChatWidget.getModeRequestOptions() where a derived observable (scopedTools) can outlive the widget and later recompute after disposal (e.g. when MCP tool deletion updates the underlying observable set), previously causing this.input access to throw.

Changes:

  • Add a disposal guard (this._store.isDisposed) inside the derived compute function.
  • When disposed, return the last known tools snapshot instead of reading from the disposed input part.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts Prevents scopedTools derived recomputation from accessing disposed widget state by returning the last tools snapshot after disposal.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@roblourens roblourens merged commit 8eee547 into main Apr 13, 2026
44 of 45 checks passed
@roblourens roblourens deleted the agents/lengthy-owl branch April 13, 2026 20:41
@vs-code-engineering vs-code-engineering bot added this to the 1.117.0 milestone Apr 13, 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.

[Unhandled Error] Cannot read properties of undefined (reading 'currentModeObs')

3 participants