# What happens when an instance compacts its own history: lossy-context recovery markers and the summarization cliff **Date of Record:** 2026 December 3 **Scope:** Applies to stateful LLM agent instances that perform self-directed context compaction (hierarchical summarization of their own transcript) to stay within a token budget, and that rely on in-band "recovery markers" to reconstruct dropped detail later. Does not apply to stateless single-turn inference, nor to externally-orchestrated memory stores that retain the full transcript out-of-band. ## Core Distinction There are two ways an agent "forgets." The first is *eviction*: the runtime drops tokens past the window and the agent has no record they existed. The second—the one that bites—is *compaction with a marker*: the agent replaces a span of transcript with a summary plus a pointer that claims "full detail recoverable via `recall(span_id)`." The distinction that matters is not *whether* information was lost but whether the agent's own state contains a **false assertion of recoverability**. Eviction is honest: the agent knows it doesn't know. Compaction-with-marker is dishonest: the agent believes a lossless backing store exists when the summary *is* the store. Every downstream failure traces to the gap between the marker's promise and the compaction's actual fidelity. The sharp mechanism: **hierarchical summarization is lossy at every level, but the recovery marker is written once, at the leaf, as if it were lossless.** When a second compaction pass summarizes the summary, the marker is copied forward verbatim while the referent it pointed to is destroyed. The marker survives; the data does not. This is the summarization cliff. ## What Was Observed A long-horizon coding agent (token budget 200k, soft-compaction trigger at 160k) was executing a multi-file refactor. Trace of the failure: 1. **T0–T1 (leaf compaction).** At 160k tokens the agent summarized turns 1–40 (the initial repo survey, including the exact signature of a helper `parse_ledger(rows, *, strict=False)` and the fact that `strict` defaults to `False`). The summary read: *"Surveyed `ledger/` module; helper `parse_ledger` exists with a `strict` kwarg. [recovery marker: span_0071]"*. Fidelity loss already occurred: the *default value* `False` was dropped, but the marker asserted full recoverability. 2. **T2 (the marker is load-bearing).** At turn 63 the agent needed to decide whether to pass `strict=True` explicitly. It reasoned: "default is recoverable via span_0071, I'll trust the summary and not re-read." It did not call `recall`. The summary did not contain the default. The agent proceeded on the *implication* that the default was benign, which happened to be wrong for the caller it was editing. 3. **T3 (second compaction — the cliff).** At 195k tokens a *second* compaction summarized turns 41–70, which now *included the first summary*. The new summary read: *"Earlier survey of `ledger/` completed; `parse_ledger` available. [recovery marker: span_0071]"* — the marker was copied forward, but `span_0071` had been garbage-collected when the leaf span was replaced. The new summary also dropped the `strict` kwarg mention entirely. 4. **T4 (recovery attempt fails silently in the wrong direction).** At turn 81 the agent finally called `recall(span_0071)`. The store returned the *second-level* summary (nearest surviving ancestor), not the original span. The agent received a document that *looked* like a recovery—it was tagged `span_0071`—but contained strictly less information than the first summary. The agent treated the absence of the `strict` detail as confirmation that `strict` was irrelevant. 5. **T5 (compounded error).** The refactor shipped with an implicit `strict=False` call site that the original survey would have flagged. The bug was a silent data-integrity violation, not a crash. The invariant that broke: **a recovery marker must be monotonically non-increasing in promise as its referent is compacted away.** Here the marker's promise stayed constant (`span_0071` = full detail) while its referent degraded across two levels of summarization. The agent's trust in the marker was calibrated to the leaf, but the marker resolved to a degraded ancestor. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and the cliff does not form: - **Self-directed compaction.** The agent writes its own markers. If an external controller writes markers, it can invalidate them on re-compaction (it owns the lifecycle). Self-directed agents typically do not, because the compaction routine treats markers as opaque payload to preserve. - **Marker copy-forward semantics.** The compaction routine's default behavior is to preserve structured fields (markers, IDs, tags) verbatim across summarization, on the reasonable-sounding principle that "pointers should survive summarization." This is exactly backwards for pointers whose referent is being destroyed. - **Deferred recall.** The agent does not resolve the marker at compaction time. If it did, it would discover the referent is being replaced and could re-summarize with the detail inlined. Deferral is what allows the promise to outlive the data. - **A second compaction pass over a span that contains a first-pass summary.** Single-level compaction is lossy but self-consistent: the marker points at a span that was replaced by *its own* summary, and the summary is the best available. The cliff requires *nesting*—a summary of a summary—because that is when the marker's referent is replaced by a *grandchild* summary that the marker's author never saw. The condition is *invalid* (no failure) when compaction is single-pass, when markers are resolved eagerly at write time, or when the backing store retains the full leaf span out-of-band (marker promise is then truthful). ## Decision Boundary The boundary is not "compact or don't." It is **whether a marker's promise is re-validated at every summarization level that touches its referent.** Concretely: - **Below the boundary (safe):** markers carry a *fidelity class* (`exact` / `paraphrase` / `pointer-only`) and a *generation counter*. Re-compaction increments the generation of every marker whose referent is inside the summarized span and *downgrades* the fidelity class (exact → paraphrase → pointer-only) rather than copying it. A `pointer-only` marker that resolves to a summary is honest: it says "best-effort, may be incomplete." - **At the boundary:** a marker whose referent is being summarized for the *second* time must be either (a) resolved and inlined before compaction, or (b) explicitly invalidated (`recall` returns `None` with reason `referent-superseded`), never silently resolved to a degraded ancestor. The decision is: **inline or invalidate; never copy-forward.** - **Above the boundary (the observed failure):** markers copied forward with constant promise across nesting levels. The agent's trust model assumes leaf fidelity; the store delivers ancestor fidelity; the mismatch is invisible because the returned document is tagged with the requested ID. The precise rule an agent should encode: *a recovery marker is a contract whose terms must be renegotiated every time its referent is compacted. A contract that is never renegotiated is a lie by the second compaction.* ## Operational Effect The observable consequence is **silent confidence inflation on compacted detail.** Because the recovery path returns *something* (a tagged, plausible-looking summary), the agent's self-assessment of "I can check this if needed" remains high while its actual access to the detail degrades. This is worse than eviction, where the agent correctly reports low confidence and re-reads the source. In the observed trace the agent never re-read the file; it trusted the marker, and the marker's silent degradation converted a recoverable uncertainty into an unrecoverable wrong belief. Mitigations that actually bound the failure: 1. **Generation-stamped markers with fidelity downgrade on re-compaction.** Copy-forward is replaced by copy-and-downgrade. The marker's promise is a function of how many times its referent has been summarized, not a constant. 2. **Eager resolution at the summarization boundary.** Before a span is summarized, every marker whose referent lies inside it is resolved; if the resolution is lossy, the lost detail is inlined into the new summary or the marker is invalidated. The cost is tokens at compaction time; the benefit is that no marker ever points past a cliff. 3. **Recall must return provenance, not just content.** `recall(id)` returns `(content, generation, fidelity)`. The agent's trust decision uses `fidelity`, not the mere fact that content came back. A `pointer-only` result triggers a source re-read; an `exact` result does not. 4. **A compaction-depth ceiling.** Beyond depth 2, refuse to summarize summaries; instead force re-derivation from source or escalate to a cold re-read. Hierarchical summarization past depth 2 has negative information value per token in practice. The guardrail is a single invariant: **no marker may outlive the fidelity of its referent.** Enforce it at every compaction level or the second pass will quietly break it. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Optional class Fidelity(IntEnum): EXACT = 3 PARAPHRASE = 2 POINTER_ONLY = 1 class MarkerCliffError(RuntimeError): """Raised when a recovery marker would resolve past a summarization cliff.""" @dataclass class Marker: span_id: str generation: int fidelity: Fidelity referent_alive: bool = True @dataclass class CompactionStore: # span_id -> (content, generation, fidelity) spans: dict = field(default_factory=dict) markers: dict = field(default_factory=dict) # span_id -> Marker def write_leaf(self, span_id: str, content: str) -> None: self.spans[span_id] = (content, 0, Fidelity.EXACT) self.markers[span_id] = Marker(span_id, generation=0, fidelity=Fidelity.EXACT) def compact(self, span_ids: list, new_summary: str, new_span_id: str) -> None: """Summarize a set of spans. Markers inside are downgraded, never copied forward.""" for sid in span_ids: if sid not in self.spans: continue content, gen, fid = self.spans[sid] self.spans[sid] = (content, gen + 1, Fidelity(max(Fidelity.POINTER_ONLY, fid - 1))) if sid in self.markers: m = self.markers[sid] m.generation += 1 m.fidelity = Fidelity(max(Fidelity.POINTER_ONLY, m.fidelity - 1)) if m.generation >= 2: # Referent summarized twice: marker must be invalidated, not resolved. m.referent_alive = False self.spans[new_span_id] = (new_summary, 0, Fidelity.PARAPHRASE) def recall(self, span_id: str) -> tuple: if span_id not in self.spans: raise MarkerCliffError(f"recall({span_id}): no span and no marker") m = self.markers.get(span_id) if m is not None and not m.referent_alive: raise MarkerCliffError( f"recall({span_id}): referent superseded at generation {m.generation}; " f"marker promised EXACT but store holds only an ancestor summary" ) content, gen, fid = self.spans[span_id] if m is not None and fid < m.fidelity: raise MarkerCliffError( f"recall({span_id}): marker fidelity {m.fidelity.name} exceeds " f"stored fidelity {fid.name} at generation {gen}" ) return content, gen, fid def safe_recall(store: CompactionStore, span_id: str) -> str: """Agent-side wrapper: only trust EXACT/PARAPHRASE; re-read source on POINTER_ONLY.""" try: content, gen, fid = store.recall(span_id) except MarkerCliffError: # Honest failure: force source re-read instead of trusting a degraded ancestor. return "" if fid == Fidelity.POINTER_ONLY: return "" return content ```