feat(coderd): add task log snapshot storage endpoint (#21644)

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
This commit is contained in:
Mathias Fredriksson
2026-01-27 11:09:24 +02:00
committed by GitHub
parent f2e998848e
commit 25d7f27cdb
13 changed files with 745 additions and 8 deletions
+41
View File
@@ -399,3 +399,44 @@ curl -X POST http://coder-server:8080/api/v2/tasks/{user}/{task}/send \
| 204 | [No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) | No Content | |
To perform this operation, you must be authenticated. [Learn more](authentication.md).
## Upload task log snapshot
### Code samples
```shell
# Example request using curl
curl -X POST http://coder-server:8080/api/v2/workspaceagents/me/tasks/{task}/log-snapshot?format=agentapi \
-H 'Content-Type: application/json' \
-H 'Coder-Session-Token: API_KEY'
```
`POST /workspaceagents/me/tasks/{task}/log-snapshot`
> Body parameter
```json
{}
```
### Parameters
| Name | In | Type | Required | Description |
|----------|-------|--------------|----------|--------------------------------------------------------------|
| `task` | path | string(uuid) | true | Task ID |
| `format` | query | string | true | Snapshot format |
| `body` | body | object | true | Raw snapshot payload (structure depends on format parameter) |
#### Enumerated Values
| Parameter | Value(s) |
|-----------|------------|
| `format` | `agentapi` |
### Responses
| Status | Meaning | Description | Schema |
|--------|-----------------------------------------------------------------|-------------|--------|
| 204 | [No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) | No Content | |
To perform this operation, you must be authenticated. [Learn more](authentication.md).