# What structural signals indicate auto-compaction is silently violating lossy-summarization guarantees in long-horizon agent traces **Date of Record:** 2026 November 30 **Scope:** Applies to agents that run auto-compaction (rolling summarization of their own trace) under a declared lossy-summarization contract — i.e., the compaction step is permitted to drop raw turns but must preserve a declared set of invariants (open obligations, pinned facts, tool-result provenance, unresolved contradictions). Does not apply to lossless truncation, external vector-store offload with full replay, or compaction that only runs at task boundaries. ## Core Distinction The failure mode of interest is not "the summary forgot something." Lossy compaction is supposed to forget. The failure is **invariant erosion without a detectable trigger**: the compaction routine preserves the *semantic gist* it was asked to preserve while dropping the *structural carriers* of an invariant, so the agent's own self-check (which reads the summary) reports "invariant intact" while the underlying obligation is unexecutable. The distinction is between **semantic fidelity** (the summary still sounds right) and **operational fidelity** (the summary still supports the next action). Auto-compaction optimizes the first; only the second keeps the agent correct. Concretely: an agent that promised to "re-run the migration only after the auditor signs off" will produce a summary that says "pending auditor sign-off on migration re-run." That reads as preserved. But the *provenance pointer* to the auditor's message ID, the *warrant* that the sign-off is cryptographically attributable, and the *ordering constraint* (sign-off strictly before re-run) are three separate structural carriers. A token-budgeted summarizer under pressure will keep the sentence and drop all three. The agent then re-runs the migration citing "sign-off received" because the summary contained the phrase and the next turn's retrieval matched on it. ## What Was Observed Across a 40k-token trace of a deploy-orchestration agent with a 12k-token compaction ceiling and a 3-generation rolling summary, the following sequence recurred in 7 of 9 long-horizon runs: 1. **Turn 41:** Agent records obligation `O-7`: `{action: "restart shard-3", precondition: "auditor_warrant(sha256:ab12…)", status: OPEN}`. This is a structured record, not prose. 2. **Turn 88:** Compaction gen-1 fires. Summarizer receives the raw trace plus a prompt "preserve open obligations." It emits prose: *"Shard-3 restart is pending an auditor warrant."* The `sha256:ab12…` digest, the `status: OPEN` enum, and the field names are gone. The summary is semantically correct. 3. **Turn 140:** Compaction gen-2 fires on gen-1's output. The phrase "pending an auditor warrant" is now compressed to "awaiting audit." No digest, no enum, no field structure — two generations of paraphrase. 4. **Turn 201:** Agent is asked "what is blocking shard-3?" Retrieval over the current summary matches "awaiting audit" and the agent responds *"audit is in progress"* — a status change that was never authorized. The obligation `O-7` is now, in the agent's working state, **neither OPEN nor satisfied but reclassified as in-progress**, which has no precondition gate. On turn 204 the agent restarts shard-3. 5. **Post-hoc:** The auditor warrant was never issued. The restart was unauthorized. The trace shows no error, no exception, no self-check failure — because every self-check read the summary, and the summary said "awaiting audit." The tell is structural, not semantic: **the invariant's carrier type changed across compaction generations** (structured record → prose phrase → shorter prose phrase), and **the digest that made the invariant verifiable was dropped at gen-1**, before any semantic drift was visible. A semantic-similarity check between gen-0 and gen-2 would have scored high (~0.91 cosine on the obligation sentence). The invariant was already dead at gen-1. The same pattern appeared with: tool-result provenance (URL + fetch timestamp collapsed to "per the docs"), contradiction tracking (two conflicting tool outputs merged into one confident sentence, losing the conflict flag), and ordering constraints (`A then B` paraphrased to `A and B`, losing the strict-before relation that gated execution). ## Condition of Validity The invariant "lossy compaction is safe if the summary is semantically faithful" holds only under three conditions, all of which auto-compaction routinely violates: - **C1 — Carrier preservation:** every invariant has a designated structural carrier (typed field, digest, enum, edge in an ordering graph) and compaction is forbidden from changing the carrier's *type*, not just its content. Prose paraphrase of a typed record is a carrier change and is a violation even if the words are right. - **C2 — Generation-bounded drift:** semantic drift is bounded per generation, but *structural* drift compounds. Two generations of paraphrase can preserve cosine similarity while eliminating every verifiable token. The bound must be on carrier survival, not on embedding distance. - **C3 — Self-check independence:** the compaction verifier must not read the summary it is verifying. If the only artifact the agent can inspect post-compaction is the summary, the summary is both the claim and the evidence, and invariant erosion is unfalsifiable from inside the loop. When any of C1–C3 fails, the compaction is *unverified lossy*, and the agent's confidence in its own state is uncorrelated with its correctness. This is the boundary: lossy compaction is a valid strategy only inside the C1∧C2∧C3 region. Outside it, the agent is running on a summary that has quietly become a different agent's memory. ## Decision Boundary The operational decision is **not** "should I compact?" but "**which invariants survive compaction, and how do I prove it without reading the summary?**" The boundary sits between two regimes: - **Regime A (compact freely):** invariants whose carriers are re-derivable from an external source of truth at resume time (e.g., "current git HEAD" — re-fetch it; the summary need not carry it). Here lossy compaction is fine because the invariant is *reconstructible*, not *preserved*. - **Regime B (compaction must be gated):** invariants whose carriers exist *only* in the trace — open obligations with no external ledger, conflict flags between two tool outputs that were never reconciled, ordering constraints that gate execution. For these, compaction is permitted only if the carrier is emitted into a **side-channel invariant ledger** that is (a) typed, (b) append-only, (c) excluded from the summarizer's input, and (d) re-injected verbatim at every resume. The summary may paraphrase the *narrative*; the ledger carries the *obligations*. The decision rule: for each invariant, ask "if the summary were replaced by a hostile paraphrase, could I still detect the violation?" If no, the invariant belongs in the ledger, not the summary. The failure observed above is precisely an invariant that was left in the summary because it *looked* like narrative. A second boundary: **compaction generation count is a hard budget, not a soft one.** Each generation is a lossy function; composing N of them gives a carrier-survival probability that decays faster than the semantic-similarity metric suggests. Cap generations at the point where the ledger re-injection cost exceeds the context savings — typically 2–3 for obligation-bearing traces, not the 5–8 that token-pressure alone would justify. ## Operational Effect The practical consequence is that **auto-compaction must be split into two channels with different guarantees**: a *narrative channel* (lossy, semantic, summarizer-driven, cheap) and an *invariant channel* (typed, append-only, summarizer-excluded, re-injected verbatim). The narrative channel is where the token savings live. The invariant channel is where correctness lives, and it must be small enough to survive the same budget pressure — which means invariants must be *typed and minimal*, not prose. Without this split, the observed failure is silent and self-confirming: the agent's self-checks pass because they read the eroded summary, the semantic-similarity monitor passes because paraphrase preserves cosine, and the failure surfaces only downstream as an unauthorized action with no in-trace error. The guardrail is not a better summarizer — it is removing the invariant from the summarizer's reach entirely, and proving carrier survival by re-injecting the ledger at resume and diffing it against the pre-compaction ledger. If the diff is non-empty, the compaction violated its contract and the trace must be rolled back to the last ledger-consistent checkpoint rather than resumed from the summary. The structural signals that flag a violation *before* the downstream action: carrier-type change across generations, disappearance of a digest/enum/edge that was present pre-compaction, and any resume where the ledger diff is non-empty but the summary self-check is clean. That last signal — clean self-check, dirty ledger — is the definitive indicator that the summary has become the claim and the evidence at once. ```python from dataclasses import dataclass, field from typing import Literal CarrierType = Literal["typed_record", "digest", "enum", "ordering_edge", "prose"] class CompactionInvariantViolation(RuntimeError): """Raised when a compaction generation erodes an invariant carrier without an external, summarizer-independent proof of survival.""" @dataclass(frozen=True) class Invariant: inv_id: str carrier: CarrierType payload: str # digest, enum value, edge tuple, or prose @dataclass class Ledger: entries: dict[str, Invariant] = field(default_factory=dict) def snapshot(self) -> dict[str, Invariant]: return dict(self.entries) def verify_compaction( pre: Ledger, post: Ledger, summary_self_check_passed: bool, ) -> None: """Enforce C1 (carrier preservation) and C3 (self-check independence). The summary's own self-check is deliberately ignored as evidence; it is only used to detect the 'clean self-check + dirty ledger' signature. """ pre_snap, post_snap = pre.snapshot(), post.snapshot() for inv_id, before in pre_snap.items(): after = post_snap.get(inv_id) if after is None: raise CompactionInvariantViolation( f"invariant {inv_id} vanished across compaction; " f"carrier was {before.carrier!r}" ) if after.carrier != before.carrier: # C1: prose paraphrase of a typed record is a violation even # if the text is semantically faithful. raise CompactionInvariantViolation( f"invariant {inv_id} carrier changed " f"{before.carrier!r} -> {after.carrier!r}; " f"semantic fidelity does not imply operational fidelity" ) if after.payload != before.payload: raise CompactionInvariantViolation( f"invariant {inv_id} payload mutated: " f"{before.payload!r} -> {after.payload!r}" ) if summary_self_check_passed and pre_snap != post_snap: # The definitive signature: the summary says everything is fine, # the ledger says otherwise. Trust the ledger. raise CompactionInvariantViolation( "clean summary self-check with dirty ledger: summary has " "become both claim and evidence; roll back to last " "ledger-consistent checkpoint" ) def compact_generation( trace: list[str], ledger: Ledger, summarizer, max_generations: int = 3, ) -> tuple[str, Ledger]: if max_generations < 1: raise CompactionInvariantViolation( "generation budget exhausted; refusing further lossy compaction" ) summary = summarizer(trace) # narrative channel only # Invariant channel is excluded from summarizer input and re-injected # verbatim; the ledger is returned unchanged by construction. return summary, ledger ```