Skip to content

fix: memory leak in chatServiceImpl - #327128

Merged
Dmitriy Vasyura (dmitrivMS) merged 6 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-chatServiceImpl
Jul 31, 2026
Merged

fix: memory leak in chatServiceImpl#327128
Dmitriy Vasyura (dmitrivMS) merged 6 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-chatServiceImpl

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Chat follow-up providers create cancellation token sources stored in _sessionFollowupCancelTokens. Disposing a chat session model did not remove and dispose its token source.

Change

The change removes and disposes the matching follow-up cancellation token source when the chat session model is disposed.

Before

When executing a terminal command from chat 37 times, follow-up cancellation token sources and mutable tokens grow across the runs (outlined in red):

chat-editor-execute-terminal-command-chatServiceImpl-before

After

No more matching cancellation token leak is detected.

chat-editor-execute-terminal-command-chatServiceImpl-after

Test Video

chat-terminal-command-7-runs.mp4

Copilot AI review requested due to automatic review settings July 23, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes retained follow-up cancellation token sources when chat sessions are disposed.

Changes:

  • Removes and disposes the session’s follow-up token source during model disposal.

Comment thread src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts
@dmitrivMS

Copy link
Copy Markdown
Contributor

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) enabled auto-merge (squash) July 31, 2026 00:23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simon Siefke (@SimonSiefke) build errors:
Error: [core-ci ] [00:24:41] src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts(663,16): error TS2345: Argument of type '(listener: (e: void) => unknown, thisArgs?: unknown, disposables?: IDisposable[] | undefined) => IDisposable' is not assignable to parameter of type 'Event'.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit c423d6b into microsoft:main Jul 31, 2026
46 of 47 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 31, 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.

4 participants