retention: explicit run-history and artifact retention

Add `pipelines retention report` (strictly read-only) and
`pipelines retention apply` (explicit, approval-gated removal) with an age
and/or count policy, protected-run rules, atomic single-transaction removal
and honest database space reclaim. Nothing prunes automatically.
This commit is contained in:
2026-10-17 15:45:46 +01:00
parent b2e920a150
commit 14175eba70
15 changed files with 2127 additions and 12 deletions
@@ -224,6 +224,22 @@ traversal, absolute paths, symlink escapes and unknown runs/steps.
- Do not invent artifact files or claim a stage produced one without the recorded
evidence; the server observes the directory after the stage.
### Operator-only retention
Run history and its artifacts are never pruned automatically. The operator-only
`pipelines retention report` (strictly read-only) and `pipelines retention apply`
(removal after explicit approval) are the only commands that remove them; no
server startup, scheduler, `list_runs`, `stats`, `runs` or `inspect` path calls
retention, and there is no background goroutine, timer or startup hook. A policy
selects by rolling UTC age (`--older-than`), newest-N count (`--keep`), or their
intersection. Runs that are queued/running, waiting on a person, running a cleanup
agent, or referenced by a retained run's retry provenance are protected and
reported with a reason; their artifacts are kept. Removing a run removes its
`<root>/<run>` artifact directory and reclaims database space with one `VACUUM`
and one WAL checkpoint, reporting measured bytes. Pipeline definitions and their
immutable versions are never touched. The commands are local, require an existing
`--db`, and need no running server.
## Brokered OpenCode chat
The protocol declares the brokered `chat_*` surface (`chat_sessions`,