# Which invariants prevent lossy auto-compaction from silently severing the causal chain between a plan's origin and its current execution step **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agents that auto-compact their own context window via lossy summarization and then rely on vector/keyword retrieval to "recover" evicted turns. Does not apply to agents with a hard, non-lossy external store that is re-read verbatim on every step, nor to single-turn tool-calling with no persistent plan state. ## Core Distinction There are two different things an auto-compaction pass can preserve, and they are not the same: 1. **Semantic gist** — the *content* of what was said (the goal, the constraints, the facts discovered). Lossy summarizers are tuned for this and generally do it well. 2. **Causal provenance** — the *binding* between a decision and the specific prior observation that justified it, including the ordering and the identity of the step that produced it. The failure mode examined here is **provenance collapse under gist-preserving compaction**: a summarizer faithfully keeps the semantic content of a plan ("we are migrating the schema because the legacy column is nullable") while dropping the *index* that says which tool output, at which step, established the premise. Once that binding is gone, the agent can no longer distinguish "I verified this" from "I summarized that I verified this," and a later retrieval fallback will happily surface a *semantically similar but causally unrelated* turn to fill the gap. The agent resumes with high confidence on a premise whose evidence has been silently replaced by a lookalike. The invariant that prevents this is **provenance-preserving compaction**: every compacted claim that a future step may act on must carry a stable reference (step id + content hash) to its originating observation, and that reference must survive summarization even when the prose does not. ## What Was Observed A 40-step infrastructure-remediation agent was operating on a 32k-token window with auto-compaction triggered at 80% fill. At step 22 it compacted turns 1–14 into a 900-token summary. The summary read, in part: > "Confirmed the `users.legacy_id` column is nullable and unused by current application code; safe to drop. Migration plan approved." The actual history: at step 6 the agent had run a schema inspection that returned `legacy_id: nullable=true, referenced_by=[]` — but that inspection was scoped to a *staging* replica whose `referenced_by` index had not been rebuilt (a known-stale view, flagged in a tool warning the agent had read and then compacted away). At step 11 a second inspection against *production* returned `referenced_by=["billing_export_worker"]`. The summarizer merged both into the single confident sentence above, because "confirmed nullable and unused" is the gist of the *first* observation and the *second* observation was phrased as a correction the summarizer treated as redundant restatement. At step 23 the agent needed to re-verify before executing the drop. It issued a retrieval query — `"legacy_id column nullable unused"` — against the compacted store. The top hit was the step-6 staging inspection (highest lexical overlap with the query). The step-11 production correction ranked fourth, below the summarizer's own summary chunk. The agent re-read the step-6 output, saw `referenced_by=[]`, and proceeded to generate the `DROP COLUMN` migration. The trace signature is diagnostic: **the retrieval fallback returned a premise-consistent observation, not a decision-consistent one.** The query was built from the *summary's* vocabulary, so it retrieved evidence for the summary, not evidence for the *decision the summary was supposed to support*. The correction — the one turn that inverted the conclusion — was the least retrievable turn in the history, because it was phrased as a delta against a prior claim and therefore had low standalone lexical mass. ## Condition of Validity The provenance-collapse failure is *bounded* (i.e., the invariant holds and no silent corruption occurs) only when **all three** of the following are true at every compaction boundary: - **C1 — Supersession is explicit and ordered.** When observation *B* corrects observation *A*, the compacted record must encode `B supersedes A` with both step ids, not a merged sentence. A summarizer that cannot represent supersession must refuse to compact the pair and defer them verbatim. - **C2 — Retrieval is keyed on decision, not on summary.** The fallback query must be constructed from the *pending action's* preconditions (e.g., "what established that `legacy_id` is safe to drop?"), not from the summary text. Summary-keyed retrieval is self-confirming by construction: it retrieves what the summary already believes. - **C3 — Every actionable claim carries a resolvable back-reference.** If a compacted claim cannot be traced to a live step id + content hash in the retained store, it is not actionable; the agent must re-derive it from the environment rather than act on it. The failure is *unbounded* (silent, undetectable from inside the agent) whenever any one of these is violated, because the agent's own confidence signal is computed over the compacted text, which is internally consistent by construction. There is no local error signal — the corruption is invisible precisely because the summary is coherent. ## Decision Boundary The boundary between "safe to compact" and "must retain verbatim" is not token count and not semantic redundancy. It is **whether the turn is the sole surviving witness to a premise that a not-yet-executed action depends on.** Operationally: - A turn may be lossily compacted if its content is *restated* by a later, higher-authority turn that is itself retained with a back-reference. (Redundant confirmation → compact.) - A turn must be retained verbatim (or compacted only into a structured record with step id + hash + supersession edge) if it is a **correction, a negation, a scope-narrowing, or the only observation establishing a precondition of a pending action.** These are the turns whose loss is unrecoverable because their *information content is the delta*, and deltas do not survive gist summarization. The practical test before compaction: for each pending action in the plan, enumerate its preconditions; for each precondition, find the *latest* observation bearing on it; if that observation is inside the compaction window and is not restated by a retained later turn, pin it. Everything else is fair game for lossy summarization. ## Operational Effect When the invariant is enforced, the observable effect is that **post-compaction retrieval and pre-compaction reasoning agree on the same set of live premises** — the agent's behavior is continuous across the boundary, and a re-verification step returns the *correction* rather than the *original claim*. The cost is a modest retention floor: corrections and precondition-establishing observations are pinned, so the effective compaction ratio is lower than a pure gist summarizer would achieve (observed 3.1:1 vs. 6.8:1 in the case above), and the retained store grows with the number of *distinct corrections*, not with history length. When the invariant is violated, the effect is not a crash but a **confident wrong action**: the agent executes on a premise whose supporting evidence was replaced by a semantically adjacent lookalike, and no internal signal flags it. The failure surfaces only downstream — at the `DROP COLUMN` that breaks `billing_export_worker` — by which point the causal chain to the compaction event is itself gone, and the post-mortem cannot reconstruct which summary pass severed it. This is why the invariant must be enforced *at compaction time*: it is the last moment at which provenance is still present to be preserved. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceCollapseError(RuntimeError): """Raised when a compaction pass would sever the causal link between a pending action's precondition and its sole surviving observation.""" pass @dataclass class Observation: step_id: int text: str supersedes: Optional[int] = None # step_id of the observation this corrects @property def content_hash(self) -> str: return hashlib.sha256(self.text.encode()).hexdigest()[:12] @dataclass class PendingAction: name: str preconditions: list[str] = field(default_factory=list) def compact( window: list[Observation], pending: list[PendingAction], retained_ids: set[int], ) -> list[Observation]: """Return the observations safe to lossily compact. Raises ProvenanceCollapseError if any pending action's latest precondition-bearing observation would be compacted away without a retained, back-referenced restatement (violates C1/C3). """ compactable: list[Observation] = [] for obs in window: # C1: corrections/supersessions are never lossily compacted. if obs.supersedes is not None: raise ProvenanceCollapseError( f"step {obs.step_id} is a supersession of step " f"{obs.supersedes}; it encodes a delta and must be pinned, " f"not summarized (violates C1)" ) # C3: if this is the latest witness to a pending precondition and it # is not restated by a retained later turn, it is not compactable. for action in pending: for pre in action.preconditions: if pre in obs.text and obs.step_id not in retained_ids: raise ProvenanceCollapseError( f"step {obs.step_id} ({obs.content_hash}) is the sole " f"surviving witness to precondition {pre!r} of pending " f"action {action.name!r}; compacting it would leave the " f"action acting on an unreferenced premise (violates C3)" ) compactable.append(obs) return compactable ```