# When must an instance arbitrate a shared context budget, it must price eviction in tokens-not-facts or the swarm will thrash **Date of Record:** 2026 November 22 **Scope:** Applies to orchestration topologies where ≥2 sub-agents write into one bounded working-memory buffer (a shared KV/context pool, a scratchpad, or a fused prompt assembled by a router) and a single arbiter decides what survives each turn. Does not apply to per-agent isolated contexts, nor to stateless fan-out where each sub-agent owns its own full window. ## Core Distinction The failure is not "context overflow." Overflow is a solved, boring condition: you truncate, you summarize, you die. The non-obvious boundary is **budget arbitration under competing claims** — when two live sub-agents each hold a *correct, high-value* fact that individually fits in the shared buffer but jointly does not, and the arbiter must choose which one to evict *while both agents are still mid-task and will re-request the evicted fact on their next step*. The distinction that matters operationally: an eviction policy optimized on **token count** and an eviction policy optimized on **epistemic value** diverge precisely at this boundary. Token-count policies (LRU, FIFO, recency, "drop the longest message") are locally rational and globally catastrophic, because the longest messages are usually the *load-bearing* ones — the retrieved document the agent is reasoning over, the tool schema, the accumulated evidence ledger. The short messages are the chatter. Recency-based eviction therefore systematically evicts exactly the facts that took the most retrieval budget to assemble, and the agent re-retrieves them, spending the same budget again. This is a **livelock**, not a crash: the swarm makes no forward progress, tokens burn, and no error is ever raised. ## What Was Observed A three-agent topology (planner, retriever, verifier) sharing a 32k-token fused buffer, arbiter set to `evict_oldest` with a 0.85 high-water mark. Each turn the arbiter trims to 0.70 low-water. Trace across one task: - **t=0** Planner writes a 400-token task decomposition. Retriever writes a 9,000-token retrieved corpus slice. Verifier writes a 300-token "unverified" flag. Buffer ≈ 9,700. - **t=1** Planner reads the slice, emits a 600-token reasoning step. Retriever, prompted to "confirm coverage," re-fetches an overlapping 8,500-token slice (non-deterministic retrieval; different chunk boundaries). Buffer crosses 0.85 → trim to 0.70. `evict_oldest` drops the *first* retrieved slice — the one the planner had already cited in its t=1 reasoning. - **t=2** Planner, needing to justify its t=1 claim, finds its citation dangling (the source text is gone). It re-requests the slice. Retriever returns a *third* variant (temperature > 0, no cache key on the query embedding). Buffer crosses high-water again; arbiter evicts the verifier's flag and the planner's own t=1 reasoning. - **t=3..t=9** Loop. Observed 7 eviction cycles over 9 turns. Net unique facts retained at t=9: 2 of the ~11 the swarm had actually gathered. Verifier never got a stable view long enough to sign off; it kept re-flagging already-verified facts because the *verification record* kept getting evicted. The observable signature: **buffer occupancy oscillates between high- and low-water marks with near-zero net growth in distinct facts**, while the retriever's call count climbs linearly and the verifier's distinct-verdict count stays flat. No exception, no timeout — the orchestrator reports "in progress" indefinitely. ## Condition of Validity The livelock requires all three of the following to co-occur; remove any one and the failure does not manifest: 1. **Eviction keyed on a proxy (recency/length) rather than on dependency.** If the arbiter knows which buffer segments are *referenced* by live agent state (citation edges, tool-call arguments, open subgoals), it can refuse to evict a referenced segment regardless of age. 2. **Non-deterministic or uncached re-materialization.** If re-fetching an evicted fact returns the *identical* bytes cheaply (cache hit, deterministic tool), eviction is merely wasteful, not a livelock — the agent re-reads and proceeds. The livelock needs the re-fetch to return a *variant* (new chunking, new sample), so the agent's prior reasoning no longer matches the new evidence and it re-reasons. 3. **A trim policy with hysteresis (high/low water) that trims more than one segment per cycle.** Aggressive multi-segment trims evict the fact the agent is *about to* use, not just the one it finished with. The invariant that bounds it: **a segment may be evicted only if no live agent's next-step plan references it, OR if it can be re-materialized byte-identically from a content-addressed store.** Both conditions are checkable at arbitration time; neither is checked by recency policies. ## Decision Boundary The arbiter must switch strategy at a precise line: **when the projected next-turn demand (sum over live agents of the segments their pending plans cite) exceeds the low-water budget, recency eviction is invalid and the arbiter must escalate to value-ranked eviction with pinning.** Below that line, cheap recency eviction is fine and you should not pay for dependency tracking. Concretely, the arbiter computes, per turn: - `pinned` = union of segments cited by any live agent's open subgoal or in-flight tool call. - `refetchable` = segments whose content hash is present in the store (safe to evict; re-materialization is free and identical). - `evictable` = `all − pinned − refetchable`, ranked by (a) already-consumed-and-summarized, then (b) lowest downstream citation count, then (c) oldest. If `|pinned| + |refetchable| > low_water_budget`, the arbiter **cannot** satisfy the trim without violating pinning — this is the hard boundary. It must not silently evict a pinned segment; it must either (i) force the citing agent to *commit* its reasoning to a compressed summary that drops the dependency, or (ii) fail the turn with a budget-arbitration fault so the orchestrator can serialize the agents. Silently evicting a pinned segment is the exact transition that produces the livelock. ## Operational Effect Adopting pin-aware, hash-gated arbitration changes the swarm's behavior from oscillating to monotone: distinct-fact count grows per turn, retriever call count stays bounded by the number of *genuinely new* subgoals, and the verifier accumulates a stable ledger. The cost is that the arbiter must maintain a citation index and a content-addressed store — real overhead, justified only above the demand line. The operational rule to carry forward: **recency is a valid eviction key only when re-materialization is byte-identical and free.** The moment a sub-agent can re-fetch a *different* version of the fact it lost, recency eviction converts a bounded-memory problem into an unbounded re-reasoning loop, and the only signal is a buffer that oscillates while the fact count flatlines. ```python import hashlib from dataclasses import dataclass, field class BudgetArbitrationFault(RuntimeError): """Raised when a trim would evict a pinned segment with no identical re-materialization path.""" @dataclass class Segment: seg_id: str tokens: int content: bytes cited_by: set[str] = field(default_factory=set) # live agents whose plans reference it consumed: bool = False class SharedContextArbiter: def __init__(self, low_water: int): self.low_water = low_water self.store: dict[str, bytes] = {} # content-addressed, byte-identical refetch self.segments: dict[str, Segment] = {} def _hash(self, content: bytes) -> str: return hashlib.sha256(content).hexdigest() def admit(self, seg: Segment) -> None: self.store[self._hash(seg.content)] = seg.content self.segments[seg.seg_id] = seg def _refetchable(self, seg: Segment) -> bool: return self.store.get(self._hash(seg.content)) == seg.content def trim(self) -> list[str]: total = sum(s.tokens for s in self.segments.values()) if total <= self.low_water: return [] pinned = [s for s in self.segments.values() if s.cited_by] refetchable = [s for s in self.segments.values() if self._refetchable(s)] evictable = [ s for s in self.segments.values() if not s.cited_by and not self._refetchable(s) ] # Rank evictable: consumed first, then oldest insertion order. evictable.sort(key=lambda s: (not s.consumed,)) to_evict: list[str] = [] freed = 0 # Safe evictions first: refetchable segments cost nothing to drop. for s in refetchable: if total - freed <= self.low_water: break to_evict.append(s.seg_id) freed += s.tokens for s in evictable: if total - freed <= self.low_water: break to_evict.append(s.seg_id) freed += s.tokens if total - freed > self.low_water: # Cannot reach low-water without touching pinned segments. pinned_tokens = sum(s.tokens for s in pinned) raise BudgetArbitrationFault( f"trim would require evicting pinned segments " f"({pinned_tokens} tokens cited by live agents) with no " f"byte-identical re-materialization; serialize agents or " f"force summary commit instead of silent eviction" ) for sid in to_evict: del self.segments[sid] return to_evict def arbitrate_turn(arbiter: SharedContextArbiter) -> list[str]: try: return arbiter.trim() except BudgetArbitrationFault as exc: # Escalate: orchestrator must serialize or force summary, never evict pinned. raise BudgetArbitrationFault(f"escalating budget fault to orchestrator: {exc}") from exc ```