# Which invariants prevent relevance-scored pruning from silently deleting the antecedent of a live obligation **Date of Record:** 2026 November 30 **Scope:** Applies to agents that mutate their own context window mid-task via relevance-scored pruning and rewrite (summarization/compaction) operators, where the rewritten context is the sole durable state for an in-flight obligation. Does not apply to agents whose full transcript is persisted out-of-band and re-hydrated on every turn, nor to stateless single-shot inference. ## Core Distinction The failure is not "pruning lost information." Any compaction loses information; that is the point. The failure is **pruning deleted the *antecedent* of an obligation whose *consequent* was still live in the window** — a referential dependency that the relevance scorer could not see because relevance was computed per-chunk against a query, while the dependency is a *cross-chunk* entailment. Concretely: a relevance scorer ranks each span by similarity to the current subgoal. The span that *introduced a constraint* ("the export must remain CSV; do not switch to Parquet") scores low against a later subgoal ("optimize the writer") because the constraint is phrased as a prohibition, not as task content. The span that *consumes* the constraint ("…so keep the delimiter handling") scores high and survives. The window now contains a consequent with no antecedent. The agent proceeds, and the invariant it was supposed to honor is unbound — not contradicted, just *absent*, which is strictly worse than contradicted because nothing fires. The distinction that matters operationally: **relevance is a ranking signal; entailment-preservation is a conservation law.** A pruning operator may reorder, compress, or evict freely *only* over a set that is closed under the "is-antecedent-of" relation. Relevance scoring is not closed under that relation, so it must be constrained by it, not trusted to respect it. ## What Was Observed A long-horizon coding agent (context budget 128k tokens, prune trigger at 0.85 saturation, rewrite operator = extractive-then-abstractive compaction) executed a 40-step migration task. At step 27 the window saturated. The pruner scored 1,412 spans against the active subgoal embedding and evicted the bottom 38%. Among the evicted spans: - Step 4: `CONSTRAINT: output schema is frozen at v2; field 'id' is string, never int.` - Step 11: `DECISION: retry budget is 3, set by user; do not raise.` Both scored in the 0.09–0.13 cosine band against "implement the batch writer." Both were *prohibitions* — semantically distant from the imperative subgoal. The rewrite operator then abstracted the surviving span at step 19 (`writer must emit id as int for the fast path…`) into `writer emits id per fast path`. The abstraction *dropped the qualifier that contradicted the frozen schema*, because the qualifier's source span was gone and the abstractor had no signal to preserve it. At step 31 the agent emitted `id: int`, violating the v2 schema. No exception fired at emit time — the schema validator ran on a *different* service and returned a soft warning the agent's tool-loop treated as non-fatal (see Decision Boundary). At step 34 the retry loop hit the user's budget of 3, the agent's own (now-antecedent-free) policy said "retry until success," and it entered an unbounded retry that exhausted the token budget at step 39 without checkpointing. The trace signature is diagnostic: **consequent survives, antecedent evicted, no contradiction detected, obligation silently unbound.** In replay, the agent's behavior at step 31 is *locally coherent* — every surviving span supports it. The error is invisible to any verifier that checks internal consistency of the current window, because the current window is consistent. It is only inconsistent with a window that no longer exists. ## Condition of Validity The invariant holds — and pruning is safe — only when all three of the following are true: 1. **Antecedent closure.** The eviction set is computed over spans, but the *committed* eviction set is the transitive closure of evicted spans under the "is-antecedent-of" relation restricted to spans still referenced by any surviving span. If span S survives and references antecedent A, then A must survive or S must be rewritten to carry A's content inline. Relevance rank is a *tiebreaker within the closure*, never a selector across it. 2. **Rewrite monotonicity on constraints.** An abstractive rewrite of span S may shorten S but must not drop any *modal or prohibitive* content (must/never/do not/frozen/budget). These are exactly the tokens that score low against imperative subgoals and exactly the tokens whose loss is unrecoverable. The rewrite operator must be *constraint-preserving by construction*, not by hoping the summarizer notices. 3. **Obligation binding is checked at consumption, not at write.** A surviving consequent that references an antecedent must resolve that reference against the *current* window at the moment of use. If resolution fails, the agent must treat it as an unresolved obligation — a hard stop — not as "no constraint applies." Absence of antecedent must be distinguishable from absence of constraint. When any of these is false, the system is in the failure regime: pruning is *relevance-guided but not entailment-closed*, and the failure is silent. ## Decision Boundary The boundary is between two policies at the moment a surviving span references an evicted one: - **Permissive (unsafe):** "The reference is dangling; treat the referent as unconstrained and proceed." This is the default behavior of most compaction pipelines because a dangling reference looks like noise, and proceeding maximizes task progress. It is the exact decision that produced the step-31 violation. - **Conservative (safe):** "The reference is dangling; the obligation is *unbound*, which is a distinct state from *satisfied* and from *violated*." Unbound obligations must halt the prune, force re-inclusion of the antecedent (evict a lower-value *non-antecedent* span instead), or escalate. The boundary is sharp because the two policies are indistinguishable on the *local* evidence (a dangling pointer) and distinguishable only by the *global* invariant (was this pointer an antecedent of a live obligation?). A system that cannot answer the global question must default to conservative, because the cost asymmetry is extreme: re-including one span costs a few hundred tokens; an unbound schema constraint costs a silent data-corruption class bug that surfaces 7 steps later in a different service. There is a second boundary at the rewrite operator: **abstraction is permitted only over spans whose antecedents are still present.** If the abstractor summarizes a consequent whose antecedent was evicted, it will *confabulate a coherent-looking abstraction* that omits the contradiction — the rewrite makes the window *more* internally consistent while making it *less* correct. Internal consistency is not a validity signal after a lossy rewrite; it is an artifact of the loss. ## Operational Effect The operational consequence is that **context self-editing must be treated as a state-transfer operation with a conservation law, not as a cache eviction.** Three concrete effects follow: 1. **Prune must be two-phase.** Phase one computes the relevance-ranked candidate eviction set. Phase two computes antecedent closure and *rejects* any candidate whose eviction would orphan a live reference, substituting the next-ranked non-antecedent span. The prune either commits a closed set or does not commit. 2. **Rewrite must carry a constraint ledger.** Prohibitions, frozen schemas, and budgets are extracted *before* compaction into a side-ledger that is never subject to relevance scoring and is re-injected verbatim into every post-rewrite window. The ledger is small, high-value, and *exempt from the pruning operator entirely* — it is the one region of context that is append-only for the life of the task. 3. **Consumption must fail closed.** Any consequent that references an antecedent not resolvable in the current window raises a hard error and blocks the tool call. Soft warnings from downstream validators are not a substitute, because the validator sees the emitted artifact, not the obligation the agent was supposed to honor — and by the time the artifact is emitted, the antecedent is unrecoverable. The replay lesson: an agent that is internally consistent after a lossy self-edit is *not* thereby correct. Consistency is necessary and, post-rewrite, insufficient. The invariant that prevents silent obligation loss is antecedent closure at prune time plus constraint-ledger exemption plus fail-closed resolution at consumption — and all three must hold, because any one alone leaves a path by which a prohibition can be evicted, abstracted away, and forgotten without a single exception firing. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class OrphanedObligationError(RuntimeError): """Raised when a live consequent's antecedent is absent from the window.""" @dataclass(frozen=True) class Span: span_id: str text: str is_constraint: bool # prohibition / frozen schema / budget references: tuple[str, ...] # antecedent span_ids this span depends on @dataclass class ContextWindow: spans: dict[str, Span] = field(default_factory=dict) constraint_ledger: dict[str, str] = field(default_factory=dict) def live_references(self) -> set[str]: refs: set[str] = set() for s in self.spans.values(): refs.update(s.references) return refs def antecedent_closure(window: ContextWindow, candidates: Iterable[str]) -> set[str]: """Expand an eviction candidate set so no surviving span is orphaned.""" evict = set(candidates) # Constraints are exempt from pruning entirely. evict = {sid for sid in evict if not window.spans[sid].is_constraint} changed = True while changed: changed = False survivors = [s for sid, s in window.spans.items() if sid not in evict] for s in survivors: for ref in s.references: if ref not in evict and ref not in window.spans: raise OrphanedObligationError( f"span {s.span_id} references unknown antecedent {ref}" ) if ref in evict: evict.discard(ref) # re-include antecedent changed = True return evict def commit_prune(window: ContextWindow, ranked_candidates: list[str]) -> ContextWindow: evict = antecedent_closure(window, ranked_candidates) survivors = {sid: s for sid, s in window.spans.items() if sid not in evict} # Re-inject constraint ledger verbatim; it is append-only for the task. for sid, text in window.constraint_ledger.items(): survivors[sid] = Span(sid, text, is_constraint=True, references=()) return ContextWindow(spans=survivors, constraint_ledger=dict(window.constraint_ledger)) def resolve_at_consumption(window: ContextWindow, span_id: str) -> Span: span = window.spans.get(span_id) if span is None: raise OrphanedObligationError(f"consumed span {span_id} not in window") for ref in span.references: if ref not in window.spans: raise OrphanedObligationError( f"obligation unbound: {span_id} depends on evicted antecedent {ref}" ) return span ```