Skip to content

Comments

Fix: disposed ChatThinkingContentPart returned by getLastThinkingPart causing DisposableStore error#296927

Merged
justschen merged 2 commits intomainfrom
copilot/fix-disposablestore-error
Feb 23, 2026
Merged

Fix: disposed ChatThinkingContentPart returned by getLastThinkingPart causing DisposableStore error#296927
justschen merged 2 commits intomainfrom
copilot/fix-disposablestore-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

ChatThinkingContentPart.dispose() did not set isActive = false, so getLastThinkingPart() could return an already-disposed thinking part still present in renderedParts. Calling appendItem on it triggered _registerDisposableStore.add on a disposed store, producing the leaked-disposable error.

Changes

  • chatThinkingContentPart.ts — Add this.isActive = false as the first statement in override dispose(), ensuring disposed parts are excluded by getLastThinkingPart's getIsActive() filter.
  • chatThinkingContentPart.test.ts — Add a test in the State management suite verifying that dispose() sets isActive to false.
Original prompt

This section details on the original issue you should resolve

<issue_title>Trying to add a disposable to a DisposableStore that has already been disposed of</issue_title>
<issue_description>```
lifecycle.ts:478 Error: Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!
at DisposableStore.add (lifecycle.ts:478:18)
at ChatThinkingContentPart._register (lifecycle.ts:555:22)
at ChatThinkingContentPart.appendItem (chatThinkingContentPart.ts:1059:11)
at ChatListItemRenderer.renderMarkdown (chatListRenderer.ts:2446:19)
at ChatListItemRenderer.renderChatContentPart (chatListRenderer.ts:1730:17)
at chatListRenderer.ts:1265:25
at Array.forEach ()
at ChatListItemRenderer.renderChatContentDiff (chatListRenderer.ts:1194:17)
at ChatListItemRenderer.doNextProgressiveRender (chatListRenderer.ts:1185:8)
at runProgressiveRender (chatListRenderer.ts:805:15)
at async.ts:1086:4


## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… DisposableStore error

Co-authored-by: jrieken <1794099+jrieken@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error adding disposable to disposed DisposableStore Fix: disposed ChatThinkingContentPart returned by getLastThinkingPart causing DisposableStore error Feb 23, 2026
@jrieken jrieken requested review from justschen and roblourens and removed request for justschen February 23, 2026 10:20
@jrieken jrieken assigned roblourens and justschen and unassigned jrieken Feb 23, 2026
@roblourens roblourens removed their assignment Feb 23, 2026
@justschen justschen marked this pull request as ready for review February 23, 2026 19:42
Copilot AI review requested due to automatic review settings February 23, 2026 19:42
@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 23, 2026
Copy link
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

This PR fixes a critical bug where getLastThinkingPart() could return an already-disposed ChatThinkingContentPart, leading to attempts to register disposables on a disposed DisposableStore. The issue occurred because disposed parts remained in renderedParts but were not filtered out by the getIsActive() check.

Changes:

  • Set isActive = false in ChatThinkingContentPart.dispose() to ensure disposed parts are excluded by getLastThinkingPart()
  • Add test coverage verifying that dispose() properly updates the isActive state

Reviewed changes

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

File Description
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatThinkingContentPart.ts Adds this.isActive = false as first statement in dispose() to prevent disposed parts from being returned by getLastThinkingPart
src/vs/workbench/contrib/chat/test/browser/widget/chatContentParts/chatThinkingContentPart.test.ts Adds test verifying dispose() sets isActive to false

@justschen justschen enabled auto-merge (squash) February 23, 2026 19:53
@justschen justschen merged commit d37a00c into main Feb 23, 2026
23 checks passed
@justschen justschen deleted the copilot/fix-disposablestore-error branch February 23, 2026 20:22
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.

Trying to add a disposable to a DisposableStore that has already been disposed of

4 participants