fix: memory leak in document paste edits by SimonSiefke · Pull Request #338233 · microsoft/vscode · GitHub
Skip to content

fix: memory leak in document paste edits - #338233

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

Dmitriy Vasyura (dmitrivMS) merged 9 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-documentPasteEdit-cacheIds

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Paste edit cleanup uses the data-transfer request ID instead of the returned edit-cache ID. When a provider declines requests, the IDs drift apart and closing the paste editor leaves old edits in the extension-host cache. Empty results are also cached even though they contain no release ID.

Change

Release paste edits using the cache ID returned with the edits, and do not cache empty results.

Before

When pasting into and closing 37 editors, with the provider declining two requests before returning each edit, 37 paste edits remain in the extension-host cache:

paste-before

After

No more paste-edit cache growth is detected in the same 37-cycle test.

Test Video

paste-test.mp4

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

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

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

🟢 Approval recommended

The cache lifecycle fix is narrowly scoped and directly covered by regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes extension-host paste-edit cache leaks caused by mismatched request and cache IDs.

Changes:

  • Releases paste edits using their returned cache ID.
  • Avoids caching empty edit results.
  • Adds regression coverage for declined and empty requests.
File Description
src/​vs/​workbench/​api/​browser/​mainThreadLanguageFeatures.ts Releases the correct paste-edit cache entry.
src/​vs/​workbench/​api/​common/​extHostLanguageFeatures.ts Skips caching empty results.
src/​vs/​workbench/​api/​test/​browser/​extHostLanguageFeatures.test.ts Tests cache release and empty-result behavior.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please see comments

@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback!

It may take a bit until I get through all of it.

I'm just wondering what do you use to create the ai review comments? Like asking copilot or claude to do a review of pr <number>? Or do you have some custom review skill?

I'm thinking to integrate some kind of ai review like that for the draft prs I first make in https://github.com/SimonSiefke/vscode/pulls?q=sort%3Aupdated-desc+is%3Apr+state%3Aopen+ before making them "more polished" PRs to VS Code.

Thanks again. :)

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Here's are standing instructions for an army of Agent Hosts :-) I made some updates since then, but this is essentially it:

When I paste a PR link into this session, you should start a new session with a clean worktree of main for that PR with the following instructions:
1) Review the PR code using Astra/Max and Opus 5.5/Max reviewers, keep in mind previous comments on the PR and fixes, if any. Focus on PR cleanliness as well as whether it has the potential to introduce any functional or performance regressions.
2) If there are no regressions identified, proceed with testing the PR using Code OSS. Make sure the leak is reproducable and fixed with PR, also cover area around the changes to ensure no functional regressions.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank YOU for all the fixes!

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Ah, I also have some review persona created from historical PR comments on vscode repo... don't ask :-)

@dmitrivMS

Copy link
Copy Markdown
Collaborator

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 3126b77 into microsoft:main Oct 5, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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