--- title: "ADR 0081: Cleanup keeps follow-up runs, deletion still releases the queue" --- * Status: accepted * Code: [`pkg/reconciler/cleanup.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/reconciler/cleanup.go), [`pkg/reconciler/finalizer.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/reconciler/finalizer.go), [`pkg/reconciler/status.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/reconciler/status.go) ## Context `cleanupPipelineRuns` prunes old runs after a final status is posted. Pruning a run that a pending follow-up still needs breaks the follow-up dependency graph ([ADR 0058]({{< relref "0058-followup-dependency-graph.md" >}})). Separately, a user can delete a PipelineRun while it is queued or running, and the provider would keep showing it in progress. ## Decision * The annotation `max-keep-runs` wins over `DefaultMaxKeepRuns`, and is capped by `MaxKeepRunsUpperLimit` when that is above zero. * `keepForFollowUps` is passed to `CleanupPipelines` and is evaluated per run about to be pruned, reading the group fresh. A run is kept when a pending follow-up of its group names it as a dependency (otherwise the follow-up would see it as missing and skip itself wrongly) or is stored on it (the follow-up would be deleted with it). A run outside any follow-up group is never kept for this reason. * When the group cannot be listed the run is kept. When a follow-up annotation in the group is corrupt, `hasWaitingDependent` logs the error and lets the run be pruned, so one broken annotation cannot block cleanup. The pending follow-ups of that group then surface as missing dependencies until the broken run is repaired. The `//nolint:nilerr` on that return carries no written reason. * `finalizeKind` stores the system namespace in the context first. Knative passes a bare context, and the provider client reads the trust policy from the controller ConfigMap, so without it every deletion of a running PipelineRun would stop reporting. * A deleted run in `queued` or `started` state is reported as `cancelled` on the provider (failure only logged), then `startNextPipelineRunInQueue` frees its slot and promotes the next candidate before `ForgetAdmission`. If the Repository is gone, the queue for it is removed instead. * `createStatusWithRetry` retries three times with sleeps of 1, 3 and 5 seconds and returns the last error. The reason for these values is not visible in the code. * The controller sets `SkipStatusUpdates`: the watcher observes PipelineRun status but never owns it, and the generated status sync would issue `UpdateStatus()` calls when informer transforms trim cached status fields ([ADR 0037]({{< relref "0037-informer-cache-transforms-strip-fields.md" >}})). ## Consequences * Runs needed by follow-ups can exceed the configured keep limit until the follow-up resolves. * The retry sleeps block the reconcile worker for up to nine seconds per status report.