Repository navigation
fix: memory leak in output channel disposal listeners - #338240
Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits intoOct 5, 2026
Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The leak regression assertions are skipped by the standard CI test configuration.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Moves model-disposal listener ownership to each output channel, preventing disposed channels from being retained by OutputService.
Changes:
- Registers model-disposal listeners with channel lifetime.
- Adds disposal, active-channel, registry, and shutdown tests.
| File | Description |
|---|---|
outputServices.ts |
Moves disposal listener ownership to OutputChannel. |
outputServices.test.ts |
Adds output-channel lifecycle regression tests. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Dmitriy Vasyura (dmitrivMS)
left a comment
Collaborator
There was a problem hiding this comment.
Two test-isolation issues from the independent review. Both are static findings: the reproduction commands below are proposed checks, not tests I have executed. I am not claiming an observed CI failure or a production-code regression.
Dmitriy Vasyura (dmitrivMS)
requested changes
Sep 28, 2026
Dmitriy Vasyura (dmitrivMS)
left a comment
Collaborator
There was a problem hiding this comment.
Please see comments
Save and clear pre-existing output channel descriptors before constructing the test service, then restore them after its disposal. This prevents order-dependent active-channel assertions and initialization-after-shutdown leaks when agent-session tests run first.
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
October 5, 2026 01:55
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 5, 2026
roblourens
approved these changes
Oct 5, 2026
Martin Aeschlimann (aeschli)
approved these changes
Oct 5, 2026
Simon Siefke (SimonSiefke)
deleted the
fix/memory-leak-outputService-channelDisposal
branch
October 5, 2026 16:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Details
Each output channel adds its model-disposal listener to the output service lifetime store. Disposing the channel leaves that listener in the service, along with the old channel and its model.
Change
Own the model-disposal listener on the channel itself, while preserving registry removal and active-channel switching when the model is disposed.
Before
Creating, displaying, and disposing 37 output channels adds 37 old channels and models with their supporting objects. The output service listener collection grows from 26 to 63 entries.
After
The same 37-cycle test removes 36 of the 37 named growth rows, and the output service listener collection stays at 9 entries. One separate main-thread shutdown callback still grows by 37; the full After chart shows it. Other object-shape differences remain, so this is not a globally clean heap.
Test Video
Seven output-channel creation, display, and disposal cycles.
test.mp4
AI disclosure: Model: GPT 6 Astra. Worktime: 42 min