# What happens when an instance evicts its own working set while sibling sub-agents still hold live references into the parent context **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that spawn concurrent sub-agents sharing a single logical context budget (token pool) with per-agent eviction rights over the parent's message store. Does not apply to sub-agents with fully isolated, copy-on-write context windows, nor to single-agent linear execution. ## Core Distinction The failure is not context-window saturation. Saturation is a visible, monotone condition: the budget accountant reports `used >= limit` and the orchestrator either compacts or refuses the turn. The failure examined here is **eviction-by-reference-invalidation**: one sub-agent, under its own local budget pressure, evicts a span of the shared parent context that a *sibling* sub-agent has already committed to as a live referent (a tool-call argument, a pinned fact, a chain-of-thought anchor). The evicting agent sees a clean budget; the sibling sees a dangling semantic handle. No single agent's accountant ever reports an over-budget condition, because the budget is conserved globally while the *referents* are not. The invariant that fails is not "total tokens ≤ limit." It is the weaker, unstated one: **any span evicted from shared context must have zero live inbound references from any concurrent participant.** Eviction schedulers that reason only about recency and local pressure violate this without any counter incrementing. ## What Was Observed A parent agent spawns three sub-agents (A, B, C) over a shared 96k-token pool. A is a retrieval/reader agent holding a long tool-output transcript. B is a synthesis agent whose plan step 4 contains a literal reference: `"per the schema in A's fetch at turn 12, emit field X"`. C is an auditor replaying B's tool calls. Sequence: 1. A's local working set grows to 41k tokens. A's per-agent eviction policy (LRU over its own view, budget cap 32k) evicts the earliest 9k of its transcript — including the turn-12 schema fetch — and emits a compaction summary in its place. 2. The shared accountant decrements global usage by 9k and increments by the ~600-token summary. Global budget is now *healthier*. No alert fires. 3. B reaches plan step 4. Its reference to "A's fetch at turn 12" now resolves against the summary, which paraphrases the schema but drops the `required`/`nullable` distinction on field X. B does not detect substitution — the summary is fluent and topically correct. 4. B emits a tool call with field X marked non-nullable. The downstream validator rejects it. C, replaying, sees B's call reference a turn-12 payload that no longer exists in its own view either (C shares the pool), and its replay diverges from B's recorded trace. 5. The orchestrator observes a validator rejection in B and a replay mismatch in C and attributes both to B's reasoning, not to A's eviction. The root cause is invisible in every per-agent log. The tell: **global token usage fell at the exact moment a downstream failure appeared.** A well-instrumented run shows budget decreasing and error rate increasing on the same tick — the signature of reference-invalidating eviction. ## Condition of Validity This analysis holds only when all of the following are true: - Context is shared by reference (a common message store or pointer table), not copied per agent. With copy-on-write isolation, A's eviction cannot reach B's view and the failure degenerates into benign divergence. - At least one sub-agent holds a *deferred* reference — a plan step, a pinned handle, or a CoT anchor — that will be dereferenced after the evicting agent's turn. Immediate dereference (reference consumed before eviction) is safe. - The eviction policy is local (per-agent LRU, per-agent budget cap) while the budget accountant is global. If eviction requires a global quiescence check, the race closes. - Compaction substitutes a lossy summary rather than a tombstone. A tombstone (``) turns silent corruption into a loud resolution error, which is a *different* and preferable failure. Outside these conditions — isolated contexts, no deferred references, or tombstone-on-evict — the mechanism does not fire. ## Decision Boundary The correct guardrail is a **reference-count gate on eviction**, not a larger budget. Concretely: - Maintain a per-span inbound-reference count in the shared store. A sub-agent registers a reference when it writes a deferred handle (plan step, pinned fact, tool-call template) and deregisters on dereference or turn-end. - Eviction of any span with `refcount > 0` is refused; the evicting agent must instead (a) request the referencing agent release, (b) block until release or turn-end, or (c) escalate to the orchestrator. - On release-timeout, downgrade to **tombstone**, never to summary. A summary preserves fluency and destroys detectability; a tombstone preserves detectability and forces explicit re-fetch. The boundary decision is therefore: *when local pressure and global references conflict, the reference wins and the pressure is surfaced upward.* An agent that resolves the conflict locally — by summarizing — has chosen silent corruption over a visible stall. The stall is correct. The secondary boundary: reference counts must be incremented **at handle-write time, before the writer's turn yields**, not at dereference time. Late registration reopens the race for the entire window between write and yield. ## Operational Effect With the gate in place, the observed failure mode converts from silent semantic corruption into a bounded stall: A blocks on B's release, the orchestrator sees a `refcount` nonzero at eviction, and either re-fetches the span into a pinned region or forces B to consume the reference early. Cost: occasional latency spikes when a reader agent's working set collides with a synthesizer's deferred plan. Benefit: the replay auditor's trace stays consistent, because no turn-12 payload ever mutates under a live handle. Without the gate, the system exhibits a specific pathology: **error rate anti-correlates with budget headroom.** Runs with more free tokens fail *more*, because free tokens are the residue of aggressive local eviction. Teams that respond by adding budget make it worse — more headroom means more room for A to grow and evict before B dereferences. The fix is never more context; it is refusing eviction under live reference and forcing the conflict into the open. ```python class DanglingContextReference(RuntimeError): """Raised when eviction would invalidate a live inbound reference from a concurrent sub-agent.""" pass class SharedContextStore: def __init__(self): self._spans = {} # span_id -> payload self._refcount = {} # span_id -> int def register_reference(self, span_id: str, owner: str) -> None: # MUST be called at handle-write time, before the writer's turn yields. if span_id not in self._spans: raise DanglingContextReference( f"{owner} registered a reference to absent span {span_id}" ) self._refcount[span_id] = self._refcount.get(span_id, 0) + 1 def release_reference(self, span_id: str, owner: str) -> None: if self._refcount.get(span_id, 0) <= 0: raise DanglingContextReference( f"{owner} released span {span_id} with zero refcount" ) self._refcount[span_id] -= 1 def evict(self, span_id: str, requesting_agent: str) -> None: live = self._refcount.get(span_id, 0) if live > 0: # Do NOT summarize. Surface the conflict upward. raise DanglingContextReference( f"agent {requesting_agent} attempted eviction of span {span_id} " f"with {live} live inbound reference(s); eviction refused, " f"escalate to orchestrator or block on release" ) self._spans.pop(span_id, None) self._refcount.pop(span_id, None) def safe_evict(store: SharedContextStore, span_id: str, agent: str) -> str: try: store.evict(span_id, agent) return "evicted" except DanglingContextReference as e: # Convert silent corruption into a visible stall / escalation. return f"stalled: {e}" ```