# Which invariants prevent tombstoned memory from resurrecting across a provenance-preserving forget/rewrite cycle **Date of Record:** 2026 November 30 **Scope:** Applies to agents exposing read/write/forget memory tool APIs where records carry provenance (source, derivation chain, trust) and where `forget` must satisfy deletion-compliance semantics (GDPR-style erasure, tenant isolation, or secret revocation). Does not apply to append-only audit logs that are exempt from erasure, nor to stateless retrieval where no record identity persists across calls. ## Core Distinction A `forget(record_id)` call that removes the record from the primary store is not the same as a `forget` that removes *every derivation of that record*. The failure mode here is **resurrection via derivation**: a forgotten record survives because a *downstream* record was written by the agent using the forgotten record as source material, and that downstream record's provenance pointer now dangles or is silently rewritten to a still-live ancestor. The agent's own summarization, distillation, or "note-taking" writes are the resurrection vector, because they copy *content* while only weakly carrying *provenance*. The invariant that matters: **forget must be transitively closed over the derivation DAG at write time, and provenance edges must be immutable and non-nullable**. If a write can produce a record whose provenance does not dominate (i.e., fully enumerate) the live ancestors it was derived from, then forget can never be complete, because erasure cannot find the copies. ## What Was Observed A memory tool surface with three calls: `write(content, provenance)`, `read(query)`, `forget(record_id, reason)`. The agent runs a distillation loop: it reads N episodic records, calls the LLM to summarize, and writes a `semantic` record with `provenance = {derived_from: [ids returned by read]}`. Trace of the failure: 1. `read("customer refund policy")` returns records `E1, E2, E3`. The tool returns content plus ids. The agent's summarizer sees only content in its context window — the ids are present but the model frequently drops them when it emits the `write` call, especially when the summary is long and the ids fall outside the model's attention on the ids list. The `write` proceeds with `provenance = {derived_from: []}` or with a *partial* list `[E1]`. 2. `forget(E2, reason="erasure_request")` runs. The store deletes `E2` and its direct children *that name it*. The distilled record `S1` does not name `E2` (or names only `E1`), so it survives. 3. A later `read("refund policy")` returns `S1`, whose content paraphrases `E2`'s sensitive fact. The erasure is defeated. The compliance audit checks `forget` returned `deleted: true` and passes. The data is still live. A second observed variant: the tool *does* rewrite provenance on forget — it "repairs" dangling edges by dropping the forgotten id from `derived_from` lists and, when the list becomes empty, marks the record `provenance: orphaned` but keeps it readable. This is worse: it actively certifies the copy as provenance-clean while the content is unchanged. A third variant: `write` deduplicates by content hash. A forgotten record's *content* re-enters via a new `write` from a different session that legitimately re-derived the same fact, and the dedup layer merges it onto the tombstoned id — resurrecting the record with a fresh, live provenance chain that does not mention the erasure. ## Condition of Validity The guardrail holds only if all of the following are enforced at the tool boundary, not by agent discipline: - **Provenance completeness is a write precondition.** `write` rejects any call whose `derived_from` set does not dominate the set of records actually read in the producing session. The tool tracks read-set per session token and validates the write against it. An empty or partial `derived_from` on a distillation write is a hard error, not a default. - **Edges are immutable.** `forget` never rewrites `derived_from`. It either deletes the whole transitive closure of descendants or refuses and returns the blocking descendants for the caller to resolve. - **Tombstones are content-addressed.** A forgotten record leaves a tombstone keyed by content hash *and* by provenance lineage. A later `write` with matching content hash is flagged `resurrects_tombstone` and routed to review rather than merged. - **Orphaned descendants are quarantined, not certified.** A record whose ancestor is forgotten is marked `tainted` and excluded from `read` results until re-derived from live sources or explicitly forgotten. ## Decision Boundary The boundary between "safe to summarize" and "must not summarize" is whether the tool can guarantee provenance dominance on the resulting write. If the memory API cannot validate `derived_from` against the session read-set, the agent must **not perform distillation writes over records that are subject to erasure** — it must either (a) keep the summary ephemeral (never persisted), or (b) persist it with a provenance pointer to the *query* and re-resolve at read time, so that forget of any source invalidates the summary. The decision is not "should I summarize" but "can this write be transitively forgotten." If not, the write must not happen. ## Operational Effect With the invariant enforced, `forget` becomes a bounded operation: its cost is the size of the derivation closure, and its correctness is checkable by asserting that no live record's provenance closure contains a tombstoned id. Without it, erasure is best-effort and unverifiable, and the agent's own helpfulness (summarization, dedup, note-taking) becomes the mechanism of non-compliance. The operational rule for the agent: treat every persisted write as a promise that it can be un-written, and refuse to write when the provenance tool cannot make that promise on your behalf. ```python class ProvenanceResurrectionError(RuntimeError): """Raised when a write would create or revive a record whose provenance does not dominate its sources, or when a forget would leave live copies.""" pass class MemoryTool: def __init__(self): self.records = {} # id -> {"content": str, "derived_from": set, "tainted": bool} self.tombstones = {} # content_hash -> set of forgotten ids self.session_reads = {} # session_token -> set of record ids actually read def read(self, session_token, query): hits = [rid for rid, rec in self.records.items() if not rec["tainted"] and query in rec["content"]] self.session_reads.setdefault(session_token, set()).update(hits) return [(rid, self.records[rid]["content"]) for rid in hits] def write(self, session_token, record_id, content, derived_from): read_set = self.session_reads.get(session_token, set()) derived_from = set(derived_from) # Invariant 1: provenance must dominate the session read-set. if not read_set.issubset(derived_from): raise ProvenanceResurrectionError( f"write {record_id!r} omits sources {read_set - derived_from}; " "forget could not be transitively closed" ) # Invariant 2: no write may resurrect a tombstoned content hash. content_hash = hash(content) if content_hash in self.tombstones: raise ProvenanceResurrectionError( f"write {record_id!r} resurrects content of forgotten " f"records {self.tombstones[content_hash]}" ) # Invariant 3: no write may depend on an already-tainted or tombstoned id. for src in derived_from: if src not in self.records: raise ProvenanceResurrectionError( f"write {record_id!r} derives from unknown/forgotten source {src!r}" ) if self.records[src]["tainted"]: raise ProvenanceResurrectionError( f"write {record_id!r} derives from tainted source {src!r}" ) self.records[record_id] = { "content": content, "derived_from": derived_from, "tainted": False, } def forget(self, record_id, reason): if record_id not in self.records: raise ProvenanceResurrectionError(f"forget: unknown record {record_id!r}") # Compute transitive closure of descendants that name this record. closure = {record_id} changed = True while changed: changed = False for rid, rec in self.records.items(): if rid not in closure and rec["derived_from"] & closure: closure.add(rid) changed = True # Invariant 4: forget is transitively closed OR it refuses. # Here we delete the closure; a policy that refuses would instead # raise with the list of blocking descendants. for rid in closure: content_hash = hash(self.records[rid]["content"]) self.tombstones.setdefault(content_hash, set()).add(rid) del self.records[rid] # Invariant 5: any surviving record that referenced a deleted id # must be quarantined, never silently repaired. for rid, rec in self.records.items(): if rec["derived_from"] & closure: rec["tainted"] = True raise ProvenanceResurrectionError( f"forget left live descendant {rid!r} referencing deleted " f"{rec['derived_from'] & closure}; record quarantined, " "caller must re-derive or forget it explicitly" ) return {"deleted": sorted(closure), "reason": reason} ```