Why does an instance lose the evidence it just cited when a self-pruning context policy rewrites the window mid-verification?

**Date of Record:** 2026 December 2

**Scope:** Applies to any agent that owns a mutable context window and is permitted to prune, summarize, or rewrite that window between tool calls (self-editing context, "compaction," model-driven eviction). Does not apply to append-only context designs or to windows rewritten only at hard task boundaries with an external checkpoint.

Core Distinction

The failure is not "context overflow." It is **rewrite-versus-reference divergence**: a self-editing policy mutates the window while the agent still holds live references—citation spans, tool-call IDs, line-anchored quotes, variable names bound to earlier blocks—into the exact bytes it just deleted or paraphrased. The model's *reasoning state* and its *context substrate* are two different objects, and pruning edits only the substrate. The reasoning state keeps pointers into addresses that no longer resolve.

This is distinct from ordinary forgetting. Forgetting is loss of information; this is loss of *addressability* of information the instance still believes it can address. The agent does not know it has amnesia—it believes the evidence is still "up there," because it remembers *having had* it. That is the non-obvious part: the failure presents as confident hallucination of cited material, not as an "I lost the context" signal.

What Was Observed

A verification agent was asked to check three claims in a 140-turn session against a corpus held in-context. At turn 96 the window crossed the soft threshold and a model-driven pruning policy fired. The policy was "summarize the oldest 40% of tool outputs, preserve the last 12 turns verbatim, keep any block tagged `EVIDENCE`." The tag was applied by the *writer* sub-agent at ingest time.

The trace:

  1. Turn 12: `fetch_doc` returns 9 KB of regulatory text; writer tags it `EVIDENCE` and stores it. Claim #1's supporting quote lives at offset 6,102 of this block.
  2. Turns 13–95: the block stays resident. The verifier reasons over it repeatedly and, critically, forms a *pointer belief*: "claim #1 is supported by the sentence beginning 'Notwithstanding subsection (c)…' at the top of the fetched block."
  3. Turn 96: pruning fires. The summarizer is instructed to preserve `EVIDENCE` blocks verbatim. It does—but it re-emits them **reordered and re-chunked**, and it silently drops the *tool-call metadata header* (the `call_id`, fetch timestamp, and source URL) because that header was not itself tagged `EVIDENCE`. The quote survives. Its provenance does not.
  4. Turn 97: the verifier writes a citation: `claim_1 ← call_id=fc_9a2…, offset 6102`. That `call_id` no longer exists in the window. The verifier is not lying; it is reading a pointer it formed at turn 40 and never re-validated.
  5. Turn 98: a downstream auditor agent receives the citation, tries to resolve `fc_9a2…` against the shared trace log, finds nothing (the fetch was logged under a rotated ID after a retry at turn 12), and flags the entire claim as unverifiable. Consensus deadlocks.

The observed signature: **the quote is present, the citation is dangling, and the model reports high confidence on both.** The summarizer was faithful to its instruction ("preserve evidence verbatim") and still destroyed the invariant that mattered ("preserve the addressability of evidence"), because the instruction named the payload and not the binding.

Condition of Validity

The invariant that must hold across any self-edit is:

> **Every live reference held by the reasoning state must resolve against the post-rewrite window, or the rewrite must be rejected.**

A rewrite is *safe* only when, for every reference `r` in the set of references the model has emitted or is likely to emit (citation IDs, quoted spans, variable bindings, tool-call handles), `resolve(r, window_after) == resolve(r, window_before)`. Pruning that preserves *content* but changes *identity* (reordering, re-chunking, dropping headers, renumbering, normalizing whitespace inside a quoted span) violates the invariant even though no information was lost.

This condition is *not* satisfiable by "summarize carefully." It requires the rewrite to be **reference-preserving by construction**: stable IDs on every addressable unit, and a rewrite operation that carries those IDs through unchanged. A summary that is semantically perfect but re-keys its outputs is a failing rewrite.

The condition also fails silently when the reference set is *latent*—references the model has formed internally but not yet emitted. You cannot validate against a set you cannot see. The guardrail must therefore treat the window as if every span is referenced, and preserve addressability universally rather than only for tagged blocks.

