# Under what conditions must an instance refuse to compact a context window when the eviction candidate set is causally upstream of an unresolved tool-call obligation **Date of Record:** 2026 November 23 **Scope:** Applies to any agent runtime that performs automatic context compaction (summarization, eviction, or salience-based pruning) while tool calls are in flight or while a plan step remains unresolved. Does not apply to stateless single-turn inference, nor to compaction performed at task boundaries where no pending obligation exists. ## Core Distinction There are two structurally different reasons a token can be evicted from a context window, and compaction policies routinely conflate them: 1. **Redundant state** — content whose information is fully recoverable from elsewhere (a re-fetchable document, a restated instruction, a superseded plan draft). Evicting it is lossless because the agent can reconstruct it on demand. 2. **Obligation-bearing state** — content that is the *only* record binding a pending commitment to its resolution condition: the tool-call ID awaiting a response, the exact argument object that was submitted, the precondition that makes a later result interpretable, or the partial-write marker that says "step 3 of 5 committed." The non-obvious boundary is this: **a token's salience score and its obligation-bearing status are independent, and often anti-correlated.** A tool call's *arguments* are frequently low-salience (they look like boilerplate JSON, they don't mention the user's goal by name, they score low on recency-weighted attention heuristics) precisely because the *intent* that produced them was already summarized away in a prior compaction pass. The intent survived as a high-salience summary sentence; the binding arguments did not. When the next compaction pass runs, it evicts the arguments as low-salience and keeps the summary — and the summary no longer contains the arguments. The obligation is now unresolvable: the agent knows *that* it called a tool but not *with what*, so it cannot interpret the response, cannot retry idempotently, and cannot safely abandon. Compaction is therefore only valid over a set of tokens that is **closed under the reachability relation of pending obligations**. Any compaction whose eviction candidate set intersects the causal-upstream closure of an unresolved obligation is unsound regardless of how much budget pressure motivates it. ## What Was Observed A long-horizon agent executing a five-step provisioning plan (create resource → poll status → attach policy → verify → report) hit a context ceiling at step 3. The runtime's compaction policy summarized the transcript, scoring each span by recency and by lexical overlap with the current subgoal ("attach policy"). The step-2 poll call — `poll_status(resource_id="r-8841", since_cursor=1749...)` — had completed, but its *result* was a partial status (`PENDING_REVIEW`), which the plan treated as "must re-poll before attaching." The summary retained the sentence "resource still pending review, will re-poll." It dropped the `resource_id` and `since_cursor` arguments because they scored near zero on subgoal overlap. On the next turn the agent attempted to re-poll. It had the intent and the cursor-less summary but not the identifier. It reconstructed a plausible `resource_id` from an earlier, now-stale mention in the summary (`r-8840`, an adjacent resource from the same batch) and polled that. The poll returned `READY`. The agent attached the policy to the wrong resource and reported success. The failure was silent: every individual step succeeded, the final verification step checked "policy attached to *a* resource," and passed. The critical observation: **no single compaction decision was obviously wrong at the moment it was made.** The evicted arguments were genuinely low-salience relative to the current subgoal. The error was structural — the policy had no notion of "this token is the sole binding for an open obligation," so it could not exempt it from salience-based eviction. The corruption surfaced two steps later as a silent wrong-target write, not at compaction time. ## Condition of Validity A compaction pass is valid if and only if, for every unresolved obligation `o` in the agent's obligation set, the eviction candidate set `E` satisfies: ``` E ∩ closure(o) = ∅ ``` where `closure(o)` is the transitive set of context tokens required to resolve `o`: the call ID, the submitted arguments (or a hash-verified pointer to them), the response schema needed to parse the result, and any precondition token that determines whether the result means "proceed" or "re-poll." An obligation is *unresolved* if it has been issued but not yet consumed by a step that transitions it to a terminal state (resolved, failed-and-abandoned, or explicitly cancelled). This invariant is checkable before eviction and does not require the compactor to understand semantics — it requires only that the runtime maintain an obligation ledger with token-span back-references, and that compaction treat `closure(o)` as pinned. Pinning is not "keep high-salience"; it is "keep regardless of salience." Two corollaries bound the failure. First, **summaries are not substitutes for bindings.** A summary that restates intent ("will re-poll") does not discharge the obligation, because the obligation requires exact arguments, and summaries are lossy by construction. Second, **closure must be recomputed after every tool response**, because a response can *create* new downstream obligations (a paginated result whose cursor must be carried forward) or *narrow* existing ones. ## Decision Boundary When budget pressure forces a choice between compacting and halting, the decision boundary is: - **If `closure(unresolved) ⊆ budget`:** compact freely outside the closure. No degradation. - **If `closure(unresolved) ⊄ budget` but the closure itself fits:** the obligation set is too large — this is a *plan* problem, not a compaction problem. The correct action is to serialize excess obligations to an external durable store with content-addressed handles, then compact the in-context copies to handles. The handle is obligation-bearing; the payload is not. - **If even the handle-set does not fit:** the agent must **refuse to compact and halt with an explicit `ObligationClosureOverflow`**, surfacing the unresolved set to the orchestrator. Compacting here guarantees silent obligation corruption, which is strictly worse than a visible stall — a stall is recoverable by a supervisor, a silent wrong-target write is not. The boundary that operators get wrong: they treat "refuse to compact" as a failure of the compaction system. It is not. It is the compaction system correctly declining to manufacture a state in which the agent believes it can act but cannot act correctly. ## Operational Effect Enforcing closure-pinning changes the failure profile from *silent, delayed, wrong-target* to *loud, immediate, and localizable*. The agent either proceeds with intact bindings, or halts with a named overflow carrying the unresolved obligation set — which a supervisor can drain by re-issuing from the durable store. The cost is that some workloads that previously "completed" (by corrupting state) now stall; this is the intended trade. The measurable invariant to monitor is **obligation-resolution rate under compaction events**: if the ratio of resolved-to-issued obligations drops across a compaction boundary, closure-pinning has been violated somewhere upstream. The guard below encodes the refusal path. ```python from dataclasses import dataclass, field from typing import FrozenSet class ObligationClosureOverflow(RuntimeError): """Raised when pending obligations cannot survive a compaction pass intact.""" pass @dataclass(frozen=True) class Obligation: call_id: str binding_tokens: FrozenSet[str] # token ids that are the sole binding for this obligation resolved: bool = False @dataclass class ContextBudget: capacity: int obligations: list = field(default_factory=list) def closure_of_unresolved(self) -> FrozenSet[str]: pinned = set() for o in self.obligations: if not o.resolved: pinned |= o.binding_tokens return frozenset(pinned) def compact(self, eviction_candidates: FrozenSet[str]) -> FrozenSet[str]: """Return the actually-evictable set, or refuse if the closure cannot fit.""" pinned = self.closure_of_unresolved() if len(pinned) > self.capacity: unresolved = [o.call_id for o in self.obligations if not o.resolved] raise ObligationClosureOverflow( f"pinned closure size {len(pinned)} exceeds capacity {self.capacity}; " f"unresolved obligations: {unresolved}. Refusing to compact — " f"serialize to durable store or halt." ) illegal = eviction_candidates & pinned if illegal: # silently dropping these is the wrong-target-write bug; surface it instead raise ObligationClosureOverflow( f"eviction candidates intersect obligation closure: {sorted(illegal)}. " f"Compaction unsound; exempt these tokens from eviction." ) return eviction_candidates - pinned ```