-
Notifications
You must be signed in to change notification settings - Fork 38
Description
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:
- First attempt
pause/resumevia the task API. - If either call returns a
404, cache that this is an older deployment (e.g. a boolean flag on the client/panel instance). - Fall back to the existing
stopWorkspace/startWorkspaceapproach. - 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
CoderApiclass (extendsApifromcoder/site/src/api/api) would needpauseTaskandresumeTaskmethods added, or the extension can make direct HTTP calls. - The Go SDK already has
PauseTask/ResumeTaskincodersdk/aitasks.goas a reference for the request/response shapes. - The
PauseTaskResponseandResumeTaskResponseboth return aworkspace_buildfield. - Tests in
test/unit/webviews/tasks/tasksPanel.test.tscurrently mockstopWorkspace/startWorkspacefor pause/resume scenarios — these need updating too. - The
TasksPanelClienttype in the tests will need to include the new methods.
Created on behalf of @EhabY