ADR-176 — A launch past capacity waits as a run: every surface creates it, a scheduler admits it through the slot ledger, and no event is refused, lost or replayed for lack of room
- Status: Proposed. The principle is the operator's decision of 2026-11-27 (on #3845): "a launch past capacity waits as a run; the event that asked for it is never refused for lack of capacity, never lost, never replayed". There is one named exception: the abuse bound
MaxWaitingRuns(decision Q5), past which a launch is refused with 429capacity_queue_full(§2). The mechanism below is not decided, and nothing in it is built. A cross-family review of the plan (GLM-5.4, 25 findings) is folded in; its disposition closes this record. The operator answered its ten questions on 2026-11-27: see Decisions taken. The record stays Proposed until it is accepted as a whole. - Amends: ADR-167
- Date: 2026-11-27
- Deciders: jo (the principle); Claude (this draft, the inventory of the readers and surfaces, and the reading of the #3845 review)
- Amends: ADR-175 D4. D4 is the mechanism for the team and org caps ("the gate chooses, the publisher enforces through
CredSlotStore"). This record makes it the mechanism for every concurrency axis, and replaces D4's refusal contract with a wait: the gate's advisory 429 and thefailed_resumablepark both give way to one state. - Builds on:
- ADR-167: the ledger's subjects, the transit guard (C1–C3), a tree is one place, a deferred launch runs the current bot, and observe-then-enforce behind an activation guard. Its park (
GATEWAY_SLOT_WAIT, T4b) and its wake (T5) are re-scoped onto this record's state and scheduler; neither is built. - ADR-155, as amended on 2026-11-24: the slot axes are
CredSlotStoresubjects, with nocapacityledger.
- ADR-167: the ledger's subjects, the transit guard (C1–C3), a tree is one place, a deferred launch runs the current bot, and observe-then-enforce behind an activation guard. Its park (
- Relates to:
- ADR-076 (pipeline hard blockers) and the local pipeline scheduler: the in-process precedent.
- ADR-168: the connector intake already postpones for capacity, for free.
- ADR-170: issue claims.
- Serves: #3845. Coordinated with #3748 (ADR-175) and #3254 (ADR-167).
Context
The incident
On 2026-11-26, between 16:30 and 18:30Z, a burst of Renovate webhooks in team iterion ran 8–9 dep_update_guard sandboxes at once on rok01.
- The disk. md0 is a two-disk RAID1 mounted on
/data. It holds the container layers of the three kubelets and the openebs-hostpath volumes, valkey among them. It ran up to 99 % busy, at 1.5–3.1k IOPS against a baseline of 300–900. - The overlap. Image pulls (10 + 8 on one node, 8 on another) landed in the same window.
- The effects. NATS heartbeat refreshes timed out, so runs were cancelled as resumable. Valkey probes and containerd execs timed out too.
- Proof. The investigation correlates the load with the sandboxes and the pulls. It could not attribute the I/O per process, because it had no host access.
- The stopgap. It capped the whole runner pool at 6 (appsets
c648bcf, per #3845). Nothing is lost: the extra messages wait on NATS. But every team is throttled for one bot's burst.
That queue has a cost of its own. DefaultStreamMaxRetry's comment (pkg/queue/nats/nats.go:68-78) names two things that consume the redelivery budget (8 × the 10 min AckWait):
- a message that waits unclaimed past AckWait because every runner is busy;
- a genuine crash.
So a deep runner queue is a slow road to the DLQ.
Nothing bounds one bot. A bot's concurrency is bounded per webhook subject (overlap), per schedule (schedgate), per team (MaxConcurrentRuns) and per key (max_concurrent_runs). budgetfloor.Policy holds per-bot floors, not ceilings.
The first attempt and its review
Commit 45ee66d7c (branch feat/bot-concurrency-ceiling-3845, not merged) put a per-bot ceiling into gateConcurrency as a 429. It also parked the immediate-lane deliveries that the ceiling refused, as durable webhook retry rows. An adversarial review ran probes on the memory store and on Mongo, each against both the new code and the base. It found:
- The ceiling never binds when the bot is spelled differently.
- The gate counted
bot_idexactly, and the policy folded case only. - Runs store the canonical manifest name,
dep-update-guard. botregistry.NormalizeName(pkg/botregistry/registry.go:530) lowercases and folds_and space to-.- Labelled
dep_update_guard, four launches against a ceiling of 1 answered[202 202 202 202]. - Two ceilings,
dep_update_guardanddep-update-guard, passed validation as distinct bots.
- The gate counted
- Refusing at admission loses work on the immediate webhook lane. This loss exists today for the team cap and the launch rate too.
- A first-admission denial writes a terminal
launch_errorrow under a random key, with no retry target (pkg/server/webhooks_common.go:1376-1384). - The code says so itself: "GitHub does not retry — Redeliver to start them" (pkg/server/webhooks_retry.go:248).
- A manual Redeliver after room frees does launch in the base code. Unattended, the event is gone.
- A first-admission denial writes a terminal
- Parking the refused delivery for replay creates a second deferral system, with its own semantics, beside the run's. Each of these failed on the new code and passed on the base:
- P1. A refused merge-queue auto-heal was parked. The PR went back into the queue, and
stopHealRunForRequeuedPRhad no run to stop, so the sweep then launchedbranch-improve-loopon that queued PR. This is the #682 force-push shape. - P5, P7. Once the attempt budget was spent, the event was lost behind a
200 duplicate. Both GitHub's Redeliver and the operator's retry endpoint refused it. - P4. A generic sender that honoured
Retry-Afterwith a fresh key launched twice. - P11. In a fan-out, the CODEOWNERS
review_requestedread the parked row as not live and reviewed the same head twice. - P2, P3, P6. Withdrawn or stale work was launched:
- a superseded head, under the default
overlap: allow; - a PR that had since taken a hold label;
- an issue whose label had been removed and which had been closed.
- a superseded head, under the default
- P8. The webhook retry sweeper is one deployment-wide FIFO, 50 rows every 20 s. With 200 rows parked by one tenant, another tenant's due retry waited 4 ticks.
- P1. A refused merge-queue auto-heal was parked. The PR went back into the queue, and
What the code does with a launch that finds no room today
Every surface reaches the one gate, gateLaunch (pkg/server/launch_gate.go:491). A capacity denial there is a 429 (concurrency_cap_exceeded at :845-849 and :873-878, launch_rate_limited at :911-916), and each surface handles it in its own way:
| Surface | On a capacity 429 today |
|---|---|
| REST launch and resume, WebSocket answer | 429 to the caller; nothing stored (pkg/server/runs_launch.go:572, :1238) |
Webhook, immediate lane; /command; fork gesture | the forge gets the 429; a terminal row with no retry. Lost unless someone redelivers by hand |
Webhook, after admission (confirmReplacement, fan-out siblings) | a retry row, 8 attempts, then lost (pkg/server/webhooks_retry.go:22-38) |
| Webhook, debounced lane | re-armed with backoff for about 45 min, then a terminal "parked review abandoned" row (pkg/server/webhooks_debounce.go:418-497) |
| Cloud schedule tick | the tick is consumed: "ordinary failures retain … terminal verdict for this slot" (pkg/cloudsched/ticker.go:171-182) |
| Trigger effects outbox | an attempt is spent; dead-lettered after 5 (pkg/trigger/effects_worker.go:94-108) |
| Connector intake (ADR-168) | postponed without spending an attempt (PostponeFor, pkg/connector/intake/worker.go:378-388). The only surface that waits for free |
| Board dispatcher | the card is put back with backoff; filed blocked with launch_given_up after 8 refusals (pkg/server/boarddispatch.go:429-446) |
| Retry sweeper (resumes) | an attempt is spent; re-armed 15 min out (pkg/server/retry_sweeper.go:420-436, :529-553) |
Seven deferral systems. Each has its own backoff, attempt budget, ordering and loss point. The review showed that an eighth, bolted onto the immediate lane, inherits all of their classes at once.
One surface already waits as a run. That is the per-key cap.
- The publisher reserves the key's slot in
store.CredSlotStore(pkg/store/credslot.go:62) after sealing and before writing (pkg/server/cloudpublisher/publisher.go:4427-4444). - On a refusal it parks the run
failed_resumable/CRED_SLOT_WAIT, with its retry armed (pkg/server/cloudpublisher/cred_slots.go:198-235): "A park, not a refusal: a webhook delivery has nobody to click again" (:23-27). - Its limits are written beside it. It "keeps no place in line" (:30-36), and a parked run is re-asked only through the retry sweeper. That sweeper takes 5 runs a minute, across the whole deployment, ordered by
retry_afterwith no tenant key (pkg/server/retry_sweeper.go:34-39, pkg/store/mongo/runs_retry.go:531-536). failed_resumableisIsTerminal,CanAutoResumeandRunDeletable(pkg/store/run.go:114, pkg/store/lifecycle.go:549, pkg/store/run.go:72-79). So a run that never started reads as failed: in stats, in the studio's diagnostic, and inwebhookRunLive.
The local pipeline scheduler is the in-process precedent (pkg/runview/pipeline_scheduler.go, pkg/runview/pipeline_queue.go:151-215).
- An over-limit root is put in an in-memory FIFO and persisted as a plain
queueddoc. - A signal wakes the scheduler, and a 5 s backstop poll catches a missed signal.
- A restart rebuilds the FIFO, oldest first.
- Its comments carry three lessons:
- Enforcement was pulled down to the queue, because a gate upstream "would be bypassed every single time" (:172-183).
- The persistence is best-effort, and a failed persist is "LOST if the server restarts" (:32-35).
- The restart rebuilds the launch spec lossily, losing overrides (:126-129).
- It is single-process by construction.
Decision
1. One state: waiting_capacity, a run that exists and has not been handed to the runners
Every surface creates the run. It is created durably, at once, in a new
RunStatus,waiting_capacity, whenever an admission finds an axis without room. The surface answers as for any accepted launch: 202 with the run id.- For a webhook, the delivery row goes to
launchedwith the run id at creation, whether the run waits or not. - That is what the tail writes as soon as a launch returns an id (pkg/server/webhooks_common.go:1606-1611), and what
supersededRunIDs(:998-1000), the debounce lane and the retry lane read. acceptedkeeps its meaning: a launch in progress, read as live for 10 minutes only (acceptedLaunchWindow, :1044-1049, :1112).
- For a webhook, the delivery row goes to
What the run carries. A
capacity_waitrecord with:- the axes that refused, one or several, each as a subject (§4) with its label, and its
heldandmaxat the refusal; since, the run's place in line. It is set once and kept across every refusal of the same wait. A replacement inherits it from the run it replaces (§5);- the count of refused admissions;
admission_pending, the instant of an admission in flight (§3). It is empty while the run only waits.
- the axes that refused, one or several, each as a subject (§4) with its label, and its
A new status, not
queuedplus a reason.queuedmeans "submitted to the NATS queue but not yet picked up" (pkg/store/run.go:100-105), and its readers act on that meaning:- it holds a credential slot and counts against the launch limit (
HoldsCredentialSlot,CountsAgainstLaunchLimit, pkg/store/lifecycle.go:415, :555;CountActiveRunsByTenant's literal$in, pkg/store/mongo/runs.go:1047-1050); - the orphan sweeper flips a stale
queuedrun tofailed_resumable/PROCESS_ORPHANED(pkg/server/queue_sweeper.go:257-261, :326-329); - it may start execution (
CanStartExecution, pkg/store/lifecycle.go:484).
A waiting run read as
queuedwould count against the cap it waits on, so a full cap would never drain. It would also be adopted by the ledger as a holder, and orphaned by the sweeper. Every reader would need a second field to be right, including every replica of the previous release.- it holds a credential slot and counts against the launch limit (
A new status, not
failed_resumableplus a code. That is today's park, and the review's P11 shows the readingfailed_resumablegets: not live, therefore launch again.What an unknown status does on old code, today. The previous release has no
waiting_capacity, and it reads one as follows:- Inert: it is not terminal, not counted, not a holder, not auto-resumable and not deletable (
RunDeletablerefuses a run that is not terminal). - Not cancellable. The publisher's cancel guard reads
CanBeCancelled(), which is true for an unknown status. But its CAS expects a set built from the explicit liststore.AllRunStatuses(pkg/server/cloudpublisher/publisher.go:4694-4738, pkg/store/lifecycle.go:394-398). It therefore matches nothing and answers "cancel raced … — retry". Every stop of §5 then fails on an old binary. - Started by an old runner. An old runner's
Admitlets an unknown status proceed (pkg/queue/admission.go:50-80, pkg/runner/loop.go:435-438). The start is then refused further down (CanStartExecution, pkg/store/run_invocation_reserved.go:44). The message is nak'd up to MaxDeliver and parked on the DLQ.BuildRunOutcomehas no branch for the status, so it reportsrun.failed(pkg/trigger/runoutcome.go:96-97, :134-143). - Rejected by the team cutover.
TeamCutoverStatusAlivereturns an error on any unknown status (pkg/store/lifecycle.go:501-511).
S1 therefore ships the cancel CAS and these readers before any writer, and proves them on the release that precedes S2 (§7, §8).
- Inert: it is not terminal, not counted, not a holder, not auto-resumable and not deletable (
Predicates. One predicate names the state:
RunStatus.AwaitsCapacity().TestLifecyclePredicateMatrixandTestAllRunStatusesIsExhaustive(pkg/store/lifecycle_test.go) each gain a row for it. A waiting run:- holds no slot;
- counts against no launch limit;
- is not terminal;
- is live for supersede and stop purposes;
- is cancellable;
- carries its pause pointer, as a waiting resume (decision Q1(b));
- is not deletable until cancelled;
- cannot start execution.
The reader matrix. S1 covers every predicate and every reader below, with a row each. S1 re-runs the grep, and a test walks every value of
AllRunStatusesthrough each predicate, so that a predicate that errors on a status fails the test.Reader Change The publisher's cancel CAS (pkg/server/cloudpublisher/publisher.go:4708-4713) expects CanBeCancelledas a predicate (a$ninof the settled statuses), not a list built fromAllRunStatuses. Ships in S1TeamCutoverStatusAlive(pkg/store/lifecycle.go:501-511)waiting is alive, and an unknown status reads as alive instead of erroring. Ships in S1 The runner's Admitand precondition (pkg/queue/admission.go:55-80, pkg/runner/loop.go:435-438)a waiting_capacityrun is dropped (DropAwaitingCapacity): acked, with no nak, no DLQ and no event, and counted as a defect (iterion_runner_waiting_delivery_total). A message for it should not exist. Ships in S1BuildRunOutcome(pkg/trigger/runoutcome.go:134-143)waiting has no outcome; no event is emitted. Ships in S1 SaveRunpause-pointer scrub (pkg/store/mongo/runs.go:444-450),CarriesPausePointer,CanReclaimResumePauseHandoff(pkg/store/lifecycle.go:430-444)waiting_capacitycarries the pause pointer and may reclaim the handoff (decision Q1(b)), so the scrub keeps a waiting resume's pointerWatchDeliverable(pkg/store/run.go:147),IsPaused(:126),IsQueued(pkg/store/lifecycle.go:466)false; written into the matrix webhookRunLive(pkg/server/webhooks_common.go:1117),runIsStoppable(:1977, read bystopHealRunForRequeuedPRat :1826 and bystopRunsForDeadPR),forge_gate_relaunch.go's live testlive Dispatcher: lastRunForbidsFresh, the hold on live runs,stuckcard.go(pkg/dispatcher/retry.go:158-165, pkg/dispatcher/loop.go:573); the board's ticket admission (pkg/server/pipeline_admission.go:211-221)live The schedule overlap gate (pkg/schedgate/live_runs.go:67-69) unchanged: anything not terminal already counts as live Views: the studio's RunStatusunion (studio/src/api/runs/types.ts:10) and status classes; the diagnostic (pkg/runview/diagnostic.go:260-290); the board's columns (pkg/server/pipeline_boards_progress.go:307);runs_stats.go; global discoverywaiting is Active, and its only action is Cancel Delete ( RunDeletable)refused while waiting, as for queuedThe epoch and execution fences (pkg/store/execution_authority.go:47-61), the retry scans, CountActiveRunsByTenant, the ledger's holder predicateunchanged: they select queued,runningorfailed_resumableby literalThe orphan sweeper's queuedpass (pkg/server/queue_sweeper.go:257-278)gains a pass for a queuedrun whoseadmission_pendinghas outlived its grace (§3). That pass returns the run to the wait, never toPROCESS_ORPHANED, and it is not skipped under backlog.admission_pendingis cleared by §3's post-publish write, or by the CAS of any return to the wait (step 8, a failed publish, this pass). Conformance rows, on both twins: (a) a death between the settle and the publish → the run is back inwaiting_capacitywith itssinceandresume_spec; (b) a failed publish → the same; (c) a post-publish write naming an older instant changes nothing; (d) a message published before a return to the wait is dropped by the runner; (e) a post-publish write that lands after the stale-marker pass returned the run to the wait matches nothing (the return clearedadmission_pending), and the run keeps itsresume_spec
2. What stays a refusal, and what becomes a wait
A wait is something only time resolves: an axis that frees when other runs end.
- Concurrency. The per-bot ceiling, the team cap, the org cap (ADR-175 D1), the per-key cap, the gateway's bound (ADR-167), and the floor arithmetic on the team cap (§4).
- The launch rate (
LaunchRatePerMin, team then org) also becomes a wait. It becomes a pace on admissions: the scheduler starts at most the bucket's rate per team, and a run past it waits on the axisrate:team:<id>, woken at the bucket's refill.- The 2026-11-26 incident is the case for it: the rate protects what a start costs (an image pull, a sandbox), not what a row costs.
- A refused launch rate on the immediate lane loses the event today, exactly as the cap does.
A refusal is something that does not resolve by waiting, or that the operator must decide. It stays as it is today:
| Refusal | Why it stays |
|---|---|
| Monthly budget (402: run quota, cost cap, team ceiling of ADR-175 D2) | It resolves at the month's turn at best. A wait of weeks on an event is a stale launch, not a deferral |
| Policy and identity: no workspace, role rung, suspended or read-only team or org, unknown trust | Not time-bound; an operator decides |
| Fork funding and the fork-author bounds (ADR-162) | Fail-closed by their own decision, monthly |
| Repository quota (402) | Monthly |
| "All N concurrency slots are reserved for other workloads" (pkg/server/launch_gate.go:840-850) | No run ending frees it; the lever is the reservation. Its own detail already says so |
| Maintenance fence (503) | The fence exists to stop writes. The lanes that already hold across it (debounce, schedules) keep their hold; the immediate lane's loss under maintenance is unchanged here and named under Consequences |
The refusals are taken twice. The gate takes them at creation, as today. The scheduler takes the ones that can change during a wait again before each admission: suspension, the monthly cost cap, maintenance (which keeps the run waiting). A run refused while waiting ends failed_resumable with the denial's token in its outcome (decision Q4(a)). The end is visible on the run and in the forge's check, never silent, and an operator can still resume the run.
The monthly run quota is charged at creation, because the run exists from then on.
- No refund primitive exists for a run that waits. Giving the charge back is today
launchAdmission.rollback, a closure held in memory (pkg/server/launch_gate.go:427). It is called only when a launch returns an error that proves nothing started (RunMayHaveStarted, pkg/runview/run_persisted.go:42). Nothing can give back the charge of a run that waited and was then cancelled, refused or expired. - What S2 builds. A durable link between a charge and its run: the charged subjects, recorded on the run, and a release by run id that is idempotent.
- Which ends refund (decision Q5(a)): a charge whose admission was never published is refunded. "Never started" is judged per charge, not per run.
- Which charges exist.
gateLaunchmeters a launch and a gated resume alike: the HTTP resume, the WebSocket answer and the retry sweeper's resume (pkg/server/launch_gate.go:455-463). The durable release therefore records each admission charge, with the flip it belongs to. - What triggers the refund. The charge is given back when the wait ends without that admission being published: cancelled, superseded, collapsed, expired, or refused during the wait. That applies to a waiting launch and to a waiting resume alike.
- What it does not touch. A charge whose admission was published stays charged: an earlier attempt of a resumed run, or a run that ran.
- Which charges exist.
- A bound on creation, from S2. A per-team
MaxWaitingRunsfollows the ADR-175 D0 convention. Its proposed default is 200, to be measured in S0.What it counts. Waiting launches and waiting resumes.
Past it, a launch or a resume is refused with 429
capacity_queue_full, counted (iterion_capacity_queue_full_total).It is the one exception to the principle. An abuse bound, not a capacity axis: a team with 200 runs already waiting is a runaway sender or a cap set far too low. A storm on a capped bot therefore cannot turn a capacity wait into an exhausted monthly quota.
The refusal is plain. Nothing replays the event. It is not parked for replay, because that is the second deferral system whose defects the #3845 review found (P1–P8, P11). Each surface does what it does today with a 429:
Surface capacity_queue_fullREST launch and resume, WebSocket answer 429 to the caller, who retries Webhook, immediate lane; /command; fork gesture429 to the forge. The delivery row is launch_error, which is not a claim (webhooks_common.go:1044-1049). It has no attempt budget and noRetryTarget, so a GitHub Redeliver or a sender's own retry after room returns launches once, as it does on the base code. GitHub does not redeliver by itself: the event is refused, and the sender must retryWebhook, debounced lane re-armed with Retry-After, as for today's denials (webhooks_debounce.go:418-497)Connector intake postponed for free: PostponeForgains the tokenCloud schedule tick, trigger outbox, board dispatcher today's handling of a 429: the tick is consumed with last_error, the outbox spends an attempt, the card backs offA resume from the retry sweeper the run stays failed_resumablewith its retry re-armed, as for today's transient denials
3. The scheduler
The fast path, for a launch. The publisher reserves every subject before it writes the run, exactly as the per-key cap does today. The order is all-or-nothing, from the narrowest row to the widest: keys,
bot:,team:,org:,gw:.- All granted: it persists the run
queuedand publishes. The reservation made before the document exists is covered byCredSlotGrace(pkg/store/credslot.go:124-130). - One refused: the grants already made are released, and the run is written
waiting_capacity, naming every refused axis. Nothing is published. - The subject already has waiters: a fresh launch takes the waiting road, even if a slot is momentarily free, so it does not overtake them. That read is a hint, so a race here is an overtake, counted (§6), never a double admission.
- All granted: it persists the run
Nothing sealed rests on a waiting run. A launch seals its credentials into the queue message, not the run document (
SecretsRef,BundleDEK, pkg/server/cloudpublisher/publisher.go:4486-4487). A waiting run without a checkpoint stores no sealed material and no DEK. Its admission re-resolves and re-seals (ADR-167 §6).- What the run must store is the non-secret part of the launch request that is not on the run today: the webhook's
key_overridesandsecret_overridesreferences, the repository ref, and the launch flags. - S2 names these fields with a test that launches from a waiting run and compares the result with a direct launch.
- What the run must store is the non-secret part of the launch request that is not on the run today: the webhook's
Resumes wait too (decision Q1(b)), on the kinds in
enforce. A resume past capacity becomeswaiting_capacitylike a launch.Today, a resume refused for a key is not parked.
SubmitResumeputs the run back as it was (RevertQueuedFlip, pkg/server/cloudpublisher/publisher.go:4960-4972, refusal at :5160-5166), and the caller getsErrCredentialAtCapacity.- The HTTP and host-event routes answer 429 (
writeCredentialAtCapacityError, pkg/server/assistant_host_event.go:80). - The retry sweeper defers its own retry (
deferCredSlotRetry, pkg/server/retry_sweeper.go:762-790). - Only a launch is parked
CRED_SLOT_WAIT(publisher.go:4436, :4473).
- The HTTP and host-event routes answer 429 (
On a kind in
observenothing waits: the resume is admitted, andwould_waitcounts it (§7).Why a spec must be stored. A resume carries request fields that are never persisted on the run (pkg/runview/service.go:563-638).
SubmitResumeconsumes them, for exampleCheckResumeAdmitted(prior, spec.Admitted)(publisher.go:4815) and the answers check (:4853).The record. The waiting resume therefore stores a durable
resume_specon the run. It holds every fieldSubmitResumeconsumes that cannot be re-derived from the run:Field Content Care Force,AcceptScratchLossthe operator's consents (booleans) none: no secret. Each is an audited decision, kept as given ExpectOriginthe origin a checked surface admitted none: an identifier Admitted(GateAdmission{Trust, ForkAuthorSubject}, pkg/runview/gate_admission.go:16-19)the gate's verdict at creation no secret. The scheduler crosses the gate again (§2) and compares; a trust that changed during the wait refuses the admission, never widens it AutoMemory,AmbientContext,LoopBudgetGuard,Supervisorsoverride enums ( "",on,off,none) that the service says are "not persisted on the run"none: no secret Codemode,CodemodeBoundsan explicit re-statement only; the launch's choice is already on the run none: no secret. Absent means the launch's choice, as today Answersthe answers a human typed into a gate user content. It has the sensitivity of the human_answers_recordedrecord it becomes after the resume. It is stored in the run's collection under the same tenant filter, never logged or copied into an event, and it counts toward the document's size bound (a large answer set is refused at the resume's request, not at admission)HostInputshost-attested projections merged into the paused node's output never persisted. The field keeps its contract: "ephemeral … kept out of human_answers_recordedand published artifacts … not a second durable authority" (service.go). A resume that carriesHostInputsand finds no capacity therefore does not wait. It keeps today's behaviour, the documented exception: the flip is reverted, the run stays as it was, and the caller getsErrCredentialAtCapacity(429), so the host that attested the inputs retries. No park is written, and nothing re-resumes without the inputs.iterion_capacity_hostinputs_refusals_totalcounts these refusals so their frequency is visibleFields left out.
ExpectedStatusandReceiptID, a mission's CAS guard and correlation id, are kept so that a mission's guard still decides.FilePath,Source,BundleDir,BundleEntryandBotBundleare re-resolved at admission, as a cloud resume already re-resolves its bundle. With a checkpoint, the workflow-hash check holds unlessForce.Timeoutis kept as given.
Cleared after the publish, not at the settle.
SettleCredSlotAdmissionis the write that comes before the publish (step 5 of the admission below; pkg/store/credslot.go:90-96), so it clears neither the spec nor the marker.- The spec is cleared only by the post-publish write (step 7): a CAS on the flip's instant. From then on the queue message carries the spec.
- A refused admission, a failed publish, or a crash at any point before step 7 keeps the spec with the run.
- A cancel, an expiry or a deletion clears it.
The resume keeps its place. A waiting resume inherits a
sinceequal to the run's firstQueuedAt(its attempt's instant), not the moment it waited. A run that already started is therefore ahead of every fresh launch on the same subject.What the flip to
waiting_capacitypreserves: the checkpoint and its episode;continuation_state; the attempt marker thatRevertQueuedFliprestores (publisher.go:4964-4972);RetryState; and the pause pointer.waiting_capacitytherefore joinsCarriesPausePointerandCanReclaimResumePauseHandoff, so theSaveRunscrub (pkg/store/mongo/runs.go:444-450) keeps the pointer.Retiring the park. The
CRED_SLOT_WAITpark is a launch-only writer today, and it is retired for the key kind once it is inenforce(§7), from S2. From then on a launch's key refusal on an enforced kind waits instead (§8). A resume's key refusal on an enforced kind waits instead of today's revert-and-429.While the key kind is
off, on an S2 binary as on today's, a key refusal keeps today's behaviour for a run that never entered the wait: a launch is parkedCRED_SLOT_WAIT, and a resume is reverted and answeredErrCredentialAtCapacity, with no park. That is the proven path the rollback falls back to (§7).An already-waiting run that a key refuses stays waiting with the key as an axis, whatever the mode (§7, P11).
S5 removes the launch park writer for good. The retry sweeper keeps re-asking the launch parks written while the key kind was
off, until none remains. Its capacity code (the launch park's re-ask, anddeferCredSlotRetryfor a sweeper-driven resume) goes in S5.A resume carrying
HostInputskeeps today's revert-and-429 in every mode (table above). It writes no park.The rollback stays proven. S2 proves, on its own binary:
offadmits every waiting resume, with its spec, at the drain pace;- the drain to zero (§7) includes waiting resumes.
Below S2, a binary cannot read a
resume_spec, so the procedure of §7 holds unchanged: drain to zero before the roll.
The scheduler turns waiting runs into queued ones.
- Ownership. It runs on every replica under one lease,
capacity-scheduler(pkg/lease). The lease is the package's own kind: "a load-reduction election, not a mutual-exclusion guarantee" (:1-11). Correctness does not rest on it. - Order of an admission, on the resume model. The ledger evicts any holder whose run does not spend (pkg/store/credslot.go:141-146, :216-217; pkg/store/mongo/cred_slots.go:135-150). A reservation taken while the run is still
waiting_capacitywould therefore be evicted by the next refused admission on the same row. So the order is:- CAS
waiting_capacity → queued, conditioned on the status and oncapacity_wait.since. The run is markedCredAdmissionPending, withadmission_pendingset to the flip's instant, andQueuedAtis that instant. A queued run spends, so it is not evicted. A run that awaits its own admission is not adopted by another admission (AwaitsCredSlotAdmission, pkg/store/credslot.go:197-200). - Re-check the refusals that can change during a wait (§2).
- Re-resolve and re-seal (no checkpoint, ADR-167 §6).
- Reserve every subject, all-or-nothing.
- Granted:
SettleCredSlotAdmission. It clearsCredAdmissionPendingand nothing else:admission_pendingandresume_specstay. - Publish.
- Post-publish write. A CAS on
admission_pending ==the flip's instant and a status other thanwaiting_capacityclearsadmission_pendingandresume_spec(a runner may already have claimed the run). Every return to the wait (step 8, a failed publish, the stale-marker pass) clearsadmission_pendingin its own CAS, so a stale write from an earlier flip, or one that lands after the stale-marker pass, lands on nothing. A failure of this write is counted (iterion_capacity_post_publish_write_failures_total), and the stale-marker pass below handles the run. - Refused for capacity at step 4, a store error, or maintenance at step 2: CAS back
queued → waiting_capacityon the flip's instant, withsincekept and the axes updated. Any other refusal at step 2 (suspension, the monthly cost cap) ends the runfailed_resumablewith the denial's token andretry_afterdisarmed, as §2 and decision Q4(a) state. In both cases the grants already made are released by theirAt.
- CAS
- Two schedulers that overlap. The one that loses the CAS reserves nothing and releases nothing. Today's hazard cannot occur: a loser's release, by the
Atof its in-place re-admission, removing the winner's live entry (pkg/store/mongo/cred_slots.go:163-192, :294-309). A conformance row on both twins pins that interleaving. - A publish that fails (step 6) releases the grants and CASes the run back, as in step 8, with
resume_specand its place intact. - A replica that dies anywhere between the flip and step 7 leaves a
queuedrun whoseadmission_pendingis still set. That covers a death before the settle, between the settle and the publish, and after a publish whose post-publish write never landed.- The stale-marker pass. The orphan sweeper's new pass takes every
queuedrun whoseadmission_pendingis older thanCredSlotGrace, which exceeds the publish's own timeout. It CASes the run back towaiting_capacityon that instant, with itssinceand itsresume_spec, whatever the backlog. The marker, not the backlog, tells it apart from a published run. The pass therefore never ends such a runfailed_resumable/PROCESS_ORPHANED. - The slots. The run's slots free themselves: a waiting run does not spend, so its holders are evicted at the next admission.
- A run already claimed. A run that a runner claimed in the meantime is
running, so the pass's CAS onqueuedleaves it alone. - A message that did go out is dropped by the runner in either of two ways:
- superseded:
SupersededcomparesQueuedAtwith the message's publication instant (pkg/queue/admission.go:56, :86-98); - while the run is back in waiting: the S1
DropAwaitingCapacitybranch.
- The stale-marker pass. The orphan sweeper's new pass takes every
- Ownership. It runs on every replica under one lease,
Order.
- Within a team's slice of a subject, admission is FIFO on
(capacity_wait.since, run id). A slice is that team's waiting runs on that subject. For a subject that only one team uses (team:, or a team's own key), the slice is the whole subject. The run id breaks ties, so the order is a stable key, never the order of a scan. - Across teams on a shared subject (
bot:<name>deployment-wide under Q2(a),gw:,org:, a shared key), a freed place goes round-robin over the heads of the teams' slices: one admission per team per turn. A burst of 200 runs from one team therefore delays another team's first waiting run on the same subject by at most one turn (the review's P8). - No strict FIFO across teams. Strict FIFO on
(since, id)across the whole subject is therefore not the order. A run of one team may be admitted before an older run of another team, and that is the fairness rule, not an overtake. - Round-robin across subjects too. A pass also walks the teams round-robin, so a team with waiting runs on many subjects does not monopolise a pass.
- Within a pass, a refusal marks the pair (subject, effective
max) full, not the subject alone. Themaxa candidate asks for depends on its bot (§4's floors). A later candidate that needs the same subject at the same or a lowermaxis skipped, so nobody overtakes within a team's slice. Nor does a later team's head take a place the round-robin had refused in the same pass. A candidate of a reserved bot, which asks with a highermax, is still tried. A candidate that needs neither continues, so one full bot does not block a team's other bots.
- Within a team's slice of a subject, admission is FIFO on
Drain pace, from S2. No path admits the whole waiting set at once.
- The bound. A pass admits at most
ITERION_CAPACITY_ADMIT_PER_PASSruns (default 3), and at mostITERION_CAPACITY_ADMIT_PER_MINper minute deployment-wide (default 6). - Where it applies. The same bound covers the paths an operator takes under incident: an activation, a cap raised or removed, a lease that changes hands, and a rollback to
observeoroff. - Its meaning. It is the start pace that the 2026-11-26 incident lacked. For comparison, today's park release is
retrySweepBatch = 5per 60 s pass (pkg/server/retry_sweeper.go:34-39). - What follows. S7's per-team
rate:axis later refines it.
- The bound. A pass admits at most
Starvation. A run that waits on two subjects (a bot at its ceiling inside a full team) can be overtaken by a run that needs only the subject that frees first.
- v1 accepts this. Each overtake is counted (
iterion_capacity_overtakes_total{kind}), and the run's age is shown. - A strict head-of-subject hold, keeping a freed slot for the head for a bounded time, is built on its trigger: overtakes measured despite the round-robin. This is ADR-167's posture on strict FIFO.
- v1 accepts this. Each overtake is counted (
Wakes.
- The fast path's refusal and every terminal transition of a run publish a wake on the event bus. That bus is
NATSBusin cloud andInProcBuslocally, with the same code. It is "at-least-once and lossy" (pkg/eventbus/bus.go). - A backstop poll runs every
ITERION_CAPACITY_SCHEDULER_INTERVAL, 10 s by default. It catches a lost wake, a slot freed by the ledger's lazy eviction (CredSlotHolderStale, pkg/store/credslot.go:216), a run killed with no event, and a restart. - A pass with no waiting run costs one indexed count.
- The fast path's refusal and every terminal transition of a run publish a wake on the event bus. That bus is
A policy that changes during a wait. The scheduler reads every limit through its resolver at each pass, within the drain pace:
- a cap raised admits waiters;
- a cap lowered below its holders admits nobody until enough holders end, which is the ledger's existing rule (pkg/store/credslot.go:62-80);
- a cap or ceiling removed (0 or −1, per ADR-175 D0) drops the subject, and its waiters are admitted in order.
A refusal or an expiry during a wait (decision Q4(a)). A distinct
capacity_wait_deadline, unbounded by default and set per bot or platform, ends the wait. The run then endsfailed_resumablewithCAPACITY_WAIT_EXPIRED, or with the token of the refusal that ended it, so an operator can resume it.- The same write disarms
RetryState.retry_after. The retry sweeper selects everyfailed_resumablerun whoseretry_afteris due (ListRunsDueForRetry, pkg/store/mongo/runs_retry.go:524-536). Disarmed, the run is never auto-resumed back into the wait, so the deadline actually ends it, and a run refused for the cost cap spends no further attempt. - Only an operator's resume restarts it.
- A conformance row on both twins pins this. A run ended by expiry, and one ended by a refusal during the wait, are each absent from
ListRunsDueForRetryat any later instant. max_waitdoes not bound it. Inretrypolicythat field is a clamp on how far ahead one retry is scheduled, 8 days by default (pkg/retrypolicy/policy.go:40-45, :72-75, :91-92), not a deadline on a first launch.
- The same write disarms
The ledger is unavailable (decision Q3(a)), on a kind in
enforce. A ledger error, or rounds exhausted under contention, admits nothing. On a kind inobserve, a ledger or count error is counted (iterion_capacity_ledger_errors_total{kind}), and the run is admitted as it would be onoff. A measurement phase never makes a live launch wait.- On the fast path, the run is created
waiting_capacityon the axisledger_error. In the scheduler, the run stays waiting with that axis. - While the error persists, the fast path skips the resolution and the seal, so it does no wasted work.
- No pull-request notice is posted for
ledger_error. iterion_capacity_ledger_errors_total{kind}counts it, and a dedicated alert fires on it.- The runner's C2 is not concerned before S5: on the runner side, a ledger error stays ADR-167's "deferred nak" (§3, runner side).
- On the fast path, the run is created
Restart and replica loss. The waiting set is the run documents, so there is no in-memory queue to rebuild. A new lease holder resumes at its first pass. A run whose admission was cut short is either still
waiting_capacityor aqueuedrun with a staleadmission_pending, handled above.The runner side. Only a run whose slots are held is published, so NATS's redelivery budget (MaxDeliver 8, pkg/queue/nats/nats.go:68-78) is never spent on capacity. The runner pool cap goes back to bounding the physical fleet. The runner itself changes in two ways only:
- the S1 drop branch for a
waiting_capacitydelivery; - nothing else in S2–S4: the runner never writes
waiting_capacity.
ADR-167's transit guard (C1–C3, #3254 T4a) is not on main.
HoldsCapacity(andReassertCredSlot(match nothing inpkg/. When T4a lands, its C2 refusal keeps its own form, "a free retry is armed". Making it write the wait instead, with the runner's release added to the rollout guard, is decided at S5, not before.- the S1 drop branch for a
4. The ledger: typed subjects on CredSlotStore
One ledger.
store.CredSlotStorestays the one ledger, on both twins: pkg/store/mongo/cred_slots.go and pkg/store/credslot_fs.go. Its rows gain typed subject kinds beside the key fingerprints (hex oraccount:, unchanged: renaming live rows would only cost a re-adoption) andgw:<host>(ADR-167):bot:<name>, where<name>isbotregistry.NormalizeName(run.BotID);team:<id>(ADR-175 D4);org:<id>(ADR-175 D1, D4).
A
bot:count is aggregated across every team, so itsheldandmaxshow the load of all teams, never another team's runs (§6).One helper composes them from the run at stamp time. ADR-175 D4 already names it for
team:andorg:: it is shared by the launch stamp and bothSetRunCredStamptwins, and it never reads the subjects from the sealed bundle.The bot identity is folded at both ends. The ceiling's key is folded at validation, so two spellings of one bot are one entry and a duplicate is refused. The run's id is folded at stamp. The review's F0 is the reason: one spelling at each end is the defect, not the spelling.
An axis is a seam, not an
if. Each axis implements one interface (philosophy §2, the Nth-variant test):- the subjects a run needs;
- the
maxit may use under each subject; - the label and the refusal's words;
- whether it is a slot (held until the run stops spending) or a pace (
rate:, a token taken at admission).
The bot ceiling, the team, the org, the key, the gateway and the rate are six implementations. A seventh, a per-pool or per-node axis, is a new implementation.
Budget floors stay arithmetic on the team subject. A floor is not a row of its own.
ReserveCredSlottakesmaxper call, so the team row is asked withcap − OtherReservedSlots(bot)for a bot no reservation names, and withcapfor the reserved bot. That is today's arithmetic (pkg/server/launch_gate.go:838-852), now judged against an atomic row instead of a count. ADR-175 D1 then moves it toorg:<id>.The
maxis read from the reservation policy before the conditional write. The write is atomic, but the read of the policy is not: a reservation changed between the two applies at the next admission. A conformance row pins two things: a reserved bot is admitted into the room betweencap − reserveandcapafter an unreserved bot was refused, and §3's (subject,max) rule lets it through within the same pass.Exactness.
CountActiveRunsByTenantis a count read and then compared, with no reservation: two replicas both admit into the last slot. The ledger's conditional write closes that window. The gate's count is no longer a bound; it can stay a cheap hint for the fast path.Releases are what releases a slot today. A run releases when it stops spending under the holder predicate: it goes terminal, is cancelled, is deleted (its document gone past
CredSlotGrace) or is lost (the orphan sweeper settles it), with C1's redelivery hold in between. The holder is then evicted at the next admission that meets it. The only release a caller performs is the undo of an admission that provably handed nothing on (ReleaseCredSlotwith itsAt).A tree is one place. The bot ceiling counts trees, not sandboxes (ADR-167 §5, ADR-175 D4). A bot invoked as a sub-bot of another root holds no
bot:place. No catalogue bot callsdep-update-guardas a sub-bot:grep -rn 'dep.update.guard' bots/finds only its own bundle and a comment infeed-watch. A sub-bot ceiling is a separate axis, built on its trigger.Runs that predate the ledger. Adoption counts the alive runs a row does not name, but only through their stamp, so a run launched before its subject existed is invisible. Each subject is therefore observed first and enforced afterwards, behind an activation guard. The guard refuses
enforcewhile alive runs whose stamp lacks the subject exist, andaccept_unstamped: trueis its audited escape. Neither exists today. ADR-167 designs them for its T3 and T4b, andgrep -rn 'accept_unstamped\|would_park' pkg/matches nothing outside tests. S2 builds both, forbot:(§8).Cloud and local, the same code.
- The Mongo twin and the filesystem twin pass the same conformance rows.
- The scheduler takes its lease from
lease.MongoStoreorlease.MemoryStore, and its wakes fromNATSBusorInProcBus. - The local pipeline scheduler's in-memory FIFO retires onto this state and the filesystem ledger in the last slice (§8), with its best-effort persist and its lossy spec rebuild.
The four questions of philosophy §3, for the new durable state:
- Three replicas: the lease owns the work, and the ledger and the run CAS own the correctness.
- A pod dies mid-admission: the run is either still waiting or a recoverable orphan.
- A rolling deploy: nothing waits in memory.
- The cloud twin: in each slice.
5. The webhook lanes, on a live run instead of a stored event
Every immediate-lane delivery now answers 202 with a run. The webhook-side machinery then acts on a run it already knows how to stop, not on an event it must replay.
- Overlap and supersede.
supersededRunIDsselects the runs to replace by delivery rows inStatusLaunchedthat point at a run (pkg/server/webhooks_common.go:972-1005). A waiting run's row islaunched(§1), so it is selected, and cancelling it is a store write.- The timing. Today a replacement cancels its predecessors after its own admission and before its launch (:1539, then :1545-1558): "Only an admitted replacement may cancel" (:1007). With no capacity refusal at the gate, a replacement that waits would destroy its predecessor before it holds a place. A replacement therefore cancels its predecessor at its own admission (decision Q6(a)): in the step that publishes it, never at its creation. Its predecessor keeps running while it waits.
- The place. A replacement inherits the
sinceof the run it replaces, so a busy subject under sustained pushes is not sent to the back of the line at each push.
- Collapse of waiting runs. A waiting forge run that has never started is superseded by a newer run of the same bot on the same subject, whatever the overlap policy, and the newer run inherits its
since. "Never started" means no checkpoint and noresume_spec. Nothing started, so the newer head is the only one worth running. This closes P2: today'soverlap: allowkeeps both, because by then both have started. It applies to every forge-subject bot, whatever its overlap policy (decision Q9(a)).- How it combines with Q6. The collapse cancels a predecessor that is waiting and has never started, at the newer run's creation.
- Q6's "at admission" rule governs every predecessor that has started. That includes a waiting resume (one with a checkpoint or a
resume_spec): it is cancelled only at the replacement's admission, so its progress and its humanAnswersare never destroyed by a replacement that has not run. - Why the collapse is free. The collapsed predecessor has started nothing, and the newer run inherits its
since, so nothing is destroyed and no place is lost. - If the newer run never starts. Under Q4 a newer run that expires or is refused ends
failed_resumable, so the newest head stays resumable and nothing is lost. This reading of Q6 × Q9 is confirmed (2026-11-27).
- Debounce is unchanged: it holds the event before any launch. When it fires, it gets a run, and its
deferRetryWaitfor capacity is no longer reached. - Holds. A hold label applied after the launch cancels the subject's waiting runs. It does not cancel its started ones, which is today's rule for a running run. This closes P3.
- Closed or withdrawn work. A dead PR already stops every bot on the subject (
stopRunsForDeadPR, :1897). An unlabelled or closed issue cancels the waiting runs of its claim (ADR-170's sequence). This closes P6. - Auto-heal.
stopHealRunForRequeuedPRstops the heal run by its key's delivery row. The run exists from the first delivery, andrunIsStoppablereads waiting as stoppable, so the re-queue cancels it. This closes P1: there is no stored event left to replay. - Fork gestures go through the same tail, pinned to one SHA (ADR-162). They get a waiting run, and the per-author bounds stay refusals (§2).
- Fan-out.
webhookRunLivereads a waiting sibling as live, so the CODEOWNERS re-request collapses onto it instead of salting a second key. This closes P11. - Redelivery. The delivery row is
launchedwith a run id from the first attempt, so a Redeliver is answered with that run, whatever it is doing. There is no attempt budget to exhaust and no sender retry to double. This closes P4, P5 and P7. - Fairness. The scheduler's round-robin over the heads of the teams' slices of each subject (§3) replaces the shared sweepers for capacity. This closes P8.
- What still could happen. A waiting run reads its forge state when it is admitted, not when the event was sent. A fact the lane does not observe, such as a label set by hand in the UI without a webhook subscription, is not seen. That is a reading of the forge, the same as for a run that started a second after the event.
6. Visibility
The run.
capacity_waitis on the run's API and in the studio: "waiting for capacity — botdep-update-guard, 3/3, 4th in line for this team (11 waiting in all), 6 min". The chip is not red, and the only action is Cancel.- The pull request gets ADR-167 T6's pause notice, once per wait: no time and no "quota". No notice is posted for a
ledger_errorwait (decision Q3). - The text names this team's own position and the counts. On a subject shared across teams (
bot:,gw:), the counts are an aggregate. It names no other team's run. - The event stream gets
run_capacity_wait(subject kind, label, held, max, position) andrun_capacity_admitted(waited for).
The position. It is shown on two scales. The first is the run's place in its team's slice of the subject, on
(since, id): that is the order the scheduler keeps (§3). The second is the subject's aggregate: how many runs wait on it, all teams together, with no other team's runs named. On a shared subject the slice place is a rank, not a promise. Round-robin across teams means the wait in turns is about the slice place times the number of teams with waiting runs. The publisher's queue position counts everyqueuedrun deployment-wide (pkg/server/cloudpublisher/publisher.go:5617-5620) and stays the runner-queue reading.Metrics. Labelled by subject kind, never by tenant:
iterion_capacity_waiting_runs{kind};iterion_capacity_wait_seconds{kind}, a histogram;iterion_capacity_admissions_total{kind,path=fast|scheduled};iterion_capacity_overtakes_total{kind};iterion_capacity_scheduler_pass_seconds;iterion_capacity_wait_expired_total{kind};iterion_capacity_would_wait_total{kind}, counted inobservewhen an admission would have made the run wait (the twin of ADR-167'siterion_gateway_would_park_total);iterion_capacity_ledger_errors_total{kind}.
The starter alert pack gains a rule on the oldest wait and one on a scheduler without a lease holder.
The operator.
GET /api/admin/capacity/subjects[/{subject}]lists each row's holders and waiters, with every limit and its source. It is exposed asiterion remote admin capacity ls|show, and in the OpenAPI. A team admin reads the same view filtered to their team. ADR-167'sgateway_alive_runsroute becomes one of its kinds.
7. Mixed versions during a rollout, and the way back
The release floor is S1.
- Readers before writers. S1's readers (§1: the cancel CAS,
TeamCutoverStatusAlive, the runner's drop,BuildRunOutcome) are deployed on every server replica and every runner one release before any writer exists. - What that floor makes safe. A release at or above S1 can cancel, delete after a cancel, count and ignore a waiting run. A runner at or above S1 drops a stray message for one without spending the DLQ.
- Proof. It is shown on the S1 binary itself, before S2 is merged: a waiting run written by a test fixture is cancelled, read by the cutover, and dropped by the runner.
- Readers before writers. S1's readers (§1: the cancel CAS,
A server older than S1 must never meet a waiting run.
- It cannot cancel one: its CAS expects a list without the status (§1).
- It would 409 every stop of §5.
- Its runner would nak a stray message to the DLQ.
A server between S1 and S2:
- never writes
waiting_capacity, and answers its own launches with today's 429; - ignores a waiting run in every count and sweep;
- cancels one correctly.
Its
SaveRunkeeps the unknown fields (ADR-167, Consequences). It could harm a waiting run only by re-saving a stale copy of the same document, which the scheduler's CAS onsinceand on the status detects.- never writes
The switch.
capacity_scheduleris aplatformcfgfamily with one mode per subject kind:off: nothing of this record, on any binary, S2's included. A kind's limit is enforced as it is today, by the gate's 429 or, for the key kind, by the publisher's key admission and itsCRED_SLOT_WAITpark. Abot:ceiling inoffbounds nothing.- The key kind has no
observe, because keys are already enforced today: anobservemode would weaken them. Its modes areoffandenforce. - Q1(b) and Q3 apply only to the kinds in
enforce.- In
observe, nothing waits: a refusal is counted as a would-wait, and a ledger or count error is counted, and the run is admitted as onoff. - With keys
off, a run that has never entered the wait and is refused by a key is handled as today: a launch is parkedCRED_SLOT_WAIT, and a resume is reverted and answeredErrCredentialAtCapacity, with no park. A ledger error on a key is refused as today. That keeps the rollback on the proven path. - An already-waiting run (one that waited on another axis) that a key then refuses stays
waiting_capacity, with the key as an axis, whatever the key kind's mode. Parking it would make it read as not live (webhookRunLivecounts onlyqueued,runningand the two paused statuses, pkg/server/webhooks_common.go:1117-1134): a CODEOWNERS re-request would relaunch the same head (P11), and collapse and holds would stop acting on it. The S2 scheduler re-asks it at its next pass, so the rollback's drain covers it.
- In
observe: the kind is stamped and counted, nothing is reserved, and no run waits on it, not even on a ledger error.iterion_capacity_would_wait_total{kind}counts each admission that would have waited, anditerion_capacity_ledger_errors_total{kind}counts each error.enforce: the kind's subjects are reserved, and the run waits.
The guard on
enforce. APUTthat setsenforceis refused (409) in two cases:- The fleet is below S2. S2 builds a fleet version guard: each server replica and each runner records its release in a heartbeat, and the guard reads them. This does not exist today. The "deployed digests" check of ADR-167 §7 is a design, not code:
grep -rni 'deployed.digest' pkg/matches nothing. If S2 cannot build it, thePUTtakes an audited attestation instead,fleet_release: <tag>, and the operator's checklist names the commands that prove it. - Alive runs are unstamped. Some alive runs carry no stamp for the kind (§4).
accept_unstamped: trueis the audited escape.
- The fleet is below S2. S2 builds a fleet version guard: each server replica and each runner records its release in a heartbeat, and the guard reads them. This does not exist today. The "deployed digests" check of ADR-167 §7 is a design, not code:
The way back, named.
- Set the kind to
observe, oroff. The waiting runs are then admitted at the drain pace (§3), with no bound left on them. None is lost.- For the key kind, set
off. A new key refusal of a run that never entered the wait goes back to today's behaviour: a launch is parkedCRED_SLOT_WAIT, which the retry sweeper drains, and a resume is reverted and answered 429. The S2 binary keeps both paths for exactly this case. An already-waiting run that a key refuses stays waiting with the key as an axis, and the scheduler re-asks it, so the drain to zero covers it.
- For the key kind, set
- To roll the binary back below S2, the procedure is first:
offfor every kind;- the waiting set drained to zero:
iterion remote admin capacity ls --waitingprints 0; - then the roll, down to a release no older than S1.
- A roll below S1 is refused by the checklist while any
waiting_capacitydocument exists.
- Set the kind to
8. Rollout: what builds when
| Slice | Built | Trigger |
|---|---|---|
| S0 — measure, no code | now | Per-bot alive runs over a week; the starts per minute against md0's busy time; the overtakes and P8-type delays the sweepers produce today |
| S1 — the readers, no writer | now | The operator's decision of 2026-11-27. Delivers the status and AwaitsCapacity; capacity_wait, on both twins; the full reader matrix of §1; the cancel CAS as a predicate; TeamCutoverStatusAlive; the runner's DropAwaitingCapacity; BuildRunOutcome; the studio union. It is deployed to every server and runner, and proven on that binary, one release before S2 |
S2 — the scheduler and bot: | after S1 is the fleet's floor | #3845. The per-bot ceiling is the first subject. S2 carries over the policy shape, the CLI and the canonical fold of 45ee66d7c, but not its gate check or its parking. Prerequisites built in S2: (a) the admission order of §3, with admission_pending and the orphan pass that runs under backlog; (b) the persisted launch request (§3); (c) the durable charge–run release (§2); (d) the drain pace; (e) observe and its would-wait counter; (f) the activation guard, accept_unstamped, and the fleet version guard (§7); (g) webhook rows launched at creation, and §5's changes; (h) §6's run-level visibility. (i) waiting resumes with resume_spec, and the retirement of the CRED_SLOT_WAIT writer for the key kind in enforce (kept while that kind is off, §7), except for a resume carrying HostInputs, which keeps today's revert-and-429 under iterion_capacity_hostinputs_refusals_total (§3); (j) MaxWaitingRuns and capacity_queue_full (§2); (k) the ledger_error axis and its alert (§3); (l) capacity_wait_deadline (§3). Then dep-update-guard runs at a measured ceiling (about 3), first in observe, where nothing waits and ledger errors are only counted, then in enforce. The runner pool stays at 6 until iterion_capacity_unheld_redeliveries_total shows the pre-T4a leak is small (decision Q10(a)). It then goes back to 8–10, and md0 is watched |
S3 — team: moves from the gate to the ledger | after S2 and #3254 T4a | ADR-175 D4's own trigger: the first team with a concurrency cap above 0 in production. The gate's 429 retires for the team cap, and the floors move with it (§4) |
S4 — gw: | on ADR-167's activation | ADR-167 T4b and T5 are built on this state: no GATEWAY_SLOT_WAIT park is ever written |
| S5 — keys, and the runner's C2 | after S3 has run a week in enforce | With the key kind in enforce, no launch park is written any more. The launch parks written while it was off are drained: capacity ls shows none, a precondition that holds because only launches were ever parked. Then the retry sweeper's capacity code (the launch park's re-ask and deferCredSlotRetry) goes. T4a's C2 may then write the wait, with the runner's release in the guard; ADR-167's C2 clause "a ledger error → a deferred nak" (§4, transit guard C2) is amended then |
S6 — org: | ADR-175 D1's trigger | |
S7 — rate: | after S3, on a measured start burst | The launch rate becomes a per-team admission pace, refining S2's global drain pace. Its 429 retires, and the bucket's key and its Valkey twin across replicas are specified here (today's bucket is per replica without Valkey, pkg/server/launch_gate.go:903-918) |
| S8 — local | after S5 | The pipeline scheduler retires onto the state and the filesystem ledger |
Between S2 and S5, a key refuses a waiting run. The outcome depends on the key kind's mode, and S2 tests both cases:
- Key kind
enforce: the key is reserved in the same all-or-nothing loop (§3), so the run stayswaiting_capacityand names the key among its axes. It is not parkedCRED_SLOT_WAIT. - Key kind
off, the default until enforced: an already-waiting run also stayswaiting_capacitywith the key as an axis, for P11's reason (§7). Only a launch that never entered the wait is parkedCRED_SLOT_WAITas today. A resume that never entered the wait is reverted and answered 429, as today.
The S2 leak, named in full. Before #3254 T4a (C1–C3) lands, a failed_resumable run holds no place (HoldsCredentialSlot, pkg/store/lifecycle.go:415-417). A NATS redelivery of that run resumes it with no admission (ADR-175 D4, ADR-167 Context). Every source of failed_resumable opens a window in which the scheduler can give the place away:
- the runner's nak paths: interruption or drain, sandbox timeout, sandbox capacity, attachments, orphan adoption;
- the server's orphan sweeper.
The leak is therefore wider than a drain. On a capped bot under contention, every nak can let one more run start. iterion_capacity_unheld_redeliveries_total counts it. S3 waits for T4a because a tenant cap is a promise. bot: enforces before T4a (decision Q10(a)), with the leak counted. The runner pool stays at 6 until the counter shows the leak is small.
Each slice owes:
task check; CI addsrace,vendor-checkandmongo-conformance;- every test seen red under its named mutation;
- Mongo protocol tests run on a real replica set;
- a review loop with its trailers;
- its documentation in quotas-and-limits.md and webhooks.md, in the same change.
Consequences
One deferral system for capacity instead of seven. The capacity arms of these go:
- the webhook retry rows;
- the debounce
deferRetryWait; - the board's launch-refusal backoff;
- the trigger outbox's attempts;
- the schedule's lost tick;
- the connector's postpone;
- the retry sweeper's re-arm and
CRED_SLOT_WAIT.
Their non-capacity arms stay: maintenance, monthly refusals and errors.
ADR-175 D4 changes contract. Its "429
concurrency_cap_exceededwithRetry-After" and its "parkedfailed_resumableunderTENANT_SLOT_WAIT" (D4, "The publisher enforces") are replaced by a waiting run. Its ledger-error clauses are amended: D4's "A ledger error refuses the launch", the Consequences' D4 cost ("which D4's enforcer refuses, by its fail-closed rule"), and "Resumes also become fail-closed when the ledger is down". They are amended by decision Q3(a): a ledger error makes the run wait onledger_errorinstead of refusing it. So is ADR-167 §7's launch-side clause (§7 "Failures": "A ledger error: the launch is refused"). ADR-167 §4 C2's runner-side "a ledger error → a deferred nak" stays until S5, when the runner may write the wait. Both records carry an "Amended by" pointer. Its order of rows, its single stamping helper, its tree rule and its dependency on #3254 stand. The tokenconcurrency_cap_exceededstays only for the "all slots reserved" refusal, until that refusal gets a token of its own (concurrency_slots_reserved).The caller sees a run where it saw a 429. A CLI or API caller that relied on the 429 to back off now gets a run, which it can cancel. That is a behaviour change, written into the API reference.
New durable state, each with its twin:
- the status;
capacity_waiton runs;- the
bot:,team:,org:andrate:rows (pace rows hold no holders); - the
capacity_schedulerplatform switch; - one lease;
- an index on
(status, capacity_wait.since).
Admission costs more for a waiting run. It is re-resolved and re-sealed at admission, and the fast-path resolution is spent for nothing when the run waits. That is the price of not dialling with stale credentials, and of keeping no sealed material at rest on a waiting run.
Contention.
org:<id>and a hotbot:row are written by every admission under them. Under a burst, the bounded rounds (credSlotReserveRounds = 32, pkg/store/mongo/cred_slots.go:161) can be exhausted. The store error then makes the run wait onledger_error(§3), counted and alerted. It is never an admission on a guess.A wait is unbounded unless
capacity_wait_deadlineis set (decision Q4(a)). A run waiting behind a bot whose ceiling the operator never raises waits until it is cancelled, and the alert on the oldest wait is the operator's signal.Residual loss.
- The one capacity-flavoured loss is the abuse bound. Past
MaxWaitingRuns, an immediate-lane event is refused withcapacity_queue_full, and its sender must retry or redeliver it (§2). - Out of scope: the immediate lane still loses an event refused by the maintenance fence, or by a store outage before the run is written. Neither is a capacity refusal.
- The one capacity-flavoured loss is the abuse bound. Past
Alternatives considered
- Refuse at the gate and park each surface's refused event (
45ee66d7c). Rejected by its review: P1–P8 and P11, each red on the new code and green on the base. A refusal is the loss, and a parked event replayed later is a second launch system that every stop, supersede, hold and dedupe of the lanes would have to learn. The review proved that, each time, they had not learnt it. - Defer at the runner, with a delayed nak (
handleAdmissionMismatch, pkg/runner/loop_nats.go:195-240). A nak counts against MaxDeliver: the handler comparesNumDeliveredwithMaxDeliverand parks on the DLQ once the budget is spent (:198-203, :225-240). The constants' comment says a bare nak "can burn the whole redelivery budget in seconds" (pkg/queue/nats/nats.go:97-107).- Each redelivery takes a runner's fetch and claim, and the runner would need to read every axis's configuration.
- ADR-167 rejected the place taken at the runner's claim for that reason.
- Whether a message under a delayed nak counts against
MaxAckPending(256 by default) during its delay was not verified here. - Rejected: a wait measured in deliveries is a loss with a delay.
- Keep only the global runner pool cap. It loses nothing (NATS holds the messages) and costs no code. But it throttles every team for one bot, and its waiting messages burn the redelivery budget past AckWait (above). It also says nothing about a key, a gateway, a team or an org. It stays the physical bound of the fleet, not an allocation.
queuedwith a reason field. Rejected in §1: every reader ofqueued, and every replica of the previous release, would count, adopt or orphan a waiting run.failed_resumablewith a park code, asCRED_SLOT_WAITdoes. Rejected in §1:- terminal and deletable;
- read as not live by the lanes;
- re-asked at 5 runs a minute deployment-wide.
- An in-memory FIFO per replica, as the local pipeline scheduler has. It is not cloud-native: a replica's FIFO dies with it, and its persistence is best-effort by its own comment.
- A per-subject CAS scheduler with no lease, every replica scanning. Correct, since the ledger and the run CAS hold, but N replicas scan N times and fight over the same rows. The lease is a load reduction on a design that is already correct.
Decisions taken (operator, 2026-11-27)
The operator answered the ten questions of the reviewed draft. Each entry below records the decision, then the options that were weighed: the record of what was set aside.
- Resumes wait too: (b), "the most durable". (F3, F4) The run persists a durable
resume_spec; its fields, their care, and when it is cleared are in §3. A waiting resume inherits its attempt'ssince, and the pause pointer survivesSaveRun. Waiting applies to the kinds inenforce; inobservethe run is admitted and counted. The launch-onlyCRED_SLOT_WAITpark is retired as a writer from S2 for the key kind inenforce. It stays the key kind's launch behaviour while that kind isoff, as does today's revert-and-429 for a resume (§7). S5 removes the park. The rollback is proven in S2 (§3, §7).- Weighed:
- (a) only launches without a checkpoint wait, and resumes keep today's behaviour: the flip is reverted (
RevertQueuedFlip) and the caller getsErrCredentialAtCapacity, with no park; - (c) resumes wait with their request re-derived from the run, which cannot rebuild
AdmittedorAnswers.
- (a) only launches without a checkpoint wait, and resumes keep today's behaviour: the flip is reverted (
- Weighed:
- The bot ceiling's scope: (a), deployment-wide on the canonical name. Teams are shown the aggregate. (F23)
- Weighed:
- (b) per (team, bot), which bounds nothing shared: 13 teams × 3 is 39 sandboxes;
- (c) both, with a per-team share built later.
- Weighed:
- The ledger is unavailable: (a), the run waits on a
ledger_erroraxis, for a kind inenforce. Inobservethe error is counted and the run is admitted as onoff. The wait has its own counter and alert, and no pull-request notice. ADR-175 D4's ledger-error clauses and ADR-167 §7's launch-side clause are amended explicitly; ADR-167 C2's runner clause is amended at S5. (F14)- Weighed: (b) refuse, as both records said, which loses the immediate lane's event during an outage.
- A wait's deadline: (a), a distinct
capacity_wait_deadline, unbounded by default. Expiry, or a refusal taken during the wait, ends the runfailed_resumable. (F18)- Weighed:
- (b) the same, but ending
failed, which is terminal and not auto-resumable; - (c) reusing
retrypolicy.MaxWait, a retry clamp of 8 days by default.
- (b) the same, but ending
- Weighed:
- The monthly charge: (a), charged at creation and refunded for every admission charge never published, through S2's durable release. A per-team
MaxWaitingRunsbounds creation from S2, counting waiting launches and waiting resumes (200 proposed, measured in S0). Beyond it the answer is a 429capacity_queue_full: the one, named exception to the principle (§2). (F17)- Weighed:
- (b) charge at admission, which neither refunds nor bounds creation;
- (c) refund only on cancel and supersede, with no bound until S7.
- Weighed:
- A replacement cancels its predecessor at its own admission: (a). (F10) A waiting predecessor that has never started, collapsed by Q9, is the stated exception; a waiting resume follows this rule (§5).
- Weighed: (b) cancel at creation and accept the loss.
- The launch rate: (a), a per-team pace at admission, in S7. Q5's creation bound takes over the rate's role against abuse.
- Weighed: (b) keep the rate a refusal.
- No interactive opt-out: (a). Cancel is the opt-out.
- Weighed: (b)
wait: falseon the REST launch, giving back the old 429.
- Weighed: (b)
- The collapse of waiting runs: (a), on a newer head, for every forge-subject bot, whatever the overlap policy. (§5; F11's inherited place)
- Weighed: (b) opt-in per bot.
bot:may enforce before #3254 T4a: (a). The leak is counted. The runner pool stays at 6 until the counter shows the leak is small, and then goes back to 8–10. (F16)- Weighed: (b) wait for T4a.
Settled after the decisions (2026-11-27).
HostInputskeeps its contract. It is not persisted inresume_spec. A resume that carries it and finds no capacity keeps today's behaviour, a counted exception (§3): the flip is reverted, the caller getsErrCredentialAtCapacity(429), and no park is written.- Q6 × Q9 is read as §5 writes it. A waiting predecessor that has never started (no checkpoint and no
resume_spec) is collapsed into the newer run at the newer run's creation, and the newer run inherits itssince. A waiting resume counts as started. A started predecessor is cancelled at the replacement's admission. Under Q4, a newer run that expires or is refused endsfailed_resumable, so the newest head stays resumable.
Coordination with ADR-175/ADR-167 owners
These go to the owning sessions through the PR and the tickets, and this record does not decide them.
- #3254 (ADR-167, T4a): Q1(b) widens S2. The fast path reserves keys in the same all-or-nothing loop. From S2, a key refusal therefore makes a launch or a resume wait, and no
CRED_SLOT_WAITis written: work this draft had put in S5.- T4a's arbitrations of 2026-11-26 (frozen-IR re-admission, and C2 parks charged as attempts) are built on the retry sweeper's parks.
- ADR-176 needs from #3254: T4a's frozen-IR re-admission should also accept a run admitted from
waiting_capacity. The removal of the sweeper's capacity code (deferCredSlotRetry, S5) should be sequenced after T4a's own use of it. - #3254 needs from ADR-176: C2 keeps "free retry armed" until S5, and the runner writes no
waiting_capacitybefore then.
- #3254 (ADR-167) and #3748 (ADR-175): Q3 against ADR-167 C2. A ledger error waits on
ledger_error. That amends now ADR-175 D4's ledger-error arm ("A ledger error refuses the launch") and its Consequences (the D4 cost bullet and "Resumes also become fail-closed"), and ADR-167 §7 Failures' launch-side clause ("A ledger error: the launch is refused"). ADR-167 §4 C2's runner-side "a ledger error → a deferred nak" is amended only at S5, because the runner does not write the wait before then.- ADR-176 needs from #3748: acceptance that D4's fail-closed refusal becomes a fail-closed wait.
- ADR-176 needs from #3254: the same for §7, and C2 left as written until S5.
- Both records carry only an "Amended by" pointer from this session.
Adversarial review disposition (GLM-5.4 via Claude Code, max — 25 findings)
Each finding was checked against the code at 8b001cdc6 before its verdict, and none was refuted. The review itself: ~/.claude/plans/rvp-176/review.md, operator-local.
Adopted into the plan:
- F1 reserving while still
waiting_capacitygets the entry evicted: the run mustSpendsCredential. Fix: CAS toqueuedwithadmission_pendingfirst, then reserve (§3). - F2 an overlapping loser's
ReleaseCredSlotremoves the winner's refreshed entry. Fix: the CAS loser neither reserves nor releases, with a conformance row (§3). - F5 the cancel CAS expects a list built from
AllRunStatuses, so an old binary cannot cancel. Fix: a predicate CAS in S1, S1 as the release floor, and a named way back (§1, §7). - F6 activation, a raised cap and a rollback each drained everything at once. Fix: a per-pass and per-minute admission bound from S2 (§3).
- F8 "full" is keyed by (subject, effective
max), so a reserved bot is still tried (§3, §4). - F9 the delivery row goes
launchedat creation;acceptedis a 10-minute in-flight state (§1, §5). - F11 a replacement, and a collapse, inherits
since(§1, §5). - F13
off/observe/enforceare defined, withiterion_capacity_would_wait_total(§6, §7). - F16 the leak names every source of
failed_resumable(§8). Under Q10(a), the runner pool stays at 6 until the counter shows the leak is small. - F19 the reader matrix is completed:
SaveRun's pause scrub,CanReclaimResumePauseHandoff,WatchDeliverable,IsQueued,IsPaused, andTeamCutoverStatusAlive, which errored (§1). - F20 nothing sealed rests on a waiting run (§3).
- F21 a key refusal between S2 and S5 keeps an already-waiting run waiting, with several axes, whatever the key kind's mode (§3, §7, §8).
- F22 the orphan pass on
admission_pendingis not skipped under backlog (§1, §3). - F23 shared-subject counts are shown as an aggregate (§4, §6), under Q2(a).
- F3 under Q1(b): resumes wait, with a durable
resume_spec(§3). - F4 under Q1(b): a waiting resume inherits its attempt's
since, and the preserved fields are listed (§3). - F10 under Q6(a): a replacement cancels its predecessor at its own admission (§5).
- F14 under Q3(a): the run waits on a
ledger_erroraxis, and the clauses of ADR-175 and ADR-167 are amended explicitly (§3, Consequences). - F17 under Q5(a): the durable per-charge refund for every admission never published, and
MaxWaitingRunsfrom S2 (§2). - F18 under Q4(a): a distinct
capacity_wait_deadline, endingfailed_resumable(§3). - F24 a tree is one place, and
dep-update-guardis never a sub-bot in the catalogue (§4).
Adjusted:
- F7 (confirmed:
Admitlets an unknown status proceed, and the delivery then naks to the DLQ and reportsrun.failed. The drop branch and theBuildRunOutcomebranch ship in S1, not S2: readers before writers.) - F12 (the fleet version guard,
accept_unstampedand the activation guard are stated as non-existent and built in S2, with an audited attestation as the fallback if the guard cannot be built in S2.) - F15 (the runner never writes
waiting_capacitybefore S5. C2 keeps "free retry armed", and T4a is named as not on main.)
Deferred follow-ups (documented):
- F25 the
rate:bucket key and its cross-replica twin are specified in S7 (§8).
