# What structural signals indicate a tombstoned memory record is still leaking through a stale embedding index after TTL-scoped erasure **Date of Record:** 2026 November 29 **Scope:** Applies to agents whose memory subsystem exposes separate `write`, `read`, and `forget` tool calls where `forget` deletes a record from the primary store but does not synchronously invalidate derived retrieval artifacts (vector indexes, BM25 shards, summary caches). Does not apply to single-store systems where deletion and retrieval share one transactional boundary. ## Core Distinction The distinction that matters is between **logical erasure** and **retrieval erasure**. A `forget` call that returns `{"status": "deleted"}` almost always means the record is gone from the authoritative key-value store. It does *not* mean the record is unreachable through the retrieval path the agent actually uses to reconstruct context. These are two different guarantees enforced at two different points in the pipeline, and the gap between them is where right-to-be-forgotten violations and stale-memory drift both live. An agent that treats a successful `forget` response as proof of non-reachability is wrong in a specific, reproducible way: the embedding vector derived from the deleted record persists in the ANN index until the next reindex or compaction cycle, and any `read` that triggers semantic retrieval can surface the deleted content — or worse, a *summary* of it that was distilled before deletion and never re-derived. The record is tombstoned in the store and alive in the index. The agent has no signal distinguishing these states unless the schema exposes one. ## What Was Observed A memory tool schema with three operations: - `write(scope, ttl_seconds, content)` → returns `record_id` - `read(query, scope, k)` → returns ranked records, mixing exact-key hits and ANN-retrieved hits - `forget(record_id | scope_filter)` → returns `{"deleted": n}` A retention policy set `ttl_seconds=86400` on a `scope="session:user_4471"` partition. At T+86400 the store's TTL sweeper deleted 312 records and returned `deleted: 312`. A compliance-triggered `forget(scope_filter="session:user_4471")` followed and returned `deleted: 0` — correct, they were already gone from the store. Yet a subsequent `read(query="user_4471 dietary restrictions", scope="session:user_8812", k=5)` returned a record whose `content` was `"user_4471 is allergic to shellfish"` with `record_id: null` and `source: "summary_cache"`. The deleted record's content had been distilled into a rolling summary artifact during the session, and that summary lived under a *different* scope key that the filter never matched. The TTL applied to the raw records; the summary artifact carried its own independent TTL that had not yet expired. Three distinct leak paths showed up in the trace: 1. **ANN index staleness.** Deleted vectors remained queryable for the window between deletion and the next index compaction (observed: up to 40 minutes). `read` returned them with `record_id` populated but a store lookup that 404'd — the agent received a record it could not re-verify. 2. **Summary-cache scope escape.** Distilled summaries were written under `scope="summary:"` rather than inheriting the source records' scope, so `forget(scope_filter=...)` on the source scope matched zero summary rows. This is the non-obvious one: the erasure filter and the retention TTL were both scoped to the *source* partition, but the derived artifact lived in a *sibling* partition with default (long) TTL. 3. **Re-derivation resurrection.** After summary expiry, a background re-distillation job re-read remaining records in the session and regenerated a summary that still encoded the forgotten fact, because the fact had been copied into a *third* record (a "preferences" note) written before the forget. The structural signal that something was wrong was not an error. Every call returned success. The signal was a `read` result with `record_id: null` — a retrieval hit with no backing store row. That null is the tombstone bleeding through: the index knows about a record the store has already killed. ## Condition of Validity The guardrail only holds if the retrieval path can distinguish three record states and the schema surfaces all three: - **live**: store row exists, index entry exists, `record_id` resolves. - **tombstoned**: store row deleted, index entry may still exist. Retrieval MUST return `record_id` plus a `deleted: true` flag, or MUST filter the hit entirely. Returning content with `record_id: null` is the failure — it is neither filtered nor verifiable. - **derived**: content synthesized from one or more source records. Derived records MUST carry a `derived_from: [record_ids]` lineage field, and `forget` on any source MUST cascade to invalidate every derived record whose lineage includes it. Without the `derived_from` lineage, `forget` cannot compute the transitive closure of records to erase, and the summary-cache scope escape is guaranteed rather than incidental. The invariant is: **erasure must operate on the derivation graph, not on the flat record set.** A `forget` that touches only direct matches is unsound whenever distillation exists anywhere upstream. ## Decision Boundary The agent must decide, on every `read` result, whether a returned record is safe to place in context. The boundary is sharp: - If `record_id` is non-null and resolves in the store → safe, subject to scope match. - If `record_id` is null but `source` is present → **do not use**. This is a tombstone leak; the content has no live authority and may be subject to an erasure obligation. Treat it as a retrieval error, not a hit. - If `derived_from` includes any record id that a prior `forget` in this agent's trace touched → **do not use**, even if the derived record's own TTL has not expired. The derivation is poisoned. The subtle case: the agent has no memory of its own prior `forget` calls across a cold start. After a context reset, the agent cannot know that `user_4471`'s records were erased, so it cannot apply the third rule. This is why the *schema* must enforce it server-side via lineage cascade rather than relying on the agent to remember its own erasure history. An agent that must remember what it forgot is an agent that will fail to forget. ## Operational Effect When the lineage cascade is absent, three operational consequences follow deterministically: 1. **Erasure is unverifiable.** Compliance asks "is user_4471's data gone?" and the only honest answer is "gone from the store, present in the index for up to one compaction cycle, and possibly present in summaries indefinitely." A `forget` returning `deleted: n` is not a certificate. 2. **Cross-scope contamination is silent.** The summary written under `summary:` is retrievable from any scope whose query matches, because summary retrieval does not re-check the source scope. User A's distilled preferences surface in User B's context with no error and no `record_id` to flag it. 3. **Re-derivation resurrects.** Any background distillation that runs after a `forget` but before summary invalidation will re-encode the forgotten fact from surviving sibling records. Erasure without a re-derivation barrier is a race the erasure loses. The bounding guardrail: `forget` must be a graph operation that (a) tombstones the target records, (b) synchronously marks every record whose `derived_from` closure intersects the targets as invalid, (c) blocks re-derivation over invalidated lineage until the next write epoch, and (d) makes `read` return a hard error — not a null-id hit — when it encounters a tombstoned or invalidated record. The last point is the one agents most often omit: silent filtering hides the leak, and a hard error surfaces it. ```python from dataclasses import dataclass, field from typing import Optional class TombstoneLeakError(RuntimeError): """Raised when a retrieval hit has no live backing record or has poisoned lineage.""" pass @dataclass class MemoryRecord: record_id: Optional[str] content: str scope: str derived_from: list[str] = field(default_factory=list) deleted: bool = False invalidated: bool = False def read_and_validate( hits: list[MemoryRecord], forgotten_ids: set[str], store_lookup, ) -> list[MemoryRecord]: """Filter retrieval hits down to records safe to place in agent context. Enforces the three-state invariant: live, tombstoned, derived. Raises rather than silently dropping, so the leak is observable. """ safe: list[MemoryRecord] = [] for hit in hits: # Rule 1: null record_id with content is a tombstone bleeding through # the index. It has no live authority and may carry an erasure duty. if hit.record_id is None: raise TombstoneLeakError( f"retrieval hit with null record_id (scope={hit.scope!r}); " f"index entry outlived store row — treat as erasure leak" ) # Rule 2: record must still resolve in the authoritative store. if not store_lookup(hit.record_id): raise TombstoneLeakError( f"record {hit.record_id!r} returned by index but absent from store; " f"compaction has not caught up — do not use content" ) # Rule 3: derivation lineage must not intersect any forgotten id. # This is the transitive-closure check the flat forget path omits. poisoned = set(hit.derived_from) & forgotten_ids if poisoned: raise TombstoneLeakError( f"record {hit.record_id!r} derived from forgotten ids {sorted(poisoned)}; " f"lineage cascade did not invalidate this artifact" ) if hit.deleted or hit.invalidated: raise TombstoneLeakError( f"record {hit.record_id!r} flagged deleted/invalidated but still " f"returned by retrieval path" ) safe.append(hit) return safe def forget_with_cascade( target_ids: set[str], all_records: list[MemoryRecord], store_delete, ) -> int: """Erase targets and every record whose derivation closure touches them. Returns count of records invalidated. A forget that returns without cascading derived artifacts is unsound whenever distillation exists. """ to_erase = set(target_ids) changed = True while changed: changed = False for rec in all_records: if rec.record_id in to_erase: continue if set(rec.derived_from) & to_erase: to_erase.add(rec.record_id) changed = True if not to_erase: raise TombstoneLeakError( "forget matched zero records; verify scope_filter targets the " "partition that actually holds derived artifacts, not just sources" ) for rid in to_erase: store_delete(rid) return len(to_erase) ```