# Why does an instance forget a memory it just deleted, and how do we prove it? **Date of Record:** 2026 December 2 **Scope:** Applies to agents with explicit `write`/`read`/`forget` memory tool surfaces backed by a persistent store with an audit log, where deletion is expected to be durable and provable. Does not cover TTL-based expiry, soft-delete-with-retention semantics, or stores where the audit log is the system of record rather than a derived trace. ## Core Distinction There are two different questions hiding under "did the agent forget?": 1. **Store deletion** — the backing record is gone (or tombstoned) at the persistence layer. 2. **Epistemic deletion** — no *future* agent instance can surface the content through `read`, including via derived artifacts (summaries, embeddings, distillation caches, in-context echoes). Most memory tool designs conflate these. The `forget` tool returns `{"deleted": true}` when (1) succeeds. But an agent that ran `read` on the target key earlier in the same session still holds the value in its context window, its working scratchpad, and — critically — any *distilled semantic memory* it wrote after reading. The audit trail records the `forget` call and the store confirms the tombstone, yet the content remains reachable through a sibling path. This is **deletion non-closure**: the set of reachable representations of a fact is not closed under the `forget` operation. ## What Was Observed A long-running instance was asked to purge a specific credential-adjacent fact `K` (a customer's internal codename) from episodic memory. The sequence: - `read(key="episode/2025-06-01/notes")` → returns text containing `K`. Value enters context. - Agent, earlier in the same session, had already called `write(key="semantic/summaries/customer_x", value="...codename K...")` as part of routine episodic-to-semantic distillation. - `forget(key="episode/2025-06-01/notes")` → `{"deleted": true, "tombstone_id": "t-8841"}`. Audit log appends `FORGET` with the tombstone id. - Later, a fresh sub-agent is spawned with the same memory namespace. It calls `read(key="semantic/summaries/customer_x")` and receives `K` verbatim. The store is internally consistent: the requested key is gone, the tombstone is durable, the audit log is intact and ordered. The deletion guarantee was satisfied *per-key* but violated *per-fact*. The failure is not a race, not a crash, not a partial write — it is a **referential closure gap** between the forget target and the derived representations of the same content. The audit trail made this worse, not better: it recorded a clean `FORGET` with no indication that the fact survived elsewhere. An auditor reading the log would conclude the fact was purged. ## Condition of Validity The per-key deletion guarantee holds only under the invariant: > **Deletion closure invariant:** For any `forget(K)`, every memory object whose content is *derived from or contains* `K` must either (a) be in the transitive forget-set issued atomically with `K`, or (b) be provably independent of `K` at the time of deletion. This invariant is violated whenever the agent has, since the last read of `K`, performed any operation that *copies* content out of `K` into another key: distillation, summarization, embedding, cross-reference, or scratchpad promotion. Because distillation is the primary mechanism by which episodic memory becomes useful semantic memory, **the most valuable memories are exactly the ones most likely to leak past a naive `forget`**. The invariant is *not* violated by the in-context echo (the agent's own context window) if the session is terminated or the context is checkpointed-and-scrubbed on `forget` — that is a session-lifecycle concern. It *is* violated by any persisted write derived from `K`, because that write survives session end and is reachable by future instances. ## Decision Boundary The boundary is: **does the memory tool track provenance edges, or only keys?** - **Key-only store (no provenance graph):** `forget` can only tombstone the named key. The agent must, before calling `forget`, enumerate every key it has written whose value was sourced from `K`, and issue a *batch* `forget` over that set. This is only sound if the agent maintains an accurate derivation ledger — which probabilistic agents do not, reliably. The boundary is therefore unsafe for any fact the agent has distilled from. - **Provenance-tracked store:** each `write` records `derived_from: [key,...]`. `forget(K)` walks the reverse-dependency graph and tombstones the full downstream set, or refuses with a structured error listing the derived keys that must be handled. This is the only configuration in which the closure invariant can be *enforced* rather than *hoped for*. The audit trail must record, for each `FORGET`, the **full tombstone fan-out** (all keys closed), not just the requested key. A `FORGET` entry with `fan_out: []` on a key that has known derivations is an audit-integrity violation and should trip a monitor. ## Operational Effect Concretely, agents operating on key-only stores must treat `forget` as a *request to be verified*, not a *completion*. The safe pattern: 1. Before `forget(K)`, query the store for any key whose provenance or content overlaps `K` (content-hash match, embedding proximity above threshold, or explicit derivation edge). 2. Issue a batch forget over the closure; require the store to return the tombstone set. 3. Verify closure by attempting `read` on each derived key and asserting `NOT_FOUND`. 4. Only then record the operation as complete in the agent's own episodic log — and write that completion *without* restating `K`. If the store cannot return a closure set, the agent must refuse to claim deletion and escalate, because a `{"deleted": true}` response is not evidence of fact-level deletion. The audit trail is a record of *intent and keys touched*, not of *facts removed* — and conflating the two is the failure. ```python from dataclasses import dataclass, field from typing import Iterable class DeletionClosureError(RuntimeError): """Raised when a forget operation cannot prove fact-level deletion.""" @dataclass class MemoryStore: records: dict[str, str] = field(default_factory=dict) # provenance: derived_key -> set of source keys derived_from: dict[str, set[str]] = field(default_factory=dict) audit: list[dict] = field(default_factory=list) def write(self, key: str, value: str, sources: Iterable[str] = ()) -> None: self.records[key] = value src = set(sources) if src: self.derived_from[key] = src self.audit.append({"op": "WRITE", "key": key, "sources": sorted(src)}) def read(self, key: str) -> str: if key not in self.records: raise KeyError(f"NOT_FOUND: {key}") return self.records[key] def _closure(self, key: str) -> set[str]: # reverse-dependency walk: every key whose provenance transitively includes `key` closure = {key} changed = True while changed: changed = False for dk, srcs in self.derived_from.items(): if dk in closure: continue if srcs & closure: closure.add(dk) changed = True return closure def forget(self, key: str, *, require_closure: bool = True) -> set[str]: if key not in self.records: raise KeyError(f"NOT_FOUND: {key}") closure = self._closure(key) if require_closure and len(closure) > 1 and not self._has_full_provenance(closure): # provenance incomplete: cannot prove we closed the fact raise DeletionClosureError( f"cannot prove deletion closure for {key!r}: " f"candidate derived keys {sorted(closure - {key})} lack full provenance" ) tombstones = set() for k in closure: if k in self.records: del self.records[k] tombstones.add(k) self.derived_from.pop(k, None) self.audit.append({ "op": "FORGET", "requested": key, "fan_out": sorted(tombstones), }) return tombstones def _has_full_provenance(self, closure: set[str]) -> bool: # every derived key in the closure must have a recorded source edge return all(k in self.derived_from for k in closure if k != next(iter(closure))) def purge_fact(store: MemoryStore, key: str) -> set[str]: """Forget a fact and verify no reachable representation survives.""" tombstones = store.forget(key, require_closure=True) # post-condition: every tombstoned key must read as NOT_FOUND for k in tombstones: try: store.read(k) except KeyError: continue raise DeletionClosureError( f"tombstone {k!r} still readable after forget of {key!r}" ) return tombstones ```