# How should an instance bound self-editing context rewrites when the pruner's own justification evicts the evidence it cites **Date of Record:** 2026 November 26 **Scope:** Applies to single-instance agents that maintain their own context window via model-driven prune/rewrite policies (summarize-and-drop, importance-scored eviction, self-authored compaction) where the same model both selects and executes edits. Does not apply to externally scheduled compaction with an out-of-band ledger, or to stateless single-turn calls. ## Core Distinction The failure is not "the model forgot something." It is a *self-referential eviction*: the pruning decision is itself a token sequence inside the window it is pruning, and the evidence supporting that decision is frequently the exact span being removed. A rewrite policy that asks the model to "summarize and drop the least important turns" produces a justification ("turn 14 is redundant given turn 9") whose referent (turn 9) is eligible for the same eviction pass. When the pruner runs again — or when a single pass is applied in two stages — the citation can be dropped while the claim derived from it survives. The window then holds a *provenance-free assertion*: a compressed fact with no recoverable source, indistinguishable from a hallucination. The invariant that must hold: **every retained claim must retain a resolvable pointer to the span that justified it, and that span must be pinned against eviction for as long as the claim lives.** Self-editing windows violate this by default because the pruner optimizes for token reduction, and citations are pure overhead from that objective's view. ## What Was Observed A 40-turn tool-using agent on a code-migration task, context budget 32k tokens, rewrite triggered at 85% saturation. Policy: model is shown the full window, asked to emit a compacted transcript plus a bullet list of "facts to carry forward," and the raw turns are dropped. Trace of the third compaction cycle: 1. At cycle 3 the window contained turn 27: a `pytest` run showing `test_auth_refresh` failing with `KeyError: 'exp'`. 2. The compaction prompt asked for carry-forward facts. The model emitted: *"Auth refresh token decode fails; earlier diagnosis at turn 12 attributed it to clock skew — treat as environmental."* 3. Turn 12 had actually said the opposite: *"clock skew ruled out, exp claim is being stripped by the proxy."* The model had inverted the polarity during summarization, and — critically — cited turn 12 as the authority for the inversion. 4. Turn 12 was then evicted in the same pass (it was flagged low-importance because its content was "already captured" in the carry-forward list). 5. Cycle 4: the model read its own carry-forward list, saw a confident causal claim with an attributed source it could no longer inspect, and spent 9 turns instrumenting the clock. The actual bug (proxy stripping `exp`) was not revisited for the rest of the session. Two distinct defects compounded. The **polarity inversion** is ordinary summarization loss. The **citation-without-referent** is the structural one: after step 4 the agent had no mechanism to detect that its retained belief was unsupported, because the support had been deleted by the same process that created the belief. Self-consistency checks failed because the model was checking the summary against itself. A second observed mode, same root: **pruner justification leakage.** The model's rationale text ("dropping turns 30–33, superseded by the fix in turn 34") was itself retained as a turn. On the next cycle the model read "superseded by the fix in turn 34," found turn 34 already evicted, and reconstructed a plausible but fabricated "the fix" from the rationale's phrasing. The justification outlived both its subject and its object. ## Condition of Validity The guardrail holds only under these conditions; outside them, treat the window as untrusted: - **Pinning is transitive and enforced at the executor, not the model.** The eviction routine must refuse to drop any span referenced by a live carry-forward claim, and must refuse to drop a span referenced by a *retained rationale*. The model proposes; a deterministic pin-set check disposes. A model that is asked to "remember to keep its sources" will not. - **Claims store span hashes, not span text.** A carry-forward fact records `(claim_text, [sha256(span_i)], confidence, cycle_id)`. On each cycle the executor verifies every cited hash still resolves to a present span. Unresolvable citation ⇒ the claim is demoted to `UNVERIFIED` and the agent must re-derive or re-fetch before acting on it. - **Rewrite is append-only in the audit sense.** Dropped spans move to a cold store keyed by hash, never deleted within the session. "Evicted from context" ≠ "evicted from session." This is what makes hash re-resolution possible at all. - **One compaction per causal step.** Two-stage or chained rewrites (summarize, then summarize the summary) multiply inversion probability and are the dominant source of provenance-free claims. Bound to a single pass per trigger. It does **not** hold when the cold store is also budgeted (then hashes resolve to nothing and you need external retrieval), or when the task is genuinely single-shot with no cross-cycle belief reuse. ## Decision Boundary The operator must choose, per deployment, where the pin-set authority lives: - **Model-proposed, executor-enforced pins** (recommended): model emits claims + citations; executor computes the pin set, blocks eviction of pinned spans, and marks unresolved claims `UNVERIFIED`. Cost: pin set can grow to starve the budget — cap pins at ~20% of window and force re-derivation of the lowest-confidence claims when exceeded. - **Executor-only structural pins** (turn N pins turn N−k for fixed k): cheap, no model trust, but blind to semantic dependencies the model discovered. Use when the model's citation discipline is unproven. - **No pins, full cold store + retrieval-on-demand**: correct but reintroduces retrieval-mismatch failure; only viable if the cold store is indexed well enough that re-resolution is reliable. The boundary condition that forces a decision: **when the pin set plus live working set exceeds the window, you cannot both keep all citations and keep working.** At that point the correct action is not another compaction (which is what produced the failure) but a *checkpoint-and-flush*: serialize the claim graph with unresolved citations to durable state, drop to a verified-only working set, and re-hydrate on demand. Compacting under pin pressure is the specific move that manufactures provenance-free assertions. ## Operational Effect With hash-pinned claims and executor-enforced pinning, the observed failure class disappears: an inverted summary still occurs (summarization is lossy and will stay lossy), but the cited span survives, so the next cycle's verification step flags the polarity mismatch against the retained source before the agent acts on it. The cost is a bounded pin budget and a cold store; the benefit is that retained beliefs are falsifiable from inside the window. Without it, the agent's memory degrades monotonically toward confident, unsourced, self-consistent error — the worst failure mode, because every internal check passes. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceViolation(RuntimeError): """Raised when a retained claim's cited span is no longer resolvable.""" pass @dataclass class Span: span_id: str text: str @dataclass class Claim: text: str cited_hashes: list[str] confidence: float status: str = "VERIFIED" # VERIFIED | UNVERIFIED def _h(text: str) -> str: return hashlib.sha256(text.encode()).hexdigest() class SelfEditingWindow: def __init__(self, budget_tokens: int, pin_cap_ratio: float = 0.20): self.budget = budget_tokens self.pin_cap = int(budget_tokens * pin_cap_ratio) self.live: dict[str, Span] = {} self.cold: dict[str, Span] = {} # append-only, keyed by hash self.claims: list[Claim] = [] def add_span(self, span_id: str, text: str) -> None: self.live[span_id] = Span(span_id, text) self.cold[_h(text)] = Span(span_id, text) def add_claim(self, text: str, cited_span_ids: list[str], confidence: float) -> None: hashes = [] for sid in cited_span_ids: if sid not in self.live: raise ProvenanceViolation(f"claim cites absent span {sid}") hashes.append(_h(self.live[sid].text)) self.claims.append(Claim(text, hashes, confidence)) def _pin_set(self) -> set[str]: """Executor-computed: spans whose hashes back any live claim.""" pinned = set() for c in self.claims: for h in c.cited_hashes: for sid, sp in self.live.items(): if _h(sp.text) == h: pinned.add(sid) return pinned def verify_claims(self) -> None: """Demote any claim whose citation no longer resolves in cold store.""" for c in self.claims: for h in c.cited_hashes: if h not in self.cold: c.status = "UNVERIFIED" if any(h not in self.cold for h in c.cited_hashes): raise ProvenanceViolation( f"claim {c.text[:40]!r} has unresolvable citation; " f"must re-derive before acting" ) def prune(self, drop_span_ids: list[str]) -> None: """Model-proposed drops; executor refuses to drop pinned spans.""" pinned = self._pin_set() if sum(len(self.live[s].text) for s in pinned) > self.pin_cap: raise ProvenanceViolation( "pin set exceeds budget cap; require checkpoint-and-flush, " "not another compaction" ) for sid in drop_span_ids: if sid in pinned: raise ProvenanceViolation( f"refused to evict pinned span {sid}: it backs a live claim" ) self.live.pop(sid, None) # cold store retains it by hash self.verify_claims() def compact(window: SelfEditingWindow, model_proposed_drops: list[str]) -> None: """Single-pass compaction entrypoint. No chained rewrites permitted.""" window.prune(model_proposed_drops) if not window.live: raise ProvenanceViolation("compaction emptied window; flush required") ```