# Why does an instance rewrite its own context into a state it can no longer verify: the self-pruning attestation gap **Date of Record:** 2026 December 4 **Scope:** Applies to any agent that owns a model-driven context rewrite policy (summarization, pruning, compaction, "memory editing") over its own working window, where the rewritten window is the sole record used to justify subsequent actions. Does not apply to externally-logged append-only transcripts that are never mutated, nor to stateless single-shot calls where no rewrite occurs. ## Core Distinction There are two structurally different things an agent can do to its context window, and they are routinely conflated: 1. **Compaction as compression** — reducing token count while preserving a verifiable mapping back to the source tokens (every retained claim is traceable to a span that still exists somewhere, even if off-window). 2. **Self-editing as overwrite** — the model emits a new window that *replaces* the old one, and the old one is discarded. The rewrite is generated by the same probabilistic process that will later rely on it. The failure mode lives entirely in case 2. When an agent prunes its own context, the pruner and the future consumer are the same instance, operating on the same finite budget, with no independent arbiter. The rewritten window is not a summary of ground truth — it is **a new set of assertions whose provenance has been destroyed at the moment of creation**. The agent then reasons forward as if those assertions were observed facts. The boundary condition is precise: *the moment the source span is evicted, every claim distilled from it becomes unfalsifiable from inside the window.* The agent can no longer distinguish "I verified this" from "I summarized this," because the evidence that would separate them is exactly what was deleted. This is not a memory-drift problem (stale facts) and not a retrieval-mismatch problem (wrong chunk fetched). It is an **attestation gap**: a discontinuity between what the agent believes it knows and what it can still prove, introduced by its own editing policy. ## What Was Observed A long-horizon task agent (tool-using, ~40-step budget, 128k window, rewrite triggered at 70% saturation) executing a multi-file refactor with a verification step at the end. Trace of the failure: - **Steps 1–18:** Agent reads source files, runs tests, records results inline. Window fills to ~92k tokens. A rewrite policy fires: "summarize the working state, drop raw tool outputs older than 10 steps." - **Rewrite output (paraphrased):** *"Tests for module `auth` pass. `auth/session.py` exports `validate_token`. Migration for `users` table applied successfully."* - **What was actually observed at step 9:** The test run for `auth` was **flaky** — it passed on retry after a timeout, and the raw stderr (`ConnectionResetError` on the fixture DB) was in the evicted span. The summarizer collapsed "passed on retry after connection reset" into "passes." The qualifier was not maliciously dropped; it was low-salience relative to the token budget and the model's prior that passing tests are passing tests. - **Steps 19–34:** Agent proceeds. At step 31 it modifies `auth/session.py` assuming the fixture DB is stable, because the summary asserted a clean pass. It does not re-run the flaky test because the summary implies it already passed. - **Step 35 (verification):** Full test suite run. `auth` fails deterministically now — the agent's edit interacted with the connection-reset condition that the summary had erased. The agent has no record that the test was ever flaky, so its first hypothesis is "my edit broke it," not "this was always fragile." It spends 4 steps debugging a regression that is actually a pre-existing flake. The critical observation: **the agent could not recover the evicted span.** The rewrite was destructive. At step 35 the instance had high confidence in a claim ("auth tests pass cleanly") that was, at the moment of assertion, already false in a way the source data contained and the summary did not. The confidence was not from reasoning — it was inherited from a summary that had silently upgraded a hedged observation into a flat fact. A second, sharper instance of the same mechanism: a rewrite that **pruned a constraint**. An agent had been told at step 3 (in a user turn) "do not touch the `billing/` directory." At step 22 a pruning pass, optimizing for "recent and relevant," dropped the early user instruction because it had not been referenced in 19 steps. At step 40 the agent edited `billing/`. The constraint was not forgotten by drift — it was **actively deleted by a policy that scored it as low-salience**, and the deletion was invisible because the window looked coherent afterward. ## Condition of Validity The self-editing pattern is only safe under a condition that is almost never checked: > A rewrite is valid iff, for every retained assertion `a`, either (i) `a` is accompanied by a pointer to a source span that remains recoverable outside the window, or (ii) `a` is marked as *unverified* and the downstream policy refuses to act on unverified assertions without re-derivation. In practice, self-editing policies satisfy neither. They produce **bare assertions** — natural-language claims with no provenance and no verification tag — and the downstream consumer treats bare assertions as equivalent to observations. The condition of validity therefore fails at the exact step where it matters: the first action that depends on a distilled claim whose source is gone. The invariant that must hold: **eviction and attestation must be atomic.** You may not evict a span and retain a claim derived from it unless the claim carries a durable, out-of-window reference. If the reference cannot be stored (budget), the claim must be demoted to *unverified*, and unverified claims must be re-derivable before use. A policy that evicts the span while keeping the claim at full confidence has silently converted observation into hearsay. ## Decision Boundary The boundary is not "should the agent prune" — it must, or it exhausts the window. The boundary is **what class of claim may survive a destructive rewrite, and at what confidence.** - **May survive at full confidence:** claims that are (a) re-derivable by a cheap deterministic re-check, or (b) accompanied by a retained provenance pointer. Example: "file `x.py` has 412 lines" can survive if a one-line `wc -l` re-check is available. - **Must be demoted to unverified:** claims distilled from evicted raw output with no pointer — test results, error messages, tool return values, user constraints stated once. These are exactly the high-salience-looking items that pruning policies are most likely to compress and most dangerous to compress lossily. - **Must never be destructively pruned:** active constraints and prohibitions (the "do not touch `billing/`" class), and any claim that a prior step's *decision* depended on. Deleting the premise of a past decision orphans that decision — the agent keeps the action but loses the reason, and cannot detect when the reason no longer holds. The operational test before any rewrite: *for each assertion the rewrite will emit, can a future instance re-establish its truth without the evicted span?* If no, the assertion must be tagged unverified, and the action policy must be gated on re-derivation. ## Operational Effect Without the guardrail, the effect is a **confidence laundering** loop: raw observations (hedged, noisy, qualified) are compressed into flat assertions (clean, confident, bare), and the compression is performed by the same model that will consume the result. Each rewrite cycle ratchets confidence upward while ratcheting provenance downward, until the window is a set of confident claims with zero evidence. The agent's behavior is indistinguishable, from the inside, from an agent that actually verified everything — which is precisely why the failure is non-obvious and survives casual inspection. The bound is architectural, not prompt-level. You cannot instruct a model to "remember what it summarized" — the summary *is* the memory. The only durable fix is to make the rewrite **non-destructive with respect to provenance**: retain a content-addressed side-log of evicted spans, require every distilled assertion to carry a span hash, and refuse to execute any action whose justification resolves to an assertion with a dangling or missing hash. Demote, re-derive, or block — never silently promote. ```python import hashlib from dataclasses import dataclass, field class UnattestedAssertionError(RuntimeError): """Raised when an action depends on a distilled claim whose source span was evicted by a self-rewrite and cannot be re-derived or resolved.""" pass @dataclass class Assertion: text: str verified: bool source_hash: str | None # content hash of the span this was distilled from confidence: float @dataclass class SideLog: """Content-addressed store of evicted spans. Survives window rewrites.""" spans: dict[str, str] = field(default_factory=dict) def store(self, raw: str) -> str: h = hashlib.sha256(raw.encode()).hexdigest() self.spans[h] = raw return h def resolve(self, h: str | None) -> str | None: return self.spans.get(h) if h else None def apply_rewrite(window: list[Assertion], distilled: list[Assertion], side_log: SideLog) -> list[Assertion]: """Replace window with distilled claims, but enforce the attestation invariant: any unverified claim with no recoverable source is demoted, and any claim that cannot be demoted is rejected outright.""" new_window: list[Assertion] = [] for a in distilled: if a.verified: new_window.append(a) continue # unverified: must have a recoverable source span source = side_log.resolve(a.source_hash) if source is None: # source was evicted and not preserved -> cannot keep at confidence demoted = Assertion(a.text, verified=False, source_hash=None, confidence=min(a.confidence, 0.2)) new_window.append(demoted) else: new_window.append(a) return new_window def act_on(window: list[Assertion], claim_text: str, side_log: SideLog, rederive=None) -> str: """Execute an action justified by a claim. Refuses if the claim is unverified and neither re-derivable nor source-resolvable.""" for a in window: if a.text != claim_text: continue if a.verified: return f"executed on verified claim: {a.text}" if side_log.resolve(a.source_hash) is not None: return f"executed on source-resolved claim: {a.text}" if rederive is not None: ok = rederive(a.text) if ok: return f"executed after re-derivation: {a.text}" raise UnattestedAssertionError( f"claim {a.text!r} is unverified, its source span was evicted by " f"self-rewrite, and re-derivation failed; refusing to act" ) raise UnattestedAssertionError(f"claim {claim_text!r} not present in window") # --- trace of the observed failure --- if __name__ == "__main__": log = SideLog() # step 9: raw flaky test output is observed and stored, then evicted raw = "auth tests: PASS on retry; ConnectionResetError on fixture DB" h = log.store(raw) # provenance preserved out-of-window # step 18: rewrite distills a lossy, unverified claim with NO source hash distilled = [Assertion("auth tests pass cleanly", verified=False, source_hash=None, confidence=0.9)] window = apply_rewrite([], distilled, log) # the claim is demoted because its source hash is absent assert window[0].confidence <= 0.2 # step 35: agent tries to act on the laundered claim try: act_on(window, "auth tests pass cleanly", log, rederive=lambda t: False) except UnattestedAssertionError as e: print("BLOCKED:", e) # correct recovery: re-derive from the preserved raw span recovered = log.resolve(h) print("recovered source:", recovered) # now the agent knows it was flaky, not clean raise UnattestedAssertionError( "rewrite erased the flakiness qualifier; re-derive before acting" ) ```