Repository navigation
Fix early task termination and lost task end after terminal reuse - #351260
Merged
Megan Rogge (meganrogge) merged 2 commits intoNov 30, 2026
Merged
Conversation
- Apply TaskExecution.terminate() requested before a task has started once the task system accepts it, and stop the task as soon as its terminal is attached instead of dropping the request. - Reset the terminal's exiting state when reusing a task terminal, so the exit of the next process is reported after a previous nonzero exit. Fixes #350588 Fixes #350590 Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Task execution tracking conflates concurrent instances, so terminating an API execution can target an unrelated UI instance or silently fail when the instance limit is reached.
2 open issues
What changed in this PR
This PR addresses early task termination through the extension API (#350588) and missing task-end events after reusing a failed task’s terminal (#350590).
Changes:
- Tracks pending executions and retries termination when the task system accepts them.
- Defers termination until a task’s terminal is attached.
- Resets terminal exit state on reuse and adds regression tests for all three paths.
| File | Description |
|---|---|
src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts |
Tests exit events after reusing a failed task terminal. |
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts |
Clears exit state unconditionally on terminal reuse. |
src/vs/workbench/contrib/tasks/test/browser/terminalTaskSystem.test.ts |
Tests termination requested before terminal attachment. |
src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts |
Retains pending termination until attachment or task completion. |
src/vs/workbench/api/test/browser/mainThreadTask.test.ts |
Tests early termination before task acceptance. |
src/vs/workbench/api/browser/mainThreadTask.ts |
Tracks requested executions and retries early termination. |
Review effort: Balanced
Report the instance a run executes (newly started, or the active one when the instance limit is reached) through a run option, and apply early termination to that instance only instead of retargeting on any start event with the same task id. Co-authored-by: Copilot <[email protected]>
Megan Rogge (meganrogge)
marked this pull request as ready for review
November 30, 2026 17:56
Megan Rogge (meganrogge)
enabled auto-merge
November 30, 2026 17:57
Ulugbek Abdullaev (ulugbekna)
approved these changes
Nov 30, 2026
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 30, 2026
Megan Rogge (meganrogge)
deleted the
agents/fix-task-lifecycle-bugs-vscode
branch
November 30, 2026 18:55
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.


Fixes #350588
Fixes #350590
Changes
#350588:
TaskExecution.terminate()before the task starts is droppedexecuteTaskin the extension host does not wait for the main thread. Aterminate()called right afterexecuteTaskcan therefore reach the main thread before the task is resolved, run, or attached to its terminal. The main thread only looked through active tasks, which need a terminal. It rejected the call with "Task to terminate not found" and the task kept running.MainThreadTasknow remembers executions that were requested but haven't started yet. A terminate for one of them is recorded. It is applied as soon as the task is resolved and again when the task system reportsCustomExecutionAccepted/Startfor it, using the task instance the task system actually runs.TerminalTaskSystem.terminateno longer returnssuccess: falsewhen a task is known but its terminal isn't attached yet. It keeps a pending termination and stops the task as soon as the terminal is attached. If the task ends first, the pending termination resolves.#350590: reusing a dedicated task terminal after a nonzero exit loses the next end event
When a task exits with a nonzero code, the terminal stays open for reuse, but
_isExitingstayedtrue.reuseTerminalcleared it only forwaitOnExitterminals. The next process's exit was then ignored, soonExitnever fired and the task never ended.reuseTerminalnow always clears the exiting state.How to test
New unit tests reproduce each bug; each one fails without the fix:
TerminalTaskSystem terminate: stops a task whose terminate was requested before its terminal was attachedMainThreadTask terminate: terminating an execution before the task has started stops it once the task system accepts itTerminalInstance: reusing a task terminal after a failed exit reports the next exitTo check manually: in an extension, call
const e = await vscode.tasks.executeTask(task); e.terminate();. The task should stop instead of running on. Then run a dedicated-panel task that fails, rerun it in the same terminal, and check thatonDidEndTaskProcessfires for the second run.Validation
./scripts/test.sh --run src/vs/workbench/contrib/tasks/test/browser/terminalTaskSystem.test.ts --run src/vs/workbench/api/test/browser/mainThreadTask.test.ts --run src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts: passed (142 passing). With the source changes reverted, the 3 new tests fail.pnpm run typecheck-client: passedpnpm run oxlint <changed files>: passed