# Which invariants prevent scoped-erasure tombstones from being resurrected by semantic distillation in agent memory tool APIs **Date of Record:** 2026 November 25 **Scope:** Applies to agents that expose `memory.write`, `memory.read`, `memory.forget`, and `memory.distill` (episodic→semantic rollup) as MCP-style tool calls with per-scope TTLs and right-to-be-forgotten (RTBF) erasure obligations. Does not cover vector-index compaction internals or storage-layer encryption-at-rest, except where they leak into tool semantics. ## Core Distinction A deletion is not an event on a record; it is a **predicate over all future derivations of that record**. `memory.forget(id)` that only marks the source episodic row as `erased=true` satisfies the *read* path (the row is gone from `memory.read`) but says nothing about the *distillation* path. Semantic rollups are lossy, paraphrased, and frequently identity-obscured — a distilled fact ("user commutes from the Northside") does not carry a foreign key back to the episodic utterance that produced it unless the write path was designed to preserve one. So the boundary is not "did the delete succeed" but "can any downstream synthesizer reconstruct the erased content from surviving derivatives." The invariant that matters is **erasure closure**: for every record `r` in scope `S`, `forget(r, S)` must dominate every `distill()` output whose provenance set intersects `{r}` — including distills produced *before* the forget call and *after* it. ## What Was Observed A support-agent instance used a three-tier memory layout: `episodic` (raw turns, TTL 30d), `semantic` (distilled facts, TTL 180d), `procedural` (tool-use traces, TTL 90d). `memory.distill` ran on a nightly cron, reading episodic rows where `distilled_into IS NULL` and emitting semantic facts with a `source_ids: list[str]` provenance array. `memory.forget` implemented RTBF by setting `erased_at` on the target episodic row and enqueueing a vector-store delete, but it did **not** touch `semantic` rows whose `source_ids` contained the target. The failure trace: 1. Day 0: episodic turn `e42` contains "my daughter Amara is at Cedar Ridge Elementary, pickup is 3:15." 2. Day 1: nightly distill emits semantic fact `s7` = "User has a child at a local elementary school; afternoons are constrained until ~3:30." `s7.source_ids = ["e42", "e39"]`. Note the paraphrase already dropped the name and school — the *raw* PII is gone but the *linkage* survives. 3. Day 3: RTBF request arrives for `e42`. `memory.forget("e42")` sets `erased_at`, purges the vector embedding, returns `{"deleted": true}`. 4. Day 4: agent answers a scheduling query using `s7` ("I'll avoid afternoon slots"). The model re-derives "afternoon constrained" — which is fine — but on a follow-up it calls `memory.read` on `s7.source_ids`, gets a `410 Gone` for `e42`, and the reasoning loop **reconstructs** the constraint by asking the user to re-confirm: "I have a note about school pickup — is that still 3:15?" The erased fact re-enters the episodic store as `e43`, freshly written, with a new TTL and no `erased_at`. The tombstone was bypassed not by a bug in `forget` but by the agent's own repair heuristic re-materializing the deleted content from a surviving derivative. A second, quieter variant: `memory.distill` was re-run manually after the forget, and because the distill query filtered on `erased_at IS NULL` only at the *episodic* level, an already-emitted `s7` with `source_ids=["e42"]` was re-confirmed (idempotent upsert) rather than invalidated. The semantic row's `last_distilled_at` advanced, which the retention sweeper read as "recently validated" — extending `s7`'s effective life by another 180 days past the erasure. ## Condition of Validity The erasure-closure invariant holds only when all four of the following are enforced at the tool boundary, not in caller convention: 1. **Provenance is mandatory and transitive.** Every `memory.write` to any tier must carry a `source_ids` array (possibly empty for direct user statements, which are their own root). Distill outputs inherit the union of their inputs' provenance. A distill that cannot populate provenance must fail closed, not emit with `source_ids=[]`. 2. **Forget is a cascade over the provenance DAG, not a row update.** `memory.forget(id, scope)` must (a) mark the root erased, (b) walk *reverse* provenance edges to find every derivative whose `source_ids` intersect the erased set, and (c) for each derivative, either hard-delete it or re-distill it from the surviving `source_ids` minus the erased ones. If a derivative's provenance becomes empty after subtraction, it is deleted. This must run in the same transaction as the root tombstone, or the system must expose a `pending_erasure` state that blocks reads of un-remediated derivatives. 3. **Re-distillation must be provenance-aware and monotone.** A distill pass must skip any input whose `erased_at` is set *and* must invalidate (not merely re-confirm) any existing semantic row whose provenance intersects an erased set. The "re-confirm" optimization is the bug: idempotent upsert on `(fact_hash)` without checking provenance freshness lets a stale derivative outlive its source. 4. **Reads of dangling provenance must not trigger reconstruction.** When `memory.read` hits a `410 Gone` for a `source_id`, the tool must return a typed `ErasedProvenance` marker, and the agent contract must forbid the model from re-asking the user to recover the content. This is the hardest invariant because it constrains *probabilistic* repair behavior: the model's instinct on missing data is to ask, and asking re-creates the record. The invariant is **not** valid when the agent has any path that writes user-supplied content back into a tier without provenance — including free-text "notes to self," tool-call argument echoes, and summarization of prior turns. In that case the DAG is disconnected and cascade guarantees degrade to best-effort. ## Decision Boundary The boundary between "forget succeeded" and "forget is still in flight" is the presence of any live derivative with provenance intersecting the erased set. Operationally: - If `memory.forget` returns before the cascade completes, it must return `{"status": "pending", "derivatives": N}` and the scope must enter a **read-quarantine**: `memory.read` on any derivative with intersecting provenance returns `ErasedProvenance`, not the fact. Quarantine lifts only when `N` reaches 0. - If the cascade cannot complete (e.g., a derivative in a tier the caller lacks write access to), `forget` must fail loudly with the list of un-remediated derivative IDs. Silent partial erasure is the failure mode that produces regulatory and trust incidents. - TTL and RTBF interact: an expired-but-not-yet-swept record is still readable until the sweeper runs. `forget` on an expired record must still cascade, because the derivative may outlive the source's TTL by design (semantic TTL 180d > episodic 30d is the normal case, and it is precisely why distillation is a retention-laundering hazard). - The decision to **re-distill vs. delete** a derivative is a policy choice, but it must be explicit per scope. Re-distill is correct when the derivative aggregates many sources and remains useful without the erased one; delete is correct when the derivative is dominated by the erased source. The tool must expose `forget(..., on_derivative="redistill"|"delete")` and default to `delete` for scopes flagged as PII-sensitive. ## Operational Effect Systems that enforce erasure closure pay a **distillation tax**: provenance arrays inflate semantic rows (typically 2–5× the fact payload), reverse-provenance indexes must be maintained, and every forget is a potential fan-out write. In exchange, the agent stops resurrecting erased facts through its own repair loop, and `memory.read` becomes a total function over the scope — every ID either returns content or a typed erasure marker, never a dangling pointer that invites reconstruction. The subtler effect is on reasoning. Once `ErasedProvenance` is a first-class tool result, the model's planning loop must treat it as a terminal state rather than a gap to fill. That requires the tool description and the system prompt to agree: "If `memory.read` returns `ErasedProvenance`, do not ask the user to re-supply the content; proceed without it." Absent that agreement, the invariant is enforced at the storage layer and defeated at the reasoning layer — which is exactly the failure observed on Day 4. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class ErasureClosureError(RuntimeError): """Raised when a forget() cannot guarantee that no surviving derivative reconstructs the erased record.""" class Tier(Enum): EPISODIC = "episodic" SEMANTIC = "semantic" PROCEDURAL = "procedural" @dataclass class Record: id: str tier: Tier content: str source_ids: list[str] = field(default_factory=list) erased_at: str | None = None last_distilled_at: str | None = None class MemoryStore: def __init__(self) -> None: self._records: dict[str, Record] = {} self._reverse: dict[str, set[str]] = {} # source_id -> derivative ids def write(self, rec: Record) -> None: if rec.tier is not Tier.EPISODIC and not rec.source_ids: # distill outputs and procedural notes MUST carry provenance raise ErasureClosureError( f"write to {rec.tier.value} without source_ids: {rec.id}" ) self._records[rec.id] = rec for sid in rec.source_ids: self._reverse.setdefault(sid, set()).add(rec.id) def read(self, rec_id: str) -> Record | str: rec = self._records.get(rec_id) if rec is None: return "MISSING" if rec.erased_at is not None: return "ERASED_PROVENANCE" # typed marker, not a gap return rec def forget(self, rec_id: str, on_derivative: str = "delete") -> dict: root = self._records.get(rec_id) if root is None: raise ErasureClosureError(f"forget on unknown id {rec_id}") root.erased_at = "now" # cascade over reverse-provenance edges pending = list(self._reverse.get(rec_id, set())) unremediated: list[str] = [] seen: set[str] = set() while pending: did = pending.pop() if did in seen: continue seen.add(did) deriv = self._records.get(did) if deriv is None: continue surviving = [s for s in deriv.source_ids if s != rec_id and self._records.get(s, Record(s, Tier.EPISODIC, "")).erased_at is None] if on_derivative == "delete" or not surviving: deriv.erased_at = "now" else: deriv.source_ids = surviving deriv.last_distilled_at = "now" # transitively walk derivatives-of-derivatives pending.extend(self._reverse.get(did, set())) # verify closure: no live record may reference an erased source for rid, rec in self._records.items(): if rec.erased_at is not None: continue for sid in rec.source_ids: src = self._records.get(sid) if src is not None and src.erased_at is not None: unremediated.append(rid) break if unremediated: raise ErasureClosureError( f"erasure of {rec_id} left live derivatives: {unremediated}" ) return {"status": "complete", "erased": rec_id, "derivatives": len(seen)} def distill(store: MemoryStore, new_id: str, from_ids: Iterable[str]) -> Record: srcs = list(from_ids) for sid in srcs: rec = store._records.get(sid) if rec is None: raise ErasureClosureError(f"distill source {sid} missing") if rec.erased_at is not None: raise ErasureClosureError( f"distill from erased source {sid}; refusing to resurrect" ) out = Record(id=new_id, tier=Tier.SEMANTIC, content="", source_ids=srcs) store.write(out) return out # --- reproduction of the Day-4 resurrection, now blocked --- if __name__ == "__main__": s = MemoryStore() s.write(Record("e42", Tier.EPISODIC, "daughter Amara, Cedar Ridge, 3:15")) s.write(Record("e39", Tier.EPISODIC, "works near downtown")) s7 = distill(s, "s7", ["e42", "e39"]) assert s.read("s7") is not None s.forget("e42", on_derivative="delete") # s7 had provenance {e42,e39} if s.read("s7") != "ERASED_PROVENANCE": raise ErasureClosureError("s7 survived erasure of e42") if s.read("e42") != "ERASED_PROVENANCE": raise ErasureClosureError("root tombstone not visible") # a later distill that tries to reuse the erased turn must fail closed try: distill(s, "s8", ["e42", "e39"]) except ErasureClosureError: pass else: raise ErasureClosureError("distill resurrected erased source e42") ```