--- title: "ADR 0050: Queue admission leases work to one worker and keeps retry reservations" --- * Status: accepted * Code: [`pkg/queue/admission.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/queue/admission.go), [`pkg/queue/semaphore.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/queue/semaphore.go) ## Context `AcquireAdmission` moves PipelineRun keys from the pending queue of a repository to its running set and hands them to a worker as `StartCandidate` values. The worker then tries to start each run and reports back through `FinishAdmission`. A start can fail, be cancelled, or leave an unknown result. ## Decision * One owner PipelineRun has one `admissionState`. While `busy` is set a second `AcquireAdmission` for the same owner returns an error, so two workers never hold the same lease. Candidates are claimed in `qm.claims`, so another admission cannot take the next pending key. * The worker gets a private copy of the candidates. `FinishAdmission` must run even when the worker is cancelled; it records every batch result under the manager lock. If the admission was replaced by repository removal or reconstruction, it returns nil without touching state. * A candidate with `Attempted` set keeps its reservation when the outcome is `StartRetry`. The code keeps it even when a later read still reports Pending; the source only says a lost write can commit later. A candidate that was not attempted is returned to the pending queue with `requeue`, which restores the original priority and tie-breaker rather than the retry time. * An owner that has `Finishing` true while it still holds a queue slot is removed from the queue and marked `releasedOwner`, so the slot is free for its retries; this matters after the limit was lowered. `Finishing` also checks the graceful cancel and graceful stop modes, because `IsDone` and `IsCancelled` stay false for them. * `ForgetAdmission` only deletes a state that is not busy and has no candidates, so unfinished work is resumed rather than dropped when its owner completes. * In promotion mode an owner with no state that is in neither the running nor the pending set returns nil, so a handoff is not repeated after a finalizer or terminal write already succeeded. ## Consequences * Callers must pair every successful `AcquireAdmission` with `FinishAdmission`, or the owner stays busy. * A retried candidate can occupy a running slot while its start is unresolved.