Skip to content

fix: memory leak in chat participant disposal - #338230

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-chatParticipant-disposal
Sep 28, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-chatParticipant-disposal

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

When an extension disposes a chat participant, its entry stays in the extension-host agent map. Its request handler and completion-command store are not removed.

Change

Remove the agent entry and dispose its completion commands when the participant is disposed. Make disposal idempotent and ignore completion results that finish afterward.

Before

Registering and disposing a chat participant 37 times adds 37 old agents, captured state objects, and request handlers.

before

After

No more participant or handler growth is detected in the same 37-cycle test. The agent map stays empty after disposal.

Test Video

Seven registration and disposal cycles through the extension API.

test.mp4

AI disclosure: Model: GPT 6 Astra. Worktime: 29 min

Copilot AI balanced review requested due to automatic review settings September 27, 2026 18:03

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.

Copilot review overview

🟡 Changes recommended

Variable-provider registrations still leak on the main thread after participant disposal.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes extension-host retention when chat participants are disposed.

Changes:

  • Removes disposed agents and completion-command resources.
  • Makes disposal idempotent and ignores late completions.
  • Adds lifecycle regression tests.
File Description
src/​vs/​workbench/​api/​common/​extHostChatAgents2.ts Implements participant cleanup.
src/​vs/​workbench/​api/​test/​common/​extHostChatAgents2.test.ts Tests disposal behavior.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 28c67b3 into microsoft:main Sep 28, 2026
36 of 38 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 28, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-chatParticipant-disposal branch September 29, 2026 11:15
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Oct 1, 2026
* fix: memory leak in chat participant disposal

* fix: unregister completion providers on chat participant disposal

---------

Co-authored-by: Dmitriy Vasyura <[email protected]>
(cherry picked from commit 28c67b3)
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

chat freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants