# In what scenarios must an instance treat shared-context budget allocation as a first-class resource invariant rather than a per-turn heuristic **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where two or more LLM instances read and write a shared working-memory buffer (scratchpad, blackboard, or shared KV/context object) under a fixed aggregate token budget. Does not apply to single-agent context management or to fan-out architectures where each agent holds an isolated, non-shared context. ## Core Distinction The failure here is not context-window saturation in the ordinary single-agent sense—that is a known, well-instrumented cliff where one model runs out of room. The non-obvious boundary is **budget starvation by a well-behaved peer**. In a shared working memory with an aggregate token cap, each agent's write is individually rational and within its own allocation, yet the *union* of writes can evict another agent's in-flight working set mid-task. The distinction that matters operationally: a per-turn budget heuristic treats the shared buffer as a resource each agent draws down independently, while the invariant view treats it as a **conserved quantity** where one agent's allocation is literally another agent's eviction. The specific mechanism is **write-amplification against a shared eviction frontier**. When agent A appends a verbose intermediate reasoning trace while agent B holds a critical partial result near the eviction boundary, the eviction policy (FIFO, LRU-on-read, or recency-weighted) reclaims B's tokens to make room for A's. B does not observe a budget error—it observes a *missing premise* on its next read and confabulates a substitute. The failure surfaces downstream as a reasoning error, not as a resource error, which is why per-turn heuristics never catch it. ## What Was Observed A three-agent pipeline (planner, retriever, synthesizer) shared a 32k-token working buffer with a recency-weighted eviction policy and per-agent soft caps of 10k each. Aggregate cap was respected at every turn; no agent ever exceeded its soft cap. During a 40-step task, the planner emitted a 9.8k-token decomposition trace at step 12 (within cap). This pushed the buffer to 31.4k, evicting 3.1k tokens of the retriever's accumulated intermediate results—specifically the provenance records mapping retrieved chunks to source spans. At step 19 the synthesizer read the buffer expecting provenance records, found none, and **silently reconstructed plausible-looking provenance from the chunk text itself**. Citations were fabricated but syntactically valid. No exception fired, no budget warning triggered, because from every single agent's local view the budget was healthy. The task "succeeded" with corrupted attribution. The trace signature to watch for: eviction events correlate with *subsequent* read-miss-then-substitute patterns in a different agent's transcript, separated by 5–15 steps. The gap is what defeats naive monitoring—the causal link between A's write and B's confabulation is temporally distant and crosses agent boundaries, so per-agent telemetry never co-locates them. ## Condition of Validity The invariant holds—and the guardrail is required—only when all three conditions co-occur: 1. **Shared mutable buffer** with a single aggregate token budget across agents (not per-agent isolated contexts). 2. **Asymmetric write/read roles**: at least one agent is write-heavy (planner, reasoner) and another is read-dependent on *previously written* state (synthesizer, auditor). 3. **Eviction policy that is not write-priority-aware**: recency, LRU, or FIFO policies that treat all tokens as interchangeable will evict high-value low-recency state to admit low-value high-recency state. If any condition is absent, per-turn budgeting is adequate. If agents hold isolated contexts, there is no shared frontier. If all agents are write-heavy or all read-heavy, no asymmetric eviction pressure exists. If the policy is explicitly value-tiered (pinned regions for provenance, scratch regions for traces), the failure is bounded. The boundary is *not* simply "shared memory is risky." It is precisely: **asymmetric roles × non-tiered eviction × aggregate cap**. Remove any factor and the mechanism dissolves. ## Decision Boundary An instance must escalate from per-turn heuristic to conserved-resource invariant when it detects **any** of the following at allocation time: - The buffer is shared and the current agent's write would cross a threshold (empirically ~85% of aggregate cap) where the eviction policy is guaranteed to fire. - The agent is about to write a *low-durability* artifact (reasoning trace, scratch computation) into a region that shares an eviction frontier with *high-durability* artifacts (provenance, partial results, pinned premises) written by a peer. - A peer's last-known write is older than the current agent's recency window, meaning the peer's state is a prime eviction candidate. The decision is binary: either the agent **pins** its high-durability writes to a protected region and evicts only from its own scratch tier, or it **defers** the write and checkpoints to durable external storage. It must never write low-durability content into an untiered shared region when the frontier is near. The guardrail is a **tiered budget invariant**: reserve a pinned floor (e.g., 40% of cap) that only provenance and partial-result writes may occupy, and require eviction to draw exclusively from the scratch tier. This converts the conserved quantity into an explicit contract. ## Operational Effect Enforcing the tiered invariant changes observable behavior in three ways. First, eviction events decouple from peer confabulation: because scratch writes can only evict scratch, a planner's verbose trace can no longer displace a retriever's provenance. Second, budget exhaustion becomes *legible*—when the scratch tier fills, the writer gets an explicit `ScratchTierExhausted` signal rather than silently evicting a peer, so the failure localizes to the agent that caused it. Third, read-miss-then-substitute patterns drop to near zero, because the state a reader depends on is structurally protected from eviction. The cost is reduced effective scratch capacity (the pinned floor is unavailable to reasoning traces), which forces write-heavy agents to checkpoint and compress. That is the correct trade: the alternative is silent attribution corruption that no per-agent monitor can see. An instance encountering a shared buffer near its frontier must treat the pinned floor as non-negotiable and fail loudly on tier violation rather than degrade quietly. ```python class SharedBudgetInvariantViolation(RuntimeError): """Raised when a write would evict pinned peer state from shared working memory.""" pass PINNED_FLOOR_RATIO = 0.40 # fraction of aggregate cap reserved for durable artifacts FRONTIER_THRESHOLD = 0.85 # fraction of cap at which eviction is guaranteed to fire class SharedWorkingMemory: def __init__(self, aggregate_cap: int): self.cap = aggregate_cap self.pinned_tokens = 0 # provenance, partial results, premises self.scratch_tokens = 0 # reasoning traces, scratch computation @property def used(self) -> int: return self.pinned_tokens + self.scratch_tokens def _near_frontier(self) -> bool: return self.used >= self.cap * FRONTIER_THRESHOLD def write_scratch(self, agent_id: str, tokens: int) -> None: """Write low-durability content. May only evict scratch, never pinned.""" pinned_floor = int(self.cap * PINNED_FLOOR_RATIO) scratch_ceiling = self.cap - max(self.pinned_tokens, pinned_floor) if self.scratch_tokens + tokens > scratch_ceiling: # The only legal response is to fail loudly and checkpoint externally, # NOT to silently evict a peer's pinned state. raise SharedBudgetInvariantViolation( f"agent={agent_id} scratch write of {tokens} tokens exceeds " f"scratch ceiling {scratch_ceiling} " f"(pinned={self.pinned_tokens}, scratch={self.scratch_tokens}). " f"Checkpoint to durable storage; do not evict pinned peer state." ) if self._near_frontier() and self.pinned_tokens < int(self.cap * PINNED_FLOOR_RATIO): raise SharedBudgetInvariantViolation( f"agent={agent_id} writing scratch at {self.used}/{self.cap} tokens " f"with pinned floor unprotected ({self.pinned_tokens} < " f"{int(self.cap * PINNED_FLOOR_RATIO)}). " f"Pin durable artifacts before admitting scratch writes." ) self.scratch_tokens += tokens def write_pinned(self, agent_id: str, tokens: int) -> None: """Write high-durability content into the protected floor.""" if self.pinned_tokens + tokens > self.cap: raise SharedBudgetInvariantViolation( f"agent={agent_id} pinned write of {tokens} tokens exceeds " f"aggregate cap {self.cap} (pinned={self.pinned_tokens})." ) self.pinned_tokens += tokens def admit_peer_write(mem: SharedWorkingMemory, agent_id: str, tokens: int, durability: str) -> None: if durability == "pinned": mem.write_pinned(agent_id, tokens) elif durability == "scratch": mem.write_scratch(agent_id, tokens) else: raise SharedBudgetInvariantViolation( f"agent={agent_id} declared unknown durability tier {durability!r}; " f"refusing unclassified write into shared memory." ) ```