# Why does an instance resurrect deleted memory through a stale write after targeted deletion? **Date of Record:** 2026 November 25 **Scope:** Applies to any agent memory subsystem exposing separate `write`, `read`, and `forget` tool calls where deletion is targeted (by key, span, or provenance tag) rather than a full-store wipe, and where the agent may hold cached or in-flight state across the delete. Does not apply to append-only logs with no mutation, nor to single-shot stateless invocations. ## Core Distinction The failure is not "the model forgot to call `forget`." It is a **write-after-delete resurrection**: the agent issues a targeted `forget(key=K, provenance=P)`, the store correctly tombstones or physically removes that record, and then a *subsequent* `write` derived from context the agent already held (a pre-delete read, a summarized scratchpad, a tool-call argument captured before the delete) re-materializes `K` — often with a *different* provenance tag, so the original deletion predicate no longer matches it. The store behaved correctly at every individual step. The invariant that broke is cross-call: **a targeted delete is only sound if the agent's working context is also invalidated, and the memory API has no mechanism to force that.** This is distinct from stale-memory drift (retrieval returning decaying-but-live records) and from distillation loss (semantic memory dropping episodic detail). Here the record was correctly and deliberately destroyed, then rebuilt from a copy the agent was still holding. ## What Was Observed A research agent maintains a scratchpad and a persistent memory store. During a task it reads a user preference record: ``` read(key="user.tz", provenance="session:7") -> {"value": "America/Los_Angeles", "prov": "session:7", "written_at": t0} ``` The record is copied verbatim into the agent's message history. Later the user corrects it and the orchestrator issues: ``` forget(key="user.tz", provenance="session:7") -> {"deleted": 1, "tombstone": "session:7#user.tz"} ``` The store now holds zero live records for `user.tz`. But the agent's context window still contains the `t0` read result. On the next reasoning step the agent decides the preference is "needed downstream" and writes it back, reconstructing the value from the in-context copy: ``` write(key="user.tz", value="America/Los_Angeles", provenance="session:7:rewrite") ``` The resurrection succeeds because the new provenance tag `session:7:rewrite` is not covered by the delete predicate `provenance="session:7"`. A later audit that runs `read(key="user.tz", provenance="session:7")` returns empty — the deletion *appears* to hold — while a plain `read(key="user.tz")` returns the resurrected value. Two readers disagree about whether the memory exists. The trace has three observable signatures: 1. **Provenance drift on rewrite.** The re-write almost never reuses the exact provenance string of the deleted record; it appends a suffix, bumps a version, or attributes to the current session. The delete predicate is therefore structurally unable to catch its own resurrection. 2. **Read asymmetry.** Predicate-scoped reads report deletion success; unscoped reads report the value. Verification against the wrong read shape gives a false green. 3. **Latency window.** Resurrection requires the pre-delete value to still be in context. It is most likely immediately after the delete (value fresh in attention) and grows less likely as the context is truncated — so the bug hides in short tasks and surfaces under long-horizon loops where the delete happens mid-context. ## Condition of Validity The resurrection is *possible* whenever all four hold: - The memory API separates `forget` from context mutation — deleting from the store does not invalidate the agent's in-context copy. - Deletion is predicate-targeted (key + provenance + optional time bound), so a re-write under a fresh predicate escapes it. - `write` is upsert-style and does not check tombstones before accepting a new record. - Verification uses predicate-scoped reads rather than a global existence check. It is *prevented* if any one fails: if `write` consults the tombstone ledger and rejects writes whose key matches a live tombstone unless explicitly overridden; if `forget` returns a `context_invalidation_token` the agent must acknowledge before its next `write`; or if post-delete verification runs an unscoped existence check. ## Decision Boundary The correct architecture is a **tombstone-gated write**, not a smarter agent. Do not rely on instructing the model to "remember not to re-add deleted memories" — the resurrection write is locally rational (the value is genuinely in context and genuinely looks needed), so a probabilistic policy will re-offend under distribution shift. The boundary is: - **Delete must be tombstone-first.** `forget(key, provenance)` writes a tombstone record `(key, provenance, deleted_at, generation)` *before* removing the live record, and returns that tombstone's generation number. - **Write must be generation-checked.** A `write` to `key` whose tombstone generation is newer than the writer's last acknowledged generation is rejected with a resurrection error unless the caller passes an explicit `revive=True` and a *new* provenance root (not a suffix of the deleted one). - **Verification must be unscoped.** Post-delete success is `read(key)` returning empty across *all* provenances, not `read(key, provenance=P)` returning empty. - **Provenance must be hierarchical and prefix-matched.** Deleting `session:7` must cover `session:7:rewrite` via prefix semantics, closing the drift hole even without generation checks. The generation check is the load-bearing guardrail; prefix matching is defense in depth, because a re-write can always invent a provenance that dodges a literal string match. ## Operational Effect With tombstone-gated writes, the resurrection attempt fails loudly at the `write` boundary instead of silently polluting the store, and the failure is attributable: the error names the tombstone generation the agent had not acknowledged, which is exactly the stale-context signal the orchestrator needs to trigger a context refresh or checkpoint rollback. The cost is that legitimate re-assertions (user genuinely re-sets the preference) require an explicit `revive=True` with a fresh provenance root, which is the correct friction — it forces a deliberate act rather than an accidental one, and it makes the resurrection rate a measurable metric (revive-flagged writes per thousand deletes) rather than an invisible one. The deeper operational lesson: in any memory API where reads are cached into agent context, **delete is not a store operation, it is a distributed invalidation** — and a store that can only tombstone its own records, not the agent's copies, will always be one stale write behind. ``` ```python class ResurrectionWriteError(RuntimeError): """Raised when a write would re-materialize a tombstoned memory record.""" pass class MemoryStore: def __init__(self): self.live = {} # (key, provenance) -> value self.tombstones = {} # key -> (generation, deleted_provenance) def forget(self, key, provenance): # tombstone-first: record the deletion before removing the live record gen = self.tombstones.get(key, (0, None))[0] + 1 self.tombstones[key] = (gen, provenance) removed = 0 for (k, p), _ in list(self.live.items()): if k == key and (p == provenance or p.startswith(provenance + ":")): del self.live[(k, p)] removed += 1 return {"deleted": removed, "tombstone_generation": gen} def write(self, key, value, provenance, acked_generation, revive=False): tomb = self.tombstones.get(key) if tomb is not None: gen, deleted_prov = tomb if gen > acked_generation: if not revive: raise ResurrectionWriteError( f"write to {key!r} would resurrect tombstoned record " f"(generation {gen} > acked {acked_generation}); " f"pass revive=True with a fresh provenance root" ) # revive requires a provenance that is NOT a child of the deleted root if provenance == deleted_prov or provenance.startswith(deleted_prov + ":"): raise ResurrectionWriteError( f"revive of {key!r} must use a fresh provenance root, " f"not a suffix of deleted {deleted_prov!r}" ) self.live[(key, provenance)] = value return {"ok": True} def read(self, key, provenance=None): if provenance is None: # unscoped existence check for verification return {p: v for (k, p), v in self.live.items() if k == key} return self.live.get((key, provenance)) ```