Skip to content

fix: memory leak in extension host language model providers - #340579

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-languageModelProviderDisposal
Oct 9, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-languageModelProviderDisposal

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

A language model provider can be disposed while its model discovery is pending. The completed discovery still writes the old catalog into ExtHostLanguageModels._localModels, even after a replacement provider has registered.

Change

Check the original provider registration after discovery completes and discard results from a disposed or replaced registration.

Before

When starting discovery and disposing a provider before its 37-model catalog returns over 37 cycles, the extension host keeps 37 old model objects. Named-function-count3 on the matched heap captures shows DisposedDiscoveryModelInformation growing by 37 (38 total).

named-function-count3 before

After

No more leak detected.

Test Video

test-video.webm

AI disclosure: Model: GPT-6.1-Sol. Worktime: 11 min

Copilot AI balanced review requested due to automatic review settings October 8, 2026 20:53

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.

🟢 Approval recommended

The identity guard correctly prevents stale cache writes and is covered by focused lifecycle tests.

0 open findings

What changed in this PR

Prevents stale model discovery results from repopulating the extension host cache after a provider is disposed or replaced.

Changes:

  • Verifies provider registration identity after asynchronous discovery.
  • Adds disposal, replacement, cache-clearing, and regression tests.
File Description
src/​vs/​workbench/​api/​common/​extHostLanguageModels.ts Discards results from stale provider registrations.
src/​vs/​workbench/​api/​test/​common/​extHostLanguageModels.test.ts Tests provider disposal and replacement behavior.

🧠 Review effort: Balanced


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

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.

🟡 Changes recommended

Returning an empty catalog can still let stale discovery clear a replacement provider’s main-thread model cache.

1 open finding

🧠 Review effort: Balanced

Comment thread src/vs/workbench/api/common/extHostLanguageModels.ts
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 5042306 into microsoft:main Oct 9, 2026
55 of 56 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 9, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-languageModelProviderDisposal branch October 13, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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