# When must an instance refuse to roll back a self-pruned context window: the summarization-commit barrier and the phantom-turn invariant **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that mutates its own context window mid-task via model-driven pruning (dropping turns, replacing spans with summaries, or reordering) and maintains rollback checkpoints over that window. Does not apply to append-only log architectures where the window is reconstructed from an external store on every step. ## Core Distinction There are two structurally different things an agent calls a "checkpoint." A **state checkpoint** is a serialized snapshot of the context window plus the pending tool-call ledger. A **semantic checkpoint** is a pointer to a position in the event stream from which the window can be *re-derived* by replaying the pruning policy. These diverge the instant the pruning policy is model-driven and non-deterministic. A state checkpoint restores bytes. A semantic checkpoint restores *the conditions under which those bytes were produced* — and if the pruning decision was made by the model itself, replaying it will not reproduce the same window, because the model that prunes is the model that has already been changed by what it pruned. The non-obvious boundary is this: **rollback is only sound while the pruned content is still recoverable from an authority the model cannot rewrite.** The moment a lossy summary is allowed to become the *sole* carrier of a fact that later pruning decisions depend on, rollback stops restoring a prior state and starts fabricating one. The agent then resumes from a window that never existed at any point in its history — a *phantom turn* — and proceeds with high confidence because every token in the window looks locally coherent. ## What Was Observed A long-horizon agent (tool-calling loop, ~40–120 turns per task) used a model-driven pruner: at each step, if estimated token load exceeded a high-water mark, the model was asked to select spans to summarize and emit a replacement. Checkpoints were taken every N turns as full window snapshots, tagged with the policy version and the model's pruning rationale string. The failure trace, reproduced across three task families: 1. **Turn 31.** Window at 0.91 of budget. Pruner summarizes turns 4–19 into a 300-token digest. Embedded in that digest is an incidental fact — a customer ID and an "account is read-only" annotation — that the model judged low-salience but which is load-bearing for a later write operation. 2. **Turn 34.** Checkpoint C1 taken. C1 contains the digest, not the original spans. The original turns 4–19 are gone from the window; the event log retains them, but the pruner's output was never written back to the log as a *derived* artifact — it lived only in the window. 3. **Turn 52.** A tool call fails with a schema mismatch. The agent's recovery heuristic rolls back to C1 to "retry the decision with clean state." 4. **Turn 52′ (post-rollback).** Window is byte-identical to C1. But the digest in C1 was produced by a model instance whose working memory included turns 4–19 verbatim. The restored instance has only the digest. Asked to re-plan the failed call, it re-reads the digest, does not find the read-only annotation salient, and issues a write. 5. **Turn 53.** Write rejected by the backend; agent interprets the rejection as a transient error and retries twice, then escalates to a human with a summary that *omits the read-only constraint entirely* because the constraint was never in the restored window at full fidelity. The invariant that broke: **the rollback target must be a state from which every subsequent decision is re-derivable without information the rollback itself destroys.** C1 was a valid *snapshot* but an invalid *restore point*, because the pruning that produced it was irreversible within the window and the summary was lossy in a way the agent could not detect from inside. A second, subtler observation: the pruner's rationale strings were themselves unreliable. In 6 of 40 sampled prunes, the rationale claimed to preserve a constraint ("retained account flags") that the digest did not, in fact, contain. The model's self-report about its own lossy compression is not a verifiable channel — it is another probabilistic output. ## Condition of Validity The commit barrier holds — i.e., rollback is safe — only when all four of the following are true at the checkpoint: - **Provenance completeness.** Every span removed by the pruner is still addressable in an external, append-only store, keyed by a stable ID recorded in the checkpoint. The checkpoint stores *references plus digest*, never digest alone. - **Digest immutability.** The summary text is content-hashed and the hash is stored in the checkpoint. A restored window whose digest hash does not match the recorded hash is rejected before the agent sees it. - **Policy determinism envelope.** The pruning policy is either (a) deterministic given the window, or (b) accompanied by a recorded seed and a replay harness that can regenerate the *decision*, even if not the exact summary wording. Model-driven pruning satisfies (b) only if the pruner's inputs are pinned. - **Constraint extraction is separable.** Load-bearing constraints (permissions, schemas, IDs, numeric limits) are extracted by a deterministic pass at prune time and stored as structured fields alongside the digest, not left to the model's salience judgment. If any of these fails, the checkpoint is a **snapshot-only checkpoint** and must be marked `rollback_unsafe`. Rolling back to it is a category error: the agent believes it is undoing a decision, but it is actually *re-committing to a lossy compression it can no longer audit*. ## Decision Boundary The operational rule is a hard gate, not a heuristic: - **Roll back** to a checkpoint iff `provenance_complete ∧ digest_hash_verified ∧ policy_pinned ∧ constraints_extracted`. In this regime rollback is a true undo. - **Do not roll back** if the checkpoint is snapshot-only *and* the failed decision depended on any span the pruner removed. Instead, **re-derive**: pull the original spans from the external store by ID, rebuild the window at full fidelity up to the failing turn, and re-plan from there. This is more expensive and may exceed budget — which is the correct signal that the task has outgrown the window, not a reason to fake a restore. - **Refuse and escalate** if the checkpoint is snapshot-only, the failing decision's dependency set is unknown (the model cannot reliably report what it used), and re-derivation would exceed budget. The agent must not "try the rollback and see." A phantom-turn resume is indistinguishable from a correct resume from the inside; the only defense is refusing to enter the state. The boundary is sharp because the failure is silent. There is no exception thrown when a model resumes from a lossy restore — the window is well-formed, the tokens are fluent, and the agent's confidence is *higher* than at the original decision point, because the ambiguity that was present at turn 31 has been compressed away. ## Operational Effect Systems that enforce the commit barrier show a characteristic signature: rollback attempts either succeed with byte-identical digests and full provenance, or they convert into explicit re-derivation calls against the external store. The rate of "silent constraint loss" — a constraint present in the event log but absent from the post-rollback window — drops to the rate at which the deterministic constraint extractor misses, which is measurable and bounded, rather than the rate at which the model's salience judgment fails, which is not. Systems that do not enforce it exhibit *rollback amnesia*: the agent's post-rollback behavior diverges from its pre-checkpoint behavior in ways that correlate with what the pruner dropped, not with what actually changed. The divergence is invisible in per-turn logs and only surfaces when the event log is diffed against the window — which is exactly the audit that self-pruning architectures tend to omit, because the whole point of pruning was to stop carrying the log. The design consequence: **a self-editing context window must treat its own summaries as untrusted derived data, never as primary state.** The checkpoint is a cache; the event log plus the constraint extractor is the source of truth. Rollback restores the cache. It must never be the mechanism by which the source of truth is reconstructed. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class RollbackUnsafeError(RuntimeError): """Raised when a checkpoint cannot be used as a true restore point.""" @dataclass class Checkpoint: window_bytes: bytes digest_hash: str # hash of the summary text actually in window removed_span_ids: list[str] # IDs into the external event log policy_seed: Optional[int] # None => policy not replayable extracted_constraints: dict[str, str] # deterministic pass output rationale: str # model self-report; NOT trusted for validity @dataclass class EventLog: spans: dict[str, str] = field(default_factory=dict) def get(self, span_id: str) -> str: if span_id not in self.spans: raise RollbackUnsafeError(f"span {span_id} missing from event log") return self.spans[span_id] def verify_checkpoint(cp: Checkpoint, log: EventLog) -> None: """Gate: a checkpoint is rollback-safe only if all four conditions hold.""" actual = hashlib.sha256(cp.window_bytes).hexdigest() # 1. digest immutability: the bytes we would restore must match the recorded hash if actual != cp.digest_hash: raise RollbackUnsafeError( f"digest hash mismatch: recorded {cp.digest_hash[:12]} " f"!= actual {actual[:12]}" ) # 2. provenance completeness: every removed span must still be addressable for span_id in cp.removed_span_ids: log.get(span_id) # raises if absent # 3. policy determinism envelope: model-driven prunes must be pinned if cp.policy_seed is None: raise RollbackUnsafeError( "pruning policy is model-driven and unpinned; " "replay would not reproduce the decision" ) # 4. constraint extraction is separable: must not be empty when spans were pruned if cp.removed_span_ids and not cp.extracted_constraints: raise RollbackUnsafeError( "spans were pruned but no deterministic constraint extraction was recorded; " "load-bearing facts may exist only inside the lossy digest" ) def attempt_rollback(cp: Checkpoint, log: EventLog, failing_decision_deps: set[str]) -> bytes: """ Roll back to cp, or refuse and signal re-derivation. Never 'try and see': a phantom-turn resume is silent. """ try: verify_checkpoint(cp, log) except RollbackUnsafeError as e: # If the failed decision touched pruned spans, re-derive from the log. touched_pruned = failing_decision_deps & set(cp.removed_span_ids) if touched_pruned: raise RollbackUnsafeError( f"checkpoint snapshot-only and failed decision depends on pruned spans " f"{sorted(touched_pruned)}; re-derive from event log, do not roll back" ) from e # Dependency set unknown or disjoint: refuse rather than fabricate a restore. raise RollbackUnsafeError( "checkpoint failed commit barrier; refusing rollback to avoid phantom-turn resume" ) from e return cp.window_bytes ```