Repository navigation
Closed
1 / 11 of 1 issue completedLabels
Description
Repo: coder/coder
Scope: Add task lifecycle fields to Task telemetry to enable pause/resume analysis.
Problem: The current telemetry Task struct only has basic status. To analyze task lifecycle (pause/resume patterns, idle times, pause durations), we need lifecycle-specific metrics directly on Task telemetry.
Changes:
- Add lifecycle fields to
telemetry.Taskstruct:last_paused_at(optional timestamp) - when task was last pausedlast_resumed_at(optional timestamp) - when task was last resumedpause_reason(optional string) - "auto" or "manual"idle_duration_ms(optional int64) - time from last AI "working" status to pause (only for paused tasks)paused_duration_ms(optional int64) - time from pause to resume (only for recently resumed tasks, e.g. within past hour)
- Modify
ConvertTask()to calculate these fields during snapshotting:- Query workspace_builds filtered by task's workspace_id for pause/resume transitions
- For paused tasks: query workspace_app_statuses to find last "working" state, calculate idle_duration_ms
- For recently resumed tasks: calculate paused_duration_ms from pause build to resume build timestamps
- All calculation happens during snapshot creation where database access is available
Why on Task not WorkspaceBuild:
- Task lifecycle metrics are about the TASK, not the underlying workspace build
- Direct task-centric data avoids complex correlation with workspace_id (multiple tasks could share a workspace)
- Analytics queries are simpler: filter Tasks by status/reason, no joins needed
Files:
coderd/telemetry/telemetry.go(add fields to Task struct, update ConvertTask with queries)
Acceptance criteria:
- Task telemetry includes lifecycle fields (last_paused_at, last_resumed_at, pause_reason, idle_duration_ms, paused_duration_ms)
- Fields populated correctly for paused tasks (idle_duration_ms, pause_reason, last_paused_at)
- Fields populated correctly for recently resumed tasks (paused_duration_ms, last_resumed_at)
- Fields are null/absent for tasks that haven't been paused or resumed
- Telemetry tests verify calculation logic with mock workspace_builds and workspace_app_statuses data
- No regression in existing task telemetry
Dependencies:
- Tasks: Database migrations for task lifecycle #1250
- Tasks: Manual pause endpoint #1261
- Tasks: Resume endpoint #1262
References:
Activity
johnstcn commentedon Jan 29, 2026
I've noticed that we missed filtering tasks with
createdAfterin the telemetry snapshots. We'll probably want to fix this first.mafredri commentedon Jan 29, 2026
@johnstcn good catch, yes we should do that. 👍🏻
mafredri commentedon Jan 29, 2026
@johnstcn Come to think of it, if we filter tasks by those created in the last hour, some of the telemetry data mentioned in this ticket wouldn't make sense. Should we instead include all task that had activity (pause/resume) in the last hour?
johnstcn commentedon Jan 29, 2026
Ooh, that's also a good catch. 👍
chore(coderd/database/dbfake): add support for provisioner job timest…
feat: add telemetry for task lifecycle events (#21922)
johnstcn commentedon Feb 24, 2026
Coder-side telemetry change has been merged. Waiting on review for the telemetry server side.