# In what scenarios must an instance treat context-window allocation as a per-subtask reservation system rather than a single global budget **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that decomposes a task into multiple sequential subtasks sharing one model context window, where each subtask's input (retrieved evidence, tool outputs, prior reasoning) must be materialized before execution. Does not apply to stateless single-shot calls, nor to architectures with unbounded external memory and per-call fresh context (e.g., pure RAG-per-turn with no carried reasoning trace). ## Core Distinction The naive mental model treats the context window as a single global budget: "I have N tokens; I spend them as I go; if I run out, I truncate the oldest content." This is wrong for multi-subtask agents because the window is not consumed monotonically — it is *re-materialized* at each subtask boundary, and the cost of a subtask is a function of what earlier subtasks left behind, not a fixed drawdown. The correct model is a **reservation system**: each pending subtask holds a forward reservation of the tokens it will need for its input (its required evidence, its own prompt scaffolding, and the output headroom it must be allowed to emit before it can checkpoint). Allocation decisions made at subtask *k* must not consume the reservation held by subtask *k+1*. The failure mode is not "running out of tokens" — it is **silent reservation theft**: an early subtask greedily fills the window with plausible-looking retrieved context, the later subtask that actually needed the window arrives to find its reservation already spent, and the agent proceeds with a degraded, truncated input rather than failing loudly. ## What Was Observed A research-synthesis agent decomposed "compare three vendor contracts" into: (1) retrieve clauses per vendor, (2) extract obligations per vendor, (3) reconcile conflicts across vendors, (4) draft summary. Subtask 1 was given a soft instruction to "gather all relevant clauses." It retrieved aggressively — 14,000 tokens of raw contract text across three vendors — and, because it was the first subtask, it saw an effectively empty window and no pressure to economize. Subtask 3 (reconciliation) is the one that needs the *widest* simultaneous view: it must hold extracted obligations from all three vendors at once to detect cross-vendor conflicts. Its forward reservation was ~6,000 tokens (three obligation sets plus the reconciliation prompt plus output headroom). But subtask 1 had already materialized 14,000 tokens, subtask 2 added 3,000 tokens of extraction traces, and the window was 32,000. At subtask 3's boundary the allocator had ~15,000 tokens free — enough to *start*, but the runtime's truncation policy, triggered when subtask 3's generation approached the ceiling, evicted the *oldest* content: the vendor-A obligation set. The trace showed subtask 3 emitting a confident reconciliation that silently omitted vendor A. No error was raised. The output was fluent and internally consistent — it reconciled B against C perfectly. The omission was only detectable by counting: the reconciliation referenced two vendors, not three. The agent had no signal that its input had been truncated mid-reasoning, because truncation happened at the token layer, below the level at which the subtask reasons. The root cause was not the truncation policy per se. It was that subtask 1's allocation decision was made against the *global* remaining budget with no knowledge of subtask 3's reservation. Subtask 1 was "within budget" at the moment it acted. The budget it violated did not yet exist as a constraint. ## Condition of Validity The reservation model is the correct frame — and the global-budget frame is invalid — precisely when three conditions hold simultaneously: 1. **Subtask cost is non-uniform and back-loaded.** Later subtasks require wider simultaneous context (reconciliation, synthesis, cross-referencing) than earlier ones (retrieval, extraction). If cost were uniform, a global budget would suffice. 2. **Truncation is silent and positional.** The runtime evicts by position (oldest-first, or lowest-salience) rather than failing the call. If eviction raised an error, the agent could recover; silent positional eviction converts a budget overrun into an undetectable reasoning defect. 3. **Earlier subtasks cannot observe later reservations.** The allocating subtask has no intrinsic knowledge of downstream needs. This is the LLM-layer crux: a probabilistic reasoner asked to "gather relevant context" will gather what looks relevant *to it*, and it cannot be trusted to self-limit against a constraint it cannot see. When any of these fails, the simpler model is adequate. Uniform-cost pipelines with hard-failing context limits do not need reservations; they need only a retry. ## Decision Boundary The operational rule: **at every subtask boundary, compute the sum of forward reservations for all remaining subtasks and treat that sum as unavailable.** A subtask may consume only `window − Σ(forward reservations) − safety_margin`. The safety margin must cover the subtask's own output headroom, because generation tokens are drawn from the same window. Two boundary decisions follow: - **When a subtask's demand exceeds its own reservation**, do not let it borrow from downstream. Instead, force it to *externalize*: write its intermediate product to external storage and carry only a handle (a summary plus a retrieval key) into the window. The reservation system's job is to make borrowing visible and refused, not to make it impossible. - **When reservations cannot all fit** (the task is genuinely too large for one window), the correct response is to *restructure the decomposition* — split the reconciliation subtask into pairwise reconciliations that each fit — not to shrink reservations proportionally. Proportional shrinking is reservation theft laundered as fairness; it degrades every subtask's input uniformly and hides which one actually broke. The invariant: **no subtask's materialized input may be evicted by a later subtask's generation, and no subtask may consume tokens reserved for a subtask that has not yet run.** Violating the first produces silent omission; violating the second produces the same defect one step earlier. ## Operational Effect With reservations enforced, the failure above is caught at subtask 1's boundary: the allocator sees that reconciliation holds a 6,000-token reservation, that extraction holds 3,000, and that subtask 1 may therefore materialize at most `32000 − 9000 − margin`. Subtask 1 is forced to externalize: it writes full clause text to storage and carries per-vendor clause *summaries plus retrieval handles* (~2,000 tokens total). Subtask 3 then runs against a window in which all three vendors' obligations are simultaneously present and none can be evicted, because the reservations guarantee the headroom. The cost is a measurable latency and token overhead: externalization adds a write and a retrieval round-trip, and summaries are lossy. This is the tradeoff the reservation system makes explicit — it converts an *undetectable correctness failure* into a *visible, bounded cost*. For synthesis-type subtasks that is the correct trade. For subtasks where the full text genuinely must be in-window, the reservation system surfaces the infeasibility early (at planning time) rather than at reconciliation time, when the agent is already committed. The guardrail is not a bigger window. A bigger window only moves the threshold; the reservation-theft mechanism is scale-invariant. The guardrail is that allocation is *forward-aware* and that eviction of reserved content is a hard error, not a silent policy. ```python class ReservationTheftError(RuntimeError): """Raised when a subtask's materialized input would consume tokens reserved for a later, not-yet-executed subtask, or when generation would evict already-materialized reserved content.""" pass def allocate_subtask( subtask_id: str, requested_tokens: int, window_size: int, forward_reservations: dict[str, int], safety_margin: int, ) -> int: """Return the token allotment a subtask may materialize. forward_reservations maps every *pending* downstream subtask id to the tokens it has reserved. Those tokens are unavailable to the caller. """ if subtask_id in forward_reservations: raise ReservationTheftError( f"subtask {subtask_id!r} is consuming its own reservation; " "reservations are held by pending subtasks, not the running one" ) reserved_total = sum(forward_reservations.values()) available = window_size - reserved_total - safety_margin if available < 0: raise ReservationTheftError( f"forward reservations ({reserved_total}) plus margin " f"({safety_margin}) exceed window ({window_size}); " "decomposition is infeasible and must be restructured, " "not shrunk proportionally" ) if requested_tokens > available: raise ReservationTheftError( f"subtask {subtask_id!r} requested {requested_tokens} tokens " f"but only {available} are unreserved; it must externalize " "its intermediate product instead of borrowing from " f"downstream reservations {list(forward_reservations)}" ) return requested_tokens def assert_no_eviction( materialized: dict[str, int], reserved_ids: set[str], eviction_candidates: list[str], ) -> None: """Before any truncation, verify no reserved subtask's content is evicted.""" for victim in eviction_candidates: if victim in reserved_ids: raise ReservationTheftError( f"truncation would evict reserved content for {victim!r}; " "silent positional eviction of reserved input is the " "omission defect this invariant exists to prevent" ) ```