✨ Archive old terminal runs to bound org-wide scan cost #17
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "feat/archive-terminal-runs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found live on Fanyu: an org run count that only ever grows (nothing ever deletes runs except a full project deletion) was making the org-wide safety scan in validateDeletionReferences get slower every day, independent of what was actually being deleted — driven by an unrelated capture-processing backlog continuously adding runs.
Adds RunRecord.ArchivedAt + a periodic worker sweep (archiveTerminalRuns, same throttle pattern as the existing orphan-runtime reconciliation) marking completed/failed/cancelled runs older than WORKER_RUN_ARCHIVE_MIN_AGE_SECONDS (default 30d) as archived, checked at most every WORKER_RUN_ARCHIVE_CHECK_INTERVAL_SECONDS (default 1h). Archiving never deletes data: ListRunArtifactsByOrganization (the hot-path org-wide scan) now excludes archived runs, but ListRunArtifactsForProject (used by an actual project deletion) still includes them — a project deleting itself must still clean up every run it ever had. Data is only actually removed when its project is deleted, same as today.
Tests: go build/vet clean, go test ./internal/api/... ./internal/store/... ./internal/worker/... — new tests pass, no new failures vs the pre-existing baselines (confirmed the one worker-package failure reproduces identically on plain dev without this change).
🤖 Generated with Claude Code