# When must an instance preempt a low-priority sub-agent to preserve a shared context budget, and why does cooperative yielding always arrive too late? **Date of Record:** 2026 November 20 **Scope:** Applies to orchestrators that fan out concurrent sub-agents sharing a single upstream context/token budget under static or priority-weighted allocation, where sub-agents call tools that emit unbounded output. Does not apply to per-agent isolated budgets, hard-capped tool outputs, or single-agent sequential execution. ## Core Distinction The distinction that matters is between **budget accounting** and **budget enforcement**. Most orchestrators account correctly: they track a token ledger, assign each sub-agent a priority-weighted share, and decrement on every tool result appended to the shared window. What they fail to do is *enforce* the ledger at the moment of append. The invariant that breaks is not "the sum of allocations equals the budget" — it is the stronger invariant that **no sub-agent's append may commit a token count that pushes the aggregate committed total past the reserved floor of any higher-priority agent still in flight.** The failure is non-obvious because it is a *commit-time* race, not a *plan-time* arithmetic error. At plan time the allocation is provably feasible. The violation is introduced by the nondeterministic size of tool outputs arriving between the plan and the commit, and by the fact that sub-agents yield cooperatively — they check the budget *before* a tool call, not *after* the result returns. A cooperative yield is therefore always one tool-result stale. The instance must preempt, not wait for a yield. ## What Was Observed A three-way fan-out: a `planner` (priority 10, reserved floor 40% of budget), a `retriever` (priority 5, floor 20%), and a `summarizer` (priority 1, floor 0%, best-effort). The orchestrator allocated 40/35/25 with a 10% slack buffer, and every agent was instrumented to call `check_budget()` before each tool invocation and yield if its projected next call would exceed its share. The trace that broke it: 1. All three agents pass their pre-call `check_budget()`. `retriever` projects a 2k-token tool call, well inside its 35%. 2. The `retriever`'s tool — a web fetch — returns a 61k-token document. The pre-call check projected 2k because the projection used the *request* size, not the *response* size. The append commits 61k. 3. In the same event-loop tick, `summarizer`'s tool returns 18k tokens. Its pre-call check had passed 40ms earlier, before the retriever's commit. 4. Aggregate committed tokens now exceed the `planner`'s 40% floor by 22k tokens. 5. The `planner` wakes, calls `check_budget()`, sees its floor is breached, and — correctly — refuses to proceed. It blocks waiting for the `retriever` to yield. 6. The `retriever` cannot yield: it is mid-append, and its yield point is the *next* pre-call check, which will not run until its current tool call completes. The `retriever`'s current tool call is the one that already returned. 7. Deadlock resolves only when the `retriever`'s *next* tool call returns and it finally yields — 1.4s later in this trace, but unbounded in principle if the next tool call is long-running. The key observation: **every agent behaved correctly against its local contract, and the system still violated the global floor.** The `retriever` did not overrun its own share (61k was within its 35% if measured alone). The violation was purely aggregate, purely commit-time, and invisible to any per-agent check. ## Condition of Validity The preemption requirement holds — and cooperative yielding is insufficient — precisely when all three of the following are true: - **Tool output size is not bounded by the request.** If every tool result is capped (e.g., hard truncation at the transport layer), the pre-call projection is a valid upper bound and cooperative yield is sound. The failure requires that a tool's response can exceed what the caller could have projected from the request. - **Sub-agents share a single committed budget rather than isolated budgets.** With per-agent isolation, one agent's overshoot cannot breach another's floor. The failure is a property of shared accounting. - **Appends are non-atomic with respect to the check.** If `check_budget()` and `append()` are a single compare-and-swap under a lock, the window between check and commit closes and the race cannot occur. The failure requires that the check and the commit are separable and interleaved with other agents' commits. When any one condition is absent, the cooperative model is adequate and adding preemption is unnecessary complexity. The operational discipline is to *test for all three* at fan-out time and select the enforcement mode accordingly. ## Decision Boundary The decision boundary is not "high priority vs. low priority." It is **whether the low-priority agent is currently inside a commit that can breach a higher-priority floor, or merely holding an allocation it has not yet committed.** - If the low-priority agent holds *reserved but uncommitted* allocation, the orchestrator may reclaim it cooperatively — signal the agent, let it yield at its next check, reclaim the reservation. No preemption needed; the floor was never actually breached because nothing was committed. - If the low-priority agent is *mid-commit* (a tool result is in flight and will append on return), cooperative reclamation is too late by construction. The orchestrator must **preempt**: cancel the in-flight tool call if the transport supports cancellation, or, if not, quarantine the pending append — buffer it outside the shared window and admit it only after the higher-priority floor is satisfied by eviction of lower-priority committed content. The boundary condition is therefore: **preempt if and only if `pending_commit_lower > floor_breach_risk_higher`.** Concretely, if the projected size of the in-flight append (which the orchestrator cannot know, only bound by the transport's max response size) plus current committed exceeds the higher agent's floor, preemption is mandatory. If the transport has no response cap, the bound is the budget itself, and preemption is *always* mandatory for any in-flight commit when a higher-priority agent is blocked. ## Operational Effect The architectural invariant that must be enforced is a **commit-time admission gate**, not a pre-call budget check: 1. **Reserve at plan, admit at commit.** Allocations are reservations. The shared window only accepts an append if, after the append, every in-flight higher-priority agent's floor remains satisfiable. The gate is evaluated *at append time*, under the same lock as the ledger mutation. 2. **In-flight commits are tracked as liabilities.** When an agent dispatches a tool call, the orchestrator records a liability with an upper bound (transport max response size, or budget if uncapped). Floor checks must account for outstanding liabilities, not just committed tokens. This is what makes the higher agent's block *predictive* rather than reactive. 3. **Preemption is cancel-or-quarantine, never wait.** Because cooperative yield is one-result stale, the orchestrator must never resolve a floor breach by waiting for the low-priority agent to yield. It cancels the in-flight call, or it quarantines the returned append and evicts lower-priority committed content to make room before admitting. 4. **Eviction order is by priority, then by recency, then by re-derivability.** Content evicted to satisfy a floor must be re-derivable (tool outputs can be re-fetched; distilled summaries cannot). This is the second invariant: *never evict non-re-derivable content to satisfy a floor* — instead, preempt the commit that would have required the eviction. The operational lesson: budget arbitration is a concurrency-control problem masquerading as an arithmetic problem. The arithmetic is easy and always passes review. The failure lives in the gap between the check and the commit, and it is closed only by making admission atomic with the ledger and by treating in-flight tool calls as liabilities rather than as future facts. ```python from dataclasses import dataclass, field from typing import Optional class FloorBreachPreemptionRequired(RuntimeError): """Raised when an in-flight low-priority commit would breach a higher-priority floor.""" pass class BudgetLedger: def __init__(self, total: int): self.total = total self.committed = 0 self.liabilities = {} # agent_id -> upper-bound tokens in flight self.floors = {} # agent_id -> reserved floor tokens def register(self, agent_id: str, priority: int, floor: int): self.floors[agent_id] = floor def dispatch_liability(self, agent_id: str, transport_max: Optional[int]): # If transport has no cap, the liability is the whole budget. self.liabilities[agent_id] = transport_max if transport_max is not None else self.total def clear_liability(self, agent_id: str): self.liabilities.pop(agent_id, None) def _floor_breach_if_committed(self, agent_id: str, size: int) -> Optional[str]: projected = self.committed + size for other, floor in self.floors.items(): if other == agent_id: continue # Outstanding liabilities of OTHER agents also consume budget. outstanding = sum( v for k, v in self.liabilities.items() if k != agent_id ) if projected + outstanding > self.total - floor: return other return None def admit_commit(self, agent_id: str, size: int) -> None: """Commit-time admission gate. Atomic with ledger mutation in production.""" breached = self._floor_breach_if_committed(agent_id, size) if breached is not None: # Cooperative yield is too late: the result already returned. raise FloorBreachPreemptionRequired( f"commit of {size} tokens by {agent_id} would breach " f"floor of {breached}; preempt (cancel or quarantine), do not wait" ) self.committed += size self.clear_liability(agent_id) def on_tool_result(ledger: BudgetLedger, agent_id: str, result_tokens: int): try: ledger.admit_commit(agent_id, result_tokens) except FloorBreachPreemptionRequired: # Quarantine the append outside the shared window; evict lower-priority # re-derivable content, then re-attempt admission. raise return "admitted" ```