Skip to content

Fix run_in_terminal wedging when cached terminal is disposed#311019

Merged
meganrogge merged 1 commit intomainfrom
merogge/fix-killed-chat
Apr 17, 2026
Merged

Fix run_in_terminal wedging when cached terminal is disposed#311019
meganrogge merged 1 commit intomainfrom
merogge/fix-killed-chat

Conversation

@meganrogge
Copy link
Copy Markdown
Collaborator

Fixes #296892
Fixes #308610

When terminal.killAll (or other terminal disposal) races with a run_in_terminal call, _initTerminal could return a stale cached terminal from _sessionTerminalAssociations because the onDidDisposeInstance cleanup hadn't propagated yet. This caused all subsequent terminal operations to fail permanently.

Added an isDisposed check before returning the cached terminal so _initTerminal falls through and creates a fresh terminal instead.

Copilot AI review requested due to automatic review settings April 17, 2026 15:23
@meganrogge meganrogge self-assigned this Apr 17, 2026
@meganrogge meganrogge added this to the 1.117.0 milestone Apr 17, 2026
@meganrogge meganrogge enabled auto-merge (squash) April 17, 2026 15:24
@meganrogge
Copy link
Copy Markdown
Collaborator Author

cc @anthonykim1

@github-actions
Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: af59b139 Current: 54b0971e

Changed (2)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after
editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after

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

Fixes a race where run_in_terminal could permanently wedge by reusing a stale cached terminal instance after the terminal was disposed (eg. via terminal.killAll), by ensuring disposed cached terminals are not reused.

Changes:

  • Add an isDisposed guard when reusing the cached foreground terminal in _initTerminal.
  • Add a unit test intended to cover the disposed-cached-terminal scenario.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts Prevents reuse of cached foreground terminal instances once they’ve been disposed.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/runInTerminalTool.test.ts Adds test coverage for the disposed cached terminal reuse regression (currently needs strengthening).

Copilot's findings

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

Comment on lines +1922 to +1925
// Verify the guard condition that _initTerminal uses:
// cachedTerminal && !cachedTerminal.isBackground && !cachedTerminal.instance.isDisposed
const wouldReuse = cachedTerminal !== undefined && !cachedTerminal.isBackground && !cachedTerminal.instance.isDisposed;
strictEqual(wouldReuse, false, 'Should not reuse a disposed cached terminal');
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This test doesn’t actually exercise RunInTerminalTool behavior: it recomputes the guard condition locally, so it will still pass even if _initTerminal stops checking instance.isDisposed (or if the reuse logic changes). To make this regression-proof, call into the tool (e.g. via prepareToolInvocation/invoke or by invoking the private _initTerminal through a cast) and assert a new terminal is created/returned when the cached association’s instance.isDisposed is true, and that the association map is updated accordingly.

Copilot uses AI. Check for mistakes.
@meganrogge meganrogge merged commit 7d58583 into main Apr 17, 2026
30 of 31 checks passed
@meganrogge meganrogge deleted the merogge/fix-killed-chat branch April 17, 2026 16:06
Copilot stopped work on behalf of meganrogge due to an error April 17, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants