feat(coderd): return log snapshot for paused tasks (#21771)

Previously the task logs endpoint only worked when the workspace was
running, leaving users unable to view task history after pausing.

This change adds snapshot retrieval with state-based branching: active
tasks fetch live logs from AgentAPI, paused/initializing/pending tasks
return stored snapshots (providing continuity during pause/resume), and
error/unknown states return HTTP 409 Conflict.

The response includes snapshot metadata (snapshot, snapshot_at) to
indicate whether logs are live or historical.

Closes coder/internal#1254
This commit is contained in:
Mathias Fredriksson
2026-01-30 16:09:45 +02:00
committed by GitHub
parent 536bca7ea9
commit 21eabb1d73
8 changed files with 432 additions and 33 deletions
+6 -2
View File
@@ -346,9 +346,13 @@ type TaskLogEntry struct {
Time time.Time `json:"time" format:"date-time" table:"time,default_sort"`
}
// TaskLogsResponse contains the logs for a task.
// TaskLogsResponse contains task logs and metadata. When snapshot is false,
// logs are fetched live from the task app. When snapshot is true, logs are
// fetched from a stored snapshot captured during pause.
type TaskLogsResponse struct {
Logs []TaskLogEntry `json:"logs"`
Logs []TaskLogEntry `json:"logs"`
Snapshot bool `json:"snapshot,omitempty"`
SnapshotAt *time.Time `json:"snapshot_at,omitempty"`
}
// TaskLogs retrieves logs from the task app.