Skip to content

tasks: pass task type through ITaskHandleDTO to prevent provider fanout - #336159

Merged
Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
rksharma-owg:fix/task-execute-provider-fanout
Nov 5, 2026
Merged

Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
rksharma-owg:fix/task-execute-provider-fanout

Conversation

@rksharma-owg

Copy link
Copy Markdown
Contributor

Description

Fixes #336152

When calling vscode.tasks.executeTask(task) with a Task obtained from vscode.tasks.fetchTasks({ type }), ExtHostTask.executeTask() serializes the task to the main thread as an ITaskHandleDTO.

Previously, ITaskHandleDTO only carried { id, workspaceFolder }, dropping the task's type.

On the main thread, both $getTaskExecution() and $executeTask() in src/vs/workbench/api/browser/mainThreadTask.ts called:

this._taskService.getTask(workspace, value.id, true); // type omitted

Because provider-contributed tasks are not in tasks.json, AbstractTaskService.getTask() falls back to:

const map = await this._getGroupedTasks({ type }); // type is undefined

which activates all registered task providers across all installed extensions, causing unnecessary extension activation and delay.

Solution

  1. Add optional type?: string; to ITaskHandleDTO in src/vs/workbench/api/common/shared/tasks.ts.
  2. Populate type: value.definition?.type in TaskHandleDTO.from() in src/vs/workbench/api/common/extHostTask.ts.
  3. Update ITaskService.getTask method signature in src/vs/workbench/contrib/tasks/common/taskService.ts to accept type?: string.
  4. Pass value.type as the 4th argument in both getTask() calls in mainThreadTask.ts ($getTaskExecution and $executeTask), mirroring how PR Fix accidently starting all onTaskType extensions when running any task; fixes #175821 #178679 fixed this for internal executions.

Verification

  • Added a unit test in extHostTask.test.ts verifying that TaskHandleDTO.from(task) preserves the task definition's type.
  • Ran npm run typecheck-client (0 errors).
  • Ran npm run hygiene (checked 12,042 files, 0 errors).
  • Ran existing task configuration unit tests (61 passing).

When executing a task obtained from fetchTasks(), the task is serialized
to the main thread as an ITaskHandleDTO. Previously, ITaskHandleDTO omitted
the task's type, causing $getTaskExecution() and $executeTask() in
mainThreadTask.ts to call taskService.getTask() without a type parameter.

When the task is not in tasks.json, AbstractTaskService falls back to
querying resolvers via _getGroupedTasks({ type: undefined }), which
activates all registered task providers across all extensions.

This updates ITaskHandleDTO to carry the optional type parameter from
the task definition and forwards it to taskService.getTask(), matching
the behavior of the internal task execution path.

Fixes microsoft#336152
Copilot AI balanced review requested due to automatic review settings September 14, 2026 15:26

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

The focused changes correctly preserve and consume the task type, with appropriate unit coverage.

Pull request overview

Threads task types through task handles to prevent unnecessary activation of unrelated task providers.

Changes:

  • Adds task type to ITaskHandleDTO and its serialization.
  • Uses the type when resolving task executions.
  • Adds focused serialization coverage.
File summaries
File Description
taskService.ts Exposes the existing optional type parameter.
extHostTask.test.ts Tests task-type preservation.
shared/tasks.ts Extends the task handle DTO.
extHostTask.ts Serializes the task definition type.
mainThreadTask.ts Passes the type into task lookup.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ThomasKes

Copy link
Copy Markdown

Hi Megan Rogge (@meganrogge), what are the chances of this PR being merged soon? This change has a significant impact on users of our VS Code extension: it would make VS Code feel much more responsive in our use cases and cut down on unwanted, unpredictable side effects during task execution. I'm happy to help or provide more context if that's useful. Thanks in advance!

@meganrogge Megan Rogge (meganrogge) left a comment

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.

Thanks, this looks good. getTask already supports filtering by type, so passing it through for executeTask() avoids activating every task provider.

@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) November 3, 2026 19:26
@meganrogge
Megan Rogge (meganrogge) merged commit 2b5aa4d into microsoft:main Nov 5, 2026
59 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 5, 2026

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

Typed lookups can exclude valid tasks whose definition type differs from their provider’s registration type, causing task execution to fail without an untyped fallback.

2 open issues

Review effort: Max

const workspace = this.getWorkspace(value.workspaceFolder);
if (workspace) {
const task = await this._taskService.getTask(workspace, value.id, true);
const task = await this._taskService.getTask(workspace, value.id, true, value.type);
const workspace = this.getWorkspace(value.workspaceFolder);
if (workspace) {
const task = await this._taskService.getTask(workspace, value.id, true);
const task = await this._taskService.getTask(workspace, value.id, true, value.type);
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.

executeTask() activates *all* extensions with a task provider when the task came from fetchTasks()

6 participants