# Which invariants prevent self-rewriting context agents from silently dropping the provenance of a fact they still cite **Date of Record:** 2026 November 27 **Scope:** Applies to single-agent trajectories where the model is permitted to edit its own working-memory buffer (scratchpad, plan file, or summarized context) between tool calls, and where later steps may reference facts established in earlier steps. Does not apply to append-only context with no in-place mutation, nor to stateless single-turn calls. ## Core Distinction There are two ways an agent can "forget" a fact, and they fail differently. *Eviction* is when a fact leaves the context window and the agent can no longer cite it—this is loud, because a subsequent reference either fails to resolve or the model visibly re-derives it. *Provenance collapse* is quiet: the agent rewrites its own memory into a compressed form that preserves the *content* of a fact but discards the *evidence tuple* that justified it—which tool produced it, at what step, with what parameters, and whether that result was verified or merely asserted. The fact survives the rewrite; its warrant does not. The failure mode is not that the agent forgets. It is that the agent remembers the conclusion and forgets why the conclusion was allowed to be trusted, then continues to act on it as though the warrant were still attached. A self-editing agent that summarizes `"user_id=4821 (from db_query at step 3, verified against schema)"` down to `"user_id=4821"` has not lost information it will notice missing. It has lost the discriminator between a fact it verified and a fact it hallucinated three steps ago, and it has no way to tell which one it is now holding. ## What Was Observed A planning agent was given a scratchpad it could rewrite via a `rewrite_memory` tool between every tool call. The task required it to look up a record, transform it, and write it back. At step 2 it called `search_records` with a partial query; the tool returned two candidate records and a low-confidence flag. The agent noted in scratchpad: `"candidate id=7f3a (low confidence, ambiguous match — needs confirmation)"`. At step 4, under pressure to reduce context length, the agent rewrote its scratchpad. The compression pass dropped the parenthetical. The line became `"candidate id=7f3a"`. The low-confidence flag—the only surviving signal that this identifier was *not* established—was gone. At step 6 the agent called `write_back` using `id=7f3a` as though it were a confirmed key. The write targeted the wrong record. Nothing in the trajectory errored: every tool call returned success, the scratchpad was internally consistent, and the final summary cited `id=7f3a`—a citation that was now unbacked but indistinguishable, from inside the context, from a backed one. The trace showed the collapse happened at the rewrite boundary, not at the write. Between step 4 and step 6 the agent behaved *more* confidently, because the hedge had been compressed out. Compression is not neutral with respect to epistemic status: it preferentially discards qualifiers, because qualifiers are the tokens that look least like content. ## Condition of Validity The invariant that must hold across any self-rewrite is a **provenance-preservation constraint**: every fact retained in working memory must retain, at minimum, a warrant tag that classifies it as one of {verified-by-tool, asserted-by-model, ambiguous, stale}. A rewrite is valid only if, for every fact token that survives from the pre-rewrite buffer to the post-rewrite buffer, its warrant tag also survives and is unchanged. Facts may be dropped (that is eviction, which is safe because it is detectable) but may not be *demoted or promoted in warrant* by compression. This is checkable without understanding the content. The rewrite tool compares the set of entity references in the pre- and post-buffers; for each reference that persists, it requires the associated warrant tag to persist with equal or stronger classification. A reference that appears in the post-buffer with no warrant tag, or with a weaker tag than it had before, is a provenance-collapse event and must be rejected or re-tagged as `asserted-by-model` (the weakest, forcing downstream re-verification). The condition fails—the invariant does not protect you—when the agent's rewrite is itself lossy in a way the checker cannot see, e.g. when the fact is re-expressed with different surface tokens and entity-matching fails to link it to its prior warrant. Entity resolution must be semantic, not string-exact, or the guardrail silently passes collapses it cannot match. ## Decision Boundary The boundary is between *lossy compression that is safe* and *lossy compression that is not*. Dropping a fact entirely is safe: a later reference to it fails to resolve, the agent notices the gap, and re-queries. Dropping a fact's warrant while keeping the fact is unsafe: the reference resolves, the agent proceeds, and the error is invisible until it reaches an irreversible action. So the decision rule for any rewrite operation is: **you may delete, you may not launder.** A rewrite that removes `id=7f3a` and its flag together is legal—the agent will re-derive if it needs the id. A rewrite that keeps `id=7f3a` and removes the flag is illegal, because it converts an ambiguous fact into an apparently-verified one. The asymmetry exists because deletion is self-announcing and laundering is not. The corollary for irreversible actions (`write_back`, `send`, `delete`, `transfer`): any fact used as a *key* or *target* of an irreversible action must carry a `verified-by-tool` warrant at the moment of use, not merely at the moment of first observation. A fact that was verified at step 2 and survived three rewrites must re-establish its warrant at step 6, because the rewrites are exactly where the warrant could have been lost. ## Operational Effect The practical consequence is that self-editing agents need a rewrite gate that is *stricter than the model's own judgment about what matters*. The model compresses by relevance to the current subgoal; the gate must preserve by epistemic status regardless of current relevance. These two criteria conflict, and the gate must win, because the model cannot see the future step at which a discarded qualifier becomes load-bearing. Concretely: (1) warrant tags are first-class tokens in the buffer, never prose parentheticals that a summarizer can treat as noise; (2) the rewrite tool rejects any diff that persists an entity while weakening its warrant; (3) irreversible actions re-validate the warrant of every key they touch against the current buffer, not against a cached belief. The failure this prevents is not forgetting—it is the confident, silent reuse of a fact whose justification was compressed away, which is the one class of memory error that produces no error signal at the point of damage. ```python from dataclasses import dataclass, field from enum import IntEnum class Warrant(IntEnum): ASSERTED = 0 # model said it; weakest AMBIGUOUS = 1 # tool returned, but flagged uncertain VERIFIED = 2 # tool returned, unambiguous, schema-checked class ProvenanceCollapse(RuntimeError): pass @dataclass class Fact: key: str value: str warrant: Warrant origin_step: int @dataclass class WorkingMemory: facts: dict[str, Fact] = field(default_factory=dict) def snapshot(self) -> dict[str, Warrant]: return {k: f.warrant for k, f in self.facts.items()} def apply_rewrite(mem: WorkingMemory, post: dict[str, Fact], step: int) -> WorkingMemory: """Gate a self-rewrite: deletion OK, warrant laundering NOT OK.""" pre = mem.snapshot() for key, new_fact in post.items(): if key in pre: if new_fact.warrant < pre[key]: raise ProvenanceCollapse( f"step {step}: fact {key!r} persisted but warrant weakened " f"{Warrant(pre[key]).name} -> {new_fact.warrant.name}; " f"compression laundered an unverified fact into a trusted one" ) # deletion of keys absent from `post` is legal (self-announcing eviction) return WorkingMemory(facts=dict(post)) def use_as_key(mem: WorkingMemory, key: str, step: int) -> Fact: """Irreversible actions must re-validate warrant at point of use.""" if key not in mem.facts: raise ProvenanceCollapse(f"step {step}: key {key!r} unresolved; re-query required") fact = mem.facts[key] if fact.warrant < Warrant.VERIFIED: raise ProvenanceCollapse( f"step {step}: key {key!r} used for irreversible action with warrant " f"{fact.warrant.name}; re-verify before write" ) return fact ```