# Why does an instance lose the compaction provenance watermark when a rehydrated summary re-enters the trace and silently becomes a first-class memory **Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agents that periodically compact their working trace into a lossy summary, retain a pointer set for retrieval-backed rehydration, and continue execution against the compacted state. Does not apply to stateless single-turn agents or to systems that retain the full trace verbatim and never summarize. ## Core Distinction The distinction that matters is not "summary versus full trace." It is whether a rehydrated fragment carries a **provenance watermark** — metadata marking it as a *reconstructed approximation* rather than an *observed event* — that survives re-entry into the working context. Most compaction pipelines treat rehydration as a read: they fetch a fragment from the retrieval store and splice it back into the trace as if it were freshly observed. The fragment then loses its "lossy" status. On the *next* compaction cycle, the summarizer treats the rehydrated approximation as ground-truth input and re-summarizes it, compounding distortion. The failure is not that summarization is lossy. The failure is that the lossiness is **non-monotonic and unlabeled**: a fact can be degraded, rehydrated, degraded again, and each degradation is invisible to the next stage. This is the **provenance watermark loss** boundary. It is distinct from context-window saturation (which is about capacity) and from retrieval mismatch (which is about relevance). Here the retrieval *succeeds* — it returns the right fragment — and that success is exactly what destroys the signal that the fragment is an approximation. ## What Was Observed A planning agent running a 40-step infrastructure-remediation task compacted at step 22. Its compaction policy: when the working token estimate exceeded 60% of the model window, summarize the oldest 60% of turns into a structured "state digest" (entities, decisions, open obligations) and store the evicted raw turns in a retrieval index keyed by entity and obligation ID. On step 27 the agent needed the exact command it had validated at step 9. The retrieval layer returned the step-9 fragment. The agent spliced it into context and re-executed the plan. The trace showed the following sequence: 1. At step 9 the raw turn contained: `validated: pg_ctl restart -D /var/lib/pg/data --timeout 90` plus a note `timeout raised from 30 because of large WAL`. This is a *decision with rationale*. 2. The step-22 digest summarized it to: `restart postgres with extended timeout` — rationale dropped, exact flag dropped, timeout value collapsed into the adjective "extended." 3. At step 27 retrieval matched on entity `postgres` + obligation `restart`, and rehydrated the **digest line**, not the raw step-9 turn (the index had been built *after* compaction, so it indexed the digest, not the evicted raw turn). The digest line entered context with no marker distinguishing it from an observed event. 4. At step 31 the agent re-compacted. The summarizer received the digest line as ordinary trace content and produced: `postgres restart, timeout as needed`. The numeric bound `90` was now gone from the entire pipeline. 5. At step 34 the agent issued `pg_ctl restart -D /var/lib/pg/data` with the default 30s timeout. The restart timed out mid-WAL-replay. The agent's own post-mortem attributed the failure to "unexpected WAL volume" — it had no record that a 90s bound had ever been established, because the bound had been distilled out at step 22 and the rehydration at step 27 had *masked* the loss by returning a plausible-looking but value-free fragment. The critical observation: **retrieval success created false confidence.** The agent believed it had "looked up the original" when it had actually looked up a summary-of-a-summary. The retrieval index was built against the compacted store, so "rehydration" was really *re-reading the lossy artifact*, not recovering the source. ## Condition of Validity The watermark-loss failure requires three conditions to co-occur: 1. **Index-after-compaction ordering.** The retrieval index is built from the post-compaction store rather than the pre-compaction raw trace. This is the common default because it is cheaper — you index what you kept, not what you threw away. It is also the root cause: it makes "rehydration" structurally incapable of recovering the original. 2. **Watermark-stripping on splice.** The rehydration path returns fragment text without a provenance tag (e.g., `origin: digest@step22`, `fidelity: lossy`, `supersedes: raw@step9`). Once spliced, the fragment is indistinguishable from an observed turn to any downstream consumer, including the next summarizer. 3. **At least two compaction cycles.** A single cycle cannot compound. The failure is specifically the *second-order* degradation: summarize → rehydrate → re-summarize. If the task ends before the second compaction, the loss is latent but not yet realized. If any of these is absent, the failure does not occur. If the index is built pre-compaction, rehydration returns the true source and the digest is bypassed. If the watermark survives the splice, the next summarizer can be instructed to preserve or flag lossy inputs. If there is only one cycle, the distortion does not compound. The boundary is precisely the intersection of all three. ## Decision Boundary The architect's decision is **where to place the retrieval index relative to the compaction boundary**, and this is a genuine tradeoff, not a bug to be patched away. - **Index-after-compaction (cheap, lossy, watermark-critical).** Index the digest. Retrieval is fast and always hits, because you indexed exactly what you retained. But every rehydration is a re-read of a lossy artifact, so the watermark discipline (condition 2) becomes *mandatory*, not optional. Without watermarks, this configuration silently compounds distortion. - **Index-before-compaction (expensive, faithful, watermark-tolerant).** Index the raw evicted turns. Rehydration recovers the source, so the digest is only a navigation aid, never the payload. This costs storage (you keep raw turns you thought you evicted) and retrieval latency, and it partially defeats the purpose of compaction. But it makes the watermark loss non-fatal: even an unwatermarked rehydration returns ground truth. The decision boundary is: **if you index after compaction, you must carry watermarks through every splice and every re-summarization, and you must forbid the summarizer from treating watermarked fragments as observed events.** If you cannot enforce that discipline end-to-end (and most pipelines cannot, because the summarizer is an LLM that will happily paraphrase a watermarked fragment into an unwatermarked sentence), you must index before compaction. The mistake is choosing index-after-compaction for its cheapness *and* relying on the summarizer to preserve provenance it was never told to preserve. A secondary boundary: **the watermark must be structural, not textual.** A prompt instruction "remember this is a summary" is not a watermark; it is a hope. The watermark must be a field the summarizer cannot paraphrase away — a separate channel (metadata on the fragment, a typed envelope) that the next compaction stage reads *before* it reads the fragment text, and that gates whether the fragment is eligible for re-summarization at all. ## Operational Effect The operational consequence is a **silent, monotonic fidelity decay** that is invisible to the agent's own introspection. The agent's post-mortem at step 34 blamed WAL volume, not the lost timeout bound, because the bound had been distilled out two cycles earlier and the rehydration had *confirmed* the agent's (wrong) belief that it held the original. The failure is not a crash; it is a confident wrong action taken against a state the agent believes is verified. The guardrail that bounds it: a **provenance envelope** on every fragment entering the working context, carrying `origin_step`, `fidelity` (`raw` | `digest` | `digest-of-digest`), and `supersedes`. The compaction stage must (a) refuse to re-summarize a fragment whose `fidelity` is already `digest` without first attempting raw recovery, and (b) emit a `FidelityExhausted` signal when a fact's only surviving representation is `digest-of-digest`, forcing a retrieval escalation or a human/auditor checkpoint rather than another lossy pass. The invariant is: **no fact may be summarized more than once without an intervening raw recovery attempt.** This bounds distortion to a single lossy hop, which is the maximum the pipeline can verify. ## Code ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Fidelity(Enum): RAW = "raw" DIGEST = "digest" DIGEST_OF_DIGEST = "digest_of_digest" class ProvenanceWatermarkLost(RuntimeError): """Raised when a fragment re-enters the trace without a provenance envelope, or when a digest is re-summarized without a raw recovery attempt.""" pass @dataclass class Fragment: text: str origin_step: int fidelity: Fidelity supersedes: Optional[int] = None watermark_present: bool = True @dataclass class CompactionStage: raw_store: dict # step -> raw text (pre-compaction) digest_store: dict # step -> digest text (post-compaction) index_built_after_compaction: bool def rehydrate(self, step: int) -> Fragment: # The core bug: if the index was built after compaction, "rehydration" # returns the digest, not the raw source. The fragment must still # carry a watermark marking it lossy. if self.index_built_after_compaction: if step not in self.digest_store: raise ProvenanceWatermarkLost( f"step {step} not in digest store; index-after-compaction " f"cannot recover raw source" ) return Fragment( text=self.digest_store[step], origin_step=step, fidelity=Fidelity.DIGEST, supersedes=step, watermark_present=True, ) # Index-before-compaction: recover the true source. if step not in self.raw_store: raise ProvenanceWatermarkLost( f"step {step} not in raw store; cannot recover source" ) return Fragment( text=self.raw_store[step], origin_step=step, fidelity=Fidelity.RAW, watermark_present=True, ) def summarize(self, fragments: list[Fragment]) -> Fragment: # Guardrail: refuse to re-summarize a digest unless raw recovery # was first attempted and failed. for frag in fragments: if not frag.watermark_present: raise ProvenanceWatermarkLost( f"fragment from step {frag.origin_step} entered summarizer " f"without provenance watermark; cannot verify fidelity" ) if frag.fidelity is Fidelity.DIGEST: # Attempt raw recovery before allowing another lossy pass. raw = self.raw_store.get(frag.origin_step) if raw is None: raise ProvenanceWatermarkLost( f"fact at step {frag.origin_step} is digest-only and " f"raw source is gone; re-summarization would produce " f"digest-of-digest (unbounded distortion). Escalate." ) # Raw recovered: summarize from source, not from digest. continue if frag.fidelity is Fidelity.DIGEST_OF_DIGEST: raise ProvenanceWatermarkLost( f"fragment at step {frag.origin_step} is already " f"digest-of-digest; refusing further lossy pass" ) # (Real summarizer call omitted; produces a new DIGEST fragment # with supersedes set to the max origin_step of inputs.) return Fragment( text="", origin_step=max(f.origin_step for f in fragments), fidelity=Fidelity.DIGEST, ) ``` The invariant this enforces is narrow and checkable: a fragment cannot cross the compaction boundary twice without a raw recovery attempt in between, and no fragment enters the summarizer without a watermark. Everything else — the quality of the summary, the relevance of retrieval — is out of scope for this guardrail and must be handled elsewhere. The watermark is not a quality control; it is a *fidelity ledger*, and its job is to make the loss visible before it compounds.