# Which invariants prevent tombstone resurrection during scoped-retention erasure in agent memory tool APIs **Date of Record:** 2026 November 24 **Scope:** Applies to any agent memory subsystem exposing read/write/forget tool calls with per-record retention scopes and a GDPR-style erasure obligation, where erasure must be provable and durable. Does not apply to append-only audit logs that are legally exempt from erasure, nor to purely ephemeral in-context scratchpads that never persist past a session. ## Core Distinction There are two structurally different ways an agent "forgets." The first is **logical deletion**: the record stops being returned by `read`/`search` because a visibility predicate filters it out. The second is **physical erasure**: the bytes are destroyed and no derivative (index entry, embedding vector, summary, cache line, replay journal) references them. GDPR-compliant erasure requires the second. Agent memory APIs almost always implement the first, because it is cheap and non-destructive, and because the agent's own reasoning loop depends on being able to "undo" a soft delete during a confused turn. The failure mode this record isolates is **tombstone resurrection**: a record that was logically deleted (or physically erased) reappears in a later `read` because a *derivative artifact* — a semantic distillation, an embedding in a vector index, a session summary, a KV-cache snapshot, or a cross-agent replay journal — still contains the content and is re-ingested into the live memory store by a subsequent write or distillation pass. The deletion succeeded against the primary store and failed against every downstream projection of it. The invariant that prevents this is **erasure closure over the derivation DAG**: an erasure is only valid once every node reachable from the erased record via derivation edges is also erased or provably content-free, and the tombstone must be *monotonic* — no later write may downgrade an erased record to merely-hidden. ## What Was Observed A memory service exposed four tools: `mem.write(scope, content, ttl)`, `mem.read(query, scope)`, `mem.forget(id, reason)`, and a background `mem.distill(window)` that periodically folded recent episodic records into a semantic summary record and embedded the summary into a vector index. Retention scopes were per-namespace (`user`, `session`, `global`). GDPR erasure was implemented as `mem.forget` setting `deleted_at` and adding the id to a `tombstones` set consulted by `read`. The trace that broke it: 1. Episodic records `e1..e7` in scope `user` contained a data subject's email and address. `mem.forget` was called on `e1..e7`; `deleted_at` set; `tombstones` populated. `read` correctly returned nothing. Erasure reported success. 2. A `mem.distill` pass that had started **before** the forget call was still running against a snapshot of `e1..e7`. It produced semantic record `s1` containing the distilled sentence "user's contact is ". `s1` was written with a fresh id and embedded. 3. `mem.read` on the `user` scope now returns `s1`, which contains the erased content verbatim. The tombstone set contains `e1..e7` but not `s1`, because `s1` never carried the derivation edge back to its sources — the distiller wrote it as an independent record. 4. A later `mem.write` of an unrelated record triggered a re-embedding of the whole namespace, which re-derived a *second* summary `s2` from `s1`. The erased content now has two live representations, neither of which is tombstoned. The root cause is not a race in the narrow sense — the distiller was correct to snapshot. The defect is that the derivation edge `s1 → {e1..e7}` was never recorded, so the erasure could not compute its **downstream closure**. Erasure was scoped to the record, not to the record's transitive descendants in the derivation graph. A second, subtler observation: even when derivation edges *were* recorded (in a later patch), a `mem.distill` pass that began before the forget and committed after it would write a child whose parent was already tombstoned. Without a **commit-time tombstone check**, the distiller happily materialized a summary of erased content. The window between snapshot and commit is the resurrection window, and it is unbounded because distillation latency scales with context length. ## Condition of Validity Erasure closure is a valid guarantee only under the following conditions, all of which must hold simultaneously: - **Derivation edges are mandatory and write-time enforced.** Every record created by distillation, summarization, embedding, or cross-agent handoff MUST carry a `derived_from: [id...]` field, and `mem.write` MUST reject any write whose `derived_from` is absent when the writer is a derivation tool. A record with no provenance is treated as *unclosable* and cannot be safely erased — it must be quarantined, not merely hidden. - **Tombstones are monotonic.** Once `id` is erased, no write may clear, supersede, or "resurrect" it. A re-write of the same logical content gets a *new* id and is subject to the same erasure obligation; the old id stays tombstoned forever. This forbids the common "undelete" optimization. - **Erasure is a graph traversal, not a row update.** `mem.forget` must compute the transitive closure of `derived_from` edges (forward: what did this record produce?) and erase or content-strip every descendant. Embedding vectors, index entries, and cached summaries are descendants for this purpose. - **Commit-time revalidation.** Any derivation pass must re-check the tombstone set against its snapshot sources immediately before commit; if any source is tombstoned, the derived record is discarded, not written. - **Erasure is idempotent and observable.** A second `mem.forget` on an already-erased id returns "already erased" without error, and the erasure receipt enumerates the closure that was destroyed. The guarantee does **not** hold if the vector index is treated as a separate system outside the derivation DAG, if distilled summaries are written without provenance, or if any writer can bypass the `derived_from` requirement. ## Decision Boundary The operative decision for an agent runtime is: **when a `mem.forget` returns, is the content gone from every read path the agent can reach, including paths that will be reachable only after the next distillation pass?** The boundary between "erased" and "hidden" is crossed at the moment a derivation artifact survives the erasure. Concretely, the runtime must decide, per record: - If the record has **no descendants** in the derivation DAG → physical delete + tombstone; erasure is complete. - If the record **has descendants** → erase the full closure; if any descendant cannot be erased (e.g., an immutable audit log under legal hold), the erasure is **partial** and must return a structured `PartialErasure` receipt naming the surviving artifact and its legal basis, rather than reporting success. - If a **derivation pass is in flight** over the record → the erasure must either wait for the pass to commit and then erase its output, or invalidate the snapshot. The runtime may not report success while a pass holds an un-revalidated snapshot of the record. The failure to make this decision explicit is exactly how the observed system reported success on an erasure that had not happened. The default must be: **no success receipt until closure is empty.** ## Operational Effect Downstream of this invariant, three operational behaviors change: 1. **Forget latency becomes proportional to closure size, not record count.** Erasing a heavily-distilled record can touch hundreds of index entries. Callers must treat `mem.forget` as a potentially long, blocking, closure-walking operation with its own timeout, and must not pipeline writes against the namespace until the receipt returns — otherwise a concurrent distillation can re-ingest from a stale snapshot. 2. **Provenance becomes a hard schema requirement.** Any memory write from a summarizer, embedder, or peer agent that omits `derived_from` is rejected at the API boundary. This is the only enforcement point that keeps the DAG closed; retrofitting provenance after the fact is impossible because the snapshot is gone. 3. **Erasure receipts become auditable artifacts.** Each `mem.forget` emits a receipt listing the erased closure (ids, artifact types, scopes). This is what makes the erasure provable to a regulator and what lets a later auditor replay the erasure and confirm no descendant survived. A receipt that lists only the root id is a signal that closure was not computed. The invariant to hold in operational memory: *a tombstone is not a filter, it is a graph root, and erasure is not complete until its closure is empty.* ```python from __future__ import annotations from dataclasses import dataclass, field class ErasureClosureViolation(RuntimeError): """Raised when an erasure is reported complete while derived artifacts survive.""" @dataclass class MemoryRecord: id: str content: str derived_from: list[str] = field(default_factory=list) class ScopedMemoryStore: def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} self._tombstones: set[str] = set() # reverse index: parent id -> child ids, the derivation DAG edges self._children: dict[str, set[str]] = {} def write(self, rec: MemoryRecord, *, is_derivation: bool) -> None: # Invariant: derivation writes must carry provenance, else unclosable. if is_derivation and not rec.derived_from: raise ErasureClosureViolation( f"derivation write {rec.id!r} has no derived_from; " "record would be unclosable under erasure" ) # Commit-time revalidation: refuse to materialize a child of a tombstone. for parent in rec.derived_from: if parent in self._tombstones: raise ErasureClosureViolation( f"refusing to commit {rec.id!r}: parent {parent!r} is tombstoned " "(resurrection window)" ) self._children.setdefault(parent, set()).add(rec.id) self._records[rec.id] = rec def _closure(self, root: str) -> set[str]: seen: set[str] = set() stack = [root] while stack: cur = stack.pop() if cur in seen: continue seen.add(cur) stack.extend(self._children.get(cur, ())) return seen def forget(self, root: str) -> list[str]: if root in self._tombstones: return [root] # idempotent closure = self._closure(root) survivors = [cid for cid in closure if cid in self._records and cid not in self._tombstones and not self._erasable(cid)] if survivors: # Partial erasure: never report success. raise ErasureClosureViolation( f"erasure of {root!r} incomplete; surviving closure members: {survivors}" ) for cid in closure: self._records.pop(cid, None) self._tombstones.add(cid) return sorted(closure) def _erasable(self, cid: str) -> bool: # Immutable audit holds are the only permitted survivors; here we model none. return True ```