fix: release terminal command history when clearing the normal buffer by SimonSiefke · Pull Request #326931 · microsoft/vscode · GitHub
Skip to content

fix: release terminal command history when clearing the normal buffer - #326931

Merged
Dmitriy Vasyura (dmitrivMS) merged 8 commits into
microsoft:mainfrom
SimonSiefke:fix/clear-terminal-command-history
Oct 5, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 8 commits into
microsoft:mainfrom
SimonSiefke:fix/clear-terminal-command-history

Conversation

@SimonSiefke

@SimonSiefke Simon Siefke (SimonSiefke) commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Details

Clearing the normal terminal buffer now removes the entire rich and partial command history, including commands in scrollback, and invalidates rich commands so their decorations are disposed. This prevents repeated task runs and terminal clears from retaining command history and decorations.

Cleanup follows the active buffer: clearing an alternate screen (for example, Vim or a pager) preserves the surviving normal-buffer output, command history, navigation markers, decorations, and current prompt state.

Before

When running the same task and clearing the terminal 37 times, retained commands and their decorations grow each time (outlined in red):

task-run-fix-clear-terminal-command-history-before

After

No more retained command or partial-command marker growth is detected.

task-run-fix-clear-terminal-command-history-after

Tests

Regression coverage drives XtermTerminal.clearBuffer() with commands in scrollback and verifies rich/partial history cleanup and rich decoration disposal. An alternate-screen round trip verifies that normal-buffer text, histories, markers, decorations, and current prompt state survive.

Validated after merging the latest main:

  • 41 tests passed across the xterm and rich/partial command detection suites in Chromium.
  • Full client typecheck passed.
  • ESLint passed for all seven changed files.

Copilot AI review requested due to automatic review settings July 22, 2026 09:17
@vs-code-engineering

vs-code-engineering Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Updates terminal clearing to remove command-detection history and prevent retained commands and decorations.

Changes:

  • Exposes viewport-clearing APIs for rich and partial command detection.
  • Invokes them before clearing the xterm buffer.
  • Adds partial command detection coverage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
capabilities.ts Adds command-clearing APIs.
commandDetectionCapability.ts Exposes rich command clearing.
partialCommandDetectionCapability.ts Exposes partial command clearing.
xtermTerminal.ts Clears command history before the buffer.
partialCommandDetectionCapability.test.ts Tests partial viewport clearing.

Comment thread src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts Outdated
# Conflicts:
#	src/vs/workbench/contrib/terminal/test/browser/xterm/xtermTerminal.test.ts
# Conflicts:
#	src/vs/workbench/contrib/terminal/test/browser/xterm/xtermTerminal.test.ts
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues terminal-shell-integration Shell integration infrastructure, command decorations, etc. labels Sep 24, 2026
Comment thread src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts Outdated

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 see inline comment.

@SimonSiefke Simon Siefke (SimonSiefke) changed the title fix: memory leak in commandDetectionCapability fix: release terminal command history when clearing the normal buffer Oct 2, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 1d92a97 into microsoft:main Oct 5, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 5, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/clear-terminal-command-history branch October 5, 2026 16:33
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 terminal-shell-integration Shell integration infrastructure, command decorations, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants