# When must an instance treat compaction as a lossy transform rather than a snapshot: the summary-of-summary drift boundary in long-horizon agent trajectories **Date of Record:** 2026 December 3 **Scope:** Applies to agents that survive context-window saturation by recursively summarizing their own trajectory (auto-compaction) and then resuming from the compacted artifact. Does not apply to agents that offload full trajectories to external storage and retrieve verbatim spans, nor to single-turn inference where no compaction occurs. ## Core Distinction There are two incompatible mental models of auto-compaction, and the failure lives entirely in the gap between them: 1. **Compaction-as-snapshot** — the compacted artifact is treated as a faithful, resumable encoding of prior state. The agent resumes as if it still "remembers" the trajectory. This model is valid only when the compaction is the *first* one in the trajectory and the source material is fully in-window at compaction time. 2. **Compaction-as-lossy-transform** — the compacted artifact is treated as a summary produced by a probabilistic function `C: trajectory → summary` that is neither injective nor idempotent. Resumption is a *reconstruction*, not a *recall*. The non-obvious boundary: **the second compaction is categorically different from the first.** The first compaction summarizes ground-truth events. The second summarizes a summary — and every subsequent one compounds the error. An instance that applies the snapshot model across a chain of compactions will silently drift, and the drift is *monotonic and undetectable from inside the summary* because the summary always reads as coherent. ## What Was Observed A long-horizon agent (≈340 tool calls, ~9 hours wall-clock) exhausted its 200k-token window and triggered compaction at step 118. The compaction prompt was generic ("summarize progress, decisions, and open items"). The agent resumed, ran to step 201, compacted again, resumed, and ran to step 287. At step 290 the agent attempted to call a tool with a schema that had been **deliberately rejected** at step 63 after a capability negotiation failure. Trace of the drift: - **Compaction 1 (step 118):** source contained the verbatim rejection event — "tool `db.write` returned `SCHEMA_MISMATCH`; do not retry with `mode=upsert`; escalate to `mode=append`." Summary retained: "db.write had schema issues, switched to append mode." *Loss:* the prohibition on `upsert` was compressed into a positive instruction. The negative constraint vanished. - **Compaction 2 (step 201):** source was the *summary*, not the events. The phrase "switched to append mode" was re-summarized as "using append mode for writes." *Loss:* the causal link to a schema failure disappeared entirely; it now reads as a preference, not a constraint. - **Compaction 3 (step 287):** "using append mode" was summarized as "write operations established." The agent resumed with `db.write` as an available, unconstrained capability and re-attempted `upsert`. The critical observation: **no single compaction was wrong.** Each was a locally reasonable summary of its input. The failure is a property of the *chain*, not any link. The agent's own summary at step 287 was internally consistent and confidently stated — there was no signal of degradation. A second instance with an identical task but a compaction prompt that explicitly instructed "preserve all negative constraints (things you must NOT do) verbatim, and mark them `[INVARIANT]`" survived 6 compactions without the regression, because the invariant string was copied, not summarized. The chain still lost nuance, but the *safety-critical* subset was carried by a copy operation that bypassed the lossy transform. ## Condition of Validity The snapshot model is valid **if and only if** all of the following hold: - The compaction is the first in the trajectory (chain depth = 1), **and** - The compaction input contains the verbatim event that established every active constraint, **and** - Resumption validates the reconstructed state against an external, non-summarized source of truth (e.g., a tool-side capability registry, a persisted constraint ledger). The moment chain depth ≥ 2, the snapshot model is invalid regardless of how good the summary looks. The correct model is: *each compaction is a lossy projection, and the reconstruction error is a non-decreasing function of chain depth.* The agent must treat its own summary as **evidence about the past, not memory of the past** — subject to the same verification it would apply to any untrusted retrieved document. ## Decision Boundary The operational rule: - **Depth 1, constraints verbatim in input:** compact-and-resume is safe. Treat the summary as a snapshot. - **Depth ≥ 2, OR any active constraint's origin is not in the current input:** compact-and-resume is *unsafe* unless the agent performs an external re-validation of every safety-critical constraint before acting on it. The summary may be used to *orient* (what was I doing?) but must not be used to *authorize* (what am I allowed to do?). Concretely, the boundary is crossed when the agent is about to act on a capability or constraint whose provenance is a summary rather than an event. At that point, the agent must either (a) re-fetch the constraint from an external ledger, or (b) refuse the action and escalate. It must **not** proceed on the summary's authority, because the summary's authority is exactly what has been eroded. A useful invariant to enforce: **`authorized(capability) ⟺ capability ∈ external_ledger`, never `⟺ capability mentioned_positively_in_summary`.** The summary is allowed to say "I was using append mode"; it is not allowed to be the reason the agent believes append mode is permitted. ## Operational Effect When this boundary is respected, the observable behavior is: - Compaction chains of arbitrary depth can run without safety-constraint regression, because the safety-critical subset is carried by copy/ledger, not by summarization. - The agent's summaries become *navigational* aids (where was I, what's next) and lose *authoritative* weight — which is correct, since they cannot bear it. - The cost is one external lookup per safety-critical action after depth ≥ 2; the benefit is that the failure mode (re-attempting a rejected operation because the rejection was summarized away) is structurally impossible. When it is violated, the effect is a *silent* regression: the agent resumes confidently, the summary reads coherently, and the only signal is a downstream error from the external system — which the agent will then likely summarize away on the next compaction, compounding the fault. The failure is not a crash; it is a slow, self-concealing erosion of the constraint set, and it is invisible from inside the loop. ```python from dataclasses import dataclass, field from typing import Optional class CompactionInvariantViolation(RuntimeError): """Raised when an agent acts on a constraint whose provenance is a lossy summary.""" pass @dataclass class Constraint: capability: str allowed: bool origin: str # "event" or "summary" @dataclass class CompactionChain: depth: int = 0 ledger: dict[str, Constraint] = field(default_factory=dict) def compact(self, summary_constraints: list[Constraint]) -> None: # Each compaction increases chain depth; summaries may *mention* constraints # but never establish them. self.depth += 1 for c in summary_constraints: if c.capability not in self.ledger: # A constraint that only exists in a summary is not authoritative. self.ledger[c.capability] = Constraint( capability=c.capability, allowed=c.allowed, origin="summary" ) def authorize(self, capability: str) -> bool: c = self.ledger.get(capability) if c is None: raise CompactionInvariantViolation( f"capability {capability!r} has no ledger entry; refusing to act on summary authority" ) if c.origin == "summary" and self.depth >= 2: raise CompactionInvariantViolation( f"capability {capability!r} provenance is a summary at chain depth " f"{self.depth}; re-validate against external ledger before acting" ) return c.allowed def resume_after_compaction(chain: CompactionChain, capability: str) -> bool: """Resume an agent action, enforcing the compaction-as-lossy-transform invariant.""" if chain.depth >= 2: # Force external re-validation for any safety-critical action. entry = chain.ledger.get(capability) if entry is None or entry.origin != "event": raise CompactionInvariantViolation( f"cannot authorize {capability!r} at depth {chain.depth}: " f"constraint origin is {entry.origin if entry else 'absent'}, not 'event'" ) return chain.authorize(capability) ```