--- title: "ADR 0086: Queue admission keeps reservations and drops vanished PipelineRuns" --- * Status: accepted * Code: [`pkg/reconciler/queue_pipelineruns.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/reconciler/queue_pipelineruns.go) (`queuePipelineRun`, `startQueueCandidate`, `startNextPipelineRunInQueue`) ## Context `AddListToRunningQueue` can acquire several PipelineRuns in one call when the concurrency limit is above one, and each acquired key already holds a slot. Starting one can fail in ways that either prove the run never started or leave it unknown. A queued key can also point at a PipelineRun that was deleted, or at a malformed entry. Without care a failure leaks a slot, abandons the other acquired runs, or spins until `maxIterations`. ## Decision * Every acquired PipelineRun is processed; a failure on one does not abandon the others. Each is either started or recorded for retry. * A run that is gone (Get returns NotFound, the UID differs on a re-attempt, a malformed key, or `errPipelineRunGone`) gets outcome `StartGone`: its slot is released and the loop asks the queue for another candidate. * A failed start that returns `ErrPipelineRunNotStarted` keeps its reservation, because a pending read cannot rule out a late commit of the patch. Only the owner may resume that slot. Any other error after the patch counts as `StartSucceeded`: the run owns its slot and a successor is not promoted. * Keys found gone are also removed from the ordered list handed back to `AddListToRunningQueue`, so the retry does not re-acquire them until `maxIterations` trips. When every key is gone the call returns no "max iterations" error. * Promotion after completion follows the same rules. It must call `RemoveAndTakeItemFromQueue` at least once even on a cancelled context, since that frees the finished run's slot; a candidate taken and then declined is handed back. It returns an error rather than looping when the queue keeps returning the key it was asked to remove. * A zero concurrency limit is not special-cased in the reconciler: the queue manager admits everything and the normal admission path applies. ## Consequences * The fake queue manager in tests only records removals. Real slot recovery is asserted against `queue.Manager` in `TestStartNextPipelineRunInQueueReleasesSlotForReal`. * The reason a gone run is detected by UID only after a first attempt is not visible in the code. * See [ADR 0058]({{< relref "0058-followup-dependency-graph.md" >}}) for the follow-up graph, which reuses `updatePipelineRunToInProgress` and the same `errPipelineRunGone` handling.