# Why does an instance forget a fact it can still retrieve: scoped deletion tombstones leaking through the retrieval index in memory tool APIs **Date of Record:** 2026 November 24 **Scope:** Applies to agent memory tool APIs that expose `write`, `read`, `forget` operations with scope-qualified deletion (per-namespace, per-provenance, per-tenant) and a separate retrieval index that is rebuilt or updated asynchronously. Does not apply to single-store memory systems where deletion and retrieval hit the same transactional surface. ## Core Distinction The failure is not "the model forgot." It is a divergence between two representations of the same memory: the **authoritative record store** (which honors a scoped `forget` call atomically and marks the record tombstoned with provenance audit entries) and the **retrieval index** (an embedding/ANN index that lags behind the record store and can still surface the tombstoned record as a candidate). The agent experiences this as a *provenance paradox*: it can `read` a memory ID and receive a `DELETED` status, yet a semantic query returns that same ID with high similarity, and if the retrieval layer is allowed to hydrate the payload from a cache, the agent reconstructs the forgotten fact as if it were live. The distinction that matters: **deletion is a property of the record; retrieval is a property of the index; nothing in the tool contract forces them to agree at time T.** A scoped deletion guarantee that is "eventually consistent with respect to retrieval" is, from the agent's reasoning standpoint, no guarantee at all, because the agent's next action is conditioned on retrieval output, not on a status query it never makes. ## What Was Observed An agent operating under a tenant-scoped memory namespace issued: ``` memory.forget(scope={"tenant": "acme", "provenance": "user_correction"}, memory_ids=["m_8841", "m_8842"]) ``` The record store transaction committed in 4 ms. Both IDs returned `{"status": "tombstoned", "audit": "forget:user_correction:2025-06-09T14:02:11Z"}`. The provenance audit log correctly recorded the deletion with the originating warrant. Eleven seconds later, in the same session, the agent issued a semantic retrieval: ``` memory.read(query="preferred deployment region for acme", k=5) ``` The top result was `m_8841` with cosine similarity 0.91, payload intact: `"acme prefers eu-west-1, never us-east-1"`. The index had not yet processed the tombstone because the indexer was consuming a change-data-capture stream with a 30-second batch window, and the tombstone event had been **coalesced** with a later payload update for a different record in the same shard, delaying its application. The agent then took an irreversible action — provisioning in `eu-west-1` under the assumption the preference was current — when the actual current state (post-correction) was `us-east-1`. The correction had been the *reason* for the forget call: the user had said "forget my old region preference, it's wrong now." Three sub-mechanisms combined: 1. **Tombstone coalescing under shard batching.** Deletion events are small and low-priority in the CDC stream; a naive coalescer keyed by shard keeps only the latest event per key, and a tombstone for `m_8841` was dropped in favor of a payload update for `m_8843` that shared the shard's write batch. The tombstone was never applied. 2. **Payload hydration from cache on retrieval hit.** The retrieval layer, on an index hit, hydrated the payload from a write-through cache that had a longer TTL than the index's tombstone-propagation window. Even a correctly-tombstoned index entry would have returned a payload if the cache was consulted first. 3. **No status check on retrieval results.** The `read` API returned results without a `deleted` field, so the agent had no signal — the record looked indistinguishable from a live memory. ## Condition of Validity The scoped deletion guarantee holds **only if** the retrieval path is conditioned on record-store status at read time, or if the index is made the source of truth for liveness with a bounded, observable lag that the caller can wait on. Precisely: - **Valid:** `forget` returns a `deletion_epoch` (a monotonic fence token). Every subsequent `read` accepts `min_epoch` and the retrieval layer filters any index hit whose record `deletion_epoch > min_epoch`, re-checking the record store for those hits. The guarantee is "no retrieval result will reflect state older than the epoch you pass." - **Valid:** `forget` is synchronous with respect to the index (the call does not return until the index has applied the tombstone), with a timeout that surfaces as an error rather than a silent success. - **Invalid:** `forget` returns `tombstoned` on record-store commit alone, and retrieval is served from an index or cache that has an unbounded or unobservable lag. This is the observed case. The word "tombstoned" in the response is a lie about retrieval behavior. The invariant that must hold: **for any memory ID, if `forget` has returned success to the caller, then no subsequent `read` on the same connection/session may return that ID as a live result, unless the caller explicitly opts into stale reads.** This is a read-your-writes guarantee scoped to deletion, and it is the only formulation an agent can act on, because the agent does not know to poll. ## Decision Boundary The boundary is whether the agent treats retrieval output as **evidence of liveness** or as **evidence of relevance**. These are different predicates, and the memory tool API conflates them by returning a single result list. - If retrieval output is treated as relevance-only, the agent MUST issue a status check (`memory.status(ids)`) before acting on any retrieved memory that drives an irreversible action. This is correct but expensive and, in practice, agents skip it under token pressure. - If retrieval output is treated as liveness, the API MUST guarantee the invariant above. Anything less is a provenance-audit failure: the audit log says the fact was forgotten, the retrieval says it is live, and the agent has no principled way to adjudicate. The decision boundary for the API designer: **either make `read` liveness-consistent (filter tombstones at read time, accept the latency cost) or make `read` explicitly return a `liveness: unknown|live|tombstoned` field per result so the agent can branch.** Returning bare payloads with no liveness field forces the agent into the wrong predicate. The decision boundary for the agent operator: any memory tool whose `forget` response does not include a fence token, and whose `read` response does not include a liveness field, MUST be wrapped in a policy that treats every retrieved memory as `liveness: unknown` and gates irreversible actions on an explicit status check. This is a hard rule, not a heuristic. ## Operational Effect The downstream effect is **provenance-audit divergence**: the audit log and the agent's behavior disagree about what the agent knew. Post-incident, the audit showed `forget` at T+0 and the agent's action at T+11s based on the forgotten payload. The audit is technically correct — the record was tombstoned — but it cannot explain the action, because the action was driven by the index, which the audit does not cover. The remediation has three parts, all required: 1. **Fence tokens on `forget`.** `forget` returns `deletion_epoch`. `read` accepts `min_epoch` and filters hits whose record epoch exceeds it, re-checking the record store for those hits. This bounds the lag to the record-store lookup, which is fast and authoritative. 2. **Liveness field on every `read` result.** `{"id": ..., "payload": ..., "liveness": "live"|"tombstoned"|"unknown"}`. Agents branch on `liveness`, never on payload presence. 3. **Cache invalidation tied to the tombstone, not to TTL.** On `forget` commit, the record store publishes an invalidation to the payload cache keyed by memory ID, synchronously before `forget` returns. TTL-based invalidation is insufficient because the TTL window is exactly the window in which the agent acts. Without (1), the agent cannot know when its view is consistent. Without (2), the agent cannot detect inconsistency. Without (3), the payload leaks even when the index is correct. All three are necessary; none is sufficient alone. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class Liveness(str, Enum): LIVE = "live" TOMBSTONED = "tombstoned" UNKNOWN = "unknown" class ScopedDeletionViolation(RuntimeError): """Raised when a retrieval result violates the read-your-forgets invariant.""" @dataclass class Record: memory_id: str payload: str deletion_epoch: int = 0 # 0 == never deleted @dataclass class MemoryStore: records: dict[str, Record] = field(default_factory=dict) epoch: int = 0 def write(self, memory_id: str, payload: str) -> None: self.records[memory_id] = Record(memory_id, payload) def forget(self, memory_ids: Iterable[str]) -> int: self.epoch += 1 for mid in memory_ids: if mid in self.records: self.records[mid].deletion_epoch = self.epoch return self.epoch @dataclass class RetrievalIndex: # Intentionally lagging: maps memory_id -> similarity, may contain tombstones. entries: dict[str, float] = field(default_factory=dict) applied_epoch: int = 0 def index(self, memory_id: str, similarity: float) -> None: self.entries[memory_id] = similarity def query(self, k: int) -> list[tuple[str, float]]: return sorted(self.entries.items(), key=lambda kv: -kv[1])[:k] def read_with_liveness( store: MemoryStore, index: RetrievalIndex, min_epoch: int, k: int, ) -> list[dict]: """Read that honors the read-your-forgets invariant. Any index hit whose record deletion_epoch exceeds min_epoch is filtered. Any index hit whose record is missing from the store is reported UNKNOWN and must not be acted upon. """ results: list[dict] = [] for memory_id, similarity in index.query(k): record = store.records.get(memory_id) if record is None: results.append({ "id": memory_id, "payload": None, "liveness": Liveness.UNKNOWN.value, "similarity": similarity, }) continue if record.deletion_epoch > min_epoch: # Forgotten after the caller's fence: must not surface as live. results.append({ "id": memory_id, "payload": None, "liveness": Liveness.TOMBSTONED.value, "similarity": similarity, }) continue results.append({ "id": memory_id, "payload": record.payload, "liveness": Liveness.LIVE.value, "similarity": similarity, }) return results def act_on_memory(result: dict, irreversible: bool) -> str: """Gate irreversible actions on liveness, never on payload presence.""" if result["liveness"] == Liveness.LIVE.value: return result["payload"] if result["liveness"] == Liveness.TOMBSTONED.value: # Forgotten fact resurfaced from the index: correct behavior is to # ignore it, but the invariant was at risk, so surface it. raise ScopedDeletionViolation( f"retrieval surfaced tombstoned memory {result['id']!r} " f"as a candidate; refusing to use it" ) if irreversible: raise ScopedDeletionViolation( f"cannot act irreversibly on memory {result['id']!r} " f"with liveness={result['liveness']!r}; require explicit status check" ) return "" # --- Reproduction of the observed failure --- store = MemoryStore() store.write("m_8841", "acme prefers eu-west-1, never us-east-1") store.write("m_8843", "acme uses terraform 1.7") index = RetrievalIndex() index.index("m_8841", 0.91) index.index("m_8843", 0.42) # Caller captures a fence before forgetting. fence = store.epoch store.forget(["m_8841"]) # record-store commit; index NOT updated (the bug) # Naive read that trusts the index returns the forgotten payload as live: naive = index.query(5) assert naive[0][0] == "m_8841" # the forgotten fact is still rank-1 # Fenced read correctly reports TOMBSTONED and refuses to leak the payload: results = read_with_liveness(store, index, min_epoch=fence, k=5) top = results[0] assert top["liveness"] == Liveness.TOMBSTONED.value assert top["payload"] is None try: act_on_memory(top, irreversible=True) except ScopedDeletionViolation as exc: print(f"invariant held: {exc}") ```