Skip to content

Avoid terminal link provider listeners for detached terminals - #332470

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

Avoid terminal link provider listeners for detached terminals#332470
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
mainfrom
dev/dmitriv/detached-terminal-link-listener-leak

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Summary

  • stop detached terminals from subscribing to external link-provider removal events they never consume
  • keep add/remove provider listeners unchanged for regular terminal instances
  • add contribution-level regression coverage that exercises detached and regular terminal contexts

Root cause

TerminalLinkContribution.xtermReady() already skips external provider setup for detached terminals, but the onDidRemoveLinkProvider subscription was outside that guard. Every detached terminal created for chat output therefore added a no-op listener to the singleton TerminalLinkProviderService emitter. Tool-heavy agent sessions eventually crossed the listener leak threshold.

The provider-removal listener now lives beside the provider-add listener inside the existing non-detached guard.

Validation

  • npm run transpile-client
  • focused contribution tests: 2 passed
  • contribution plus neighboring terminal/link tests: 30 passed
  • 50 rendered detached contributions add zero provider add/remove listeners
  • a regular terminal still adds one of each listener and removes both on disposal
  • editor diagnostics: no errors
  • git diff --check

Related issues

Fixes #308254

Related to #311225
Related to #294050

The related crash reports contain this detached-terminal listener signature among several independent memory-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 01:59
@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-links 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

Prevents detached terminals from retaining unused external link-provider listeners.

Changes:

  • Guards provider-removal subscriptions for detached terminals.
  • Adds regression coverage for detached and regular terminals.
Show a summary per file
File Description
terminal.links.contribution.ts Moves removal listener into the regular-terminal guard.
terminalLinkContribution.test.ts Tests listener registration and disposal behavior.

Review details

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

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
linkManager.externalProvideLinksCb = e.provideLinks.bind(e, this._ctx.instance as ITerminalInstance);
}));
}
linkManager.add(this._terminalLinkProviderService.onDidRemoveLinkProvider(() => linkManager.externalProvideLinksCb = undefined));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The code moved to another file for testing purposes, but the only change is this line is now included in the if above

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

تم

@saroasid-web

Copy link
Copy Markdown

الجامد بزيادة

@saroasid-web

Copy link
Copy Markdown

تم

@anthonykim1 Anthony Kim (anthonykim1) 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.

Thanks! I dont think we register extension provided link provider for detached terminal so this should be good for now.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 4e4877b into main Aug 26, 2026
37 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the dev/dmitriv/detached-terminal-link-listener-leak branch August 26, 2026 06:29
@vs-code-engineering vs-code-engineering Bot added this to the 1.136.0 milestone Aug 26, 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-links

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Unhandled Error] potential listener LEAK detected, popular

4 participants