Skip to content

Fix terminal tool progress listener leak - #332460

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
mainfrom
dev/dmitriv/terminal-continue-listener-leak
Aug 25, 2026
Merged

Fix terminal tool progress listener leak#332460
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
mainfrom
dev/dmitriv/terminal-continue-listener-leak

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • stop each rendered terminal tool progress row from subscribing to the shared onDidContinueInBackground emitter
  • route matching UI updates through TerminalChatService's existing active progress-part registry
  • preserve the Agent Host event and update every active rendering of the matching terminal tool session
  • add regression coverage with 50 actual rendered progress parts, including duplicate rows for one terminal session

Log evidence

The newest populated Insiders session (20260823T004915) reported:

[error] potential listener LEAK detected, popular: Error
    at ... onDidContinueInBackground
    at ... createToolInvocationSubPart

The allocation stack pointed to ChatTerminalToolProgressPart: every terminal tool row registered a listener on one service-wide emitter. A sufficiently long chat therefore crossed the listener threshold even though each row only cared about its own terminal tool session.

Fix

TerminalChatService.continueInBackground now walks its already-maintained active progress-part set and directly marks parts whose terminal tool session ID matches. This removes the O(number of rendered terminal rows) listeners while preserving duplicate-row updates and the service event consumed by Agent Host.

Validation

  • npm run transpile-client
  • focused rendered-part regression test: 1 passed
  • combined ChatTerminalToolProgressPart and TerminalChatService suites: 23 passed
  • the rendered-part test mounts 50 real rows, verifies the emitter listener count remains constant, and confirms both rows sharing one session ID update their toolbar state
  • editor diagnostics: no errors in the changed files
  • git diff --check

A fresh-session log reproduction was not practical because the original warning requires dozens of live terminal-tool rows. The regression test directly exercises 50 rendered rows.

Related issues

Related to #311225.
Related to #294050.

These are non-closing references: both reports cover broader memory-growth scenarios with additional retention paths, so this change may mitigate one contributor without establishing a complete fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 25, 2026 00:40
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the terminal General terminal issues that don't fall under another label label Aug 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.

Pull request overview

Fixes terminal tool progress listener accumulation by routing updates through TerminalChatService.

Changes:

  • Removes per-row background-event listeners.
  • Updates all matching active progress parts centrally.
  • Adds service-level regression coverage.
Show a summary per file
File Description
terminalChatService.test.ts Tests progress-part notification behavior.
terminalChatService.ts Dispatches updates through the active-part registry.
terminal.ts Extends the progress-part contract.
chatTerminalToolProgressPart.ts Exposes session identity and direct update handling.

Review details

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@anthonykim1

Anthony Kim (anthonykim1) commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

LGTM, thank you

  • Seems like better design - although Im not sure how true of a leak it was given onDidContinueInBackground being wrapped in this._register) in this._register(this._terminalChatService.onDidContinueInBackground(.

cc Megan Rogge (@meganrogge)

@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.136.0 milestone Aug 25, 2026
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit c659a2c into main Aug 25, 2026
27 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the dev/dmitriv/terminal-continue-listener-leak branch August 25, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

terminal General terminal issues that don't fall under another label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants