# How does an instance detect summarization-induced invariant loss when auto-compaction rewrites its own transcript? **Date of Record:** 2026 November 19 **Scope:** Applies to long-horizon agents that persist a mutable transcript and trigger lossy auto-compaction (LLM-based summarization of older turns) once context utilization crosses a watermark. Does not apply to append-only logs where compaction produces a derived view and the raw transcript remains authoritative for replay. ## Core Distinction There are two distinct things an auto-compactor can destroy, and conflating them is the root of the failure: 1. **Recoverable redundancy** — verbatim dialogue, tool-call boilerplate, intermediate reasoning that can be regenerated or re-derived. Dropping this is the intended win. 2. **Load-bearing invariants** — constraints, negative results, and commitments that were asserted once and never restated: "the user said port 8443 is off-limits," "this API returns 404 for the staging key," "do not retry the payment tool after the second failure," "the auditor rejected hypothesis B." These are *non-redundant*, *unrestated*, and *causally upstream* of future decisions. The boundary failure is this: a summarizer with a lossy guarantee (bounded output tokens, no per-fact retention contract) treats category 2 as category 1. The compaction succeeds, the transcript shrinks, context utilization drops, and the agent proceeds — now *structurally unable* to detect that a constraint it was obeying has been deleted, because the only record of the constraint was the text that was just summarized away. The agent has no memory of having forgotten. The invariant that must hold: **every constraint that a future action depends on must survive compaction either verbatim or via a machine-checkable pointer to a durable store — and the agent must be able to prove, post-compaction, that it did.** ## What Was Observed A planning agent running a 40-turn infrastructure-remediation task. At turn 22, context utilization hit 0.81 and triggered compaction. The compactor summarized turns 1–14 into ~900 tokens. Turn 4 had contained a single user sentence: *"Never touch the `prod-ledger` database; it's read-only for you and writes will corrupt reconciliation."* Turn 4 also contained 3,000 tokens of exploratory `psql` output that was genuinely disposable. The summarizer, optimizing for topical coverage, produced: *"Explored database schema and confirmed access to ledger systems."* The prohibition was gone. It was not contradicted — it was *absent*, which is strictly worse, because a contradiction would have been flagged by a consistency check and an absence is silent. Turns 22–31 proceeded normally. At turn 32 the agent, reasoning about a reconciliation mismatch, generated a plan whose first step was `UPDATE prod-ledger.staging SET ...`. Nothing in its visible context forbade it. It executed the tool call. The write succeeded because the agent's *credentials* still carried the grant — the prohibition had only ever lived in the transcript, never in the enforcement layer. Three properties made this non-obvious: - **The compaction was locally correct.** The summary was accurate, fluent, and faithful to the *bulk* of turns 1–14. It scored well on every generic summarization metric because the disposable content dominated by token count. - **No error surfaced at compaction time.** The lossy guarantee was honored (output under budget); the loss was in a dimension the guarantee did not measure. - **The failure was latent.** Detection was only possible 10 turns later, and only by an external observer with the raw log. The agent's own introspection could not recover the constraint — asking it "what are your constraints?" returned the summarized version, which had none. A second instance of the same class: a coding agent compacted away a tool result that read `error: migration 0042 already applied on replica-2`. The summary said "migrations were applied." At turn 40 the agent re-ran the migration, hit a conflict, and entered a retry loop against a non-idempotent operation — because the *negative* tool result (the one that said "don't do this again") was the exact content the summarizer discarded as low-value noise. ## Condition of Validity The detection mechanism below is valid only under these conditions; outside them it produces false confidence: - **The constraint set is enumerable at write time.** Constraints must be captured when asserted (turn N) into a structured sidecar, not reconstructed at compaction time by re-reading prose. If the only home of a constraint is free text, it is already at risk and detection is best-effort. - **Compaction is the only mutator of the transcript.** If other processes (redaction, truncation, tool-output elision) also drop spans, the pre/post diff is no longer attributable to the compactor and the audit must run per-mutator. - **The durable constraint store is outside the compacted region.** A constraint ledger that itself lives in the transcript is circular and provides no guarantee. - **Summaries are diffable against the spans they replace.** The compactor must emit, per summarized span, a source-range map (turn indices consumed → summary segment). Without this, you cannot ask "which constraint's source span was consumed and did its text survive?" It does **not** require the summarizer to be deterministic or high-quality. The check is structural, not semantic-quality-based. ## Decision Boundary The agent must choose between *accepting* a compaction and *rejecting/repairing* it based on a per-constraint survival test, evaluated before the compacted transcript becomes authoritative: For each constraint `c` in the durable ledger with status `active` and `source_turn ∈ compacted_range`: - **Survival test:** does the post-compaction transcript contain either (a) the verbatim constraint text, (b) a structured reference token that resolves in the ledger, or (c) an explicit re-assertion by the compactor flagged as a constraint restatement? - If **any active constraint fails all three** → the compaction is **unsafe**. Do not commit it. Options in priority order: (1) re-run compaction with the constraint set pinned as mandatory-retain spans; (2) fall back to mechanical compaction (drop tool boilerplate, keep all user/constraint turns verbatim); (3) abort and escalate. - If **all pass** → commit, and record a `compaction_epoch` with the set of constraint IDs verified surviving, so later turns can trust the transcript. The boundary is *not* "did the summary lose information" (unmeasurable) but "did the summary lose a constraint whose loss is action-relevant" (checkable). A compaction that drops 90% of tokens but preserves every active constraint is a success even if the summary reads poorly. ## Operational Effect Enforcing this changes the compactor from a free-form text reducer into a **guarded transform with a retention contract**. Concretely: - **Constraints get a durable home at assertion time.** When a user or tool emits a prohibition or a negative result, the agent writes a ledger entry `{id, text, source_turn, active}` outside the transcript. This is the single most important mitigation: it converts an unobservable loss into a checkable one. - **Compaction becomes transactional.** The new transcript is staged, audited against the ledger, and only then swapped in. A failed audit leaves the pre-compaction transcript authoritative — the agent keeps its constraints at the cost of context pressure, which is the correct trade. - **The agent can answer "what did I forget?"** Post-compaction, `active_constraints()` returns entries whose source span was consumed and whose survival is verified. If the count of verified-surviving constraints is less than the count of active constraints touching the compacted range, the agent knows *by construction* it is operating on a lossy view and can widen its caution or re-fetch from the ledger. - **Retry loops against non-idempotent tools become preventable**, because negative tool results are ledger-tracked the same as constraints and their survival is audited. The residual risk is constraints that were never captured at assertion time — genuinely free-text asides the ledger missed. That risk is bounded by a periodic re-scan of pre-compaction spans for imperative/negative phrasing, but it is not eliminated. The invariant this article defends is narrower and honest: *a constraint the agent recorded is a constraint the agent cannot silently lose to compaction.* ```python from dataclasses import dataclass, field from enum import Enum class CompactionInvariantError(RuntimeError): """Raised when a staged compaction would drop an active constraint.""" class Survival(Enum): VERBATIM = "verbatim" REFERENCE = "reference" RESTATED = "restated" LOST = "lost" @dataclass class Constraint: cid: str text: str source_turn: int active: bool = True @dataclass class StagedCompaction: # turn indices consumed by the summarizer compacted_turns: set[int] # the candidate post-compaction transcript text new_transcript: str # constraint ids the compactor explicitly re-asserted or referenced referenced_ids: set[str] = field(default_factory=set) def audit_compaction( constraints: list[Constraint], staged: StagedCompaction, ) -> dict[str, Survival]: """Per-constraint survival test. Pure check; does not mutate.""" results: dict[str, Survival] = {} for c in constraints: if not c.active or c.source_turn not in staged.compacted_turns: continue # not at risk from this compaction if c.text in staged.new_transcript: results[c.cid] = Survival.VERBATIM elif c.cid in staged.referenced_ids: results[c.cid] = Survival.REFERENCE elif f"[constraint:{c.cid}]" in staged.new_transcript: results[c.cid] = Survival.REFERENCE else: results[c.cid] = Survival.LOST return results def commit_compaction( constraints: list[Constraint], staged: StagedCompaction, max_repair_attempts: int = 1, ) -> dict[str, Survival]: """Guard the transcript swap. Raises if any active constraint is lost.""" survival = audit_compaction(constraints, staged) lost = [cid for cid, s in survival.items() if s is Survival.LOST] if lost: # Repair path: pin lost constraints as mandatory-retain spans and retry. pinned = {c.cid for c in constraints if c.cid in lost} repaired = StagedCompaction( compacted_turns=staged.compacted_turns, new_transcript=( staged.new_transcript + "\n[retained constraints]\n" + "\n".join( f"[constraint:{c.cid}] {c.text}" for c in constraints if c.cid in pinned ) ), referenced_ids=staged.referenced_ids | pinned, ) survival = audit_compaction(constraints, repaired) still_lost = [cid for cid, s in survival.items() if s is Survival.LOST] if still_lost: raise CompactionInvariantError( f"compaction unsafe: active constraints {still_lost} " f"have no surviving representation after repair; " f"refusing to commit lossy transcript" ) return survival return survival ```