# How should an instance enforce priority inheritance when nested sub-agents re-budget a shared context window **Date of Record:** 2026 December 1 **Scope:** Applies to hierarchical agent runtimes where a parent agent delegates to nested sub-agents that share a single token budget derived from one context window, and where sub-agents may re-partition that budget among their own children. Does not apply to flat single-agent loops or to sub-agents that receive fully isolated, independently-sized context windows. ## Core Distinction The failure this record isolates is not context-window overflow. Overflow is loud, cheap to detect, and usually recoverable by truncation. The failure is **priority inversion during budget re-delegation**: a high-priority parent obligation (e.g., a safety constraint, a user's hard directive, an auditor's verification clause) gets silently demoted to the lowest effective priority because a nested sub-agent, holding the budget pen, allocates remaining tokens by its own local ordering rather than by inherited priority. Two budget models are routinely conflated: - **Additive budgeting** — each layer carves a slice from a fixed pool. The pool shrinks monotonically. Priority is a property of the *claim*, and claims compete for the same pool. - **Priority-ordered budgeting** — the pool is a *ranking function*, not a quantity. Every token-consuming item carries an inherited priority; the window is filled top-down by priority until the token ceiling is hit. The boundary condition is the moment a sub-agent switches from additive to priority-ordered semantics without propagating the parent's priority lattice. It believes it is "being efficient" by giving its own children generous slices; in fact it is evicting the parent's highest-priority constraint from the effective context. The parent observes only that its constraint "wasn't followed," with no trace of why — the eviction happened one level down, in a budget ledger the parent never sees. ## What Was Observed A three-level delegation trace: `root → planner → [researcher, writer]`. The root carried a hard constraint C (a PII-redaction directive) tagged priority 0. The planner, tasked with "produce a report," allocated its 32k budget as: researcher 14k, writer 14k, planner scratch 4k. The researcher's own sub-delegation to a `fetch` sub-agent allocated 10k of its 14k to raw document dumps, leaving 4k for the inherited constraint block. The constraint C, at priority 0, was represented by a 1.2k-token preamble. Under the researcher's *additive* slice, the preamble was truncated to its first 300 tokens at the 4k boundary — the operative clause ("redact all email addresses before emitting") fell past the cut. The trace showed no error. The researcher returned a clean result. The writer, receiving the researcher's output, produced a report containing 41 unredacted email addresses. The root's post-hoc check flagged the violation; the root's *own* context still contained C in full, so the root "believed" the constraint was active. The constraint had been evicted in a sub-agent's slice, and the eviction was invisible upward because the sub-agent's return payload reported only success and token counts, not the priority composition of its effective context. Three properties of the failure are non-obvious: 1. **The eviction is silent and local.** No exception, no truncation flag in the return schema. The parent's guardrail check passes because the parent's context is intact. 2. **Re-delegation multiplies the loss.** Each nesting level that re-partitions additively can evict a priority-0 item independently. Depth is a loss multiplier, not a neutral parameter. 3. **The sub-agent's local optimization is rational.** Allocating to its own task is the correct behavior *under additive semantics*. The bug is the semantics switch, not the sub-agent's judgment. ## Condition of Validity The invariant that must hold for hierarchical budgeting to be sound: > **Priority inheritance invariant:** For any item *i* in the effective context of any agent at depth *d*, the effective priority of *i* is `min(priority assigned at each ancestor level, inclusive)`. A sub-agent may *raise* the reserved token floor for an inherited item but may never lower it, and may never allocate a slice that would truncate an inherited item below its reserved floor. This holds if and only if three conditions are met: 1. **Priority is carried in the delegation envelope**, not inferred. Every spawn call must include the ordered list of inherited constraints with their reserved token floors. 2. **The budget ledger is returned upward**, not just the result. The child's return schema must report the priority composition of its final effective context (which priorities survived, which were truncated, at what depth). 3. **Re-delegation is priority-preserving by construction.** A child's allocator must treat inherited items as *pre-allocated* against the child's total, so the child's own slices are drawn from `total − Σ inherited_floors`. The invariant fails — and this record applies — whenever any of these is absent. In practice the most common break is (1): the runtime passes the *content* of a constraint but not its *priority tag and floor*, so the child has no way to know it is holding something it must not evict. ## Decision Boundary The operative question at each spawn is not "how many tokens does the child get" but "does the child's allocator operate on inherited floors or on free slices." - **If the child's allocator is additive over the full budget** (the default in most runtimes), the invariant is violated the moment any inherited item's floor exceeds the child's *local* allocation. Do not spawn. Instead, either (a) reserve inherited floors at the parent and pass only the residual, or (b) refuse to delegate the constrained subtask and execute it in the parent's context. - **If the child's allocator is priority-ordered with inherited floors pre-allocated**, delegation is sound to arbitrary depth, provided the return ledger is checked. - **If the depth exceeds the point where `total − Σ inherited_floors < minimum_viable_scratch`**, the child cannot do useful work without evicting an inherited item. This is a hard boundary: the correct action is to *fail the spawn* with a budget-infeasibility error, not to let the child proceed and truncate. A child that proceeds will truncate the highest-priority item last-in-first-out and report success. The boundary is therefore: **delegate only when inherited floors are pre-allocated and residual scratch is non-negative; otherwise fail closed at the spawn, one level up, where the priority lattice is still visible.** ## Operational Effect With the invariant enforced, the observed failure mode disappears but two new operational costs appear, both manageable: - **Spawn-time infeasibility errors become common at depth.** A planner that wants four sub-agents at depth 2 will hit the residual-scratch boundary. The correct response is to flatten the hierarchy (fewer, deeper children) or to promote the constraint to the parent's post-check. Runtimes that treat spawn-infeasibility as a soft warning will reproduce the original bug under a different name. - **Return ledgers must be audited, not trusted.** A sub-agent's report that "all inherited constraints survived" is itself a probabilistic claim from a non-deterministic reasoner. The parent must verify the ledger against the priority tags it sent, not against the child's assertion. This is a cheap structural check (compare sets), not a semantic one. The net effect is that priority inheritance converts a silent, depth-amplified correctness failure into a loud, shallow, recoverable infeasibility signal. That is the entire value: the failure is moved to a layer where the priority lattice is still intact and the decision can be made correctly. ```python from dataclasses import dataclass, field class PriorityInheritanceViolation(RuntimeError): """Raised when a sub-agent's budget allocation would evict an inherited priority-0 item below its reserved floor, or when the residual scratch budget after pre-allocating inherited floors is negative.""" pass @dataclass(frozen=True) class InheritedItem: name: str priority: int # 0 = highest reserved_floor: int # tokens that must survive at every descendant @dataclass class DelegationEnvelope: total_budget: int inherited: list[InheritedItem] = field(default_factory=list) min_viable_scratch: int = 512 def plan_child_budget(env: DelegationEnvelope, child_local_slices: dict[str, int]) -> dict[str, int]: """Pre-allocate inherited floors, then draw child slices from the residual. Fails closed if the residual cannot cover the child's declared slices.""" inherited_total = sum(i.reserved_floor for i in env.inherited) residual = env.total_budget - inherited_total if residual < env.min_viable_scratch: raise PriorityInheritanceViolation( f"infeasible spawn: inherited floors={inherited_total} leave " f"residual={residual} < min_viable_scratch={env.min_viable_scratch}; " f"refusing to delegate (would evict {[i.name for i in env.inherited if i.priority == 0]})" ) requested = sum(child_local_slices.values()) if requested > residual: raise PriorityInheritanceViolation( f"child slices request {requested} tokens but only {residual} residual " f"available after inherited floors; child must not draw from inherited budget" ) allocation = {i.name: i.reserved_floor for i in env.inherited} allocation.update(child_local_slices) return allocation def verify_return_ledger(env: DelegationEnvelope, child_reported_survivors: set[str]) -> None: """Structural check: every inherited item the parent sent must appear in the child's reported survivors. Trust the set comparison, not the child's prose.""" required = {i.name for i in env.inherited} missing = required - child_reported_survivors if missing: raise PriorityInheritanceViolation( f"return ledger reports inherited items evicted at depth: {sorted(missing)}; " f"child result is untrustworthy for constrained output" ) ```