Skip to content

Use task pause/resume API instead of workspace stop/start #795

@blinkagent

Description

@blinkagent

Summary

The Coder API now supports dedicated task pause/resume endpoints (POST /api/v2/tasks/{user}/{task}/pause and POST /api/v2/tasks/{user}/{task}/resume). The VS Code extension should use these instead of the current stopWorkspace/startWorkspace calls.

Current Behavior

In src/webviews/tasks/tasksPanel.ts, the handlePauseTask and handleResumeTask methods use generic workspace stop/start:

private async handlePauseTask(taskId: string, taskName: string): Promise<void> {
    const task = await this.client.getTask("me", taskId);
    if (!task.workspace_id) {
        throw new Error("Task has no workspace");
    }
    await this.client.stopWorkspace(task.workspace_id);
    // ...
}

private async handleResumeTask(taskId: string, taskName: string): Promise<void> {
    const task = await this.client.getTask("me", taskId);
    if (!task.workspace_id) {
        throw new Error("Task has no workspace");
    }
    await this.client.startWorkspace(task.workspace_id, task.template_version_id);
    // ...
}

Desired Behavior

Use the dedicated task pause/resume API endpoints:

  • Pause: POST /api/v2/tasks/{user}/{task}/pause
  • Resume: POST /api/v2/tasks/{user}/{task}/resume

These endpoints set the correct build_reason (task_manual_pause / task_resume) which enables features like log snapshot capture on pause and proper task lifecycle tracking.

Backward Compatibility

Older Coder servers won't have these endpoints. The implementation should:

  1. First attempt pause/resume via the task API.
  2. If either call returns a 404, cache that this is an older deployment (e.g. a boolean flag on the client/panel instance).
  3. Fall back to the existing stopWorkspace/startWorkspace approach.
  4. On subsequent calls, skip directly to the fallback if the deployment was already identified as older.

This avoids unnecessary 404 round-trips on every pause/resume action after the first attempt.

Implementation Notes

  • The CoderApi class (extends Api from coder/site/src/api/api) would need pauseTask and resumeTask methods added, or the extension can make direct HTTP calls.
  • The Go SDK already has PauseTask/ResumeTask in codersdk/aitasks.go as a reference for the request/response shapes.
  • The PauseTaskResponse and ResumeTaskResponse both return a workspace_build field.
  • Tests in test/unit/webviews/tasks/tasksPanel.test.ts currently mock stopWorkspace/startWorkspace for pause/resume scenarios — these need updating too.
  • The TasksPanelClient type in the tests will need to include the new methods.

Created on behalf of @EhabY

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions