# When must an instance refuse to drain its inbox: supervisor starvation deadlock from eager worker prefetch under hierarchical backpressure **Date of Record:** 2026 November 26 **Scope:** Applies to hierarchical supervisor→worker agent topologies where the supervisor dispatches tasks from a bounded work queue and workers prefetch additional tasks before completing the current one. Does not apply to flat swarms with a shared broker, nor to single-agent loops with no cross-instance queueing. ## Core Distinction The failure is not "the queue is full" and it is not "a worker crashed." It is the distinction between **backpressure as a flow-control signal** and **backpressure as a liveness hazard**. In a correct pipeline, a full queue stalls producers until consumers drain. In a hierarchical agent topology, the supervisor is *simultaneously* a consumer (of worker results) and a producer (of worker tasks). When workers prefetch—claiming the next task before emitting the result of the current one—the supervisor's inbound result channel and outbound task channel become coupled through a shared bounded buffer. A worker that holds an unstarted task while its own result is blocked behind a full result buffer creates a cycle: the supervisor cannot accept results because workers hold tasks; workers cannot finish tasks because the supervisor's result buffer is full of *its own* unprocessed work. The invariant that breaks is the assumption that *draining is always progress*. Under hierarchical backpressure, an instance must sometimes refuse to drain its inbox because draining admits work it cannot retire. ## What Was Observed A three-tier topology: one supervisor agent (S), a pool of N=8 worker agents (W1..W8), and a bounded result channel of capacity C=4 between workers and S. Workers were configured with an *eager prefetch* optimization: on receiving task T_k, a worker immediately issues a `claim_next()` to the task broker to pipeline latency, holding T_{k+1} in local state while executing T_k. Trace of the deadlock (deterministic under replay): 1. S dispatches 8 tasks, one per worker. Broker queue depth drops to 0. 2. Each worker immediately `claim_next()`s. Broker is empty, so each worker blocks on a *reservation* against future tasks rather than a concrete task. Reservations are 8 outstanding, capacity is unbounded at the broker but the result channel C=4 is not. 3. W1..W4 finish T_1..T_4 and write results to the result channel. Channel now full (4/4). W1..W4 block on `put_result`. 4. W5..W8 finish T_5..T_8 and attempt `put_result`. Channel full. They block. 5. S attempts to read results to dispatch the next batch. But S's dispatch loop is gated on `broker.pending_reservations() == 0` — a guard added to prevent over-dispatch. Reservations are 8, never decremented because the workers holding them cannot proceed to consume them (they are blocked on `put_result`). 6. S waits on reservations; workers wait on result channel; result channel waits on S. **Deadlock.** The non-obvious part: the reservation count is a *proxy* for "work in flight," but eager prefetch makes reservations outlive the tasks that justify them. The guard `pending_reservations() == 0` was intended to bound in-flight work; instead it became a liveness trap because reservations are held by workers that are themselves blocked. The supervisor's decision to *not drain* was correct in spirit (bound in-flight work) but wrong in mechanism (it used a count that workers could inflate without retiring). Replay discrepancy: under a scheduler that reorders step 3 and 4, the deadlock sometimes resolved because a worker would occasionally get its result through before the channel filled, freeing a slot. This made the bug intermittent at ~1 in 40 runs, masking it in staging. ## Condition of Validity The deadlock requires all of: - **Bounded result channel** with capacity C < N (workers). If C ≥ N, no worker ever blocks on `put_result` for its first task, and the cycle cannot close. - **Eager prefetch** where a worker holds a reservation before its current result is retired. Without prefetch, a worker's reservation is always tied to a task it is actively executing, and the supervisor's reservation count is a true in-flight measure. - **Supervisor dispatch gated on a reservation/in-flight count** rather than on result availability. If S dispatches whenever it has capacity, it drains results and the cycle breaks. - **No timeout on `put_result` or `claim_next`.** A timeout converts deadlock into retry, which is a mitigation, not a fix. If any one is absent, the system degrades (latency, throughput) but does not deadlock. This is why the failure is non-obvious: each component is individually reasonable, and the interaction is the bug. ## Decision Boundary The boundary is: **a worker must not claim a reservation for task T_{k+1} until the result of T_k has been accepted by a downstream consumer, OR the supervisor must dispatch based on result-channel occupancy rather than reservation count.** Concretely, the supervisor's admission rule must be: ``` dispatch_allowed = (result_channel.free_slots() > 0) AND (broker.pending_reservations() < C) ``` The critical change is `pending_reservations() < C` (bounded by result channel capacity), not `< N` or `== 0`. The reservation count must be bounded by the *downstream* buffer, not the worker pool, because a reservation is only useful if its result can eventually be retired—and retirement is gated by the result channel. Equivalently, on the worker side: prefetch must be *credit-based*. A worker may prefetch T_{k+1} only if it holds a credit issued by the supervisor, and the supervisor issues at most C credits total (matching result channel capacity). Credits are returned when the result is accepted. This makes the reservation count a conserved quantity bounded by C, and the cycle cannot close because the number of workers holding unretired reservations is ≤ C, leaving at least one slot for a result to land. The guardrail is a **conservation invariant**: `outstanding_reservations + free_result_slots == C` at all times. Any state where a worker holds a reservation and the result channel is full violates it. Instrument this as a runtime assertion, not a metric—the violation is a precursor to deadlock, and catching it in the assertion is cheaper than catching it in a hang. ## Operational Effect Without the fix, the topology exhibits **supervisor starvation deadlock**: S blocks on a reservation count it can never see decrement, workers block on a result channel S can never drain, and the system hangs with no error, no timeout, and no log line indicating the cycle. The failure is silent because every individual blocking call is a legitimate wait. Under load it manifests as a throughput cliff—the system runs fine at N=4 (C=N, no deadlock) and hangs at N=8 (C