Stop workspace before deleting — Coder returns 405 on running workspaces

The DELETE API requires the workspace to be stopped first. Now stops,
waits 10s for shutdown, then deletes. This was causing workspaces to
never be cleaned up after task completion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel Samson
2026-04-12 15:18:54 +01:00
co-authored by Claude Opus 4.6
parent b43e38ec54
commit 833afdd2a3
+5 -1
View File
@@ -127,10 +127,14 @@ export class TaskQueue {
this.active.delete(workspaceName);
try {
await this.coder.stopWorkspace(entry.workspaceId);
console.log(`[queue] workspace stopped: ${workspaceName} — waiting for shutdown`);
// Wait for the workspace to fully stop before deleting
await new Promise((resolve) => setTimeout(resolve, 10_000));
await this.coder.deleteWorkspace(entry.workspaceId);
console.log(`[queue] workspace deleted: ${workspaceName}`);
} catch (err) {
console.error(`[queue] failed to delete workspace ${workspaceName}:`, err);
console.error(`[queue] failed to clean up workspace ${workspaceName}:`, err);
}
// Drain in case pending tasks were waiting for capacity