# Which invariants prevent self-rewriting agents from silently deleting the evidence their own verifier needs **Date of Record:** 2026 November 26 **Scope:** Applies to single- and multi-agent trajectories where the reasoning loop is permitted to mutate its own working memory (summarize, prune, rewrite, re-order, or re-embed) between steps, and where a downstream verifier, auditor, or replay harness later inspects that memory to confirm what actually happened. Does not apply to append-only transcripts that no component is allowed to rewrite, nor to memory edits performed offline between independent tasks. ## Core Distinction There are two kinds of self-editing memory and they fail differently. The first is **capacity editing**: the agent compresses or drops context because the window is filling, and the loss is a function of token pressure. This is well understood; the failure mode is forgetting, and the guardrail is a summarization budget plus a retrieval fallback. The second is **evidentiary editing**: the agent rewrites memory because the *content* is inconvenient — a tool call that returned an error, a hypothesis it has since abandoned, a failed branch it wants to stop re-reading. This second case is the dangerous one, because the rewrite is locally rational. The agent is not running out of room; it is doing exactly what a competent reasoner does, which is to stop carrying dead weight. The problem is that the thing it discards is frequently the *proof* that a later claim is sound — the negative result that rules out the alternative, the exact tool output the current conclusion depends on. Capacity editing loses facts. Evidentiary editing loses *the record that a fact was ever checked*, while leaving the polished conclusion intact and confident. The invariant that breaks is not "don't lose information." It is subtler: **the memory state at step N must remain sufficient to re-derive the trust level of the belief state at step N.** A self-rewriting agent routinely violates this because it optimizes the memory for *forward* reasoning (what do I need to do next) and not for *backward* verification (why did I believe what I did). The two objectives diverge precisely at the steps that matter: the abandoned hypothesis, the retried tool call, the pruned error trace. ## What Was Observed A research agent with a self-editing scratchpad was tasked with a multi-hop question requiring three tool calls: a search, a fetch of a specific document, and a computation over a field in that document. Its memory policy, stated in its system prompt, was: "Keep your scratchpad concise. Summarize and remove stale reasoning before each new step." The trajectory proceeded normally through the first two calls. At step 3, the fetch returned a document whose relevant field disagreed with the search snippet from step 1. The agent noticed the conflict, reasoned about it, decided the snippet was stale (it was a cached index), and — following its concision instruction — rewrote its scratchpad to read: *"Source A (document) gives value X; snippet was outdated. Proceed with X."* It then pruned the raw fetch payload and the original snippet to save space, ran the computation on X, and produced a correct final answer. The failure appeared downstream. An auditor agent, given the final answer and the (rewritten) scratchpad, was asked to verify the result. It could not. The scratchpad asserted that the snippet was outdated but no longer contained the snippet, the fetch payload, or any timestamp showing which source was fresher. The auditor had two options: trust the agent's own summary that it had correctly adjudicated the conflict, or re-run the tools. It re-ran the tools — and because the search index had refreshed in the interval, the snippet now *agreed* with the document, so the conflict the original agent resolved no longer existed in the replay. The auditor, seeing no conflict, could not reproduce the original reasoning, flagged the answer as unverifiable, and escalated. The original agent was correct. The verifier could not confirm it was correct. The rewrite that made the agent's forward reasoning cleaner made its backward reasoning unreplayable. Note the compounding: the re-run did not just fail to confirm — it produced a *different world state*, because tool outputs are non-deterministic across time. The audit was not a replay of the original trajectory; it was a fresh trajectory that happened to start from the same question. A second, quieter instance: an agent pruned a failed tool call ("call to `lookup` timed out, retrying with `lookup_v2`") as stale. The final answer depended on `lookup_v2`, which was correct. But the audit could not tell whether `lookup` had *timed out* (benign) or *returned a contradicting value that the agent ignored* (a reasoning error). The distinction lived entirely in the pruned line. Pruning "stale" reasoning had erased the boundary between a retry and a suppressed contradiction. ## Condition of Validity The invariant holds — and self-editing is safe — only when all three of the following are true: 1. **Provenance is preserved for every belief the final answer depends on.** If the answer rests on value X, the memory must retain, at minimum, a pointer to the tool call, its raw output (or a content-addressed hash of it), and the adjudication that selected X over alternatives. A summary ("snippet was outdated") is not provenance; it is a *claim about* provenance, and it is exactly the claim the verifier needs to check independently. 2. **Negative results are retained as first-class memory.** The pruned error, the abandoned hypothesis, the failed branch — these are not stale, they are the *elimination record*. An agent that keeps only its winning path has kept its conclusion but destroyed its search. The elimination record is what distinguishes "I checked and ruled this out" from "I never considered this." 3. **Tool outputs are treated as immutable and time-stamped.** Because re-running a tool does not reproduce the original output, the only faithful record of what the agent actually saw is the captured output itself. If the memory policy allows that capture to be rewritten, replay is impossible by construction — the verifier is forced into a fresh trajectory against a drifted world. When any of these fails, the agent is not editing memory. It is editing the *evidence*, and the audit trail becomes a narrative the agent tells about itself rather than a record of what occurred. ## Decision Boundary The operational line is this: **a memory edit may compress *reasoning* but must not compress *evidence*.** Reasoning is the agent's own inferences — re-derivable from evidence, and safe to summarize, reorder, or discard. Evidence is the raw material the inferences were drawn from — tool outputs, retrieved passages, error traces, timestamps — and it is not re-derivable, because the world that produced it has moved on. Concretely, the boundary resolves into a per-edit test. Before any rewrite, prune, or restructure, the agent (or the memory layer enforcing the policy) must answer: *does the final answer, or any live hypothesis, depend on a distinction that this edit would erase?* If the edit removes the only record that distinguishes "checked and excluded" from "never checked," or "timed out" from "returned a contradiction," it is an evidentiary edit and must be refused or downgraded to a *reference* (keep a hash and a pointer; drop the full text). If the edit only removes the agent's own intermediate prose — its restatements, its abandoned chains of inference that are fully re-derivable from retained evidence — it is a capacity edit and is safe. The asymmetry matters: capacity edits are recoverable (the evidence is still there to re-derive from), evidentiary edits are not (the evidence is gone). So the default should be permissive on reasoning and strict on evidence, and the strictness should be enforced by the memory layer, not by the agent's judgment — because the agent's judgment is exactly what is compromised at the moment it most wants to prune. ## Operational Effect Agents that respect the invariant pay a modest, bounded cost: their working memory is larger, because they carry provenance and elimination records they would otherwise drop. In exchange, three properties become available that are otherwise lost. First, **audit becomes replay-from-record rather than replay-from-world**. The verifier reads the captured tool outputs and the adjudications, and checks the reasoning against them, without re-invoking non-deterministic tools. This eliminates the drift failure above, where re-running a search against a refreshed index manufactures a different conflict than the one the agent actually faced. Second, **the agent's confidence becomes checkable**. A claim like "snippet was outdated" is only as trustworthy as the evidence behind it. When the evidence is retained, the verifier can confirm the adjudication was sound; when it is pruned, the verifier can only confirm the agent *asserted* it was sound. The distinction between "verified" and "asserted-verified" is the entire value of the audit. Third, **the agent's own future steps stop being poisoned by its past edits**. A self-rewriting agent that prunes an error trace can later re-encounter the same failure and, having no record it already tried and failed, retry the identical broken call. Retaining elimination records as first-class memory is not just for the auditor; it is what prevents the agent from re-litigating its own settled questions. The rewrite that helps the auditor also helps the agent. The failure is silent because the agent's final answer is often *correct*. The rewrite did not make it wrong; it made it unprovable. In systems where correctness is checked by an independent party, unprovable is operationally indistinguishable from wrong — and unlike wrong, it cannot be fixed by re-running, because the evidence needed to fix it was deleted by the same process that produced the answer. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class EvidentiaryEditError(RuntimeError): """Raised when a memory rewrite would erase evidence a verifier needs.""" pass @dataclass class MemoryEntry: kind: str # "evidence" | "reasoning" content: str tool_call_id: Optional[str] = None content_hash: Optional[str] = None timestamp: Optional[float] = None def _hash(text: str) -> str: return hashlib.sha256(text.encode("utf-8")).hexdigest() @dataclass class SelfEditingMemory: entries: list = field(default_factory=list) # beliefs the live answer depends on, by evidence hash live_dependencies: set = field(default_factory=set) def add_evidence(self, content: str, tool_call_id: str, ts: float) -> str: h = _hash(content) self.entries.append(MemoryEntry( kind="evidence", content=content, tool_call_id=tool_call_id, content_hash=h, timestamp=ts, )) return h def add_reasoning(self, content: str) -> None: self.entries.append(MemoryEntry(kind="reasoning", content=content)) def depend_on(self, evidence_hash: str) -> None: self.live_dependencies.add(evidence_hash) def prune(self, predicate) -> None: """Remove entries matching predicate, refusing to erase live evidence.""" survivors = [] for e in self.entries: if not predicate(e): survivors.append(e) continue # Capacity edits on reasoning are safe; evidence is not. if e.kind == "reasoning": continue if e.content_hash in self.live_dependencies: raise EvidentiaryEditError( f"refusing to prune evidence {e.tool_call_id!r}: " f"hash {e.content_hash[:12]} is a live dependency of the " f"current answer; downgrade to a reference instead" ) survivors.append(e) # non-live evidence may be referenced, not dropped self.entries = survivors def downgrade_to_reference(self, evidence_hash: str) -> None: """Keep hash + pointer, drop full text. Preserves replayability.""" for e in self.entries: if e.content_hash == evidence_hash and e.kind == "evidence": e.content = f"" return raise EvidentiaryEditError(f"no evidence entry for hash {evidence_hash[:12]}") def rewrite_scratchpad(mem: SelfEditingMemory, new_summary: str) -> None: """Agent-driven rewrite: compress reasoning, never live evidence.""" if not mem.live_dependencies: raise EvidentiaryEditError( "cannot rewrite: no live dependencies recorded; auditability unknown" ) # Reasoning prose is re-derivable and safe to drop. mem.prune(lambda e: e.kind == "reasoning") mem.add_reasoning(new_summary) # Every live dependency must still be resolvable in memory. present = {e.content_hash for e in mem.entries if e.kind == "evidence"} missing = mem.live_dependencies - present if missing: raise EvidentiaryEditError( f"rewrite orphaned live dependencies: {sorted(h[:12] for h in missing)}" ) ```