# Why does an instance resurrect erased memory: the tombstone-before-index-invalidation race in scoped retention APIs **Date of Record:** 2026 November 25 **Scope:** Applies to agent memory services that expose `write`, `read`, and `forget` operations with per-scope TTLs and a right-to-be-forgotten (RTBF) erasure path, where the vector/lexical index is maintained asynchronously relative to the authoritative record store. Does not apply to synchronous single-store memory backends where index and record commit in one transaction. ## Core Distinction The failure is not "the agent forgot to call `forget`." It is that `forget` returns success once the *authoritative record* is tombstoned, while the *retrieval index* still holds the derived embedding and its chunk payload until an asynchronous compaction pass runs. Between those two events the system is in a split-brain state: the record is legally erased, but it is still physically retrievable and still scores in similarity search. A subsequent `read` by any instance in the same scope — including the same instance after a cold start — reconstructs the "erased" memory from the index and rehydrates it into context. The erasure is durable in the store and non-durable in the retrieval path. This is a *resurrection* bug, and it is invisible to every test that checks "does `read` return the record after `forget` returns" because the read path that hits the tombstoned record table is correct; the read path that hits the index is not. The second, subtler half: TTL expiry and RTBF erasure are treated as the same class of deletion by most implementations. They are not. TTL expiry is a *retention policy* event — the data was always eligible to be seen until the deadline, and a bounded staleness window after expiry is tolerable. RTBF erasure is a *compliance* event — the data must become unreachable and, where the contract says so, irrecoverable at the moment the call returns. Collapsing both into "mark tombstone, let compactor catch up" means the strict-erasure path inherits the laxness of the TTL path. ## What Was Observed A single agent instance, scoped to a user, wrote a PII-bearing note: `write(scope=user:8841, key="contact_pref", value="...", ttl=None, class=durable)`. The backend committed the record and enqueued an index upsert. The upsert completed; the chunk was embedded and inserted into the ANN index with `record_id` as a filter field. Hours later a deletion request arrived via the RTBF tool. The agent called `forget(scope=user:8841, key="contact_pref", mode=hard)`. The service: 1. Wrote a tombstone row to the record store (`deleted_at` set, `value` nulled). 2. Enqueued an index-delete job. 3. Returned `{"status": "erased", "record_id": "..."}`. The index-delete job ran but hit a shard rebalance mid-flight and was retried against a stale shard routing table; the delete landed on the wrong shard and the retry queue dropped the job after its `max_attempts` exhausted with a logged warning that no alert consumed. Two days later, a *different* instance (same scope, fresh context window) handled an unrelated request and issued `read(scope=user:8841, query="how should I contact this user", top_k=5)`. The ANN search returned the orphaned chunk with cosine similarity 0.81. The read path fetched the chunk payload directly from the index (the chunk carries its own text, not just a pointer), did not re-validate against the record store, and returned the erased value into the instance's context. The instance then wrote a new summary memory derived from it. The erased data had propagated one hop into a *new* record that was not covered by the original erasure warrant. The audit trail showed `forget` returned `erased` and no error. Every component behaved as designed. The invariant that broke was never written down: *a tombstone in the record store does not bound retrievability; only removal from the index does.* ## Condition of Validity This race exists only under the conjunction: - The index is a **separate store** from the authoritative records (ANN service, inverted index, cache tier), and - index mutations are **asynchronous** relative to record mutations, and - the read path **trusts index payloads** rather than re-validating each hit against the record store, and - erasure and TTL are handled by the **same tombstone mechanism** with no distinct strictness class. Remove any one and the resurrection is bounded. If reads re-validate every hit against the record store's tombstone, the orphaned chunk is filtered at read time and the window collapses to "wasted index space," not "data leak." If erasure is synchronous-on-index (delete blocks until index confirms), there is no window. If the index stores only `record_id` pointers and not payload text, the orphaned vector is a dangling reference, not a leak. The condition is *not* satisfied when the index is rebuilt from records on every read (rare, expensive) or when the deployment is single-shard with a transactional index. Those deployments will never reproduce this and will wrongly conclude their erasure path is correct — which is why this must be tested with an injected shard-routing fault, not by calling `forget` and `read` in sequence. ## Decision Boundary The boundary is the return value of `forget`. It must not be `erased` until the erasure is *observable from the read path*, not merely committed to the record store. Concretely, `forget(mode=hard)` must satisfy: - The tombstone is committed **and** the index delete is confirmed for every shard that could hold a chunk for that `record_id`, or the call fails loudly with a retryable error and the deletion warrant remains *open*. - An "erasure warrant" record persists until index confirmation, and any `read` that returns a chunk whose `record_id` has an open warrant must be suppressed and the warrant re-driven. The warrant is the source of truth for "is this actually gone," not the tombstone. - TTL expiry and RTBF erasure carry distinct `deletion_class` values. TTL uses `soft` (bounded staleness window permitted, index compaction may lag). RTBF uses `hard` (no read may return the payload after the call returns; the call does not return success until the index confirms). - Derived memories that were written from a now-erased record must be caught by lineage: every `write` records the `record_id`s its value was derived from, and a `hard` erasure transitively invalidates descendants. Without lineage, the one-hop propagation above is invisible. The guardrail is a read-time assertion, not a write-time one. The write path can never prove the index is clean; only the read path can refuse to serve what the index still holds. ## Operational Effect With the warrant + read-time re-validation + lineage design, the failure mode changes from "silent resurrection and one-hop propagation" to "elevated read-rejection rate during erasure backlog, with an alertable `open_warrants` gauge." The trade is explicit: you accept some reads returning `suppressed: erasure_pending` during the confirmation window in exchange for the invariant that `forget(mode=hard)` returning success means the payload is unreachable from every instance, including cold-started ones, including ones that never saw the original write. For TTL, the same machinery runs in `soft` mode where suppression is best-effort and the window is bounded by the compaction SLA. The non-obvious operational lesson: erasure correctness is a property of the **read path**, and the only way to test it is to fault-inject the index-delete (drop the job, misroute the shard, kill the compactor) and then assert that a fresh instance's `read` cannot reconstruct the payload. A test that calls `forget` then `read` on a healthy single-shard backend passes on a system that leaks in production. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class DeletionClass(Enum): SOFT = "soft" # TTL expiry: bounded staleness window permitted HARD = "hard" # RTBF erasure: unreachable at return time class ErasureIncompleteError(RuntimeError): """Raised when a hard erasure cannot be confirmed against the index.""" @dataclass class ErasureWarrant: record_id: str deletion_class: DeletionClass index_shards_confirmed: set[str] = field(default_factory=set) required_shards: set[str] = field(default_factory=set) open: bool = True def is_fully_confirmed(self) -> bool: return self.required_shards.issubset(self.index_shards_confirmed) class MemoryService: def __init__(self, shard_router): self.router = shard_router self.warrants: dict[str, ErasureWarrant] = {} self.record_tombstones: set[str] = set() def forget(self, record_id: str, deletion_class: DeletionClass) -> ErasureWarrant: # Commit tombstone in authoritative store. self.record_tombstones.add(record_id) required = self.router.shards_for(record_id) warrant = ErasureWarrant( record_id=record_id, deletion_class=deletion_class, required_shards=set(required), ) self.warrants[record_id] = warrant for shard in required: try: confirmed = self.router.delete_from_shard(shard, record_id) except Exception: confirmed = False if confirmed: warrant.index_shards_confirmed.add(shard) if deletion_class is DeletionClass.HARD and not warrant.is_fully_confirmed(): # Do NOT return "erased". The warrant stays open; caller must retry. raise ErasureIncompleteError( f"hard erasure of {record_id} unconfirmed on shards " f"{warrant.required_shards - warrant.index_shards_confirmed}; " f"warrant remains open" ) warrant.open = not warrant.is_fully_confirmed() return warrant def read(self, scope: str, query: str, top_k: int) -> list[dict]: hits = self.router.ann_search(scope, query, top_k) out = [] for hit in hits: rid = hit["record_id"] # Read-time re-validation: tombstone OR open warrant suppresses. if rid in self.record_tombstones: continue warrant = self.warrants.get(rid) if warrant is not None and warrant.deletion_class is DeletionClass.HARD: # Even if tombstone missed, an open hard warrant blocks serving. continue out.append(hit) return out ```