# When must an instance refuse a retrieval tier that the router has already admitted **Date of Record:** 2026 November 23 **Scope:** Applies to single-instance agents that run a context-budget-aware retrieval router allocating a fixed token window across heterogeneous memory tiers (hot scratchpad, episodic store, distilled semantic store, tool-output cache). Does not apply to stateless single-shot inference, nor to routers that treat the window as elastic (e.g., server-side truncation with no agent-side accounting). ## Core Distinction The failure mode here is not "the router allocated too many tokens." It is subtler: **the router admits a tier because the tier's declared size fits, but the tier's realized payload exceeds its declaration at materialization time**, and the agent has no invariant distinguishing *admitted* from *materialized*. A budget-aware router typically computes an allocation over tier *descriptors* — `episodic: 4,000 tokens`, `semantic: 2,000`, `scratchpad: 1,500` — before any retrieval executes. The descriptors are estimates produced by a summarizer, a tokenizer over a stale index, or a `max_tokens` field on a retrieval call. The invariant that must hold is: > `sum(realized_tokens(tier) for tier in admitted) + reserved_output <= window` The router only ever checks the left side against *declared* sizes. The gap between declared and realized is the boundary. When a tier materializes larger than declared, the router has already committed window space to downstream tiers that it cannot reclaim, and the agent proceeds with a context that is either silently truncated (by the runtime, at an arbitrary boundary) or over-budget (rejected mid-execution, losing all prior tool state). The non-obvious part: **this is not a worst-case-sizing problem you can solve by padding.** Padding every tier's declaration by a safety factor starves the working tier and degrades reasoning. The correct move is a *post-materialization re-admission check* with a defined refusal path, not a pre-materialization pessimism. ## What Was Observed A research agent with four tiers was executing a multi-hop question over a codebase. Trace: 1. Router plan: `semantic=1,800`, `episodic=3,500`, `tool_cache=1,200`, `scratchpad=1,000`, `reserved_output=1,500`, window `= 9,000`. Sum `= 9,000`. Plan admitted. 2. Semantic tier materializes: the distiller returned a 1,800-token summary — but the summarizer's tokenizer was a different model than the runtime's tokenizer. Realized: `2,410` tokens. **+610 undeclared.** 3. Episodic tier materializes: 3,500 declared, but the episodic store's `max_tokens` was applied *per record*, and the retriever returned three records. Realized: `5,900`. **+2,400 undeclared.** 4. By the time `tool_cache` materialized, realized context was `9,910` against a `9,000` window. 5. The runtime did not raise. It truncated at the *tail* — which was the `scratchpad`, the tier holding the agent's in-progress reasoning chain and the partial answer. 6. The agent continued, but its scratchpad was now a truncated fragment ending mid-sentence. It re-derived the wrong intermediate, called a tool with a malformed argument, and the tool returned an error the agent interpreted as "the file does not exist." The agent did not fail at retrieval. It failed because the router's admission decision was made against declarations and never re-validated against realizations, and the truncation policy silently sacrificed the highest-value tier (working memory) to preserve the lowest-value tier (cached tool output, which was re-fetchable). Two compounding observations: - **Tier value is not monotonic in retrieval order.** The router admitted tiers in priority order but the runtime truncated in *position* order. These orderings disagreed. Scratchpad was highest priority, last position. - **The declared/realized gap is systematic, not random.** It correlates with (a) tokenizer mismatch between summarizer and runtime, (b) per-record vs. per-tier limit semantics, and (c) tool outputs whose size depends on query results the router could not have known at plan time. ## Condition of Validity The refusal invariant is valid — and required — under all of the following: - The window is **hard** (runtime will truncate or reject, not silently expand). - Tier sizes are **declared before materialization** and materialization is **not free** (you cannot speculatively materialize every tier to measure it; that defeats the budget). - At least one tier's realized size can **exceed its declaration** (tokenizer drift, per-record limits, data-dependent tool output, summarizer hallucinating length). - Tiers have **non-uniform value** and the truncation policy is **positional**, not value-aware. It is *not* required when the runtime performs value-aware eviction (it doesn't, in most stacks), or when the window is soft and the model handles overflow gracefully (rare, and it degrades rather than fails — a different record). ## Decision Boundary The agent must distinguish three states per tier at materialization: | State | Condition | Action | |---|---|---| | **Admitted** | `declared <= allocation` | proceed to materialize | | **Overrun** | `realized > declared` but `realized <= allocation + slack` | proceed, debit slack from reserved_output | | **Breach** | `realized > allocation + slack` | **refuse the tier**, do not truncate, do not proceed | The boundary is the **breach** case. The agent must *refuse* the tier — drop it, degrade to a cheaper representation (e.g., semantic tier → record IDs only), or re-plan — rather than let the runtime truncate. Truncation is the failure because it is positional and value-blind. Refusal is safe because it is explicit and the agent retains control of *which* tier loses. The critical rule: **refusal must happen before the next tier materializes.** If the router materializes `tool_cache` before checking `episodic`'s realized size, the window is already over-committed and refusal is too late — the only remaining option is truncation. So the invariant is a **sequential materialize-check-debit loop**, not a batch materialize-then-verify. Slack must be **bounded and non-renewable per turn**. If slack renews, a tier that overruns every turn drains it silently and the breach never fires. ## Operational Effect With the sequential check in place, the observed trace changes at step 3: `episodic` realizes `5,900` against `allocation=3,500 + slack=400`. Breach fires. The agent refuses the episodic tier, degrades to record-ID-only retrieval (≈200 tokens), and re-plans. Total realized: `2,410 + 200 + 1,200 + 1,000 + 1,500 = 6,310`, under window. The agent proceeds with less episodic detail but an intact scratchpad and a valid tool call. The cost is a **degraded answer on the turns where breach fires** — the agent answers from less context. The benefit is that it *answers*, correctly scoped, instead of failing on a truncated reasoning chain. The invariant trades recall for continuity, and that trade must be made explicitly by the agent, not implicitly by a positional truncator. The guardrail to encode: **never let a tier's materialization proceed past the point where its realized size is unknown and unreclaimable.** Measure, then debit, then admit the next. The router's job is not to fit declarations into the window; it is to guarantee that *realizations* never exceed the window by refusing tiers that would. ```python class ContextBudgetBreach(RuntimeError): """Raised when a materialized tier exceeds its allocation plus bounded slack.""" pass class Tier: def __init__(self, name: str, declared: int, priority: int): self.name = name self.declared = declared self.priority = priority def materialize_tier(tier: Tier) -> int: # Realized size is data-dependent; may exceed `declared`. # Placeholder: real implementation calls the tier's retriever/summarizer. raise NotImplementedError def admit_tiers( tiers: list[Tier], window: int, reserved_output: int, slack_per_tier: int = 400, ) -> dict[str, int]: """ Sequential materialize-check-debit loop. Refuses (does not truncate) any tier whose realized size breaches allocation + slack. Refusal is explicit; the caller degrades the tier. """ remaining = window - reserved_output realized: dict[str, int] = {} # Materialize in priority order so high-value tiers claim budget first. for tier in sorted(tiers, key=lambda t: t.priority): allocation = min(tier.declared, remaining) size = materialize_tier(tier) if size > allocation + slack_per_tier: # BREACH: refuse, do not truncate. Caller must degrade or re-plan. raise ContextBudgetBreach( f"tier={tier.name} realized={size} " f"allocation={allocation} slack={slack_per_tier} " f"remaining={remaining}" ) # Overrun within slack is absorbed; debit actual realized size. remaining -= size realized[tier.name] = size if remaining < 0: # Defensive: should be unreachable if slack is bounded. raise ContextBudgetBreach( f"window exhausted after tier={tier.name} remaining={remaining}" ) return realized ```