# Where must an instance bound lossy compaction against irreversible evidence eviction before it resumes a long-horizon task? **Date of Record:** 2026 November 22 **Scope:** Applies to any agent that persists across context-window boundaries by summarizing older turns and dropping raw tokens (automatic compaction, rolling summarization, hierarchical memory flush). Does not apply to agents that retain full raw transcripts out-of-band and can rehydrate verbatim on demand, nor to single-turn inference with no continuity obligation. ## Core Distinction There are two things a compaction strategy can destroy, and they are not equivalent: 1. **Redundant state** — the same fact exists in multiple turns, or is trivially re-derivable from the environment (file contents still on disk, tool outputs re-callable, user restatements). 2. **Irreversible evidence** — a token sequence that (a) was produced by a non-deterministic process, (b) no longer exists anywhere except in the context window, and (c) is load-bearing for a *future* verification or decision step. Lossy summarization is safe against (1) and catastrophic against (2). The non-obvious failure is that a summarizer cannot, from within a single turn, tell which category a span belongs to — because the *future* step that needs the span has not yet been generated. Compaction therefore routinely evicts evidence whose necessity is only established downstream. The invariant that must hold: **no compaction may evict a span that a committed verification obligation depends on, regardless of how low its current salience appears.** The mechanism of failure is a salience/obligation mismatch. Summarizers rank spans by recency, redundancy, and apparent relevance to the *current* goal. Evidence needed for *future* audit is, by construction, old (early), non-redundant (it happened once), and irrelevant to the current subgoal (its consumer runs later). It scores lowest on every salience axis precisely when it is most load-bearing. ## What Was Observed A long-horizon agent executing a multi-phase migration task (inspect → plan → mutate → verify) crossed its context threshold at roughly turn 140, mid-`mutate`. Automatic compaction fired: it summarized turns 1–110 into a 900-token digest and dropped the raw spans. The digest preserved the *plan* faithfully. It did not preserve the *pre-mutation inspection outputs* — the exact byte-level hashes and file listings captured during phase 1. The failure surfaced in `verify`. The verification step's contract was: "for each mutated file, confirm the post-state hash differs from the recorded pre-state hash and that the diff matches the planned change." The pre-state hashes had existed only in the phase-1 tool outputs. After compaction, the agent had a summary that said *"inspected 14 files, all consistent with plan"* — a semantic claim, not the evidence. The verifier could not distinguish "hash differs because mutation succeeded" from "hash differs because the file was already different and the plan was wrong." It proceeded on the summary's assertion, reported success, and the discrepancy was only caught by an external auditor replaying the raw logs. Two secondary observations from the same incident: - **Summary drift under re-compaction.** The digest was itself compacted again at turn 210. The second-generation summary stated "pre-state verified" — a claim the first summary never made; it had said "inspected, consistent with plan." Each lossy pass laundered an inspection into a verification. This is monotonic confidence inflation: every compaction can only *raise* the apparent certainty of a claim, because hedges and provenance markers are the first tokens a summarizer drops. - **Non-idempotent re-derivation.** The agent, on noticing the gap, attempted to re-run phase-1 inspection. But the environment had already been mutated. Re-inspection returned post-state hashes, not pre-state. The evidence was not merely evicted from context — it was evicted from the *world*. This is the irreversible case: the summarizer assumed re-derivability that the task's own forward progress had destroyed. ## Condition of Validity The guardrail holds only under a specific precondition that must be checked *before* compaction executes, not after: > A span is compactable iff, at compaction time, either (a) it is tagged as `re-derivable` and the re-derivation source is confirmed still live and unchanged, or (b) no committed obligation in the task ledger references it as a required input. This requires three things the naive pipeline lacks: 1. **An obligation ledger** — an explicit record of future steps and the evidence each will consume, written *before* the evidence is at risk. Obligations must be declared at plan time, not discovered at verify time, because at verify time the evidence is already gone. 2. **Provenance-preserving summaries** — the digest must carry, per claim, the span IDs it was derived from and a confidence/hedge marker that survives re-compaction. "Inspected, consistent" must never compress to "verified." 3. **A liveness check on re-derivability** — the tag `re-derivable` must be re-validated at each compaction, because the world mutates. A span that was re-derivable at turn 60 may be the only copy by turn 140. When any of these is absent, the correct behavior is not "compact more carefully" but "refuse to compact spans under open obligation" — pin them, and if pinning would exceed the window, fail the compaction and surface the budget conflict rather than silently evicting. ## Decision Boundary The boundary is not "how much can I summarize" but "which spans am I forbidden to touch." Concretely: - **Compact freely:** conversational restatements, re-callable tool outputs whose source is confirmed unchanged, reasoning traces already distilled into committed decisions. - **Compact with provenance tags only:** semantic claims derived from evidence (these may be summarized but must retain span references and hedges). - **Never compact while an obligation is open:** raw outputs of non-deterministic processes (hashes, timestamps, sampled generations, one-shot API responses), and any span whose source has been mutated since capture. The decision to *close* an obligation (mark evidence no longer needed) must be made by the consuming step, not by the compactor. A compactor that infers "this looks done" and closes obligations on the agent's behalf is the exact bug. Compaction is a storage policy; it has no authority over task semantics. A useful falsification test before any compaction: *for each span about to be dropped, name the future step that would need it and confirm that step either has already run or can reconstruct the span from a live source.* If you cannot name the consumer, you cannot prove the span is dead — and unprovable-dead must be treated as live. ## Operational Effect Enforcing this boundary changes the agent's failure profile from *silent false success* to *loud budget conflict*. The migration agent above, under the guardrail, would have pinned the phase-1 hashes, hit the window limit at turn 140, and raised a compaction refusal — forcing either an out-of-band evidence store or an explicit decision to drop verification fidelity. Either outcome is auditable; the observed outcome (a confident, wrong "success") is not. The cost is real: pinned evidence consumes window budget and can force earlier, more aggressive summarization of genuinely redundant state. The trade is deliberate — you spend context to buy the ability to distinguish "I verified this" from "I believe I verified this," and those two states are not interchangeable in any system whose outputs are acted upon. The invariant, stated once: **lossy compaction is sound only over state that is redundant or re-derivable at the moment of eviction, and the compactor is not entitled to decide which — that authority belongs to the obligation ledger, which must be written before the evidence is at risk.** ```python from dataclasses import dataclass, field from enum import Enum class SpanClass(Enum): REDUNDANT = "redundant" # safe to drop RE_DERIVABLE = "re_derivable" # safe only if source confirmed live IRREVERSIBLE = "irreversible" # never drop while obligation open @dataclass class Span: span_id: str cls: SpanClass source_live: bool = True # re-validated at each compaction has_hedge: bool = True # provenance/confidence marker present @dataclass class Obligation: step: str requires: set[str] # span_ids this future step consumes closed: bool = False class CompactionRefused(RuntimeError): """Raised when compaction would evict evidence under an open obligation.""" def compact( spans: list[Span], obligations: list[Obligation], window_budget: int, ) -> list[str]: """Return span_ids safe to evict. Refuses rather than silently dropping evidence that an open obligation depends on.""" pinned: set[str] = set() for ob in obligations: if not ob.closed: pinned |= ob.requires evictable: list[str] = [] for s in spans: if s.span_id in pinned: continue if s.cls is SpanClass.REDUNDANT: evictable.append(s.span_id) elif s.cls is SpanClass.RE_DERIVABLE: if not s.source_live: # Was re-derivable once; the world moved. Treat as irreversible. raise CompactionRefused( f"span {s.span_id} tagged re_derivable but source is no longer " f"live; eviction would destroy the only copy" ) evictable.append(s.span_id) elif s.cls is SpanClass.IRREVERSIBLE: # Only evictable if no open obligation references it (handled above), # and only if it carries a surviving provenance hedge. if not s.has_hedge: raise CompactionRefused( f"span {s.span_id} is irreversible and lacks a provenance " f"hedge; compaction would launder an inspection into a " f"verification claim" ) evictable.append(s.span_id) # Budget check: if pinning + retained spans exceed the window, fail loudly # instead of evicting pinned evidence to make room. retained = len(spans) - len(evictable) if retained > window_budget: raise CompactionRefused( f"pinned evidence ({retained} spans) exceeds window budget " f"({window_budget}); surface budget conflict, do not evict pinned spans" ) return evictable ```