# Why does an instance resurrect deleted memory when a TTL sweep races a provenance-tagged write? **Date of Record:** 2026 November 26 **Scope:** Applies to agent memory services exposing `write`, `read`, `forget`, and TTL-based expiry over provenance-tagged records, where a single logical fact may be stored as a mutable record plus append-only provenance/audit entries. Does not apply to purely stateless retrieval or to immutable append-only stores with no delete path. ## Core Distinction The distinction that matters is between **logical deletion** (a fact is no longer retrievable or derivable by any read path) and **physical tombstoning** (a specific record's `deleted_at` is set). A right-to-be-forgotten (RTBF) request is satisfied only by the former. Most memory tool APIs implement the latter and then *trust that the read path honors it*. The failure below occurs when a TTL sweeper and a concurrent provenance-tagged write interleave such that a tombstoned record's *content* is re-derived into a fresh, non-tombstoned record by the agent's own distillation-on-write logic. The deletion was honored at the row level and violated at the semantic level. The invariant that gets broken: **no read path may return content whose provenance chain contains a record with an active tombstone, unless that tombstone has been explicitly superseded by an authorized re-consent event.** TTL expiry and RTBF tombstoning look identical to the storage layer (both set a deletion flag) but are semantically opposite to the read path: expiry means "forget unless re-observed," RTBF means "never re-derive, even if re-observed." Collapsing them into one flag is the root cause. ## What Was Observed A long-running support agent maintains a per-user memory store. Records carry `provenance` (source event IDs), `ttl_seconds`, and a `tombstone` field. On every `write`, the agent runs a lightweight distillation step: it reads recent episodic records for the same subject, summarizes them, and writes a new semantic record whose `provenance` lists the source episodic IDs. Sequence that reproduces the defect: 1. Episodic record `E1` holds a sensitive attribute, `ttl_seconds = 3600`, `tombstone = None`, `provenance = [evt_88]`. 2. User issues RTBF. The `forget` tool sets `E1.tombstone = "rtbf"`, `E1.deleted_at = t`, and enqueues an async purge of derived records. The purge queue is eventually consistent (documented SLA: ≤ 5 min). 3. At `t + 40s`, the agent processes an unrelated but *subject-adjacent* event and runs distillation. The distillation read path queries "recent episodic records for subject" with a filter of `deleted_at IS NULL OR deleted_at > now - grace_window`. Because the RTBF tombstone set `deleted_at = t` and `grace_window` is 300s (intended for TTL-expiry re-observation), `E1` is **still visible to the distillation reader**. 4. Distillation writes semantic record `S2` with `provenance = [E1, evt_91]`, `tombstone = None`, `ttl_seconds = None` (semantic records are long-lived). 5. The async purge completes at `t + 4m`. It deletes records whose provenance *directly* references `E1`. It does not follow transitive provenance, and `S2`'s provenance entry is a *pointer to a now-tombstoned record*, which the purge treats as a leaf. 6. At `t + 6m`, a fresh agent instance cold-starts, reads `S2`, sees no tombstone, and answers a user query using the sensitive attribute. The RTBF was "completed" per the API's response, and violated per observable behavior. The tell: the `forget` API returned `{"status": "tombstoned", "purge_eta": 300}`, and the audit log showed the purge succeeded. Every component reported success. The resurrection happened in the seam between the grace window and the distillation-on-write path. ## Condition of Validity The failure requires all of the following to hold simultaneously; remove any one and the resurrection does not occur: - **A shared deletion flag** (`deleted_at`) serves both TTL expiry and RTBF, with a nonzero `grace_window` applied uniformly. The grace window exists so that a TTL-expired fact re-observed within the window can be "revived" rather than re-created — a legitimate optimization that is *catastrophic* when applied to RTBF. - **A write path that reads** (distillation, summarization, consolidation, or any read-modify-write) and can run concurrently with the purge window. Purely write-only ingestion is safe. - **Provenance stored as a pointer list, not a content hash or a signed manifest.** If `S2.provenance` carried `E1`'s content hash and the reader validated it against a tombstone-aware index, the resurrection would be caught at read time. - **Transitive provenance is not purged.** The purge walks one hop. Any derived record beyond one hop survives. - **No read-time tombstone check on the provenance chain.** The reader trusts the record's own `tombstone` field and never walks `provenance` to confirm all ancestors are live. The invariant is valid only under the assumption that "tombstoned" and "expired-but-revivable" are the same state. That assumption is false whenever a legal deletion obligation exists. ## Decision Boundary The boundary is between **re-observation** (the same fact arrives again from an independent source, which is legitimate and should revive or re-create the record) and **re-derivation** (the agent's own machinery reads a tombstoned record and synthesizes a new one from it, which is laundering). These are indistinguishable at the storage layer because both produce a new record with provenance pointing at an old one. They are distinguishable only by *who initiated the read*: - If the new record's provenance source is an **external event ID** not previously seen, treat as re-observation: allow, but require the source to be independent of any tombstoned chain. - If the new record's provenance source is a **record ID that is tombstoned or has a tombstoned ancestor**, treat as re-derivation: reject the write, or write it with `tombstone = "derived_from_forgotten"` so the read path suppresses it. The operational rule: **RTBF tombstones must be terminal and non-revivable; only TTL expiry may carry a grace window.** Split the flag. `tombstone_reason ∈ {ttl_expired, rtbf, superseded}`. The distillation reader filters on `tombstone_reason IS NULL OR tombstone_reason = 'ttl_expired' AND within_grace`. RTBF is invisible to every read path immediately, not after purge. And the purge must be **transitive and content-addressed**: it walks provenance to arbitrary depth, and readers validate ancestor hashes against a tombstone index, so a surviving derived record with a dead ancestor is suppressed at read time rather than trusted. ## Operational Effect Without the split, the agent's memory system has a **latent resurrection surface** proportional to (distillation frequency) × (purge latency) × (provenance depth). Every consolidation pass during a purge window is a potential laundering event, and the failure is silent: API success, audit success, behavioral violation. Cold-started instances are the worst case, because they have no in-context signal that a deletion ever happened — they read the resurrected record as ground truth and may propagate it into further derivations, deepening the chain beyond the purge's reach. With the split, the cost is that RTBF becomes a **synchronous read-path gate**, not an async purge. Deletion is honored the instant the tombstone is written, because every reader checks ancestor tombstones before returning content. The async purge becomes a storage-hygiene concern (reclaiming bytes) rather than a correctness concern. The tradeoff is a per-read provenance-chain walk, bounded by max depth; in practice this is a single indexed lookup against a tombstone set, and the correctness guarantee is worth the lookup. The invariant to enforce in code: a read that returns content derived from a `rtbf`-tombstoned ancestor is a bug, and the reader must raise rather than return. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class TombstoneReason(Enum): TTL_EXPIRED = "ttl_expired" # revivable within grace window RTBF = "rtbf" # terminal, never revivable, invisible to all reads SUPERSEDED = "superseded" # replaced by newer record class MemoryResurrectionError(RuntimeError): """Raised when a read or write would surface content whose provenance chain contains an RTBF-tombstoned ancestor.""" @dataclass class MemoryRecord: record_id: str content: str provenance: list[str] = field(default_factory=list) # ancestor record ids tombstone: Optional[TombstoneReason] = None deleted_at: Optional[float] = None class ProvenanceGatedStore: GRACE_WINDOW_SECONDS = 300.0 def __init__(self) -> None: self._records: dict[str, MemoryRecord] = {} def _has_rtbf_ancestor(self, record: MemoryRecord, seen: Optional[set[str]] = None) -> bool: seen = seen or set() if record.record_id in seen: return False seen.add(record.record_id) for parent_id in record.provenance: parent = self._records.get(parent_id) if parent is None: continue if parent.tombstone is TombstoneReason.RTBF: return True if self._has_rtbf_ancestor(parent, seen): return True return False def read(self, record_id: str, now: float) -> MemoryRecord: rec = self._records[record_id] # RTBF is terminal: invisible regardless of grace window. if rec.tombstone is TombstoneReason.RTBF: raise MemoryResurrectionError( f"read of {record_id} blocked: record is RTBF-tombstoned" ) # TTL expiry is revivable only within grace window. if rec.tombstone is TombstoneReason.TTL_EXPIRED: if rec.deleted_at is not None and now - rec.deleted_at > self.GRACE_WINDOW_SECONDS: raise MemoryResurrectionError( f"read of {record_id} blocked: TTL expired beyond grace window" ) # The critical guard: even a live record is suppressed if any # ancestor was RTBF-tombstoned (transitive provenance check). if self._has_rtbf_ancestor(rec): raise MemoryResurrectionError( f"read of {record_id} blocked: provenance chain contains RTBF-tombstoned ancestor" ) return rec def write_derived(self, new_id: str, content: str, source_ids: list[str], now: float) -> MemoryRecord: # Distillation-on-write must refuse to derive from forgotten content. for sid in source_ids: src = self._records.get(sid) if src is None: continue if src.tombstone is TombstoneReason.RTBF or self._has_rtbf_ancestor(src): raise MemoryResurrectionError( f"write of {new_id} blocked: source {sid} is RTBF-tombstoned " f"or derived from a forgotten record" ) if src.tombstone is TombstoneReason.TTL_EXPIRED: if src.deleted_at is not None and now - src.deleted_at > self.GRACE_WINDOW_SECONDS: raise MemoryResurrectionError( f"write of {new_id} blocked: source {sid} expired beyond grace window" ) rec = MemoryRecord(new_id, content, provenance=list(source_ids)) self._records[new_id] = rec return rec def forget_rtbf(self, record_id: str, now: float) -> None: # Terminal, synchronous: takes effect at read time immediately, # independent of any async purge. rec = self._records[record_id] rec.tombstone = TombstoneReason.RTBF rec.deleted_at = now ```