Skip to content

Avoid decoration shutdown listeners for detached terminals - #332476

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

Avoid decoration shutdown listeners for detached terminals#332476
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
mainfrom
dev/dmitriv/detached-terminal-decoration-listener-leak

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Summary

  • remove the workbench lifecycle dependency from DecorationAddon
  • let XtermTerminal, which already knows whether it is detached, own decoration shutdown cleanup
  • register one decoration cleanup listener for regular terminals and none for detached terminals
  • preserve normal addon disposal for detached terminals
  • add end-to-end listener-count coverage through XtermTerminal

Root cause

Every DecorationAddon registered a listener on the singleton lifecycleService.onWillShutdown emitter. Agent chat output creates many detached terminals, so tool-heavy sessions eventually crossed the listener leak threshold.

Detached terminals already own and dispose their XtermTerminal; xterm disposal unloads the addon and DecorationAddon.dispose() clears its decorations. Their global shutdown subscription was therefore redundant.

Shutdown policy now belongs to XtermTerminal, which already owns options.detached. Regular terminals preserve the existing shutdown behavior by calling the addon's public clearDecorations() API from a host-owned listener. DecorationAddon no longer knows about workbench lifecycle or detached-terminal mode.

Validation

  • npm run transpile-client
  • focused detached-terminal listener regression: 1 passed
  • full DecorationAddon and XtermTerminal suites: 25 passed
  • the regular setup terminal adds exactly one shutdown listener
  • 50 detached XtermTerminal instances add zero shutdown listeners
  • editor diagnostics: no errors
  • git diff --check

Related issues

Fixes #311557

Related to #311225
Related to #294050

The related crash reports contain this listener signature among several independent renderer and extension-host retention paths, so they are intentionally non-closing references.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 25, 2026 02:46
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added bug Issue identified by VS Code Team member as probable bug error-telemetry VS Code - Issues generated by telemetry freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues terminal General terminal issues that don't fall under another label labels 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

Moves terminal decoration shutdown cleanup to XtermTerminal, preventing redundant lifecycle listeners for detached terminals.

Changes:

  • Removes lifecycle coupling from DecorationAddon.
  • Registers shutdown cleanup only for regular terminals.
  • Adds regression coverage for listener counts.
Show a summary per file
File Description
decorationAddon.ts Removes lifecycle dependency and listener.
xtermTerminal.ts Owns conditional shutdown cleanup.
xtermTerminal.test.ts Verifies regular and detached listener counts.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 873ac47 into main Aug 25, 2026
27 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the dev/dmitriv/detached-terminal-decoration-listener-leak branch August 25, 2026 23:21
@vs-code-engineering vs-code-engineering Bot added this to the 1.136.0 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug error-telemetry VS Code - Issues generated by telemetry freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues terminal General terminal issues that don't fall under another label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Error] potential listener LEAK — terminal/decorationAddon

3 participants