Add run size_bytes and delete_runs to free disk space

Every run summary carries size_bytes (artifact tree, server-created Pi
session directories and an estimate of the run's database rows), cached in
pipeline_runs.size_bytes, invalidated by triggers, measured when a run
finishes and backfilled in the background. delete_runs removes terminal
runs with every scoped row and server-owned file, refuses active ones with
a reason, and pushes runs_removed to subscribers. pipelines runs rm is the
CLI form; retention apply now shares the complete row deletion.
This commit is contained in:
2026-10-31 22:11:14 +00:00
parent 62b56e66d0
commit 31e89e872b
20 changed files with 1421 additions and 12 deletions
+11
View File
@@ -78,6 +78,9 @@ type runner struct {
// admission. It is separate from the stage's own notify policy.
notifyMu sync.Mutex
notifyModes map[int64]string
// sizeKick wakes the background run-size backfill (sizeLoop); nil when the
// loop is not running (a runner built directly in a test).
sizeKick chan struct{}
}
func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
@@ -1349,6 +1352,12 @@ func (r *runner) finishRunState(id int64, name, workspace, status, outcome, diag
status, outcome, diagnostic = "failed", "error", "deliverable contract: "+err.Error()
}
}
// Measure the run's footprint while it is still recorded as active: its
// files are final, and measuring after the terminal status is written would
// widen the window in which a client sees the run finished but still owned.
// The status write re-marks the cache stale, so the background sizer then
// records the exact value including the final output row.
size := r.finishedSize(id)
if err := r.store.FinishRun(c, id, status, outcome, diagnostic, input); err != nil {
log.Printf("finish run %d: %v", id, err)
}
@@ -1373,7 +1382,9 @@ func (r *runner) finishRunState(id int64, name, workspace, status, outcome, diag
CurrentStage: currentStage,
CompletedSteps: completed,
FinishedAt: detail.FinishedAt,
SizeBytes: size,
}, true)
r.kickSizes()
if status != protocol.RunStatusCanceled {
r.notifyTerminalStep(id, status)
}