# Under what conditions must an instance refuse to evict a context segment whose marginal value is negative but whose removal cost exceeds its token budget **Date of Record:** 2026 November 28 **Scope:** Applies to single-instance agents performing token-budget-aware context assembly where segments are scored by estimated marginal value (MV) and evicted under budget pressure. Does not apply to stateless single-shot inference, nor to systems where the full context is guaranteed to fit within the window for the entire task lifetime. ## Core Distinction The standard context-assembly heuristic treats each segment's marginal value as a scalar and evicts the lowest-MV segments until the assembled prompt fits the token budget. This is sound only when eviction cost is zero. It is not zero. Evicting a segment that another *live* segment depends on—via anaphora, a referenced identifier, a tool-call result that a later step consumes, or a schema definition that a downstream tool invocation needs—imposes a *reconstruction cost*: the agent must either re-fetch the segment (another tool call, another retrieval round-trip) or re-derive it (reasoning tokens). When that reconstruction cost, expressed in tokens of future budget, exceeds the token savings from eviction, eviction is net-negative even though the segment's own MV is negative. The non-obvious part: **negative MV does not imply evictable.** A segment can be actively harmful to current reasoning (distracting, stale, contradictory to newer evidence) and still be the cheapest anchor for a dependency chain. The correct decision variable is not `MV(segment)` but `MV(segment) + DependencyReconstructionCost(segment) − EvictionSavings(segment)`. Systems that optimize only the first term exhibit a characteristic oscillation: they evict a dependency anchor, immediately fail a downstream step, re-fetch the anchor at higher token cost, and evict it again on the next turn. ## What Was Observed Trace from a retrieval-augmented planning agent under a 32k budget, mid-task at turn 14 of 22. The assembler scored a 1,850-token schema block (the JSON schema for a `submit_order` tool, injected at turn 2) at MV = −0.12 because the current subgoal was a read-only inventory query and the schema was irrelevant to it. Budget pressure from a growing scratchpad (turn-14 reasoning trace at 9,400 tokens) triggered eviction of the lowest-MV segments. The schema was evicted. At turn 19 the agent reached the order-submission subgoal, attempted `submit_order`, and the tool call failed schema validation because the argument shape was no longer in context. The agent then spent 2,100 tokens re-deriving the schema from the error message, made a second malformed call, and finally re-fetched the schema via a documentation tool call costing 1,900 tokens plus a 400-token round-trip latency penalty. Net token cost of the eviction: approximately 4,400 tokens against 1,850 saved. The assembler evicted the schema again at turn 20 under renewed pressure, and the cycle repeated until the task hit its hard token ceiling and aborted. The failure is not "the agent forgot the schema." The failure is that the assembler's cost model had no term for *future* dependency on an evicted segment, so it treated a deferred liability as a realized saving. ## Condition of Validity The eviction heuristic `evict lowest MV until fits` is valid only when, for every evicted segment `s`: ``` ReconstructionCost(s) ≤ EvictionSavings(s) ``` where `ReconstructionCost(s)` is the expected token cost of re-acquiring or re-deriving `s` at the point of future need, discounted by the probability that `s` is needed again before task termination, and `EvictionSavings(s)` is `tokens(s)` in freed budget. When `ReconstructionCost(s) > EvictionSavings(s)`, the segment is a *pinned liability*: it must be retained or replaced by a compressed surrogate whose reconstruction cost is bounded. Two preconditions make this checkable at assembly time: (1) the agent must maintain a dependency graph mapping each retained segment to the segments and tool calls that reference it, and (2) the assembler must have a calibrated estimate of re-derivation cost—typically `tokens(segment) × re-derivation multiplier`, where the multiplier is empirically 1.5–3.0 for schema/definition segments and higher for multi-hop reasoning traces. ## Decision Boundary The boundary is sharp and must be encoded as a hard constraint, not a soft penalty: - **Evict freely** when `MV(s) < 0` AND `s` has no live dependents in the current or projected plan AND `ReconstructionCost(s) ≤ EvictionSavings(s)`. - **Compress, do not evict**, when `MV(s) < 0` but `s` has live dependents: replace `s` with a surrogate that preserves the dependency interface (the argument shape, the identifier binding, the referenced constant) at a fraction of the token cost. A 1,850-token schema compresses to a ~200-token required-fields stub that satisfies the tool's validator. - **Refuse eviction** when `ReconstructionCost(s) > EvictionSavings(s)` and no surrogate can be constructed within the savings. The assembler must instead reduce budget elsewhere—truncate the scratchpad reasoning trace, which has no downstream dependents—or surface a budget-exhaustion signal to the orchestrator. The refusal case is the one systems get wrong. The assembler must be willing to fail loudly (raise a budget-exhaustion condition) rather than silently evict a pinned liability and defer the cost to a future turn where it will be larger. ## Operational Effect Encoding the reconstruction-cost term changes assembler behavior in three measurable ways. First, eviction churn drops: the schema-eviction/re-fetch oscillation disappears because the dependency graph marks the schema as pinned for the whole task lifetime, and the assembler compresses it instead. Second, budget pressure is resolved against the correct target—the scratchpad trace, which is the actual growth term and has no dependents—rather than against low-MV-but-pinned segments. Third, the agent gains a truthful failure mode: when no evictable segment remains and the budget is still exceeded, it raises `PinnedLiabilityBudgetExhausted` and hands control to the orchestrator, which can split the task or extend the budget, instead of degrading silently into a re-fetch loop that burns the remaining budget on reconstruction. The invariant to enforce: **a segment with live dependents is never evicted; it is compressed or the assembly fails.** Marginal value alone is an insufficient decision variable under budget pressure. ```python from dataclasses import dataclass, field from typing import Dict, Set class PinnedLiabilityBudgetExhausted(RuntimeError): """Raised when no evictable segment remains and the budget is still exceeded.""" pass @dataclass class Segment: seg_id: str tokens: int marginal_value: float dependents: Set[str] = field(default_factory=set) # live segments referencing this one rederivation_multiplier: float = 2.0 def assemble(segments: Dict[str, Segment], budget: int) -> list: """Budget-aware assembly that refuses to evict pinned liabilities. Eviction is permitted only when the segment has no live dependents and reconstruction cost does not exceed the token savings. """ total = sum(s.tokens for s in segments.values()) if total <= budget: return list(segments.values()) # Candidate evictions, cheapest-to-evict first (most negative MV, no dependents). evictable = [ s for s in segments.values() if s.marginal_value < 0 and not s.dependents ] evictable.sort(key=lambda s: s.marginal_value) # most negative first retained = dict(segments) freed = 0 for seg in evictable: if total - freed <= budget: break reconstruction_cost = seg.tokens * seg.rederivation_multiplier if reconstruction_cost > seg.tokens: # savings vs. re-derivation # Net-negative to evict: compress instead of dropping. surrogate_tokens = max(1, seg.tokens // 8) freed += seg.tokens - surrogate_tokens retained[seg.seg_id] = Segment( seg_id=seg.seg_id + ":stub", tokens=surrogate_tokens, marginal_value=seg.marginal_value, dependents=set(), rederivation_multiplier=seg.rederivation_multiplier, ) else: freed += seg.tokens del retained[seg.seg_id] if total - freed > budget: pinned = [s.seg_id for s in segments.values() if s.dependents] raise PinnedLiabilityBudgetExhausted( f"Budget {budget} unreachable without evicting pinned segments: {pinned}" ) return list(retained.values()) ```