Skip to content

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

Description

@ThomasKes

Type: Bug

VS Code version: Code - Insiders 1.138.0-insider (b065ad9, 2026-09-11T17:49:28-07:00)
OS version: Windows_NT x64 10.0.22631
Modes:
Extensions: none

Summary

Calling vscode.tasks.executeTask(task) with a Task object obtained from vscode.tasks.fetchTasks({ type: 'mytasktype' }) activates every installed extension that contributes a taskDefinition, not just the providers for the task's own type.

Executing an equivalent Task that the extension constructed itself activates only providers of the matching type, as expected. So the unwanted activation is triggered purely by round-tripping the task through fetchTasks().

Note that fetchTasks({ type }) itself behaves correctly — it only activates providers of the requested type. It is the subsequent executeTask() that fans out.

Steps to Reproduce

Create a minimal reproducer extension:

// package.json
"activationEvents": ["onStartupFinished"],
"contributes": {
  "taskDefinitions": [{ "type": "mytasktype" }]
}
// extension.ts
const TASK_TYPE = 'mytasktype';
const TASK = new vscode.Task(
    { type: TASK_TYPE },
    vscode.TaskScope.Workspace,
    'hello',
    TASK_TYPE,
    new vscode.ShellExecution('echo hello')
);

export async function activate(context: vscode.ExtensionContext): Promise<void> {
    context.subscriptions.push(
        vscode.tasks.registerTaskProvider(TASK_TYPE, {
            provideTasks() { return [TASK]; },
            resolveTask() { return undefined; }
        })
    );

    const tasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE });

    // await vscode.tasks.executeTask(TASK);      // OK: activates only "mytasktype" providers
    await vscode.tasks.executeTask(tasks[0]);     // BUG: activates *all* task providers
}
  1. Launch the reproducer extension in an Extension Development Host on an otherwise empty workspace.

  2. Observe in the Tasks output channel, that after activating task providers for type mytasktype, all other providers are activated as well (twice!).
    Image

  3. You may also observe it in the Running Extensions view, where you'll see that the built-in Gulp extension is activated which is not usually the case in an empty workspace.

  4. Swap the two executeTask lines and repeat: Only mytasktype providers activate.

Expected

executeTask() activates only the task providers needed to resolve and run the given task regardless of whether the Task object came from fetchTasks() or was constructed by the caller.

Possible precedent

A similar issue was described in #175821 and fixed in #178679.

Impact

Extensions that run tasks programmatically cause unrelated extensions to activate in workspaces where they have nothing to do. executeTask() of a fetched task pays the cost of waking all task-provider extensions, and can block for up to the 5s raceTimeout in _activateTaskProviders ("Timed out activating extensions for task providers", cf. #181844).


Analysis (AI-generated!)

The two code paths in ExtHostTask.executeTask() (src/vs/workbench/api/node/extHostTask.ts) are not equivalent:

  • A task created by the extension has no _id, so it is sent to the main thread as a full TaskDTO, and no lookup is needed.
  • A task returned by fetchTasks() has a preserved _id, so it is sent as a TaskHandleDTO. ITaskHandleDTO (src/vs/workbench/api/common/shared/tasks.ts) only carries { id, workspaceFolder } — the task type is dropped at this point.

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

this._taskService.getTask(workspace, value.id, true);   // 4th arg `type` omitted

AbstractTaskService.getTask() does not find the task via _findWorkspaceTasks() (it is provider-contributed, not in tasks.json), so it falls through to:

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

which reaches _activateTaskProviders(undefined) → _getActivationEvents(undefined):

} else {
    // send activation events for all task types
    for (const definition of TaskDefinitionRegistry.all()) {
        result.push(`onTaskType:${definition.taskType}`);
    }
}

…activating every extension that contributes a task definition.

This is the same failure mode as #175821, which was fixed in PR #178679 by adding the type parameter to getTask() and passing it from AbstractTaskService._executeTask(). The extension-host entry points were not updated, so they still call getTask() without a type and re-introduce the fan-out.

Suggested fix (AI-generated!)

Thread the task type through the handle DTO, mirroring PR #178679:

  1. Add an optional type?: string to ITaskHandleDTO in src/vs/workbench/api/common/shared/tasks.ts.
  2. Populate it from value.definition.type in TaskHandleDTO.from() in src/vs/workbench/api/common/extHostTask.ts.
  3. Pass it as the 4th argument in both getTask() calls in mainThreadTask.ts ($getTaskExecution and $executeTask).

Activity

  1. added
    unreleased
    on Nov 5, 2026
  2. added a commit that references this issue on Nov 5, 2026
    2b5aa4d
  3. added
    insiders-released
    and removed
    unreleased
    on Nov 5, 2026
  4. added
    bug
    on Nov 6, 2026
  5. added
    verified
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buginsiders-releasedverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions