Skip to content

Release inline request edit input and listeners when editing finishes - #337895

Merged
Dmitriy Vasyura (dmitrivMS) merged 6 commits into
mainfrom
agents/leak-chat-inline-edit-input
Sep 26, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 6 commits into
mainfrom
agents/leak-chat-inline-edit-input

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Related to #146841

With the default chat.editRequests: inline, clicking a request creates an inline ChatInputPart through ChatWidget.createInput. createInput registers about 10 listeners and autoruns on the widget's own store (onDidLoadInputState, onDidFocus, onDidAcceptFollowup, inputEditor.onDidChangeModelContent, chatAgentService.onDidChangeAgents, input.onDidChangeCurrentChatMode, contextKeyService.onDidChangeContext, two autoruns, and the scoped instantiation service), and clickedRequest adds 3 more listeners. They were only released when the whole widget was disposed, so every edit left them behind:

  • the autoruns read the inline input's selectedToolsModel.entriesMap / selectedLanguageModel, keeping them subscribed to the global LanguageModelToolsService.toolSets, and through them the disposed input part, its CodeEditorWidget, TextModel and DOM;
  • listeners accumulated on global emitters (chatAgentService.onDidChangeAgents, contextKeyService.onDidChangeContext);
  • the edit listeners captured the edited request view model, so the replaced ChatRequestModel/ChatResponseModel stayed alive too.

Edit-only disposables now go into a per-edit DisposableStore (_editingDisposables), which createInput receives for the inline input and which is cleared in finishedEditing. The main input keeps using the widget's store. createInput subscribes to the input part it created rather than the active one (this.input), so the main input's autoruns can't switch to the inline input while an edit is open. finishedEditing clears the inline input and paste-target holders instead of only disposing the input, and only the main input gets the getting-started tip presenter (the tip only applies to the empty state; previously an edit replaced the main input's presenter and left it bound to the disposed inline input).

Retainer path (heap snapshot):
LanguageModelToolsService.toolSets._observers → Derived (ChatSelectedTools.entriesMap) → AutorunObserver (ChatWidget._store), and ObservableValue (owner ChatInputModelSelectionController) → ChatInputPart.container → <div class="chat-edit-input-container">

Measurement

Per inline edit (send + edit) Without this change With this change
CodeEditorWidget / TextModel +1 / +1 flat
ChatRequestModel / ChatResponseModel +2 / +2 (replaced request kept) +1 / +1 (the new request)
Detached DOM +36 nodes, +19 roots flat
Emitter / DisposableStore instances ~+265 / ~+260 +4 / +5 (the new request)
Heap after GC ~+1 MB ~+0.1 MB

How this was measured

Code OSS (Electron, dev build) with the mock LLM server from scripts/chat-simulation (no sign-in), driven over CDP with Playwright. After a warm-up round and after each of 4 rounds: 4× forced GC, live instance counts via Runtime.queryObjects on the class prototypes, and DOM.getDetachedDomNodes (descendants of every detached root, queried from a throwaway CDP session). "Without this change" means only this fix reverted. The retainers were identified from heap snapshot retainer paths.

Added a ChatWidget test for the inline edit path: it creates the main input, starts and finishes an inline edit, and checks that the inline input, its scoped instantiation service, listeners and autoruns are released, and that the main input keeps its tip presenter (fails without this change).

ChatWidget.createInput registered its listeners and autoruns on the widget store also when creating the inline edit input, so every inline edit kept the disposed input part, its editor and the edited request alive until the widget was disposed. Scope them to the edit.

Related to #146841

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 25, 2026 06:10
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues label Sep 25, 2026

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

Persistent references and a dynamic autorun can still retain the completed inline edit, while the test bypasses the affected path.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Scopes inline request-edit resources to each edit lifecycle to prevent listener and DOM retention.

Changes:

  • Adds a per-edit disposable store.
  • Disposes edit listeners and services when editing finishes.
  • Adds listener cleanup coverage.
File Description
chatWidget.ts Scopes inline-edit resources and listeners.
chatWidget.test.ts Adds edit-listener cleanup testing.

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

…e input holders

- createInput subscribes to the input it created instead of the active one, so the main input's autoruns cannot switch to the inline input during an edit
- finishedEditing clears the inline input and paste target holders instead of only disposing the input
- only the main input gets the getting-started tip presenter
- test the inline edit path

Co-authored-by: Copilot <[email protected]>
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as ready for review September 25, 2026 21:35
roblourens
roblourens previously approved these changes Sep 25, 2026
…ne-edit-input

# Conflicts:
#	src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts
@github-actions

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: ca1020a2 Current: 15053429

Changed (2)

chat/scrollAnchoring/chatScrollAnchoring/CompletedVisibleHeader/Dark
Before After
before after
chat/scrollAnchoring/chatScrollAnchoring/CompletedOffscreenHeader/Light
Before After
before after

2 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit f8db09b into main Sep 26, 2026
54 of 56 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the agents/leak-chat-inline-edit-input branch September 26, 2026 20:00
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Sep 27, 2026
…microsoft#337895)

* Release inline request edit input and listeners when editing finishes

ChatWidget.createInput registered its listeners and autoruns on the widget store also when creating the inline edit input, so every inline edit kept the disposed input part, its editor and the edited request alive until the widget was disposed. Scope them to the edit.

Related to microsoft#146841

Co-authored-by: Copilot <[email protected]>

* Bind inline edit subscriptions to their own input and clear the inline input holders

- createInput subscribes to the input it created instead of the active one, so the main input's autoruns cannot switch to the inline input during an edit
- finishedEditing clears the inline input and paste target holders instead of only disposing the input
- only the main input gets the getting-started tip presenter
- test the inline edit path

Co-authored-by: Copilot <[email protected]>

* Add the per-edit disposables holder to the inline edit renderer test

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>

(cherry picked from commit f8db09b)

Adapted for VSCode-UTCS: this fork has no customization migration notice,
so only the getting-started tip is skipped while a request is edited.
Upstream's chatWidget.test.ts additions depend on test helpers from
features this fork did not take and are left out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UoeuD6W9qnRA5qYK2dNZvP
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants