Skip to content

fix: track disposables for serialized tool invocations in thinking part#302641

Open
vikeychen wants to merge 1 commit intomicrosoft:mainfrom
vikeychen:fix/chat-thinking-tool-disposable-leak
Open

fix: track disposables for serialized tool invocations in thinking part#302641
vikeychen wants to merge 1 commit intomicrosoft:mainfrom
vikeychen:fix/chat-thinking-tool-disposable-leak

Conversation

@vikeychen
Copy link

@vikeychen vikeychen commented Mar 18, 2026

Summary

  • Fix disposable leak for serialized tool invocations (toolInvocationSerialized) in ChatThinkingContentPart
  • trackToolMetadata only created a DisposableStore in toolDisposables for live toolInvocation kind, causing appendItem to silently drop disposables for serialized tools via toolDisposables.get(id)?.add()
  • This led to leaked ChatToolInvocationPart instances (and child CodeBlockPart / MenuWorkbenchToolBar) when loading session history, accumulating listeners on ActionViewItemService.onDidChange

Details

The recent fix in #302595 correctly added disposable to the createToolPart return value. However, the disposable is still silently dropped for toolInvocationSerialized because trackToolMetadata only calls toolDisposables.set(toolCallId, toolStore) inside the kind === 'toolInvocation' branch.

This fix creates the DisposableStore for all tool invocation kinds before the kind-specific state tracking branch, ensuring serialized tools' disposables are properly tracked and cleaned up when the thinking part is disposed.

The `trackToolMetadata` method only created a `DisposableStore` entry in
`toolDisposables` for live `toolInvocation` kind, but not for
`toolInvocationSerialized`. This caused `appendItem` to silently drop
the disposable via the optional chaining `toolDisposables.get(id)?.add()`
when rendering serialized tools (e.g. when loading session history).

As a result, `ChatToolInvocationPart` instances (and their child parts
including `CodeBlockPart` with `MenuWorkbenchToolBar`) were never disposed,
leading to listener accumulation on `ActionViewItemService.onDidChange`.

Fix by creating the `DisposableStore` for all tool invocation kinds
(both live and serialized) before the kind-specific state tracking branch.
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.

2 participants