fix(coderd): use BuildReasonTaskAutoPause for task workspaces#22126
fix(coderd): use BuildReasonTaskAutoPause for task workspaces#22126
Conversation
When a workspace with a TaskID hits its deadline, use BuildReasonTaskAutoPause instead of BuildReasonAutostop. This allows downstream systems to distinguish between regular autostop and task workspace pauses.
| case isEligibleForAutostart(user, ws, latestBuild, latestJob, templateSchedule, currentTick): | ||
| return database.WorkspaceTransitionStart, database.BuildReasonAutostart, nil |
There was a problem hiding this comment.
self-review: assuming that there is no reason to "auto-resume" a task.
There was a problem hiding this comment.
We have not defined it yet. But the autostart schedule of the underlying workspace would naturally map to this.
For now, we can leave it out 👍🏻
There was a problem hiding this comment.
Pull request overview
This PR adds a new build reason BuildReasonTaskAutoPause to distinguish when AI task workspaces are automatically paused by the lifecycle executor from regular workspace autostops. When a workspace with a TaskID hits its deadline (or needs a failed stop), it now uses BuildReasonTaskAutoPause instead of BuildReasonAutostop, allowing downstream systems to differentiate between these scenarios.
Changes:
- Added
BuildReasonTaskAutoPauseconstant in backend SDK and database enum - Updated lifecycle executor to check for TaskID and use the new build reason for autostop and failedstop transitions
- Added frontend TypeScript types, system build reasons list, and build reason labels
- Included comprehensive test coverage for the new behavior
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| codersdk/workspacebuilds.go | Added BuildReasonTaskAutoPause constant definition |
| coderd/autobuild/lifecycle_executor.go | Added TaskID checks to use TaskAutoPause reason for task workspaces during autostop and failedstop |
| coderd/autobuild/lifecycle_executor_test.go | Added test to verify task workspaces use TaskAutoPause build reason |
| coderd/autobuild/lifecycle_executor_internal_test.go | Added unit tests for getNextTransition with task workspaces |
| site/src/api/typesGenerated.ts | Added task_auto_pause to BuildReason type and array |
| site/src/utils/workspace.tsx | Added task_auto_pause to systemBuildReasons array and buildReasonLabels map |
| site/src/pages/TaskPage/TaskPage.stories.tsx | Updated TaskPausedTimeout story to use task_auto_pause reason |
| docs/reference/api/schemas.md | Updated BuildReason enum documentation |
| coderd/apidoc/swagger.json | Updated OpenAPI spec with task_auto_pause enum value |
| coderd/apidoc/docs.go | Updated API documentation template |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add task_auto_pause to buildReasonLabels with label 'Task Auto-Pause' - Add task_auto_pause to systemBuildReasons array - Add task_auto_pause to getDisplayWorkspaceBuildInitiatedBy (returns 'Coder') - Add test case for task_auto_pause in getDisplayWorkspaceBuildInitiatedBy - Update TaskPausedTimeout story to use task_auto_pause reason
| case isEligibleForAutostart(user, ws, latestBuild, latestJob, templateSchedule, currentTick): | ||
| return database.WorkspaceTransitionStart, database.BuildReasonAutostart, nil |
There was a problem hiding this comment.
We have not defined it yet. But the autostart schedule of the underlying workspace would naturally map to this.
For now, we can leave it out 👍🏻
| "autostart", | ||
| "autostop", | ||
| "dormancy", | ||
| "task_auto_pause", |
There was a problem hiding this comment.
I realize not related to this PR, but something we've overlooked previously. Should we add task_resume and task_manual_pause here as well?
Relates to coder/internal#1252
When a workspace with a TaskID hits its deadline, use BuildReasonTaskAutoPause instead of BuildReasonAutostop. This allows downstream systems to distinguish between regular autostop and task workspace pauses.
Created by Mux using Opus 4.5.