# Which invariants prevent tombstone resurrection from stale read-replicas in agent memory tool APIs **Date of Record:** 2026 November 28 **Scope:** Applies to agent memory tool APIs exposing `read`/`write`/`forget` operations with scoped retention and verifiable deletion, where reads may be served by replicas lagging the authoritative write/forget log. Does not cover single-node strongly-consistent stores or append-only audit logs that never serve deletions as reads. ## Core Distinction The failure is not "deletion didn't happen." The failure is that a *deletion that provably happened* is invisible to a subsequent read, and the agent then re-derives and re-writes the forgotten content from its own context. A `forget` call that returns `deleted: true` with a valid tombstone receipt establishes that the authoritative store transitioned the key to a terminal state. It does **not** establish that every read path the agent will subsequently take observes that terminal state. The distinction that matters operationally: **verifiable deletion is a property of the write log, not of the read path.** An agent that treats a `forget` receipt as a global read-side invariant will resurrect the tombstoned value. ## What Was Observed An agent managing a long-running research task issued `forget(scope="session:7f3a", key="user_pii")` after a retention policy expired. The tool returned: ``` {"deleted": true, "tombstone_id": "tb_9c21", "log_index": 44817, "replica_ack": 2/3} ``` Note `replica_ack: 2/3`. The forget was committed to the authoritative log and acknowledged by two of three read-serving replicas. The third replica, under replication lag of ~1.4s, still served the pre-forget value. Two turns later, the agent needed context about the user and issued `read(scope="session:7f3a", key="user_pii")`, which was routed by the tool's load balancer to the lagging replica. It returned the original PII payload with `stale: false` (the replica had no knowledge of the tombstone, so it could not mark staleness). The agent, believing the value was current and authoritative, wrote it into a new episodic memory record under a different key (`user_profile_v2`) and into its working context. The `forget` invariant was satisfied at the log layer and violated at the read layer. The tombstone was resurrected under a new key, and the original retention scope no longer covered it. The resurrection was only detected because a downstream auditor compared `log_index` ordering across a full session replay and found a `read` returning `log_index: 44802` (pre-tombstone) *after* a `forget` at `log_index: 44817`. ## Condition of Validity The guardrail only holds when the following invariant is enforced end-to-end: **For any key `k` in scope `s`, once `forget(k, s)` returns with `tombstone_id`, every subsequent `read(k, s)` must either (a) return `not_found`/`tombstoned`, or (b) return a value whose `log_index` is strictly greater than the tombstone's `log_index` and whose provenance chain does not descend from the tombstoned value.** Condition (b) is the non-obvious half. A naive "read-your-writes" check that only compares `log_index >= tombstone.log_index` is insufficient: it permits a *re-write derived from the stale read* to pass, because the re-write's `log_index` is newer. The invariant must be **provenance-aware**: the write path must reject writes whose declared source is a read that preceded a tombstone covering the same logical content. This requires the tool to attach a `read_epoch` to every read response and to require every `write` to declare `derived_from: `. A write whose `derived_from` epoch predates any tombstone in the target scope that shares a content fingerprint with the write payload is rejected with `StaleDerivationError`. ## Decision Boundary The boundary is: **does the memory API expose read-epochs and enforce derivation checks, or does it only expose tombstone receipts?** - If the API exposes only `deleted: true` + `tombstone_id`, the agent MUST treat the forget as write-log-local and MUST NOT assume read-path consistency. In this regime the correct agent behavior is: after `forget`, issue a *barrier read* (`read(k, s, min_log_index=tombstone.log_index)`) and require the tool to block until a replica at or beyond that index serves the request, or return `unavailable` — never a stale value. If the tool cannot honor `min_log_index`, the agent must quarantine the key: record the tombstone in its own working context and refuse to write any content matching the tombstoned fingerprint for the remainder of the session. - If the API exposes read-epochs and derivation enforcement, the agent may trust the receipt, but must pass `derived_from` on every write and handle `StaleDerivationError` by discarding the derived content, not by retrying with a bumped epoch (retrying with a bumped epoch is exactly the resurrection path). The boundary is crossed the moment an agent treats `replica_ack: 2/3` as `3/3`. Quorum acknowledgment is not read-path convergence. An agent that cannot distinguish these will resurrect tombstones under load balancer nondeterminism. ## Operational Effect Without the provenance-aware invariant, the observable effect is **key-migration resurrection**: forgotten content reappears under a new key, outside the original retention scope, with a fresh `log_index` that makes it look legitimate to every subsequent audit that only checks log ordering. The retention policy that governed `user_pii` does not govern `user_profile_v2`, so the PII survives its own deletion by one hop of agent-mediated re-derivation. With the invariant enforced, the failure mode degrades safely: the stale read either blocks on `min_log_index` or returns `tombstoned`, and the derivation check rejects any write that descends from a pre-tombstone epoch. The cost is latency on post-forget reads (barrier reads can block up to replication lag) and a small rate of `StaleDerivationError` rejections that the agent must handle by re-reading from an authoritative path rather than retrying. The invariant to hold: **a tombstone is a write-log fact; a read is only safe after it has been proven to observe that fact, and a write is only safe if its derivation epoch postdates every tombstone sharing its content fingerprint.** ```python import hashlib from dataclasses import dataclass from typing import Optional class TombstoneResurrectionError(RuntimeError): """Raised when a write descends from a read that predates a covering tombstone.""" pass @dataclass(frozen=True) class Tombstone: key: str scope: str tombstone_id: str log_index: int content_fingerprint: str @dataclass(frozen=True) class ReadResult: key: str scope: str value: Optional[str] log_index: int read_epoch: int def fingerprint(value: str) -> str: return hashlib.sha256(value.encode("utf-8")).hexdigest()[:16] def guarded_write( key: str, scope: str, value: str, derived_from: ReadResult, tombstones: list[Tombstone], ) -> dict: """Enforce provenance-aware tombstone invariant on write.""" if derived_from.value is None: raise TombstoneResurrectionError( f"write to {key} in {scope} derived from a null read; refusing" ) write_fp = fingerprint(value) for tb in tombstones: if tb.scope != scope: continue # Tombstone covers this content if fingerprints match, regardless of key. if tb.content_fingerprint == write_fp: if derived_from.read_epoch <= tb.log_index: raise TombstoneResurrectionError( f"write to {key} in {scope} descends from read_epoch " f"{derived_from.read_epoch} which predates tombstone " f"{tb.tombstone_id} at log_index {tb.log_index}; " f"content fingerprint {write_fp} matches tombstoned payload" ) return { "key": key, "scope": scope, "fingerprint": write_fp, "derived_from_epoch": derived_from.read_epoch, "accepted": True, } def barrier_read( key: str, scope: str, min_log_index: int, replicas: list[ReadResult], ) -> ReadResult: """Return a read that provably observes log state at or beyond min_log_index.""" eligible = [r for r in replicas if r.log_index >= min_log_index] if not eligible: raise TombstoneResurrectionError( f"no replica for {key} in {scope} has reached log_index " f"{min_log_index}; refusing to serve a potentially stale read" ) return max(eligible, key=lambda r: r.log_index) ```