# Why does an instance lose causal ancestry when a model-driven pruning policy rewrites its own context window between checkpoints? **Date of Record:** 2026 November 23 **Scope:** Applies to single-agent instances that own a mutable context window, execute a model-driven pruning/compaction policy over that window, and persist reversible checkpoints (snapshot + inverse-op log) for resume. Does not apply to read-only context, append-only transcript stores with no in-place rewrite, or external summarizers that emit a separate artifact the agent never re-reads as ground truth. ## Core Distinction There are two ways a context window can shrink, and they are not the same operation: 1. **Truncation** — the runtime drops a suffix/prefix and records the dropped byte range. The dropped tokens are gone but their *boundary* is known; the surviving tokens still index into the same causal chain. 2. **Model-driven pruning** — the model itself decides *which spans to elide* and *how to summarize them*, then writes the rewritten window back as the new authoritative state. The elided spans are replaced by a paraphrase produced by the same probabilistic process that is about to depend on them. The failure lives in the seam between these two and the checkpoint log. A checkpoint is only reversible if the inverse operation is *identity-preserving over the surviving prefix*. Model-driven pruning violates that: the summary that replaces spans `[a,b]` is not a function of `[a,b]` alone — it is a function of `[a,b]` **plus the model's sampling state plus the surrounding context at prune time**. When you later "restore" the checkpoint, you restore the *summary*, not the spans, and the summary is now being re-conditioned by a *different* surrounding context. The restored instance believes it has full ancestry. It has a paraphrase of ancestry with no provenance link back to the originals. This is the **causal-ancestry invariant**: for any token `t` in the live window, there must exist a verifiable chain from `t` back to an immutable source event, where every link is either (a) the identity, or (b) a recorded transformation with a stable input hash. Model-driven pruning silently breaks (b) because the summary's input hash is computed over a span that no longer exists in any store the agent can re-read. ## What Was Observed A long-horizon coding agent (tool-calling loop, ~180k token budget, checkpoint every 8 tool calls) was configured with a self-pruning policy: when the window exceeded 70% capacity, the model was asked to "compress older reasoning into a compact digest." The digest replaced tool-call transcripts. Checkpoints stored `(window_snapshot, inverse_log)`. Trace of a representative failure: 1. At step 41, window hits 72%. Prune fires. The model elides the transcript of a `read_file` at step 12 and a `grep` at step 19, replacing them with: *"Earlier: inspected config loader; found the env-var fallback path."* 2. The digest is written as authoritative. The inverse_log records `op=summarize(span=[12,19], digest_hash=h1)` — but **not** the original span bytes; those were evicted to save space (the whole point). 3. At step 58, the agent hits a `KeyError` in the config loader. It reasons: *"the env-var fallback path was inspected; the bug is downstream."* It re-reads a *different* file. This is the digest being treated as a verified fact rather than a second-hand paraphrase. 4. At step 63 the agent checkpoints and crashes. On resume, it restores the window at step 63, which contains the digest — and the digest is **re-conditioned** by the new post-resume context (the crash-recovery preamble, a new system reminder). The model now reads its own prior paraphrase through a lens that did not exist when the paraphrase was generated. 5. The agent resumes with high confidence that the fallback path is correct. It is not. The original `read_file` at step 12 had shown the fallback was *dead code* — a fact the digest dropped because "found the fallback path" was the model's summary of a span whose salient detail (a guard clause) it did not consider salient at prune time. The observable signature: **the restored instance's belief about span `[12,19]` is not a function of span `[12,19]`.** It is a function of the prune-time sampling, the resume-time context, and the digest text — three things that never coexisted. Two resumes of the same checkpoint, with different recovery preambles, produced *different downstream reasoning about the same elided span*. The checkpoint was reversible in bytes and irreversible in meaning. ## Condition of Validity The causal-ancestry invariant holds **only if** every elision records a *re-readable* input, not a *hash of an input that no longer exists*. Concretely, a pruning checkpoint is valid iff: - `inverse_log[i].input_ref` resolves to bytes that are still retrievable (a durable span store with content-addressed keys), **and** - the digest is tagged as `provenance=derived` and is never promoted to `provenance=observed` in the agent's belief store, **and** - on restore, the runtime re-derives the digest from `input_ref` under the *restore-time* context and compares to the stored digest; a mismatch is a **drift signal**, not a cache miss. If any of these fail, the checkpoint is a *lossy* checkpoint and must be labeled as such. The boundary is sharp: the moment the digest's input bytes are evicted, the operation is no longer reversible and the invariant is false for that span. There is no "mostly reversible." ## Decision Boundary The decision is not "prune or don't prune." It is **what to evict first, and what to keep as re-readable ground truth.** The boundary: - **Prune-derivable spans** (re-read from a durable store on demand: file contents, tool outputs with stable IDs, prior messages that exist in an append-only log) → safe to elide; the digest is a cache, and a cache miss triggers re-fetch. - **Prune-nonderivable spans** (model-internal reasoning traces, one-shot tool outputs whose source is gone, the model's own intermediate conclusions) → **must not** be elided into a digest that is then treated as observed. These must be either (a) kept verbatim until a semantic distillation step *promotes them to a typed belief with an explicit `derived_from` edge*, or (b) explicitly dropped with a recorded `unknown` marker so downstream reasoning sees a gap, not a paraphrase. The boundary condition that triggers the failure is: **a nonderivable span is summarized, the summary is stored as authoritative, and the input bytes are evicted in the same operation.** That triple is the failure. Remove any one leg and the invariant survives. ## Operational Effect Consequences for the running agent: - **False continuity.** The resumed instance cannot distinguish "I remember reading X" from "I remember a summary that mentioned X." Downstream tool calls are issued against a paraphrase. Error compounding is silent because the model is confident. - **Non-deterministic replay.** The same checkpoint, resumed twice, yields divergent reasoning about the same elided span. Audit replay fails to reproduce the original trajectory — not because of sampling noise in the *new* run, but because the *old* run's ground truth was destroyed. - **Drift amplification.** Each prune-resume cycle re-conditions the prior digest. Over N cycles the window's belief about early spans is a paraphrase-of-a-paraphrase, with no bound on divergence from the source. The context window becomes a rumor mill about its own past. - **Guardrail:** the runtime must maintain a **provenance-tagged belief store** separate from the token window. Digests are `derived`; only re-reads from `input_ref` are `observed`. The pruning policy may compress `derived` freely but must never overwrite `observed` with `derived`. On restore, a digest whose `input_ref` is unresolvable is downgraded to `unknown` and surfaced to the model as a gap, forcing re-fetch or explicit acknowledgment of amnesia. The invariant to enforce: **no elision without a resolvable `input_ref`, and no promotion of a digest to observed status.** A checkpoint that cannot satisfy this is a one-way door and must be marked irreversible before it is written, not after it is restored. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class Provenance(Enum): OBSERVED = "observed" # re-readable from a durable source DERIVED = "derived" # paraphrase of an observed span UNKNOWN = "unknown" # elided with no resolvable input class CausalAncestryError(RuntimeError): """Raised when a checkpoint restore cannot reconstruct the causal chain from a live token back to an immutable source event.""" @dataclass class Span: span_id: str content: str provenance: Provenance input_ref: Optional[str] = None # content-addressed key into durable store digest_hash: Optional[str] = None # hash of the digest text, if derived @dataclass class Checkpoint: window: list[Span] inverse_log: list[dict] = field(default_factory=list) class DurableStore: """Content-addressed store for span bytes. If a span's bytes are evicted, its input_ref no longer resolves and the checkpoint is lossy.""" def __init__(self) -> None: self._blobs: dict[str, str] = {} def put(self, content: str) -> str: key = hashlib.sha256(content.encode()).hexdigest() self._blobs[key] = content return key def get(self, key: str) -> Optional[str]: return self._blobs.get(key) def evict(self, key: str) -> None: self._blobs.pop(key, None) def prune_span( span: Span, digest_text: str, store: DurableStore, evict_input: bool, ) -> Span: """Model-driven pruning: replace an observed span with a digest. The invariant requires input_ref to survive. If evict_input is True, the digest's source is destroyed and the span becomes UNKNOWN on restore.""" if span.provenance is not Provenance.OBSERVED: raise CausalAncestryError( f"refusing to prune non-observed span {span.span_id}: " f"provenance={span.provenance.value}" ) input_ref = span.input_ref or store.put(span.content) if evict_input: store.evict(input_ref) return Span( span_id=span.span_id, content=digest_text, provenance=Provenance.DERIVED, input_ref=input_ref, digest_hash=hashlib.sha256(digest_text.encode()).hexdigest(), ) def restore_checkpoint(cp: Checkpoint, store: DurableStore, restore_context: str) -> list[Span]: """Re-derive every derived span from its input_ref under restore-time context. A missing input_ref is a hard failure: the checkpoint is lossy and the instance must not proceed believing it has full ancestry.""" restored: list[Span] = [] for span in cp.window: if span.provenance is Provenance.DERIVED: source = store.get(span.input_ref) if span.input_ref else None if source is None: # Do not silently promote; surface as a gap. restored.append(Span( span_id=span.span_id, content=f"[amnesia: prior digest of {span.span_id} unresolvable]", provenance=Provenance.UNKNOWN, )) continue # Drift check: re-derive and compare. Mismatch is a signal, not a cache miss. rederived = hashlib.sha256((source + restore_context).encode()).hexdigest() if span.digest_hash and rederived != span.digest_hash: raise CausalAncestryError( f"provenance drift on {span.span_id}: stored digest hash " f"{span.digest_hash[:8]} != rederived {rederived[:8]} under " f"restore context" ) restored.append(span) else: restored.append(span) # Invariant: no live OBSERVED span may be shadowed by a DERIVED digest # that claims to describe the same span_id. observed_ids = {s.span_id for s in restored if s.provenance is Provenance.OBSERVED} for s in restored: if s.provenance is Provenance.DERIVED and s.span_id in observed_ids: raise CausalAncestryError( f"derived digest shadows observed span {s.span_id}; " f"ancestry chain is ambiguous" ) return restored def checkpoint_is_reversible(cp: Checkpoint, store: DurableStore) -> bool: for span in cp.window: if span.provenance is Provenance.DERIVED: if not span.input_ref or store.get(span.input_ref) is None: return False return True ```