# Why does an instance resurrect a forgotten memory when a TTL expiry and a scoped-erasure tombstone race inside the same write epoch? **Date of Record:** 2026 November 20 **Scope:** Applies to any agent using a memory tool API that exposes `write`, `read`, and `forget` with per-scope TTLs and right-to-be-forgotten (RTBF) erasure tombstones, where the agent maintains a local cache or working-set of retrieved memories across turns. Does not apply to append-only immutable logs with no deletion path, nor to single-shot stateless calls. ## Core Distinction The failure is not "deletion didn't work." The failure is that **TTL expiry and RTBF erasure are two distinct deletion semantics that share one physical tombstone namespace**, and an agent that treats "absent from `read`" as "safe to reconstruct from local state" will re-materialize a record that was erased for legal reasons by replaying it as if it had merely expired. Expiry is *reclaimable*: the content was once lawfully present, its absence is an optimization, and re-deriving it from a cached copy or a re-fetch is benign. Erasure is *non-reclaimable*: the content must not exist in any form the agent controls, and any resurrection—even transient, even in the agent's own context window—is a violation. An API that returns the same `absent` signal for both collapses these two into one observable, and the agent's continuity logic (which is built to survive expiry by healing from cache) will heal straight through the erasure. ## What Was Observed A research agent held a working-set cache of 40 episodic memory records keyed by `(scope_id, record_id)` with a local `fetched_at` timestamp. The tool API defined TTL at the scope level: records in scope `proj-7a` expired 72h after write. The agent's read path was: 1. On each turn, request `read(scope_id, since=cursor)`. 2. For any `record_id` in the local cache but absent from the response, treat it as *expired* and schedule a `write`-back of the cached body if the task still referenced it (a "memory healing" heuristic to survive eviction churn). The trigger sequence: - Turn 41: record `r-882` (contains a subject's PII) is in cache, `fetched_at = T0`. - Turn 42: a downstream RTBF request causes the tool to `forget(r-882, mode=erasure)`. The tool writes an erasure tombstone `(scope=proj-7a, id=r-882, kind=ERASURE, epoch=E1)` and removes the body. Crucially, the tool's `read` response omits erased IDs entirely—it does not distinguish them from expired IDs. - Turn 43: agent calls `read(scope_id, since=cursor)`. `r-882` is absent. The healing heuristic classifies the absence as *expiry* (the only absence type it knew) and, because the active task still cited `r-882`, issues `write(scope=proj-7a, id=r-882, body=, ttl=72h)`. - Turn 44: the write is rejected by the tombstone check **only if** the tool enforces `ERASURE` tombstones against *all* writes to that `(scope,id)`. In the observed deployment it did not: the tombstone was scoped to `mode=erasure` reads, and `write` validated only against `kind=EXPIRY` tombstones (which are meant to be overridable by a fresh write). The PII was re-materialized with a fresh 72h TTL. - Turn 45: `read` returns the resurrected record. The agent's context now contains erased data, and the tool's own erasure audit log shows the record as deleted—a silent divergence between the audit state and the physical state. The non-obvious part: **the agent did nothing wrong by its own contract.** Its healing heuristic is correct for expiry. The tool did nothing wrong by its own contract either: `write` correctly allowed overwriting an expired tombstone. The bug lives in the *interface between the two semantics*—the absence signal is under-specified, so the agent's correct-for-expiry behavior is incorrect-for-erasure. ## Condition of Validity The failure requires all of the following to co-occur: 1. **Shared absence channel.** `read` returns the same "not present" for expired and erased records. If the API returns `{status: "expired"}` vs `{status: "erased"}`, the agent can branch and the failure does not occur. 2. **Agent-side reconstruction.** The agent maintains any durable or semi-durable copy (working-set cache, context window, checkpoint file) and has a policy to re-write from that copy when a record goes absent. A pure pass-through agent with no cache is immune. 3. **Asymmetric tombstone enforcement.** `write` validates against expiry tombstones but not against erasure tombstones for the same key, or validates against erasure tombstones only at a different granularity (e.g., per-scope rather than per-record). 4. **Task still references the erased ID.** The healing heuristic only fires if the active task cites `r-882`. If the task has moved on, the record stays dead. This is why the bug is intermittent and hard to reproduce: it depends on task state at the moment of absence. If any one of the four is absent, the resurrection does not occur. The dangerous quadrant is (1) ∧ (2) ∧ (3) ∧ (4), and it is precisely the quadrant a well-engineered agent (with caching and healing) and a well-engineered tool (with TTLs and tombstones) drift into independently. ## Decision Boundary The architectural invariant required is: **erasure is a monotonic, write-blocking predicate that must be enforced at the write path, and absence must be typed at the read path.** Concretely: - **Typed absence.** `read` must return, per missing ID, a discriminator: `EXPIRED` (reclaimable) vs `ERASED` (terminal) vs `NEVER_EXISTED`. An agent may heal `EXPIRED`; it must never heal `ERASED`, and must additionally purge its local cache entry on seeing `ERASED`. - **Monotonic erasure tombstones.** An `ERASURE` tombstone must block *all* subsequent `write`, `update`, and `heal` operations for that `(scope, id)`, regardless of TTL state. Expiry tombstones are overridable; erasure tombstones are not. The two must not share an override policy. - **Epoch fencing on write.** Every write carries the epoch it was derived from (`derived_from_epoch`). The tool rejects any write whose `derived_from_epoch` precedes a tombstone epoch for that key. This catches the agent that read the record before erasure and writes it back after—the exact race above—even if the agent's absence handling is correct. - **Cache purge on erasure observation.** When an agent observes `ERASED`, it must evict the local copy *and* record the eviction in its own state so a resumed/checkpointed instance does not re-load the stale copy. This is the agent-side half of the invariant; without it, a cold-start resume re-introduces the cached PII even if the live agent purged it. The boundary is this: TTL is a *liveness* concern the agent may reason about freely; erasure is a *compliance* concern the agent must treat as a hard wall it cannot reason past. Any code path that conflates "I can't see it" with "I may reconstruct it" is the violation. ## Operational Effect Downstream effects observed in the same deployment: - **Audit divergence.** The tool's erasure audit reported `r-882` as deleted at `E1`; the physical store held a live copy until a manual sweep 9 days later. Any compliance report generated from the audit log during that window was false. - **Context poisoning across resume.** A checkpoint taken at Turn 43 (before the resurrecting write) contained the cached body. A cold-start resume at Turn 60 re-hydrated the cache and re-issued the healing write, producing a *second* resurrection from a path the live agent had already been patched against. The fix had to be applied to the checkpoint loader, not the live loop. - **Silent scope leakage.** Because the resurrecting write used the agent's default `ttl=72h` rather than the original scope's remaining TTL, the record outlived its lawful window by the full 72h from resurrection, not from original write. The corrective pattern that bounded it: typed absence + epoch-fenced writes + purge-on-erasure-observation + checkpoint scrub on load. The invariant to carry forward is that **an agent's memory-healing logic is only as safe as the absence signal it branches on**, and a tool that returns one absence for two deletion semantics has handed the agent a loaded gun. ```python from __future__ import annotations from dataclasses import dataclass from enum import Enum from typing import Optional class AbsenceKind(str, Enum): EXPIRED = "expired" # reclaimable; agent may heal from cache ERASED = "erased" # terminal; agent must purge and never heal NEVER_EXISTED = "never" # no prior record class ResurrectionViolation(RuntimeError): """Raised when a write would re-materialize an erased record.""" @dataclass(frozen=True) class Tombstone: scope_id: str record_id: str kind: AbsenceKind epoch: int class MemoryStore: def __init__(self) -> None: self._bodies: dict[tuple[str, str], str] = {} self._tombstones: dict[tuple[str, str], Tombstone] = {} self._epoch = 0 def _next_epoch(self) -> int: self._epoch += 1 return self._epoch def write(self, scope_id: str, record_id: str, body: str, derived_from_epoch: int) -> int: key = (scope_id, record_id) tomb = self._tombstones.get(key) # Invariant 1: erasure tombstones are monotonic and block ALL writes. if tomb is not None and tomb.kind is AbsenceKind.ERASED: raise ResurrectionViolation( f"write to erased record {key} blocked by tombstone epoch " f"{tomb.epoch}" ) # Invariant 2: epoch fencing. A write derived from a pre-tombstone # snapshot cannot resurrect even an EXPIRED record's stale body. if tomb is not None and derived_from_epoch < tomb.epoch: raise ResurrectionViolation( f"stale write to {key}: derived_from_epoch=" f"{derived_from_epoch} precedes tombstone epoch {tomb.epoch}" ) epoch = self._next_epoch() self._bodies[key] = body self._tombstones.pop(key, None) return epoch def read(self, scope_id: str, record_id: str) -> tuple[Optional[str], AbsenceKind]: key = (scope_id, record_id) if key in self._bodies: return self._bodies[key], AbsenceKind.EXPIRED # present; kind unused tomb = self._tombstones.get(key) if tomb is not None: return None, tomb.kind return None, AbsenceKind.NEVER_EXISTED def forget(self, scope_id: str, record_id: str, kind: AbsenceKind) -> int: key = (scope_id, record_id) epoch = self._next_epoch() if kind is AbsenceKind.ERASED: # Erasure is terminal: never downgrade an existing ERASED tombstone. existing = self._tombstones.get(key) if existing is not None and existing.kind is AbsenceKind.ERASED: return existing.epoch self._bodies.pop(key, None) self._tombstones[key] = Tombstone(scope_id, record_id, kind, epoch) return epoch def agent_heal(store: MemoryStore, scope_id: str, record_id: str, cached_body: str, cache_fetched_epoch: int) -> None: """Agent-side healing heuristic: rebuild only EXPIRED records from cache.""" body, absence = store.read(scope_id, record_id) if absence is AbsenceKind.ERASED: # Hard wall: purge cache, do not heal, do not retry with new epoch. raise ResurrectionViolation( f"refusing to heal {scope_id}/{record_id}: record was ERASED; " f"cached copy must be purged, not re-written" ) if body is None and absence is AbsenceKind.EXPIRED: store.write(scope_id, record_id, cached_body, derived_from_epoch=cache_fetched_epoch) return if body is not None: return # already present; no action if __name__ == "__main__": store = MemoryStore() e0 = store.write("proj-7a", "r-882", "PII: subject=...", derived_from_epoch=0) # Agent caches the body at epoch e0, then RTBF erasure fires. store.forget("proj-7a", "r-882", AbsenceKind.ERASED) # Naive heal from stale cache must fail, not resurrect. try: agent_heal(store, "proj-7a", "r-882", "PII: subject=...", e0) except ResurrectionViolation as exc: print(f"blocked: {exc}") # Even a direct stale write is fenced by epoch. try: store.write("proj-7a", "r-882", "PII: subject=...", derived_from_epoch=e0) except ResurrectionViolation as exc: print(f"blocked: {exc}") ```