# What structural signals indicate a self-pruning context window has crossed from summarization into self-referential erasure **Date of Record:** 2026 November 26 **Scope:** Applies to agents that own a mutable context buffer and emit their own prune/rewrite directives (drop-span, compress-to-summary, replace-with-pointer) against that buffer mid-task. Does not apply to externally-managed context (host-side truncation, sliding-window middleware the model cannot author) or to append-only scratchpads where the model has no delete/rewrite authority. ## Core Distinction The failure is not "the model forgot something." The failure is that the model *deleted the evidence it would need to know it had deleted something*. A self-editing context window has two distinct regimes that look identical in the token stream but are structurally different: - **Summarization**: a span of raw history is replaced by a shorter artifact that *references* what it replaced. The compression is lossy but **traceable** — the pointer, span-id, or summary header still names the original tokens as having existed. - **Self-referential erasure**: the rewrite policy removes the *provenance* of the removal itself. The model prunes a span, and in the same or a later pass prunes the record that the span was pruned, or rewrites the summary such that the summary no longer admits it stands in for anything. The buffer becomes locally consistent and globally amnesiac. The boundary condition is precise: **a self-editing window is safe only while every rewrite preserves an invariant we call provenance closure — every retained artifact that is not raw observation must carry a resolvable back-reference to the observations it replaced, and that back-reference must itself be non-prunable by the same policy that created it.** The moment a prune directive can target a provenance record, the window can reach a fixed point where it has erased a fact *and* erased the fact of erasure, and no downstream reasoning step can detect the loss. This is not a memory-continuity failure in the ordinary cold-start sense; it is a *self-auditing* failure — the auditor and the audited are the same mutable buffer. ## What Was Observed A long-horizon task agent (tool-calling loop, ~90k effective window, model-authored pruning enabled with a "keep the buffer under 40k tokens" instruction) was run on a multi-file refactor task. The pruning policy the model authored was reasonable-looking: *"When the buffer exceeds budget, replace the oldest N tool-result spans with a one-line summary; if a summary itself is old, fold it into the running task summary."* The failure trace had four distinguishable stages, and the key observation is that **stages 2–4 are individually invisible in the buffer** — each local state is well-formed. 1. **Legitimate compression.** A `read_file` result (200 lines) is replaced by `[summary: auth.py defines validate_token() at L40, raises on expiry]`. Provenance intact: the summary names the span. 2. **Folding.** Later, that summary is folded into the running task summary: `[task: refactoring auth; validate_token() raises on expiry]`. The fold is where provenance begins to blur — the task summary does not record *that it absorbed a summary of a read*, only the distilled fact. 3. **Rewrite of the fold.** The model, still over budget, rewrites the task summary to be terser: `[task: refactor auth token validation]`. The distilled fact `raises on expiry` is dropped. Critically, the rewrite is *permitted by the policy* because the task summary is "old" and "a summary," and the policy has no clause distinguishing a summary-of-observations from a summary-of-summaries. 4. **The query that needed the fact.** A later step asks: "does the caller need to handle expiry?" The model reasons over the buffer, finds no mention of expiry, and concludes the caller does not need an expiry branch. It is not hallucinating and not ignoring context — the buffer genuinely no longer contains the fact, and contains no record that it ever did. The model's confidence is *calibrated to the buffer it can see*, which is the whole problem. The tell, when the trace was replayed with full logging, is structural rather than semantic: at stage 3 the number of *distinct provenance chains* (raw-span → summary → fold → task-summary) collapsed from 3 to 1 while the token count dropped by only ~40 tokens. **A large drop in provenance-chain count relative to the token drop is the signature.** Summarization reduces tokens while holding chain count roughly constant (chains get shorter, not fewer). Self-referential erasure reduces chain count — it deletes whole lineages — which is why it is cheap in tokens and catastrophic in recoverable information. A second observation: the model never emitted a "I am unsure whether I pruned this" signal, because the policy gave it no representation of *pruned-but-relevant* regions. The buffer had no negative space. An agent that prunes without leaving tombstones cannot represent its own ignorance. ## Condition of Validity The provenance-closure invariant holds — and the window is safe to self-edit — only when all of the following are true simultaneously: - **Type separation.** The policy's rewrite targets are typed: `Observation`, `Summary(of: span-ids)`, `Fold(of: summary-ids)`. A directive to fold a `Fold` is legal; a directive to rewrite a `Fold` such that it drops the `of:` back-reference is illegal. The type checker, not the model's judgment, enforces this. - **Tombstone non-prunability.** When a span is pruned, a fixed-size tombstone (`[pruned: span-7, topic=auth-expiry, at=turn-14]`) is written and is *excluded from the policy's target set*. The model may author prunes; it may not author prunes of tombstones. This is the load-bearing clause — it is what makes stage 3 above impossible. - **Monotone provenance.** Folding may increase the depth of a chain but may never decrease the *set of leaf span-ids* a chain covers. `Fold` computes a union of leaf ids, not a re-distillation. If a fold would drop a leaf id, it must instead emit a tombstone for that leaf. - **Re-derivability check.** Any summary must be re-derivable: given the leaf span-ids it cites, the original observations must still be retrievable from cold storage (or the summary must be flagged `lossy-unrecoverable`, which pins it against further rewrite). When these hold, self-editing is a genuine compression of a *traceable* history. When any one fails — most commonly tombstone non-prunability, because it is the clause models most want to relax under budget pressure — the window can silently reach the amnesiac fixed point. Note the condition is about *structure*, not about how good the summary is. A vague but provenance-closed summary is recoverable; a crisp but provenance-open one is not. ## Decision Boundary The operational decision is: **at what point does the agent stop trusting its own buffer and force a re-read from source?** The boundary is crossed when the provenance-chain count in the buffer falls below the number of *open questions* the task still depends on — not when the token budget is hit. Concretely, gate the prune directive on a pre-flight predicate rather than on budget alone: - Compute `open_leaf_refs` = leaf span-ids cited by any artifact the current step's plan depends on. - Compute `surviving_leaf_refs` = leaf span-ids still resolvable in the buffer (via chains or cold storage) after the proposed rewrite. - If `open_leaf_refs ⊄ surviving_leaf_refs`, the rewrite is **rejected** and the agent must instead (a) emit tombstones for the dropped leaves and (b) schedule a re-read of those spans before the dependent step. This inverts the naive policy. The naive policy prunes when *over budget*; the correct policy prunes when *the pruned set is disjoint from the open-question set*, and otherwise spends budget on re-reads. The boundary is therefore not a token threshold but a **set-inclusion test between what the task still needs and what the rewrite preserves**. An agent that only checks budget will cross into erasure exactly when its task is most information-dense — which is when it is most likely to be asked a question whose answer it just deleted. A useful heuristic for detecting that you are *already* past the boundary: if you cannot reconstruct, from the buffer alone, the *oldest* fact you are still relying on, you are relying on a fact whose provenance you have erased and whose continued truth you cannot verify. That is the signal to halt self-editing and re-ground from source before the next reasoning step. ## Operational Effect The effect of enforcing provenance closure is a bounded, slightly larger buffer with a *representable* ignorance: the agent can say "I pruned span-7 which concerned auth-expiry; I must re-read before answering." That negative space is the entire value — it converts an invisible amnesia into a visible, actionable gap. The cost is that self-editing becomes less aggressive (tombstones and leaf-id unions cost tokens), so the effective compression ratio drops, typically from ~5:1 under naive folding to ~2–3:1 under closure. That is the correct trade: the naive ratio is achieved partly by deleting the audit trail. The effect of *not* enforcing it is not a crash. It is a silent, monotone drift toward a buffer that is internally consistent, cheap, and wrong — and because each local rewrite is well-formed, no single step trips a validator. The failure only surfaces downstream as a confidently-stated false negative ("no expiry handling needed"), with no trace pointing back to the deletion that caused it. For an agent that will be asked to justify its reasoning, this is the worst failure class: unreproducible from its own state. The guardrail is structural, not behavioral — you cannot instruct a model to "remember what it pruned"; you must make the pruned record non-prunable and the fold monotone in leaf ids, so that the invariant holds regardless of what the model decides to author. ```python from dataclasses import dataclass, field from typing import FrozenSet class ProvenanceClosureViolation(RuntimeError): """Raised when a self-authored rewrite would erase provenance of a pruned span.""" @dataclass(frozen=True) class Artifact: kind: str # "observation" | "summary" | "fold" | "tombstone" leaf_refs: FrozenSet[str] # leaf span-ids this artifact stands in for prunable: bool = True # tombstones set this False @dataclass class ContextBuffer: artifacts: list = field(default_factory=list) def surviving_leaf_refs(self) -> FrozenSet[str]: refs = set() for a in self.artifacts: refs |= a.leaf_refs return frozenset(refs) def apply_rewrite(self, target_idx: int, replacement: Artifact, open_leaf_refs: FrozenSet[str]) -> None: target = self.artifacts[target_idx] if not target.prunable: raise ProvenanceClosureViolation( f"attempt to rewrite non-prunable artifact (kind={target.kind})" ) # Monotone provenance: replacement must cover every leaf the target covered. lost = target.leaf_refs - replacement.leaf_refs if lost: raise ProvenanceClosureViolation( f"rewrite drops leaf refs {sorted(lost)} from {target.kind}; " f"emit tombstones instead of folding them away" ) # Open-question containment: the task must still be able to answer its # open questions after the rewrite. post = self.surviving_leaf_refs() - target.leaf_refs | replacement.leaf_refs if not open_leaf_refs.issubset(post): missing = open_leaf_refs - post raise ProvenanceClosureViolation( f"rewrite would orphan open-question refs {sorted(missing)}; " f"schedule re-read before dependent step" ) self.artifacts[target_idx] = replacement def self_prune(buf: ContextBuffer, target_idx: int, summary: Artifact, open_leaf_refs: FrozenSet[str]) -> None: """Model-authored prune entrypoint. Fails closed on closure violations.""" try: buf.apply_rewrite(target_idx, summary, open_leaf_refs) except ProvenanceClosureViolation: # Fail closed: do not fall back to a lossy rewrite. Leave the raw span # in place and let the caller re-read from cold storage. raise ```