Skip to content

Commit b3b3929

Browse files
committed
fix(coderd): prevent idle state from showing for paused/errored tasks
Previously, the deriveTaskCurrentState function would return app status (including "idle" state) for all tasks, regardless of their status. This caused stopped or errored tasks to incorrectly appear in the "Waiting for input" tab if they had an idle app status. Now, the function only returns app status for tasks with "active" status. For paused or errored tasks, the function returns nil or an appropriate state based on their actual condition. This fix is implemented in the backend state machine rather than filtering on the frontend, ensuring the task state is semantically correct at the source. --- 🤖 This change was written by Claude Code using Coder Tasks and reviewed by a human 🏂
1 parent 02bac71 commit b3b3929

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

coderd/aitasks.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,14 @@ func deriveTaskCurrentState(
341341
) *codersdk.TaskStateEntry {
342342
var currentState *codersdk.TaskStateEntry
343343

344-
// Ignore 'latest app status' if it is older than the latest build and the
345-
// latest build is a 'start' transition. This ensures that you don't show a
346-
// stale app status from a previous build. For stop transitions, there is
347-
// still value in showing the latest app status.
348-
if ws.LatestAppStatus != nil {
344+
// Only use app status for active tasks. For paused or errored tasks,
345+
// we should not report app status (like "idle") since the workspace
346+
// is not actually running and waiting for input.
347+
if dbTask.Status == database.TaskStatusActive && ws.LatestAppStatus != nil {
348+
// Ignore 'latest app status' if it is older than the latest build and the
349+
// latest build is a 'start' transition. This ensures that you don't show a
350+
// stale app status from a previous build. For stop transitions, there is
351+
// still value in showing the latest app status.
349352
if ws.LatestBuild.Transition != codersdk.WorkspaceTransitionStart || ws.LatestAppStatus.CreatedAt.After(ws.LatestBuild.CreatedAt) {
350353
currentState = &codersdk.TaskStateEntry{
351354
Timestamp: ws.LatestAppStatus.CreatedAt,

0 commit comments

Comments
 (0)