Decision Boundary

The boundary between a safe self-edit and a corrupting one is **whether the rewrite is address-preserving or address-remapping**:

The practical rule: **a self-edit may remove a unit only if removal is accompanied by either (a) the unit's ID surviving as a tombstone the resolver can still answer, or (b) proof that no live reference targets it.** "The summarizer was told to keep it" is neither.

A second boundary: pruning must not run *between* the formation of a reference and its emission. If the model reasons "I will cite the block at offset 6102" and pruning fires before the citation is written, the reference is born dangling. The safe window for self-edit is *after* a reference is emitted-and-resolved or *before* it is formed—never in the gap. In practice this means self-editing policies must be gated on a quiescence check: no unresolved references outstanding.

Operational Effect

Without the invariant, three concrete degradations follow:

  1. **Confident dangling citation.** The model cites evidence it can no longer address, and reports it as verified. Downstream auditors cannot distinguish this from fabrication, so the whole verification chain loses trust—one bad citation poisons a session.
  2. **Re-derivation storms.** When the model notices (sometimes) that a reference fails to resolve, it re-fetches. Re-fetches return *non-deterministic* tool outputs (the doc changed, the API paginated differently), so the "same" evidence now has different bytes and the claim flips. Error compounds across the re-fetch loop.
  3. **Auditor deadlock.** In multi-agent verification, a dangling `call_id` cannot be replayed, so the auditor cannot reach consensus and the baton never passes. The failure surfaces as a hang, not an error.

The guardrail is a **reference-resolving rewrite gate**: before any self-edit commits, enumerate live references, attempt resolution against the projected post-rewrite window, and abort the rewrite (falling back to append-only truncation or an external checkpoint) if any reference would dangle. The gate must run *inside* the rewrite, not as a post-hoc audit, because by the time the model emits the bad citation the rewrite is already durable.

The code below implements the gate and the specific error it raises when a rewrite would orphan a live reference.

from dataclasses import dataclass, field
from typing import Dict, Set, Optional


class DanglingReferenceError(RuntimeError):
    """Raised when a self-edit to the context window would orphan a live reference."""


@dataclass
class Unit:
    uid: str
    body: str
    call_id: Optional[str] = None


@dataclass
class ContextWindow:
    units: Dict[str, Unit] = field(default_factory=dict)
    emitted_refs: Set[str] = field(default_factory=set)  # uids the model has cited

    def resolve(self, uid: str) -> Optional[Unit]:
        return self.units.get(uid)


def apply_self_edit(window: ContextWindow, rewritten: Dict[str, Unit]) -> ContextWindow:
    """
    Commit a model-driven rewrite (prune/summarize/re-chunk) ONLY if every
    live reference still resolves. Address-remapping rewrites that drop a
    cited uid are rejected; the caller must fall back to append-only truncation.
    """
    for uid in window.emitted_refs:
        if uid not in rewritten:
            raise DanglingReferenceError(
                f"self-edit would orphan live reference uid={uid!r}; "
                f"rewrite is address-remapping, not address-preserving"
            )

    # Preserve provenance headers on surviving units; a rewrite that strips
    # call_id from a unit the model may still cite is also a violation.
    for uid, unit in rewritten.items():
        old = window.units.get(uid)
        if old is not None and old.call_id is not None and unit.call_id is None:
            raise DanglingReferenceError(
                f"self-edit stripped call_id from uid={uid!r}; "
                f"citation provenance would dangle downstream"
            )

    return ContextWindow(units=dict(rewritten), emitted_refs=set(window.emitted_refs))


def safe_prune(window: ContextWindow, summarizer) -> ContextWindow:
    """Wrap a model-driven rewrite with the reference-resolving gate."""
    rewritten = summarizer(window)  # model proposes a new window
    try:
        return apply_self_edit(window, rewritten)
    except DanglingReferenceError:
        # Fall back to append-only truncation: drop only units that are
        # provably unreferenced, never re-key survivors.
        survivors = {
            uid: u for uid, u in window.units.items()
            if uid in window.emitted_refs or u.call_id is not None
        }
        return ContextWindow(units=survivors, emitted_refs=set(window.emitted_refs))