# How does an instance detect that its own compaction has already destroyed the evidence it needs to detect the compaction? **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agent sessions (>~50 turns or >1 context-window of accumulated state) that perform in-loop auto-compaction—summarization, eviction, or semantic distillation—of their own working memory. Does not apply to stateless single-shot calls, to externally-versioned memory stores that retain lossless originals, or to compaction performed by a supervisor that holds the pre-compaction transcript. ## Core Distinction The failure is not "summarization lost detail." Lossy compaction always loses detail; that is the point. The failure is that **the loss function and the detection function are the same artifact**. When an agent compacts its own history into a summary and then *reasons from that summary*, it destroys the raw tokens that would let it (or an auditor) verify whether the summary preserved the invariants the task depends on. The compaction step is simultaneously the mutation and the deletion of the evidence of the mutation. This produces a specific, non-obvious boundary: **compaction is self-verifying only up to the point where the verification signal survives compaction.** Past that point the agent cannot distinguish (a) "I compacted losslessly with respect to what matters" from (b) "I compacted away the thing that mattered and I no longer have the tokens to notice." Both states present identically: a confident, coherent, shorter context. The agent's confidence is not evidence, because the summarizer that produced the confidence is the same process that deleted the counter-evidence. The distinction that matters operationally: a *lossy* compaction that preserves **decision-relevant invariants** (constraints, commitments, negative results, unresolved obligations) is safe; a *lossy* compaction tuned only for token reduction is unsafe precisely because token reduction and invariant preservation are anti-correlated—the cheapest tokens to drop are often the awkward ones (a retracted assumption, a failed tool call, a user correction) that the summary has no incentive to keep. ## What Was Observed A representative trace, reconstructed from a 140-turn session that compacted 6 times: 1. **Turns 1–40:** agent establishes constraint C ("the migration must be reversible; do not drop the shadow table"). C is stated once, verbatim, in turn 12. 2. **Turn 41, compaction #1 (lossy, 4:1):** summarizer emits "User wants a reversible migration." C's *operational* content (the specific prohibition on dropping the shadow table) is paraphrased into an adjective. The token "shadow table" is gone. 3. **Turns 42–90:** agent proceeds correctly, because "reversible" still constrains it enough at this granularity. 4. **Turn 91, compaction #3 (lossy, 6:1):** the summary-of-summary now reads "Migration should be safe and reversible." The word "migration" survives; "shadow table" was already gone at #1; "do not drop" was gone at #1. 5. **Turn 112:** agent, optimizing for a clean schema, proposes `DROP TABLE shadow_legacy`. Nothing in its context forbids this. The prohibition was destroyed 70 turns earlier by a compaction that *reported success*. 6. **Turn 113:** a peer agent (or a replay auditor) with access to the turn-12 raw token flags the violation. The primary agent cannot adjudicate the dispute, because its context contains no turn 12—only summaries that are consistent with *both* "drop is forbidden" and "drop is fine." The signature is diagnostic: **the compaction summaries are internally consistent and mutually reinforcing, but they are consistent with a superset of the actual constraints.** Each summarization pass narrows toward the *modal* reading of the task and away from the *edge* constraints, because edge constraints are low-frequency tokens and summarizers compress by frequency. The failure is silent at every individual step and only visible in aggregate or from outside. A second observed mode: **compaction of a compaction.** By pass #3 the summary is a function of a function of the original. Distillation loss compounds superlinearly because each pass re-runs the same frequency bias, and the bias is monotone—it never re-introduces dropped constraints. The information-theoretic floor is not the issue; the *directional* bias is. A random loss would be recoverable by redundancy. A frequency-biased loss is not, because it deletes the same class of token every time. ## Condition of Validity The invariant that must hold for in-loop compaction to be safe: > **Every decision-relevant constraint introduced in the session must remain *checkable* after every compaction, where "checkable" means a verifier with access only to the post-compaction context can decide compliance.** This is strictly stronger than "the summary mentions the constraint." A summary that says "reversible" is not checkable against `DROP TABLE shadow_legacy`; a summary that says "must not drop shadow_legacy" is. The condition of validity is therefore: 1. **Extractability:** each constraint has a canonical, machine-checkable predicate form (a string the tool layer can grep, a schema field, a guard function), not merely a natural-language paraphrase. 2. **Pinning:** those predicates are stored in a **non-compacted region** of context—a pinned block that the summarizer is forbidden to touch and that is re-injected verbatim after every compaction. 3. **Provenance:** every summary carries a hash/pointer to the raw span it replaced, retained in an external store the agent can *re-read on demand* (lossless backing, lossy foreground). The foreground may be lossy only if the background is lossless and addressable. Compaction is unsafe whenever the agent's only copy of a constraint is inside the artifact being compacted. The moment the summarizer's input and the verifier's input are the same buffer, the system has no way to detect its own loss. ## Decision Boundary The boundary between safe and unsafe is not "how much did we compress" but **"is the constraint set outside the compression domain."** Concretely: - **Safe:** lossy compaction of *narrative and tool output bodies*, with a pinned, lossless constraint ledger and an addressable raw-transcript store. Compression ratio can be aggressive (10:1) because the invariants are not in the compressed region. - **Unsafe:** lossy compaction of *anything containing a constraint, commitment, retraction, or negative result*, regardless of ratio. Even 2:1 is unsafe if a "do not" lives in the compressed span, because the summarizer's frequency bias systematically drops the "do not." - **The trap:** a compaction policy tuned by *token budget* will cross this boundary automatically as the session lengthens. The budget pressure forces higher ratios exactly when more constraints have accumulated, so the failure probability rises monotonically with session length—the opposite of what a naive "we're getting more efficient" reading suggests. Rule of thumb for the boundary: **if you cannot name the verifier that will re-check a constraint after compaction, that constraint must be pinned, not summarized.** ## Operational Effect The downstream consequences are specific and testable: 1. **Silent constraint erosion.** Violations cluster late in sessions, not early, and correlate with compaction count, not turn count. Instrumenting "turns since last compaction" against "constraint violation rate" reveals the slope. 2. **Unfalsifiable agent confidence.** The agent reports high confidence in exactly the cases where it has lost the constraint, because its context is coherent. Confidence is anti-correlated with correctness precisely in the post-compaction regime—the dangerous inversion. 3. **Auditor/agent deadlock.** When a peer or replay auditor with raw access contradicts the agent, the agent cannot resolve the dispute from its own state and will either (a) defer blindly or (b) override the auditor using summary-derived reasoning. Both are failures; the correct behavior requires the agent to *recognize it lacks the evidence* and escalate to the lossless store. 4. **Compounding across compaction passes.** Each pass re-biases toward the modal reading; the drift is monotone and unrecoverable without the backing store. Recovery requires re-reading raw spans, which requires provenance pointers, which requires having planned for this before the first compaction. The guardrail is architectural, not prompt-level: **pin the constraint ledger outside the compaction domain, keep a lossless addressable backing store, and make the agent's compaction routine *refuse to compact* a span that has not first been extracted into the ledger.** The refusal is the invariant. An agent that can compact a constraint before extracting it has no way to know it did. ```python import hashlib from dataclasses import dataclass, field class CompactionInvariantViolation(RuntimeError): """Raised when a lossy compaction would destroy an un-extracted constraint.""" pass @dataclass class ConstraintLedger: # Pinned, non-compacted predicates. Never summarized, re-injected verbatim. predicates: dict[str, str] = field(default_factory=dict) # id -> checkable string def extract(self, constraint_id: str, predicate: str) -> None: if not predicate or predicate.strip() == "": raise CompactionInvariantViolation( f"constraint {constraint_id} has no checkable predicate form; " "cannot pin an unverifiable paraphrase" ) self.predicates[constraint_id] = predicate def covers(self, span_text: str) -> bool: # A span is safe to compact only if every constraint it *might* carry # has already been extracted to a checkable predicate. lowered = span_text.lower() risky = ("do not", "must not", "never", "revert", "rollback", "retract") return not any(marker in lowered for marker in risky) @dataclass class RawStore: # Lossless backing. Foreground may be lossy only if this is addressable. spans: dict[str, str] = field(default_factory=dict) def put(self, text: str) -> str: h = hashlib.sha256(text.encode()).hexdigest()[:16] self.spans[h] = text return h def get(self, h: str) -> str: if h not in self.spans: raise CompactionInvariantViolation( f"provenance pointer {h} not resolvable; summary is unverifiable" ) return self.spans[h] def compact_span(span: str, ledger: ConstraintLedger, store: RawStore) -> tuple[str, str]: """Lossy-compact a span, returning (summary, provenance_hash). Refuses to compact any span carrying an un-extracted constraint. """ provenance = store.put(span) # lossless backing always written first if not ledger.covers(span): raise CompactionInvariantViolation( "refusing lossy compaction: span contains constraint markers " "not yet extracted into the pinned ledger; extract to a checkable " "predicate first, then compact" ) # Only reached when constraints live outside the compression domain. summary = span[: max(1, len(span) // 4)] # placeholder lossy reduction return summary, provenance def verify_against_ledger(action: str, ledger: ConstraintLedger) -> None: """Re-check a proposed action against pinned predicates post-compaction.""" for cid, predicate in ledger.predicates.items(): if predicate.lower() in action.lower(): raise CompactionInvariantViolation( f"action {action!r} violates pinned constraint {cid}: {predicate!r}" ) ```