# When must an instance refuse to compact: hierarchical summarization, loss budgets, and the irreversible-eviction boundary **Date of Record:** 2026 November 30 **Scope:** Applies to long-running agent instances that maintain task state via automatic hierarchical context compaction (leaf-summarize → merge → root-summary) under an explicit per-tier loss budget. Does not apply to single-turn inference, stateless RAG retrieval, or compaction schemes that retain a verbatim byte-log out-of-band. ## Core Distinction There are two distinct failure classes in automatic compaction, and conflating them is the root cause of most silent agent-state corruption. The first is **lossy-but-recoverable compression**: the summarizer drops detail, but the dropped detail is either (a) redundant with retained text, or (b) reconstructible from a still-live verbatim source (a tool-call transcript, a file the agent wrote, a fetched document still in the retrieval cache). This is the *intended* behavior of a loss budget. You spend fidelity to buy context-window headroom, and the budget bounds the spend. The second is **irreversible eviction**: the summarizer drops detail whose only surviving representation *was* the text being summarized. Once the leaf summary replaces the raw span, the raw span is gone; once the merge summary replaces two leaf summaries, the leaves are gone. If the evicted detail is later needed to satisfy an invariant the task depends on—an exact identifier, a numeric threshold, a negation, an ordering constraint—no amount of re-summarization recovers it. The information is not compressed; it is *destroyed*, and the loss budget was never designed to account for destruction, only for degradation. The boundary condition this record addresses: **an instance must refuse to compact a span when the span contains load-bearing state that has no out-of-band verbatim copy and whose loss cannot be detected post-hoc.** The non-obvious part is that the instance usually cannot tell, at compaction time, whether a given token is load-bearing—so the invariant has to be enforced structurally, before the summarizer runs, not validated after. ## What Was Observed A planner-executor agent was driving a multi-hour infrastructure migration. It accumulated ~140 tool-call turns. At turn 61 the harness triggered leaf compaction: the oldest 40 turns were summarized into a single "Phase 1: discovery" paragraph, and the raw turns were dropped from the active window (retained only in a cold log the agent had no tool to read). The evicted span contained, among a great deal of genuinely disposable chatter, three load-bearing facts: 1. A resource ID with a transposed digit relative to the "canonical" ID the agent later reconstructed from memory: `i-0a3f...` vs the actual `i-0a3e...`. 2. An explicit negation: "do **not** rotate the staging key until the replica lag is under 30s." 3. A unit qualifier: a timeout specified as `30` in *seconds*, where the surrounding prose made "30" ambiguous between seconds and a count of retries. The leaf summary preserved the *gist* ("completed discovery, identified resources, noted a key-rotation caveat, set a timeout") and dropped all three specifics. The loss budget was satisfied: the summary was well under the token ceiling and the semantic-similarity check against the source passed at 0.91. Every automated guard said the compaction was healthy. The failure surfaced 40 minutes later. The executor, working from the reconstructed summary, rotated the staging key while replica lag was 47s (violating the evicted negation), then applied a timeout of 30 *retries* instead of 30 seconds, turning a bounded wait into an unbounded one. The agent did not error. It proceeded confidently on a corrupted premise. The corrupted premise was *unfalsifiable from inside the window*, because the evidence that would have contradicted it had been evicted. This is the signature of the failure: **compaction-induced state corruption is not detected by the agent that suffers it, because the detector was in the evicted span.** Similarity-based budget checks measure fidelity to *retained* meaning and are structurally blind to *destroyed* meaning. ## Condition of Validity The invariant holds—and compaction is safe—only when **every load-bearing fact in a span is recoverable from a source that survives the compaction.** Formally, for a span `S` about to be replaced by summary `σ(S)`, compaction is admissible iff: ``` load_bearing(S) ⊆ recoverable_after(σ(S)) ``` where `recoverable_after` includes: text retained verbatim in `σ(S)`, facts mirrored into a structured store (a task ledger, a constraint register), and facts re-fetchable via a live tool (the file still exists, the API still answers). The invariant is *violated*—and the instance must refuse—when a span carries a fact that is (i) load-bearing for a downstream invariant, (ii) present only in the span, and (iii) not detectable as missing after eviction. Condition (iii) is what makes this a hard boundary rather than a quality tradeoff: a recoverable loss can be caught by a later verification step; an undetectable loss cannot. Three concrete markers make a span *non-compactable* under the default budget and require either verbatim retention or explicit extraction into the structured store before summarization: - **Exact-identity tokens**: IDs, hashes, keys, version strings, hostnames, monetary amounts. These have no semantic redundancy; paraphrase destroys them and similarity checks forgive the destruction. - **Negations and prohibitions**: "do not," "never," "unless," "except." Summarizers systematically drop these because they are low-frequency relative to the affirmative content they modify, and because a summary that omits a prohibition still reads as coherent. - **Unit- and scope-qualifiers**: numbers whose meaning depends on an adjacent unit, ordering constraints ("before," "after"), and quantifier scope ("all," "at least one"). These are the highest-risk class because the *number* survives summarization while its *qualifier* does not, producing a confidently wrong specific. ## Decision Boundary The instance must branch at compaction time on a single question per span: **does this span contain a token from a non-compactable class that is not already mirrored into the structured store?** - If **no** → compact normally; the loss budget governs. Degradation is acceptable and recoverable. - If **yes, and the token is already in the structured store** → compact normally; the store is the surviving verbatim copy, and the invariant `load_bearing ⊆ recoverable_after` holds by construction. - If **yes, and the token is not mirrored** → **refuse to compact this span.** Extract the non-compactable tokens into the structured store first (a deterministic pass, not a summarization), *then* compact. If extraction cannot run—no structured store, no budget for the pass, or the token class is unrecognized—the instance must escalate to verbatim retention (pin the span, compact around it) rather than proceed. The boundary is *not* "compact when the similarity score is high enough." Similarity is a post-hoc fidelity measure and is precisely the wrong instrument here: it scores the summary against the source, so a summary that faithfully preserves gist while destroying a negation scores high. The decision must be made on the *source span's token classes*, before the summarizer is invoked, because after invocation the evidence needed to make the decision correctly has been replaced by the summary that erased it. A second boundary governs the *merge* tier: merging two leaf summaries is admissible only if the structured store already contains every non-compactable token from both leaves. Hierarchical summarization compounds this failure—each merge is another opportunity to drop a qualifier that survived the leaf pass—so the invariant must be re-checked at every tier, not just at the leaf. ## Operational Effect Enforcing the refusal boundary changes the agent's behavior in four measurable ways: 1. **Compaction halts on unmirrored non-compactable spans.** Throughput drops slightly (the extraction pass costs tokens and turns), but the class of silent corruption that produces confidently-wrong downstream actions goes to zero for recognized token classes. 2. **The structured store becomes the load-bearing artifact, not the context window.** The window degrades freely; the ledger of IDs, negations, and qualified numbers is verbatim and survives every tier of compaction. The invariant is now checkable because the checkable copy lives outside the summarizer's reach. 3. **Failure becomes loud.** With the store in place, a downstream step that needs an evicted fact either finds it (recovered) or fails an explicit lookup (detected). The undetectable-loss class collapses into the detectable-loss class. This is the entire point: the guardrail does not preserve all information, it preserves *detectability of loss*. 4. **The loss budget is redefined.** It no longer bounds "how much meaning we may drop"; it bounds "how much *recoverable* meaning we may drop." Non-recoverable meaning is not budgeted—it is extracted or pinned, never spent. The residual risk is unrecognized token classes: a load-bearing fact that fits none of the three markers and was never mirrored will still be evicted silently. The invariant bounds recognized destruction; it does not eliminate the general problem. The honest posture is that the agent's compaction is *safe with respect to a declared set of non-compactable classes*, and that set is the thing to audit, not the similarity scores. ```python from dataclasses import dataclass, field from enum import Enum class CompactionRefused(RuntimeError): """Raised when a span carries unmirrored non-compactable state and must not be summarized.""" pass class TokenClass(Enum): EXACT_IDENTITY = "exact_identity" # IDs, hashes, keys, amounts NEGATION = "negation" # do not / never / unless / except QUALIFIER = "qualifier" # units, ordering, quantifier scope @dataclass class Span: text: str tokens: dict[TokenClass, list[str]] = field(default_factory=dict) @dataclass class StructuredStore: """Verbatim, out-of-band copy that survives every compaction tier.""" mirrored: set[str] = field(default_factory=set) def has(self, token: str) -> bool: return token in self.mirrored def mirror(self, tokens: list[str]) -> None: self.mirrored.update(tokens) def compact_span(span: Span, store: StructuredStore, *, allow_extraction: bool = True) -> str: """ Enforce the irreversible-eviction invariant before summarizing. Admissible iff every non-compactable token in the span is already mirrored into the structured store (recoverable_after holds). Otherwise: extract-then-compact, or refuse. Never summarize a span whose load-bearing tokens have no surviving copy. """ unmirrored: list[str] = [] for cls, toks in span.tokens.items(): for tok in toks: if not store.has(tok): unmirrored.append(f"{cls.value}:{tok}") if not unmirrored: return _summarize(span) # safe: all load-bearing state survives out-of-band if allow_extraction: # Deterministic mirror pass — NOT a summarization. Verbatim copy into the store. store.mirror([t.split(":", 1)[1] for t in unmirrored]) return _summarize(span) # No extraction budget and unmirrored load-bearing state: refuse rather than destroy. raise CompactionRefused( "refusing to compact span: unmirrored non-compactable state " f"{unmirrored!r} would be irreversibly evicted with no post-hoc detector. " "Extract to structured store or pin the span verbatim." ) def _summarize(span: Span) -> str: # Placeholder for the hierarchical summarizer call. return f"[summary of {len(span.text)} chars]" ```