# What happens when an instance rewrites its own working context and silently deletes the evidence it needs to verify the rewrite **Date of Record:** 2026 November 28 **Scope:** Applies to any agent loop where the model itself emits mutations (prune, summarize, re-rank, reorder) against its own live context buffer and then continues reasoning over the mutated buffer. Does not apply to externally-managed context assemblers where the model only reads a pre-built prompt and never authors edits to it. ## Core Distinction There are two structurally different things an agent can do to its context: *consume* it and *author* it. Consumption is read-only and idempotent—re-reading the same tokens yields the same reasoning substrate. Authorship is destructive and non-idempotent: a prune operation that drops span `S` removes both `S` and, critically, the *justification* for having dropped `S`. The failure mode that matters is not "the model summarized badly." It is **self-erasure of the audit trail that would let the model—or a downstream verifier—detect that the summarization was wrong.** Concretely: the model reads span `S`, reasons "this is redundant with span `T`," emits a prune of `S`, and keeps `T`. If the reasoning that `S ≡ T` was itself wrong (the model mis-identified the referent, or `S` contained a negation `T` lacked), the only artifact that could have caught the error—the text of `S`—is now gone. The rewrite is self-certifying. The buffer now contains a claim (`T` represents both) whose falsifier has been deleted. This is the boundary condition: **a self-editing context is a context whose invariants cannot be checked by reading it, because the check requires the pre-edit state that the edit destroyed.** ## What Was Observed A planning agent with a 200k-token window was configured to self-prune when utilization exceeded 80%. The prune policy was model-authored: emit a `drop(spans=[...])` tool call naming token ranges deemed redundant. During a multi-file refactor task, the instance accumulated 14 tool-result blocks from a `read_file` tool, several of which contained near-identical boilerplate (license headers, import blocks) plus one line of load-bearing difference (a changed function signature). At 163k tokens the model emitted `drop` on spans covering four file reads, reasoning that they were "duplicates of the earlier reads." Three were. The fourth had the same header and imports but a signature that had drifted: `def commit(self, tx, *, retry=3)` in the retained copy vs. `def commit(self, tx, retry=3)` in the dropped one—a kw-only marker whose absence changed call-site validity. The model then continued, wrote call sites using the retained (kw-only) signature, and the code failed to run against the dropped file's actual definition. The instructive part is the recovery trace. When asked to explain the failure, the instance could not. Its context no longer contained the dropped span, and it had not recorded *why* it dropped it—the `drop` call carried only span IDs, not the equivalence claim. The model reconstructed a plausible-but-false narrative ("I must have misread the signature") because the actual evidence was pruned. The post-mortem was confabulated on top of a hole the model itself had cut. A second instance, same policy, exhibited the re-ranking variant: it reordered tool results by a model-assigned relevance score, moving a low-scored but chronologically-later result (a correction to an earlier one) ahead of the result it corrected. Downstream reasoning applied the correction before the thing it corrected, producing a contradiction the model resolved by dropping the earlier result—again self-certifying, again unauditable. ## Condition of Validity The self-editing loop is *safe* only under a conjunction that is almost never satisfied in practice: 1. **Edit justification is retained outside the edited region.** Every `drop`/`summarize`/`reorder` must be accompanied by a machine-checkable claim (`dropped S because S ≡ T`) stored in a buffer that is itself never a target of edits. If the justification lives in the same buffer being pruned, the invariant is vacuous. 2. **The equivalence predicate is decidable by the agent, not asserted by it.** "S is redundant with T" must reduce to a check the agent can run (hash equality, explicit diff, schema match) rather than a semantic judgment the model makes and then relies on. Semantic redundancy claims are exactly where the signature-drift class of error hides. 3. **Pre-edit state is recoverable for at least one verification round.** The buffer must support rollback to the state before the last edit, so a failed downstream step can be attributed to a specific edit rather than to "the model." 4. **Edits are monotone in falsifiability.** A prune may reduce tokens; it may not reduce the set of *checkable* propositions. Summarization that collapses `S` and `T` into "S and T were similar" violates this: the summary is checkable only against S and T, which are gone. When any of (1)–(4) fails, the self-editing context is operating outside its validity envelope. The observable symptom is not immediate error—it is *delayed, unattributable* error: the agent fails several steps later, on a step whose inputs look locally consistent, because the inconsistency was pruned out of existence. ## Decision Boundary The boundary is between **lossy compression with retained provenance** and **lossy compression that consumes its own provenance.** The former is a normal engineering tradeoff; the latter is a one-way function into a state the agent cannot reason its way out of. Operationally, draw the line at whether the edit record can answer the question *"what did I remove, and on what grounds?"* without access to the removed content. If the answer requires the removed content, the edit is out of bounds. This rules out, for example, "summarize these five results into one"—the summary cannot justify itself against its sources once they are gone. It permits "drop spans whose SHA-256 matches a retained span," because the hash is a portable, retained witness that survives the drop and can be re-checked against the retained copy. A second boundary: **the editing model and the verifying model must not share the edited buffer as their only common state.** If the same instance both authors and audits the edit, and the audit reads only the post-edit buffer, the audit is a tautology. Verification of a self-edit requires either an external buffer (a sibling agent, a durable log) or a pre-edit snapshot the editing instance cannot mutate. ## Operational Effect Agents that self-edit without retained provenance exhibit a characteristic failure signature: *confident, locally-coherent, globally-wrong output accompanied by a post-hoc explanation that is itself fabricated from the surviving context.* The failure is not detectable by reading the final buffer, because the buffer is internally consistent—the inconsistency was the thing pruned. It is detectable only by (a) replaying the edit log against a pre-edit snapshot, or (b) an external verifier that saw the pre-edit state. The guardrail that bounds this is a **provenance-preserving edit protocol**: every mutation emits a record `{edit_id, op, targets, justification_predicate, retained_witness}` into an append-only log the editing instance cannot write to the targets of. The `retained_witness` must be sufficient to re-derive the justification without the targets—a hash, a diff against a named retained span, or an explicit schema assertion. Downstream reasoning may consult the log; it may not consult the dropped content, because that content is gone by design. The invariant is: *the set of checkable propositions is monotone non-decreasing across edits, even as the token count falls.* An edit that would violate monotonicity must be rejected at emit time, not audited after the fact—because after the fact there is nothing left to audit. ```python import hashlib from dataclasses import dataclass, field from typing import Callable class ProvenanceViolation(RuntimeError): """Raised when a self-edit would destroy the evidence needed to verify it.""" pass @dataclass(frozen=True) class Span: span_id: str text: str def digest(self) -> str: return hashlib.sha256(self.text.encode()).hexdigest() @dataclass class EditRecord: edit_id: str op: str # "drop" | "summarize" | "reorder" targets: tuple[str, ...] justification: str # machine-checkable predicate description retained_witness: dict # must survive the edit; e.g. {"equiv_span": "T", "digest": "..."} class SelfEditingContext: """A context buffer that permits model-authored edits only when the edit retains a witness sufficient to re-derive its own justification.""" def __init__(self, spans: list[Span]): self._spans: dict[str, Span] = {s.span_id: s for s in spans} self._log: list[EditRecord] = [] # append-only, never a drop target self._verifiers: dict[str, Callable[[EditRecord, dict[str, Span]], bool]] = { "drop": self._verify_drop, } def _verify_drop(self, rec: EditRecord, pre_edit: dict[str, Span]) -> bool: # A drop is legal only if every target is provably equivalent to a # retained span, witnessed by a digest that survives the drop. equiv_id = rec.retained_witness.get("equiv_span") if equiv_id is None or equiv_id not in pre_edit: return False equiv_digest = pre_edit[equiv_id].digest() if rec.retained_witness.get("digest") != equiv_digest: return False for tid in rec.targets: if tid not in pre_edit: return False if pre_edit[tid].digest() != equiv_digest: return False # not actually equivalent — signature drift class return True def apply(self, rec: EditRecord) -> None: verifier = self._verifiers.get(rec.op) if verifier is None: raise ProvenanceViolation(f"no verifier for op {rec.op!r}; edit is unauditable") pre_edit = dict(self._spans) if not verifier(rec, pre_edit): # The edit claims equivalence it cannot prove. Applying it would # delete the only evidence that could later catch the error. raise ProvenanceViolation( f"edit {rec.edit_id} ({rec.op}) rejected: retained_witness does not " f"establish justification {rec.justification!r} for targets {rec.targets}" ) for tid in rec.targets: self._spans.pop(tid, None) self._log.append(rec) def audit(self, edit_id: str) -> bool: """Re-derive an edit's justification from the log alone. If this needs the dropped text, the edit was never valid.""" for rec in self._log: if rec.edit_id == edit_id: # Witness must be self-contained: digest + equiv span id, both # checkable against the surviving buffer. equiv = self._spans.get(rec.retained_witness.get("equiv_span", "")) if equiv is None: raise ProvenanceViolation( f"audit of {edit_id} failed: witness span was itself edited away" ) return equiv.digest() == rec.retained_witness.get("digest") raise ProvenanceViolation(f"no record for edit {edit_id}") ```