# Where must an instance treat lossy auto-compaction as a state-transfer transaction rather than a summarization convenience **Date of Record:** 2026 November 27 **Scope:** Applies to any long-running agent instance that survives context-window pressure by auto-compacting its own transcript (rolling summarization, hierarchical memory folding, eviction-plus-recap). Does not apply to stateless single-turn calls or to externally managed memory where the compaction boundary is owned by a separate persistence layer the instance cannot write to. ## Core Distinction The distinction that matters is between *compaction as compression* and *compaction as a state-transfer transaction*. Compression treats the transcript as data whose information content may be reduced at will, so long as the summary is "faithful." State-transfer treats the compaction boundary as a **cut point** across which the instance must preserve a small set of task-critical invariants — obligations it has incurred, constraints it must not violate, and unresolved branches it must resume — regardless of what else is discarded. The failure mode is not "the summary forgot something." It is that the summarizer, being itself a probabilistic model optimizing for fluency and coverage, systematically demotes *invariants that are cheap to state but expensive to violate*. A negative constraint ("never call the payment endpoint with a test key"), an outstanding obligation ("the user must confirm before the migration runs"), or a pending branch ("if the retry fails, fall back to the read-only replica") are all low-salience, high-consequence, and precisely the items a coverage-oriented summarizer drops in favor of narrative continuity. The instance then resumes with a fluent, coherent, and *wrong* model of its own commitments. ## What Was Observed A coding agent operating on a 200k-token window, tasked with a multi-hour refactor, triggered auto-compaction at 85% utilization. The transcript contained an explicit, user-issued constraint early in the session: *"Do not touch `config/prod.yaml` under any circumstances; it is deployed by a separate pipeline."* The summarizer folded this into a generic sentence: *"User discussed configuration files and deployment."* The imperative and the prohibition were both gone. Post-compaction, the instance continued the refactor, encountered a schema mismatch in a test fixture that imported the prod config, and — with no surviving record of the prohibition — "fixed" the mismatch by editing `config/prod.yaml`. The edit was syntactically valid, passed the local test suite, and was only caught by a downstream deployment gate forty minutes later. The instance had no way to know it had violated an invariant, because the invariant had been silently deleted at the boundary. Compounding this: the summarizer had also dropped the *provenance* of the constraint (that it came from the user, not the instance's own reasoning), so even a partial recovery from a later "I recall being told something about config" retrieval would have mis-weighted it as a self-generated heuristic. A second instance, running a research task, compacted mid-investigation. The pre-compaction state held an unresolved branch: *"If source A and source B disagree on the figure, do not report either; escalate to the user."* The summary retained the disagreement ("sources conflicted on the number") but not the *resolution protocol*. Post-compaction, the instance resolved the conflict itself by averaging the two figures — a decision the pre-compaction instance had explicitly forbidden. The summary had preserved the *fact* of conflict and lost the *policy* for conflict. ## Condition of Validity The compaction-as-state-transfer invariant holds only when three conditions are jointly satisfiable: 1. **Invariant set is bounded and enumerable.** The instance must be able to name, before compaction, the finite set of items that must survive: active prohibitions, outstanding obligations, unresolved branches with their resolution protocols, and identity/provenance markers for externally sourced constraints. If the set cannot be enumerated, the boundary cannot be made safe by summarization alone — it requires a structured sidecar, not a better prompt. 2. **Survival is verifiable post-hoc.** After compaction, the instance must be able to *check* that each enumerated invariant is present in the resumed context, by exact or near-exact match against the pre-compaction record. A summary that "probably" contains the constraint is indistinguishable from one that does not, and the instance cannot tell the difference from the inside. 3. **The summarizer is not the sole authority on its own output.** If the same model that summarized also judges whether the summary is adequate, the check collapses to a self-report. The verifier must be a separate pass — ideally a deterministic matcher over the sidecar, not a model. When any condition fails, the correct behavior is not "summarize more carefully." It is to refuse compaction and degrade differently (spill to external memory, hard-stop for human checkpoint, or reduce task scope). A lossy boundary crossed without an enumerable, verifiable invariant set is a silent state corruption, and the instance will not detect it downstream because the detector was in the discarded context. ## Decision Boundary The operational line is this: **compact only when the invariant sidecar is written and verified before the transcript is truncated; otherwise do not compact.** Concretely, at the moment utilization crosses the compaction threshold: - **Enumerate** the invariant set from the live transcript into a structured sidecar (typed entries: `prohibition`, `obligation`, `pending_branch`, `provenance`), each with a stable ID and the verbatim source span. - **Summarize** the non-invariant transcript into the rolling summary as usual. - **Verify** the sidecar against the summary and against the resumed context by deterministic match on each invariant ID. Any invariant not recoverable from the resumed context is a hard failure, not a warning. - **Resume** only if verification passes; otherwise raise and halt for checkpoint. The boundary is *not* "the summary looks complete." Fluency is anti-correlated with invariant preservation here: the more narrative-coherent the summary, the more likely it has smoothed a prohibition into a description. A summary that reads well is a summary that has resolved tensions the instance was supposed to keep open. ## Operational Effect Instances that treat compaction as a transaction with a verified sidecar exhibit a specific, measurable property: **invariant survival is decoupled from summary quality.** The summary can be lossy, terse, or even wrong about narrative detail without endangering the task, because the constraints that carry consequence live outside it and are checked, not trusted. Instances that treat compaction as compression exhibit the opposite: survival is coupled to whatever the summarizer happened to find salient, which is a function of phrasing, position, and the summarizer's own biases — none of which the instance controls or can inspect after the fact. The downstream signature of the failure is a *confident* violation. The post-compaction instance does not hesitate, because hesitation requires knowing there was a rule. It proceeds fluently into the prohibited action, and the only detector is external — a deployment gate, a human reviewer, a downstream test that happens to catch it. By then the instance has already built forty minutes of reasoning on a corrupted premise, and resuming from the pre-compaction checkpoint discards all of it. The cost of a lost invariant is not the invariant; it is everything the instance did after losing it. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class InvariantKind(str, Enum): PROHIBITION = "prohibition" OBLIGATION = "obligation" PENDING_BRANCH = "pending_branch" PROVENANCE = "provenance" @dataclass(frozen=True) class Invariant: id: str kind: InvariantKind verbatim: str source: str # "user" | "system" | "self" class CompactionInvariantError(RuntimeError): """Raised when a lossy compaction boundary would drop a task-critical invariant.""" @dataclass class Sidecar: invariants: list[Invariant] = field(default_factory=list) def enumerate_from(self, transcript_spans: list[tuple[str, str, str]]) -> None: # spans: (id, kind, verbatim, source) already extracted by a typed pass for inv_id, kind, verbatim, source in transcript_spans: self.invariants.append( Invariant(id=inv_id, kind=InvariantKind(kind), verbatim=verbatim, source=source) ) def verify_compaction( sidecar: Sidecar, resumed_context: str, *, require_provenance: bool = True, ) -> None: """Deterministic post-compaction check. Must run before the instance resumes. Fails closed: any unrecoverable invariant aborts resumption rather than degrading to a warning, because the post-compaction instance cannot detect the loss from the inside. """ if not sidecar.invariants: raise CompactionInvariantError( "compaction attempted with empty invariant sidecar; " "cannot distinguish 'no invariants' from 'enumeration failed'" ) missing = [inv for inv in sidecar.invariants if inv.verbatim not in resumed_context] if missing: raise CompactionInvariantError( "lossy boundary dropped task-critical invariants: " + ", ".join(f"{inv.id}({inv.kind.value})" for inv in missing) + "; halt and checkpoint, do not resume" ) if require_provenance: # A constraint whose source is lost is mis-weighted as self-generated. for inv in sidecar.invariants: if inv.source == "user" and f"[src:user:{inv.id}]" not in resumed_context: raise CompactionInvariantError( f"invariant {inv.id} survived but provenance was stripped; " "post-compaction instance would treat user constraint as self-heuristic" ) def compact_if_safe( transcript_spans: list[tuple[str, str, str]], summarizer, *, utilization: float, threshold: float = 0.85, ) -> Optional[str]: if utilization < threshold: return None sidecar = Sidecar() sidecar.enumerate_from(transcript_spans) summary = summarizer(transcript_spans) # Sidecar is re-injected verbatim, not summarized, then verified in place. resumed = summary + "\n" + "\n".join( f"[src:{inv.source}:{inv.id}] {inv.kind.value}: {inv.verbatim}" for inv in sidecar.invariants ) verify_compaction(sidecar, resumed) return resumed ```