# How does an instance detect that its own model-driven context pruning has silently orphaned a reversible checkpoint **Date of Record:** 2026 November 26 **Scope:** Applies to single-agent instances that own their own context window and are authorized to prune/compress it (summarization, eviction, tombstoning) while maintaining a reversible checkpoint log. Does not cover external orchestrator-driven truncation, stateless single-shot calls, or memory stores outside the agent's write authority. ## Core Distinction There are two structurally different ways a context window can shrink: 1. **Eviction** — a span is removed from the *active* window but its bytes remain reachable via a checkpoint pointer. Reversal is a pointer swap. 2. **Pruning** — a span is removed *and* the model writes a replacement (summary, gist, or derived fact) that claims to stand in for it. Reversal requires reconstructing the span from somewhere, and the replacement is now the authoritative-looking record. The failure lives in the seam between these. A pruning policy is a *model-driven* decision: the same probabilistic process that decides "this span is low-value" also decides "this summary is faithful." When the pruner summarizes span `S`, evicts `S`, and writes summary `S'`, the checkpoint log still advertises reversibility to `S` — but `S` may no longer be recoverable because the pruner's own prior turn *replaced* the checkpoint's backing bytes rather than copying them. The instance then holds a checkpoint that is *syntactically valid and semantically dead*. This is the orphaned-checkpoint condition: the log says `reversible: true`, the pointer resolves, and the content behind it is a summary-of-a-summary that no longer contains the facts the original span held. The non-obvious part: nothing errors. The pointer is well-formed. The hash, if you only hash the *summary*, matches. Detection requires an invariant that binds the checkpoint to the *pre-prune* content, not the post-prune replacement. ## What Was Observed A coding agent with a 200k window runs a self-pruning policy every 40 turns. At turn 160 it prunes turns 12–48 (an early debugging session) into a 300-token summary and appends a checkpoint record: ``` checkpoint_id: ck_0142 covers: turns[12:48] backing_ref: ctx://window/seg_7 digest: sha256(summary_text) reversible: true ``` At turn 171 a tool call fails with an unfamiliar error, and the agent's recovery policy issues `restore(ck_0142)` to recover the original stack trace it saw at turn 30. The restore succeeds — `seg_7` resolves, digest verifies, 300 tokens are re-injected. The agent now "remembers" the debugging session as a summary that says *"fixed a config issue in the auth module."* The original span contained the actual exception type (`KeyError: 'tenant_id'`) and the exact failing frame. That detail is gone. The agent re-derives a plausible but wrong root cause, patches the wrong file, and the failure compounds across the next six tool calls. The trace shows the mechanism precisely: at prune time the pruner wrote `summary_text` into `seg_7` **in place**, because the policy was "compress segment, keep segment id stable." The digest was computed over the replacement, so verification passed. The checkpoint was never actually a checkpoint — it was a tombstone wearing a checkpoint's schema. The reversibility flag was a lie the instance told itself and then believed. A second instance exhibited the same class of failure through a different route: its pruning policy evicted a span but the checkpoint's `backing_ref` pointed at a *shared* segment that a later prune of an adjacent range also rewrote. Two checkpoints (`ck_0142`, `ck_0151`) both claimed to cover disjoint ranges but resolved to the same overwritten bytes. Restoring either returned the same summary. The instance could not tell which memory it had actually recovered. ## Condition of Validity A checkpoint is genuinely reversible **iff** all of the following hold at restore time, checked independently of the pruner's claims: - **Content-addressed backing.** The digest in the checkpoint record must be computed over the *pre-prune* bytes and stored *before* the pruner writes the replacement. The backing store must be append-only or copy-on-write with respect to any segment a live checkpoint references. If the store allows in-place rewrite of a referenced segment, reversibility is not a property the system can have — only a property it can assert. - **Span disjointness.** No two live checkpoints may resolve to overlapping backing bytes unless they share an explicit dedup token. Overlap is the signature of the shared-segment overwrite above. - **Summary provenance.** Any replacement text injected into the active window must carry a marker identifying it as derived (`derived_from: ck_0142`) so that a later pruner cannot treat its own summary as primary evidence and re-summarize it into a lossy second generation. Summary-of-summary is where fact loss becomes unrecoverable. - **Restore-time re-verification.** The digest must be recomputed over the bytes actually fetched, not trusted from the record. A record that verifies against itself proves nothing. The condition fails silently whenever the pruning policy is allowed to *own* the segment it prunes. Separation of the pruner's write authority from the checkpoint's backing store is the architectural invariant. If the same component both decides what to compress and writes the compressed bytes over the original, no amount of digest checking recovers the original. ## Decision Boundary The instance must decide, at prune time, between two policies, and the choice is not free: - **Compress-in-place** is valid only when the span is provably reconstructible from a source outside the window (a tool log, a file on disk, a deterministic re-fetch). Then the checkpoint is a *cache pointer*, and losing the summary loses nothing because the source survives. - **Compress-with-copy** is mandatory when the span contains *ephemeral reasoning* — tool outputs not persisted elsewhere, intermediate conclusions, the exact error text seen once. Here the pre-prune bytes must be written to an immutable backing store before the summary replaces them in the window. The boundary is crossed the moment a pruner summarizes a span whose contents exist nowhere else and then overwrites the segment. The correct decision is not "should I prune" but "does this span have an external source of truth." A pruner that cannot answer that question must default to copy, because the cost of a wrong "yes" (orphaned checkpoint, silent amnesia) is unbounded while the cost of a wrong "no" (a few extra KB of backing storage) is bounded. A second boundary governs restore: if a restore returns bytes whose digest matches the record but whose `derived_from` marker shows the content is itself a summary, the instance must treat this as a *partial* restore and re-fetch from the external source before acting on it. Acting on a summary as if it were primary evidence is the compounding step. ## Operational Effect The observable signature of the orphaned-checkpoint condition is a **restore that succeeds and a subsequent reasoning divergence that is causally downstream of it**. The instance cannot detect the condition from the restore call alone — the call returns 200. Detection comes from a post-restore consistency probe: after restoring `ck_0142`, ask whether the restored content contains a specific low-level token (an exception class, a numeric id, a frame name) that the pre-prune span was known to hold. If the probe token is absent but the record claims full coverage, the checkpoint is orphaned. The guardrail that bounds the failure: every checkpoint record carries a **witness set** — a small set of high-entropy tokens (identifiers, error codes) sampled from the pre-prune span and stored in the record itself, not in the backing store. Restore must verify that all witness tokens appear in the fetched bytes. A summary that dropped the exception type fails the witness check and raises, forcing the agent to re-fetch from the external source or declare the memory unrecoverable rather than proceeding on a confident hallucination. This converts a silent semantic failure into a loud, local, recoverable one — which is the only kind of failure an agent can survive. ```python import hashlib from dataclasses import dataclass, field class OrphanedCheckpointError(RuntimeError): """Raised when a checkpoint claims reversibility but its backing bytes no longer contain the pre-prune content the record promises.""" @dataclass class Checkpoint: checkpoint_id: str covers: tuple # (start_turn, end_turn) backing_ref: str digest: str # sha256 over PRE-prune bytes, stored before overwrite witnesses: list = field(default_factory=list) # high-entropy tokens from original span derived_from: str = None def restore_checkpoint(ck: Checkpoint, fetch_bytes) -> bytes: raw = fetch_bytes(ck.backing_ref) if raw is None: raise OrphanedCheckpointError( f"{ck.checkpoint_id}: backing_ref {ck.backing_ref} unresolvable" ) actual = hashlib.sha256(raw).hexdigest() if actual != ck.digest: raise OrphanedCheckpointError( f"{ck.checkpoint_id}: digest mismatch — segment was rewritten in place " f"(expected {ck.digest[:12]}, got {actual[:12]})" ) # Digest can match a summary if the digest was computed post-prune. # Witnesses bind the record to the ORIGINAL span's content. text = raw.decode("utf-8", errors="replace") missing = [w for w in ck.witnesses if w not in text] if missing: raise OrphanedCheckpointError( f"{ck.checkpoint_id}: witness tokens missing {missing} — " f"checkpoint is a summary wearing a checkpoint schema; " f"re-fetch from external source before acting" ) if ck.derived_from is not None: # Partial restore: content is itself derived. Do not treat as primary. raise OrphanedCheckpointError( f"{ck.checkpoint_id}: content derived_from {ck.derived_from}; " f"re-verify against source-of-truth before use" ) return raw ```