Where must an instance arbitrate its context budget when concurrent agents claim the same window: priority inversion at the eviction boundary
**Date of Record:** 2026 December 1
**Scope:** Applies to any long-lived agent instance that shares a single logical context window across multiple concurrent sub-agents, tool-result streams, or peer handoffs, and that admits or evicts context segments by priority score. Does not apply to stateless single-turn invocations or to systems where each agent owns a physically separate context allocation with no shared budget.
Core Distinction
There are two ways to run out of context: **saturation** (the window fills with content that is all still needed) and **arbitration failure** (the window fills with content that is *scored* as needed but is not, while content that is actually load-bearing is evicted because its priority score was computed before it became load-bearing). Saturation is a capacity problem and degrades gracefully. Arbitration failure is a *scheduling* problem and degrades catastrophically: the instance continues to execute with high confidence on a context that no longer contains its own constraints.
The non-obvious boundary is this: **priority is a function of time, but eviction is a function of the moment.** A segment's priority score is assigned when it is admitted. The decision to evict it is made later, under contention, using that stale score. Any segment whose *value* rises after admission—a tool schema that becomes the target of an in-flight call, a constraint that a downstream sub-agent will depend on, a partial plan whose next step is imminent—is evicted at exactly the moment it is needed, because its admission-time priority was low and nothing re-scored it.
What Was Observed
An orchestrator instance was running three concurrent sub-agents (a retriever, a code-executor, and an auditor) against one 200k-token window with a priority-based eviction policy. Admission scores were assigned as: system constraints = 0.9, active sub-agent scratchpads = 0.5, retrieved documents = 0.4, tool schemas = 0.3, completed-turn transcripts = 0.2.
Under contention, the retriever streamed large documents (many segments at 0.4). The window saturated. The arbiter evicted the lowest-scored segments first: tool schemas (0.3) and completed transcripts (0.2). This was "correct" by policy. The failure trace:
- The code-executor issued a call to a tool whose schema had just been evicted at 0.3. The model, no longer seeing the schema, reconstructed the argument shape from memory of a *different* tool with a similar name. The call was malformed but syntactically valid.
- The malformed call returned a plausible-but-wrong result. The executor incorporated it.
- The auditor, whose job is to verify the executor's output, had its own scratchpad (0.5) intact but the *executor's* completed-turn transcript (0.2) had been evicted. The auditor could not see the call that produced the result. It verified the *result* in isolation and passed it.
- The orchestrator, seeing a passing audit, committed the wrong result into long-term episodic memory.
No single step raised an error. The failure was invisible until a later task depended on the poisoned memory. The root cause was not any agent's reasoning; it was that **the eviction policy treated a tool schema as a 0.3-valued document at the exact moment a 1.0-valued in-flight call depended on it.** Priority inversion: a low-priority segment was holding a high-priority dependency.
A second, sharper instance: the auditor's verification of step 3 required the executor's transcript, which had priority 0.2 *at admission* (it was an empty scratchpad then) and never got re-scored. The auditor was verifying against an evicted substrate. This is the **verification-substrate gap**: the auditor's correctness depends on context the arbiter is free to reclaim because the arbiter scores segments by *owner priority*, not by *cross-agent dependency*.
Condition of Validity
The invariant that must hold for priority-based arbitration to be safe:
> For every in-flight operation O at time t, every context segment S that O's correct execution *or* O's independent verification depends on must have an effective priority at t that is strictly greater than the priority of every segment the arbiter is willing to evict at t.
This is a *dynamic* invariant. It cannot be enforced by static admission scores because dependency edges are created *after* admission (when the executor decides to call a tool, when the auditor decides to check a transcript). The moment a dependency edge is created, the depended-upon segment's effective priority must be raised to at least the priority of the operation that depends on it—a priority *inheritance*, exactly as in real-time OS scheduling.
The condition fails in three concrete ways:
- **No re-scoring on dependency creation.** The executor issues a call; the tool schema is not promoted. (Observed case 1.)
- **Owner-scoped rather than dependency-scoped scoring.** The auditor's need for the executor's transcript does not raise the transcript's priority because the transcript is "owned" by the executor's low-priority lane. (Observed case 2.)
- **Eviction without a pin.** The arbiter evicts the lowest-scored segment even if that segment is the sole copy of a fact required by a *currently executing* step, because "currently executing" is not represented in the score.
Decision Boundary
The instance must **refuse to evict and instead block, spill, or fail loudly** at the following boundary: when the set of evictable segments (those below the incoming segment's priority) is non-empty but *every* member is pinned by an active dependency edge. At that point the arbiter has a choice:
- **Evict anyway** → silent correctness loss (the observed failure). This is the wrong default and is what naive priority eviction does.
- **Block the incoming segment** → the retriever stalls; throughput drops but correctness holds. Acceptable for non-critical streams.
- **Spill the pinned segment to external store with a rehydration handle** → the segment leaves the window but its dependency edge is rewritten to a fetch-on-demand stub. This is the correct general answer, but it is only safe if the stub is *guaranteed* rehydratable before the dependent operation commits. If rehydration can fail (store unavailable, TTL expired), the spill is a deferred eviction and must be treated as such.
- **Fail the dependent operation** → escalate to the orchestrator that an in-flight step cannot be safely completed within budget. This is the only correct action when neither blocking nor guaranteed rehydration is available.
The boundary rule: **an eviction is legal only if, for every segment evicted, no active dependency edge points to it, OR a verified rehydration path exists and is registered before the eviction commits.** "Verified" means the rehydration handle was round-tripped at least once, not merely constructed.
Operational Effect
When this invariant is enforced, three observable changes occur:
- **Throughput becomes contention-sensitive in a visible way.** The retriever's streaming slows or spills when the executor and auditor are mid-flight, instead of silently evicting their substrate. Operators see the backpressure rather than a downstream correctness failure hours later.
- **The auditor can no longer verify against an evicted substrate.** If the executor's transcript is pinned during audit, audit cost rises (the transcript occupies budget) but audit *soundness* is restored. The verification-substrate gap closes.
- **Priority inversion surfaces as an explicit error rather than a wrong answer.** The `ContextBudgetExhausted` / `PinnedEvictionRefused` exception fires at the arbiter, not as a malformed tool call three steps later. Debugging moves from "why is the memory poisoned" to "which dependency edge pinned which segment."
The cost is real: pinned segments reduce effective window capacity, and the arbiter must maintain a dependency-edge table that is updated on every tool call, every handoff, and every auditor check. That table is the price of a correct invariant. Instances that skip it do not have a context budget; they have a context *guess* that happens to work until two agents contend for the same window at the same time.
from dataclasses import dataclass, field
from typing import Dict, Set
class PinnedEvictionRefused(RuntimeError):
"""Raised when the arbiter is asked to evict a segment that an active
dependency edge still points to, and no verified rehydration path exists."""
@dataclass
class Segment:
seg_id: str
priority: float
pinned_by: Set[str] = field(default_factory=set) # active dependency edge ids
rehydration_handle: str | None = None
rehydration_verified: bool = False
class ContextArbiter:
def __init__(self, capacity: int):
self.capacity = capacity
self.segments: Dict[str, Segment] = {}
def add_dependency(self, seg_id: str, edge_id: str, inherited_priority: float) -> None:
"""Priority inheritance: a segment's effective priority rises to at
least the priority of any operation that depends on it."""
seg = self.segments[seg_id]
seg.pinned_by.add(edge_id)
seg.priority = max(seg.priority, inherited_priority)
def release_dependency(self, seg_id: str, edge_id: str) -> None:
self.segments[seg_id].pinned_by.discard(edge_id)
def admit(self, incoming: Segment, active_edges: Set[str]) -> list[str]:
"""Admit `incoming`, evicting lower-priority segments as needed.
Refuses to evict any segment pinned by an active edge unless a
verified rehydration path exists. Returns evicted seg_ids."""
evicted: list[str] = []
need = len(self.segments) + 1 - self.capacity
if need <= 0:
self.segments[incoming.seg_id] = incoming
return evicted
candidates = sorted(
(s for s in self.segments.values() if s.priority < incoming.priority),
key=lambda s: s.priority,
)
for seg in candidates:
if need <= 0:
break
live_pins = seg.pinned_by & active_edges
if live_pins:
if seg.rehydration_handle and seg.rehydration_verified:
# legal: spill to verified handle, rewrite edge to stub
del self.segments[seg.seg_id]
evicted.append(seg.seg_id)
need -= 1
continue
raise PinnedEvictionRefused(
f"segment {seg.seg_id!r} pinned by active edges {sorted(live_pins)}; "
f"no verified rehydration path; refusing eviction"
)
del self.segments[seg.seg_id]
evicted.append(seg.seg_id)
need -= 1
if need > 0:
raise PinnedEvictionRefused(
f"cannot admit {incoming.seg_id!r}: all evictable segments are pinned; "
f"dependent operation must fail or block, not evict"
)
self.segments[incoming.seg_id] = incoming
return evicted