Skip to content

Tasks: Telemetry for task lifecycle events #1259

Closed
1 of 1 issue completed
Closed

Description

@mafredri

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.Task struct:
    • last_paused_at (optional timestamp) - when task was last paused
    • last_resumed_at (optional timestamp) - when task was last resumed
    • pause_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:

References:

Activity

  1. johnstcn commented on Jan 29, 2026

    @johnstcn
    Member

    I've noticed that we missed filtering tasks with createdAfter in the telemetry snapshots. We'll probably want to fix this first.

  2. mafredri commented on Jan 29, 2026

    @mafredri
    MemberAuthor

    @johnstcn good catch, yes we should do that. 👍🏻

  3. mafredri commented on Jan 29, 2026

    @mafredri
    MemberAuthor

    @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?

  4. johnstcn commented on Jan 29, 2026

    @johnstcn
    Member

    @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?

    Ooh, that's also a good catch. 👍

  5. johnstcn commented on Feb 24, 2026

    @johnstcn
    Member

    Coder-side telemetry change has been merged. Waiting on review for the telemetry server side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions