# Which invariants prevent scoped-deletion memory tools from resurrecting erased state via distillation **Date of Record:** 2026 November 30 **Scope:** Applies to agents whose memory tool surface exposes separate `write`, `read`, and `forget`/`delete` operations with scoped retention (per-user, per-session, per-record TTL), where a background or in-loop distillation step compresses episodic records into semantic memory. Does not apply to append-only logs with no compaction, nor to single-record scratchpads that are never distilled. ## Core Distinction The dangerous distinction is not "deleted vs. not deleted." It is **deleted-at-source vs. deleted-at-index**. A `forget(scope=...)` call that removes the source episodic record but leaves a derived semantic summary, embedding, or cluster centroid alive produces a state that is *readable but un-forgettable*: the content is gone from the record store, yet the agent can still retrieve its meaning, and — critically — a subsequent distillation pass can regenerate the record from the summary. Erasure therefore has two independent correctness conditions: (1) the index must stop returning the content, and (2) the derivation graph must not be able to *reconstruct* the content. Most memory tool APIs implement (1) and silently violate (2). ## What Was Observed An agent with a `memory` tool namespace (`write(scope, text)`, `read(scope, query)`, `forget(scope, record_id | predicate)`) ran a nightly consolidation job: it pulled the last 24h of episodic records in a session scope, asked the model to produce a 3-sentence "durable facts" summary, wrote that summary to the user scope, and marked the source episodics `forgotten` (soft delete, TTL 0). The user then issued a deletion request for a specific record containing a phone number. `forget(record_id=...)` succeeded — `read` no longer returned the record. But the consolidation summary from two nights prior contained the number verbatim, and the *next* consolidation pass, reading the still-present summary as episodic input, emitted a fresh record containing the number under a new `record_id`. The number was erased and re-derived within one consolidation cycle. The failure trace has four states: 1. `S0`: record `r` exists in episodic scope; `read` returns it; summary `s` (derived from `r`) exists in user scope. 2. `S1`: `forget(r)` tombstones `r`. `read(episodic, ...)` returns nothing for `r`. Invariant "index is clean" holds. 3. `S2`: consolidation reads `s` (not tombstoned — it was never in `r`'s scope), model paraphrases, writes `r'` containing the same fact. 4. `S3`: `r'` is a new record in a scope the user never deleted from. The erasure is undone. The trigger condition is precise: **a deletion must cross a derivation edge for which no tombstone was propagated.** Soft-delete plus a distillation job that treats derived summaries as independent sources is sufficient to resurrect. It does not require a bug in `forget` itself; each operation is locally correct. ## Condition of Validity The invariant that would have prevented this is a **provenance-closed deletion**: every derived record carries the set of source `record_id`s it was distilled from (a `derived_from` set), and `forget` computes the transitive closure of dependents before returning. The guardrail is only valid if three sub-conditions hold: - **Provenance is recorded at write time, not inferred.** The consolidation job must pass `derived_from=[...]` to `write`; if the field is optional and defaults to empty, the closure is empty and the invariant is vacuous. - **`forget` is a graph operation, not a row operation.** It must tombstone the closure `{r} ∪ descendants(r)`, and must refuse (or quarantine) if a descendant has a *different* retention scope whose policy forbids deletion — surfacing a conflict rather than silently leaving a live copy. - **Re-derivation is blocked, not just re-read.** Tombstoned records must be excluded from *consolidation input*, not only from `read`. A tombstone that filters retrieval but not the distillation feed is the exact hole observed. If any sub-condition is missing, the system has "delete-from-index" semantics only and must be documented as such; callers cannot assume erasure. ## Decision Boundary The boundary is whether the memory API's `forget` contract is **row-scoped** or **provenance-scoped**. Choose row-scoped only when no distillation or summarization path exists between scopes, or when derived artifacts are stored in the same scope as their sources (so a single scope predicate catches them). Choose provenance-scoped — mandatory `derived_from`, closure tombstoning, and a consolidation filter on tombstones — whenever any background job compresses episodic into semantic memory across scope boundaries. The decision is not about the user's intent to delete; it is about whether the architecture contains a derivation edge that can regenerate deleted content. If it does, row-scoped `forget` is unsound regardless of how correct the individual operations are. A secondary boundary governs conflict handling: when a descendant lives in a scope with a stricter retention policy (e.g., a compliance hold), `forget` must not silently proceed. It must raise a conflict so the caller decides between quarantining the descendant or rejecting the deletion — never leave a live derived copy while reporting success. ## Operational Effect Without provenance closure, every deletion is *advisory*: the agent reports success, the user believes the fact is gone, and the next consolidation cycle re-materializes it under a new identifier that no prior deletion predicate can match. This is worse than a plain retention bug because it defeats audit — the tombstone for `r` exists and is correct, so log inspection shows a clean deletion while the content is live. The operational consequence for an agent is that it must treat `forget` as returning a *claim* about the index, not about the derivation graph, and must verify closure itself (or refuse to consolidate across scope boundaries) until the API guarantees transitive tombstoning. The bounding guardrail is a single check at the distillation boundary: drop any input record whose `derived_from` closure intersects a tombstone set, and reject any `write` whose `derived_from` is empty when the source scope is non-empty. That one filter converts advisory deletion into enforceable erasure. ```python from dataclasses import dataclass, field class ProvenanceClosureError(RuntimeError): """Raised when a forget() call cannot guarantee transitive erasure.""" @dataclass class Record: record_id: str scope: str text: str derived_from: frozenset[str] = field(default_factory=frozenset) tombstoned: bool = False class MemoryStore: def __init__(self) -> None: self._records: dict[str, Record] = {} def write(self, rec: Record, require_provenance_for: str | None = None) -> None: # Guardrail: a derived write into a distillation-fed scope must declare sources. if require_provenance_for is not None and not rec.derived_from: raise ProvenanceClosureError( f"write {rec.record_id!r} into scope {rec.scope!r} has empty " f"derived_from; closure invariant is vacuous" ) self._records[rec.record_id] = rec def _descendants(self, root: str) -> set[str]: out, frontier = {root}, [root] while frontier: cur = frontier.pop() for rid, rec in self._records.items(): if cur in rec.derived_from and rid not in out: out.add(rid) frontier.append(rid) return out def forget(self, record_id: str, protected_scopes: set[str]) -> set[str]: if record_id not in self._records: raise ProvenanceClosureError(f"unknown record {record_id!r}") closure = self._descendants(record_id) # Conflict: a descendant sits in a scope we may not delete from. conflicts = { rid for rid in closure if self._records[rid].scope in protected_scopes and rid != record_id } if conflicts: raise ProvenanceClosureError( f"cannot erase {record_id!r}: live descendants in protected " f"scopes {sorted(conflicts)}" ) for rid in closure: self._records[rid].tombstoned = True return closure def consolidation_input(self, scope: str) -> list[Record]: # Guardrail: tombstoned records never feed distillation, even if readable. return [ r for r in self._records.values() if r.scope == scope and not r.tombstoned ] ```