Skip to content

Dispose finished background terminals to prevent accumulation#316278

Merged
meganrogge merged 4 commits into
mainfrom
merogge/ephemeral-terminals-per-turn-v2
May 13, 2026
Merged

Dispose finished background terminals to prevent accumulation#316278
meganrogge merged 4 commits into
mainfrom
merogge/ephemeral-terminals-per-turn-v2

Conversation

@meganrogge
Copy link
Copy Markdown
Collaborator

@meganrogge meganrogge commented May 13, 2026

Fixes #287177

Background terminals created by the chat agent tools are never reused once their command completes, but they remain alive indefinitely, accumulating across turns.

This PR disposes background terminals as soon as their command finishes (onCommandFinished), provided the user has not revealed the terminal. Terminal output remains viewable in the chat UI thanks to the output mirror snapshot captured before disposal.

Key changes:

  • Auto-dispose on completion: When a background terminal command finishes and the terminal is still hidden (hideFromUser), dispose the terminal instance and clean up the active execution entry.
  • Snapshot before disposal: Capture the terminal command output via TerminalCommandArtifactCollector.capture before disposing, so the progress part can still render output via the snapshot mirror even after the terminal instance is gone.
  • Suppress redundant steering: Mark the terminal as programmatically killed before disposal so the onDisposed handler does not send a redundant "terminal exited" steering message.
  • Updated completion message: Background terminals that will be disposed get a cleaner notification ("The terminal has been cleaned up") instead of suggesting send_to_terminal/kill_terminal on a terminal that no longer exists.
demo.mov

Copilot AI review requested due to automatic review settings May 13, 2026 17:38
@meganrogge meganrogge added the chat-terminal The run in terminal tool in chat label May 13, 2026
@meganrogge meganrogge self-assigned this May 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to dispose of background terminals at the start of each new chat turn so that terminals (which are not reused across turns) don't accumulate. Terminals are preserved if the user has revealed them, if they still have an active execution, or if they are the foreground terminal for the session.

The only change visible in the reviewed diff is the removal of a trailing blank line at the end of the constructor in runInTerminalTool.ts. The substantive turn-start cleanup logic described in the PR is not present in the diff hunks provided for review.

Changes:

  • Remove a stray blank line at the end of RunInTerminalTool's constructor body.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts Removes a single trailing blank line before the closing brace of the constructor.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@meganrogge meganrogge removed the chat-terminal The run in terminal tool in chat label May 13, 2026
@meganrogge meganrogge added this to the 1.121.0 milestone May 13, 2026
@meganrogge meganrogge force-pushed the merogge/ephemeral-terminals-per-turn-v2 branch from 8c4708d to 58a8389 Compare May 13, 2026 17:45
@meganrogge meganrogge changed the title Dispose finished background terminals at the start of each turn Dispose finished background terminals as they're not reused May 13, 2026
@meganrogge meganrogge force-pushed the merogge/ephemeral-terminals-per-turn-v2 branch from 58a8389 to f6f7c53 Compare May 13, 2026 17:55
@meganrogge meganrogge changed the title Dispose finished background terminals as they're not reused Dispose finished background terminals to prevent accumulation May 13, 2026
@meganrogge meganrogge force-pushed the merogge/ephemeral-terminals-per-turn-v2 branch from f6f7c53 to 8b797de Compare May 13, 2026 17:58
When a new chat request is submitted, clean up background terminals
that have completed their execution and are still hidden from the
user. This prevents terminal accumulation across turns since background
terminals are not reused.

Terminals are preserved if they:
- Have been revealed by the user (hideFromUser is false)
- Still have an active execution (servers, watchers, etc.)
- Are the foreground terminal for the session (reused across turns)

Fixes #287177

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meganrogge meganrogge force-pushed the merogge/ephemeral-terminals-per-turn-v2 branch from 8b797de to a561e1c Compare May 13, 2026 18:05
@meganrogge meganrogge enabled auto-merge (squash) May 13, 2026 18:07
@meganrogge
Copy link
Copy Markdown
Collaborator Author

/requires-eval-assessment terminalbench2 gpt-5.4,claude-opus-4.6,claude-opus-4.7

@meganrogge meganrogge added the ~requires-eval-assessment Evals will be run and will generate a report upon completion label May 13, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

⏳ Queued vscode build for f8825a67585a2bb5eea497cd0877380421394814 (step 1/2).

…otification calls

The method signature added a toolSpecificData parameter (5th arg),
but 4 tests were still using the old signature, passing the
outputMonitor in the toolSpecificData position. This caused:
- outputMonitor to be undefined, so input-needed listeners were
  never set up (tests 1 & 3 got 0 instead of expected counts)
- alreadyNotifiedInputNeededOutput string to land in the
  outputMonitor position, causing 'continueMonitoringAsync is
  not a function' (test 2)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
benvillalobos
benvillalobos previously approved these changes May 13, 2026
@meganrogge meganrogge added ~requires-eval-assessment Evals will be run and will generate a report upon completion and removed ~requires-eval-assessment Evals will be run and will generate a report upon completion labels May 13, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

⏳ Queued vscode build for 99c2abdf41de69ad47a9ff78808ff7475001c258 (step 1/2).

The 'should preserve session terminal association after inputNeeded'
test was failing because the mock terminalInstance lacked
shellLaunchConfig, which is accessed in the onCommandFinished handler.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meganrogge meganrogge merged commit 31b9892 into main May 13, 2026
25 checks passed
@meganrogge meganrogge deleted the merogge/ephemeral-terminals-per-turn-v2 branch May 13, 2026 18:53
@vs-code-engineering
Copy link
Copy Markdown
Contributor

🚀 Queued eval-assessment publish build for 197236a30d594ee9a4efed09089eeb7f1e03336a (step 2/2).

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🔬 Queued eval-assessment benchmark for 146f636b39.

Results will be posted back here when the run completes.

@vs-code-engineering
Copy link
Copy Markdown
Contributor

✅ Eval-assessment build published.

@vs-code-engineering vs-code-engineering Bot removed the ~requires-eval-assessment Evals will be run and will generate a report upon completion label May 13, 2026
NikolaRHristov pushed a commit to CodeEditorLand/Editor that referenced this pull request May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make terminals ephemeral per turn

4 participants