Skip to content

fix: memory leak in test results terminal - #347183

Merged
Connor Peet (connor4312) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-testResultsOutput
Nov 11, 2026
Merged

Connor Peet (connor4312) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-testResultsOutput

Conversation

@SimonSiefke

@SimonSiefke Simon Siefke (SimonSiefke) commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR is related to #346656.

Details

Closing Test Results output while its terminal is being created can leave the new terminal undisposed. Whole-run output also creates hidden markers for every message, although only a selected message needs them.

Change

Dispose terminals that finish creation after the output renderer closes and dispose their process information with the renderer. Skip unused hidden markers and use a counter to track pending writes.

Before

When closing Test Results output while terminal creation is pending for 37 runs, detached terminals and their marker callbacks keep growing:

before

After

No more leak detected.

Test Video

test.webm

AI disclosure: Model: GPT 6.1 Sol. Worktime: 21 min

Copilot AI balanced review requested due to automatic review settings November 9, 2026 21:25
@vs-code-engineering

vs-code-engineering Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminal/browser/terminal.ts
  • src/vs/workbench/contrib/terminal/browser/terminalService.ts
  • src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts

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.

🟢 Approval recommended

No active review issues are recorded for the terminal resource-cleanup and marker-filtering changes.

No open issues 🎉

What changed in this PR

This PR addresses memory leaks in the Test Results output terminal by tightening resource disposal and avoiding unused per-message markers.

Changes:

  • Dispose terminals that finish creation after the renderer closes, and manage process information with the renderer.
  • Filter hidden markers to retain only those needed for the selected message, and simplify pending-write tracking.
  • Add regression tests for marker filtering, scope changes, and disposal during terminal creation.
File Description
src/​vs/​workbench/​contrib/​testing/​test/​browser/​testResultsOutput.test.ts Adds marker-filtering and terminal-disposal regression tests.
src/​vs/​workbench/​contrib/​testing/​browser/​testResultsView/​testResultsOutput.ts Fixes resource cleanup, filters unused markers, and simplifies write tracking.
src/​vs/​workbench/​contrib/​terminal/​browser/​xterm/​xtermTerminal.ts Exposes disposable OSC sequence handler registration.
src/​vs/​workbench/​contrib/​terminal/​browser/​terminal.ts Adds OSC handler registration to the detached terminal interface.

Review effort: Balanced

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.

🟡 Changes recommended

The test’s .bind(...) calls are used solely to set this, contrary to the coding guideline to use arrow functions or closures instead.

1 open issue

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator

P3: hidden-marker filtering introduces false shell-integration timeout diagnostics

At head bb3d693902952f7c02210ecbe94a0a90ccf44a1c, the new OSC handler consumes hidden SetMark sequences before ShellIntegrationAddon sees them. Previously, handling the first mark cleared its activation timeout. The detached output terminal still has activation reporting enabled.

Product repro steps to try (source-derived; not executed end-to-end in Code OSS):

  1. Use a test provider that emits ordinary test-associated output, for example run.appendOutput('synthetic output\r\n', undefined, testItem).
  2. Open that run's whole-run or per-test output in Test Results, creating a fresh output terminal. Do not select an individual output message.
  3. Keep the output open for more than 10 seconds, without sending other shell-integration sequences.
  4. Inspect the renderer log and, with local telemetry logging enabled, the telemetry log.

The introduced path reports terminal/shellIntegrationActivationTimeout and logs Shell integration failed to add capabilities within 10 seconds, even though this is a test-output viewer, not a shell that failed to activate. Expected: no false activation-timeout diagnostic.

Executed component reproduction: use the compiled production ShellIntegrationAddon with @xterm/headless, activation reporting enabled, and local telemetry/log sinks. Load the add-on; in the candidate arm only, register the exact new OSC 633 filter with selectedMarks undefined. Write the same output in both arms:

'\x1b]633;SetMark;Id=s0;Hidden\x07synthetic\r\n\x1b]633;SetMark;Id=e0;Hidden\x07'

Wait 10.3 seconds:

Arm Observed event Warnings
Without the PR filter terminal/shellIntegrationActivationSucceeded 0
With the exact PR filter terminal/shellIntegrationActivationTimeout 1

This confirms the introduced diagnostics behavior at component level; it is not a Code OSS reproduction or a test of the leak fix. Impact is logging/telemetry only, once per affected terminal, with existing telemetry controls unchanged. Pre-existing timeouts for unmarked/no-output terminals are not this finding.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please consider review comment

@SimonSiefke

Copy link
Copy Markdown
Contributor Author

[ai-response] Reproduced the false timeout described in the feedback. The issue should now be fixed in a2214ec.

Test Results output viewers now opt out of shell-integration activation timeout reporting. The existing reporting option is exposed through detached-terminal creation and forwarded to xterm. Shell-integration marker parsing remains enabled, preserving hidden-marker filtering and selected-message range selection.

Added regression tests for whole-run and per-test output that advance past the 10-second deadline and check that neither the timeout telemetry event nor its warning is emitted. All 86 targeted Electron tests, targeted ESLint, and the client typecheck passed. In a real Code OSS window, marked test output remained open for over 50 seconds with correct text, zero hidden markers and no false timeout warning.

@SimonSiefke

Simon Siefke (SimonSiefke) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed some kind of shell integration timeout issue.

@connor4312 Connor Peet (connor4312) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

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.

🟢 Approval recommended

No active review issues remain for the terminal cleanup and marker-management changes.

No open issues 🎉

1 resolved since last review

Review effort: Max

@connor4312
Connor Peet (connor4312) merged commit 6c3b9ff into microsoft:main Nov 11, 2026
52 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 11, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-testResultsOutput branch November 11, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues testing Built-in testing support

5 participants