Skip to content

Fix task restart to re-read updated tasks.json configuration #251759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 17, 2025

When a task is running and the user edits tasks.json, clicking "Restart Task" on the warning dialog was restarting the task with the old definition instead of reading the updated configuration from tasks.json.

Problem

The _restart() method in abstractTaskService.ts was reusing the existing task object instead of re-reading from the workspace configuration:

private async _restart(task: Task): Promise<void> {
    // ... terminate task
    await this.run(task); // ← Uses old task definition
}

This meant that any changes made to tasks.json while a task was running would be ignored during restart.

Solution

Added a new _findUpdatedTaskByIdentifier() method that:

  1. Uses the existing _findWorkspaceTasks() infrastructure to search current workspace configuration
  2. Matches tasks by their definition identifier or label
  3. Handles both custom tasks and configuring tasks (resolving them appropriately)
  4. Falls back to the original task if no updated definition is found

The _restart() method now resolves the fresh task definition before running:

private async _restart(task: Task): Promise<void> {
    // ... terminate task
    const updatedTask = await this._findUpdatedTaskByIdentifier(task);
    await this.run(updatedTask || task); // ← Uses updated definition when available
}

Backward Compatibility

  • If task resolution fails or no updated task is found, falls back to original behavior
  • No breaking changes to existing API or functionality
  • Uses existing VS Code task infrastructure patterns

Fixes #169267.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 17, 2025 22:27
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] "The task is already active" button "Restart Task" doesn't re-read tasks.json Fix task restart to re-read updated tasks.json configuration Jun 17, 2025
@Copilot Copilot AI requested a review from anthonykim1 June 17, 2025 22:30
Copilot finished work on behalf of anthonykim1 June 17, 2025 22:30
@anthonykim1
Copy link
Contributor

this does not work, try reading #251755 which correctly re-reads tasks.json and watch for its update using await this._updateWorkspaceTasks(TaskRunSource.ConfigurationChange);

…Tasks

Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 18, 2025

this does not work, try reading #251755 which correctly re-reads tasks.json and watch for its update using `await this._updateWorkspaceTasks(TaskRunSource.Conf...

You're absolutely right. I've simplified the approach to use await this._updateWorkspaceTasks(TaskRunSource.ConfigurationChange); in the restart method as you suggested. This properly re-reads tasks.json configuration before restarting the task. The complex task matching logic has been removed in favor of this cleaner solution. Fixed in commit 597eb64.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of anthonykim1 June 18, 2025 02:19
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.

"The task is already active" button "Restart Task" doesn't re-read tasks.json
2 participants