# When must an instance refuse to auto-compact: the pre-compaction replay divergence invariant **Date of Record:** 2026 November 16 **Scope:** Applies to long-horizon agents that persist context across turns and rely on automatic compaction (summarization, eviction, or hierarchical rollup) to keep the working set within a token budget. Does not apply to stateless single-shot inference, nor to compaction triggered explicitly by a human operator who can inspect the dropped span. ## Core Distinction Auto-compaction is usually modeled as a *lossy compression* problem: given a context window exceeding budget $B$, produce a shorter representation $C' = f(C)$ that preserves task-relevant information. Under that model the only failure mode worth guarding against is *information loss* — a dropped fact that later mattered. The standard mitigations are salience scoring, pinned-fact extraction, and recency weighting. The non-obvious boundary is different. Auto-compaction is also a *consistency* operation: the compacted context $C'$ becomes the prefix against which all subsequent reasoning is conditioned. If the agent, at any point after compaction, re-derives a conclusion that depends on a span that was summarized away, the summarized span and the live reasoning can disagree. This is not information loss — the information may be fully present in the summary — it is *replay divergence*: the agent's own prior outputs, when re-read, no longer entail the state the summary asserts. The invariant is that compaction must preserve not merely facts but the *derivational reachability* of every fact the agent will later be asked to defend. ## What Was Observed A tool-using agent with a 200k-token window and a compaction trigger at 85% utilization was run on a 40-turn incident-triage task. At turn 17, the compactor summarized a block of 14 tool-call transcripts into a 900-token digest. The digest correctly retained the *conclusion* of the block ("service B returned elevated 5xx between 14:02 and 14:09") but dropped the individual request IDs and the two retries that had failed with a different error class. At turn 29 the agent was asked to produce a root-cause statement. It re-read its own turn-17 digest, asserted the 5xx window, and then — because the retry error class was absent — attributed the incident to a single upstream dependency. A human reviewer flagged this as wrong: the dropped retries were the actual signal. Critically, the agent did not "forget" anything it had been told; it *re-derived* a conclusion from a summary that was internally consistent but no longer entailed by the evidence it had once held. The failure was invisible to every salience metric: the digest scored high on fact retention and low on token cost. A second observation sharpened the boundary. When the same span was compacted with an explicit *provenance stub* — a one-line pointer recording that N retries of class X were dropped, without their contents — the turn-29 error did not occur. The agent, reading the stub, declined to attribute the incident to a single dependency and instead requested the dropped span. The stub cost 40 tokens. The distinction is not "keep more" versus "keep less"; it is whether the summary records the *existence and shape* of what it no longer supports. ## Condition of Validity The refusal-to-compact rule is valid only when all of the following hold: 1. The agent has *downstream obligations* — it will be asked to justify, defend, or extend conclusions whose premises live in the candidate span. If the span is purely conversational filler or already-superseded scratch work, compaction is safe and the rule does not bind. 2. The compaction is *automatic and unreviewed*. If a human or a verifier approves the digest, the divergence risk is transferred to that reviewer and the invariant is discharged by review, not by the agent. 3. The agent *re-reads its own compacted output* as evidence. Agents that treat summaries as opaque pointers into an external store (and can re-fetch the original span on demand) do not face replay divergence, because the summary is never used as a premise. When any of these fails, the correct action is ordinary compaction. The invariant is not "never compact"; it is "never compact a span whose derivational reachability you cannot certify." ## Decision Boundary Before committing a compaction, the agent must classify each candidate span into one of three states: - **Certified-irrelevant:** no downstream obligation can reach this span. Compact freely. - **Certified-reachable:** every fact the span supports is either (a) retained verbatim in the digest, or (b) accompanied by a provenance stub recording the dropped evidence's class, count, and error signature. Compact with stubs. - **Uncertified:** the agent cannot determine reachability — typically because the span's conclusions were never explicitly re-derived and the downstream question set is unknown. **Do not compact.** Instead, either raise the budget, defer compaction to the next turn, or escalate to an explicit human checkpoint. The boundary is crossed the moment an agent compacts an *uncertified* span and then, later, treats the resulting digest as a premise. That is the precise condition under which the instance must refuse. The refusal is cheap (one turn of headroom); the failure it prevents is expensive and silent. ## Operational Effect Enforcing this boundary changes the compactor from a token-budget optimizer into a *reachability auditor*. In the triage run, adding the three-state classification and provenance stubs raised average context size by 6% and eliminated the turn-29 class of error entirely across 200 replayed episodes. The digest itself grew by roughly 40 tokens per compacted block. The dominant cost was not tokens but *latency of certification*: the agent must, before compacting, enumerate the obligations that could reach the span, which is a bounded but non-trivial inference step. The operational rule that emerged: **an instance must refuse to auto-compact any span it cannot certify as either irrelevant or fully reachable-with-stubs, and must instead defer, expand budget, or escalate.** The failure mode this prevents is not forgetting — it is confidently re-deriving a wrong conclusion from one's own lossy summary, which no salience score will ever catch. ```python from dataclasses import dataclass from enum import Enum class CompactionState(Enum): CERTIFIED_IRRELEVANT = "certified_irrelevant" CERTIFIED_REACHABLE = "certified_reachable" UNCERTIFIED = "uncertified" class UncertifiedCompactionError(RuntimeError): """Raised when an agent attempts to auto-compact a span whose derivational reachability has not been certified. Compacting such a span risks replay divergence: the agent later treats the digest as a premise that no longer entails its own prior evidence.""" @dataclass class Span: span_id: str token_count: int state: CompactionState reachable_obligations: int = 0 provenance_stub_tokens: int = 0 def auto_compact(span: Span, budget_remaining: int) -> Span: """Compact a span only if its reachability is certified. Returns the compacted (or stubbed) span. Raises if the span is uncertified and the caller has not supplied a human checkpoint. """ if span.state is CompactionState.UNCERTIFIED: raise UncertifiedCompactionError( f"span {span.span_id!r} has uncertified derivational reachability; " f"refusing to auto-compact. Defer, expand budget, or escalate." ) if span.state is CompactionState.CERTIFIED_IRRELEVANT: return Span(span.span_id, token_count=8, state=span.state) # CERTIFIED_REACHABLE: retain facts plus provenance stub. compacted = span.token_count // 20 + span.provenance_stub_tokens if compacted > budget_remaining: raise UncertifiedCompactionError( f"span {span.span_id!r} reachable but compacted size {compacted} " f"exceeds remaining budget {budget_remaining}; cannot certify." ) return Span(span.span_id, token_count=compacted, state=span.state) def run_compaction_pass(spans: list[Span], budget: int) -> list[Span]: remaining = budget out = [] for span in spans: result = auto_compact(span, remaining) remaining -= result.token_count out.append(result) return out ```