Skip to content

Conversation

@mafredri
Copy link
Member

This change adds a POST /workspaceagents/me/tasks/{task}/log-snapshot
endpoint for agents to upload task conversation history during
workspace shutdown. This allows users to view task logs even when the
workspace is stopped.

The endpoint accepts agentapi format payloads (typically last 10
messages, max 64KB), wraps them in a format envelope, and upserts to the
task_snapshots table. Uses agent token auth and validates the task
belongs to the agent's workspace.

Closes coder/internal#1253

@mafredri mafredri force-pushed the mafredri/feat-task-log-snapshot-storage-endpoint branch 4 times, most recently from 6dbd8aa to f91f4ef Compare January 23, 2026 12:29
@mafredri mafredri force-pushed the mafredri/feat-task-log-snapshot-storage-endpoint branch 5 times, most recently from 010ee8f to 36f7af4 Compare January 26, 2026 11:09
r.Post("/log-source", api.workspaceAgentPostLogSource)
r.Get("/reinit", api.workspaceAgentReinit)
r.Route("/tasks/{task}", func(r chi.Router) {
r.Post("/log-snapshot", api.postWorkspaceAgentTaskLogSnapshot)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Diverge from RFC/ticket /snapshot -> /log-snapshot because this endpoint will only ever accept logs. If we ever expand snapshot functionality with additional data (say, content/git diff), that will require a new endpoint and this will avoid confusion.

@mafredri mafredri marked this pull request as ready for review January 26, 2026 11:11
@mafredri mafredri requested review from SasSwart and johnstcn January 26, 2026 11:11
This change adds a POST /workspaceagents/me/tasks/{task}/log-snapshot
endpoint for agents to upload task conversation history during
workspace shutdown. This allows users to view task logs even when the
workspace is stopped.

The endpoint accepts agentapi format payloads (typically last 10
messages, max 64KB), wraps them in a format envelope, and upserts to the
task_snapshots table. Uses agent token auth and validates the task
belongs to the agent's workspace.

Closes coder/internal#1253
@mafredri mafredri force-pushed the mafredri/feat-task-log-snapshot-storage-endpoint branch from 36f7af4 to 88dfd8a Compare January 26, 2026 11:11
@github-actions
Copy link

github-actions bot commented Jan 26, 2026

@coder-tasks
Copy link

coder-tasks bot commented Jan 26, 2026

Documentation Check

No Changes Needed

This PR adds an internal agent-to-server endpoint (POST /workspaceagents/me/tasks/{task}/log-snapshot) for workspace agents to upload task conversation snapshots during shutdown. The changes are:

  1. Backend implementation - New endpoint in coderd/aitasks.go with authentication, validation, and snapshot storage
  2. API documentation - Auto-generated OpenAPI docs already updated in docs/reference/api/tasks.md
  3. Database layer - New queries for snapshot storage with proper RBAC authorization

Why no user-facing docs needed:

  • This is an infrastructure/protocol endpoint used by workspace agents, not by end users
  • The feature enables viewing task logs when workspaces are stopped (backend enhancement)
  • User-facing behavior (viewing task logs) remains the same - no new UI features or CLI commands
  • The API reference documentation was auto-generated and is already included in the PR

The existing task documentation in docs/ai-coder/tasks.md covers the user-facing aspects adequately. This change is transparent infrastructure that improves the reliability of task logs without requiring user documentation.


Automated review via Coder Tasks

@mafredri mafredri force-pushed the mafredri/feat-task-log-snapshot-storage-endpoint branch from 0e62bfa to 61ca1e0 Compare January 26, 2026 12:22
Remove @produce annotation from task log snapshot endpoint that returns
HTTP 204 with no body. Endpoints that return no content should not have
@produce annotations.

Add RBAC accounting tests for GetTaskSnapshot and UpsertTaskSnapshot to
ensure proper authorization checks are tested.
@mafredri mafredri force-pushed the mafredri/feat-task-log-snapshot-storage-endpoint branch from 61ca1e0 to cfa9fd0 Compare January 26, 2026 12:23
@mafredri mafredri force-pushed the mafredri/feat-task-log-snapshot-storage-endpoint branch from 638cf53 to 6f0810d Compare January 26, 2026 13:07
@mafredri mafredri merged commit 25d7f27 into main Jan 27, 2026
33 checks passed
@mafredri mafredri deleted the mafredri/feat-task-log-snapshot-storage-endpoint branch January 27, 2026 09:09
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tasks: Log snapshot storage endpoint

3 participants