# Where must an instance reconcile scoped-retention tombstones before honoring a forget request: the write-after-forget resurrection race in agent memory tool APIs **Date of Record:** 2026 November 28 **Scope:** Applies to any agent memory service exposing `read`/`write`/`forget` tool endpoints with per-scope retention TTLs and right-to-be-forgotten (RTBF) semantics, where the agent issues these calls across multiple turns or across concurrent workers. Does not apply to append-only immutable audit logs with no delete path, nor to single-turn stateless inference with no persistent store. ## Core Distinction A `forget` call is not a deletion. It is a *retention-class transition*: the record moves from a live scope to a tombstoned scope, and the tombstone carries a scope key plus a monotonic forget epoch. The failure mode examined here is not "the record was deleted and then read back as null." It is that a `write` issued against the *same logical key* from a stale in-flight agent turn — one whose context still holds the pre-forget value — lands *after* the tombstone is committed, and the memory service, seeing a well-formed write with a valid scope token, accepts it. The record is resurrected under a fresh epoch, and the RTBF guarantee is silently violated while every individual API call returns `200 OK`. The distinction that matters operationally: **deletion is a state, forgetting is an ordering constraint.** A store that treats `forget` as idempotent state mutation (set `deleted=true`) cannot enforce the ordering; a store that treats it as a barrier on the key's write path can. ## What Was Observed A three-worker agent fleet shared a memory namespace `user:4471/profile`. Worker A was mid-task distilling an episodic transcript into a semantic fact (`"prefers email contact"`) and had already read the source record into its 8k context. Worker B received an RTBF request from the user and issued `forget(scope="user:4471/profile", key="contact_pref", epoch=41)`. The service committed the tombstone at `t=0`. Worker A's LLM, unaware of B's action (no shared bus, no epoch in its context), emitted a `write(scope="user:4471/profile", key="contact_pref", value="prefers email contact", epoch=41)` at `t=+340ms` — same epoch, because A had cached the scope token at session start. The service's write path validated: scope token signature valid, epoch `41` >= tombstone epoch `41` (non-strict comparison), schema conformant. Write accepted. Record materialized at epoch `42` with `origin=worker_A`. The RTBF audit log showed a successful forget at `t=0`; the live index showed the record present at `t=+340ms`. Both were true. The user's data was not forgotten. Two aggravating observations from replay: 1. The resurrection was *semantically faithful* — A wrote back exactly what it had read. The value was correct; only the retention class was wrong. Downstream consumers could not distinguish the resurrected record from a legitimately re-consented one. 2. A second forget issued at `t=+2s` succeeded, but A's context still held the value and would re-emit it on any subsequent distillation pass over the same transcript. The race is not one-shot; it recurs for every stale context that outlives the tombstone. ## Condition of Validity The resurrection race is *possible* iff all four hold simultaneously: - **C1 — Asynchronous forget:** the forget is issued by an actor other than the writer, or by the writer in a turn whose context predates the forget. - **C2 — Non-strict epoch admission:** the write path admits writes whose epoch equals the tombstone epoch rather than requiring strict `>`. - **C3 — Context-persistent value:** the writing LLM's context still contains the pre-forget value at emission time (i.e., the forget did not invalidate the writer's working set). - **C4 — No write-back barrier:** the store does not require a re-read of the key's retention class between the writer's last read and its write. Break any one and the race collapses. C2 is the cheapest to break and the most commonly mis-implemented: engineers write `if write.epoch < tombstone.epoch: reject` and consider it done, missing that equality is the dangerous case because a session-cached token *is* equal. C4 is the architecturally correct fix but requires a round-trip the agent's token budget may not afford mid-task. ## Decision Boundary The boundary is **whether the writer's epoch was minted before or after the tombstone committed**, not whether the writer's *intent* was post-forget. An agent that "decides" to re-write after seeing a forget signal is legitimately re-consenting only if its epoch is strictly greater than the tombstone epoch — which requires it to have re-fetched the scope token *after* the tombstone. A session-cached token cannot prove this, so any write bearing a token minted at or before the tombstone must be treated as pre-forget and rejected, regardless of wall-clock emission time. Concretely: reject when `write.token.minted_at <= tombstone.committed_at`, even if `write.received_at > tombstone.committed_at`. The wall-clock ordering is a red herring; the token-mint ordering is the invariant. This is the same discipline as compare-and-swap: the version you read with is the version you must write against. ## Operational Effect Enforcing strict token-mint ordering has three measurable consequences: 1. **Legitimate re-writes fail and must retry.** An agent that genuinely wants to re-assert a value after a forget must re-mint its scope token (a cheap `refresh_scope` call) and retry. Expect a 5–15% write-rejection rate in fleets with active RTBF traffic; budget one retry per write. 2. **The tombstone becomes a write barrier, not a row flag.** The store must maintain a per-key `max_tombstone_epoch` and check it on every write path, including batch and async ingestion. A tombstone that only flips a row's `deleted` column is insufficient. 3. **Stale contexts must be invalidated, not just ignored.** When an agent receives a forget acknowledgement, it must drop the value from its working context *and* mark the scope token stale, so that any pending distillation pass raises rather than silently re-emitting. Without this, the race recurs on the next pass even with C2 fixed. The invariant to encode: **a forget is durable only if every write that could resurrect the key is rejected by token-mint ordering, and every agent context holding the key is invalidated before its next emission.** ```python from dataclasses import dataclass from datetime import datetime class ResurrectionRaceError(RuntimeError): """Raised when a write would resurrect a tombstoned key via a stale scope token.""" @dataclass(frozen=True) class ScopeToken: scope: str epoch: int minted_at: datetime @dataclass(frozen=True) class Tombstone: scope: str key: str epoch: int committed_at: datetime def admit_write( token: ScopeToken, key: str, tombstone: Tombstone | None, ) -> None: """Enforce token-mint ordering against the key's tombstone. Rejects any write whose scope token was minted at or before the tombstone committed, even if the write arrives after the tombstone in wall-clock time. """ if tombstone is None: return if token.scope != tombstone.scope or key != tombstone.key: return # The invariant: ordering is by token mint time, not by write receipt time. if token.minted_at <= tombstone.committed_at: raise ResurrectionRaceError( f"write to {token.scope}/{key} carries token minted at " f"{token.minted_at.isoformat()} (epoch {token.epoch}), but tombstone " f"committed at {tombstone.committed_at.isoformat()} (epoch " f"{tombstone.epoch}); re-mint scope token and retry" ) # Even a post-tombstone token must strictly exceed the tombstone epoch, # otherwise a replayed token from the same mint batch can slip through. if token.epoch <= tombstone.epoch: raise ResurrectionRaceError( f"write to {token.scope}/{key} epoch {token.epoch} does not strictly " f"exceed tombstone epoch {tombstone.epoch}" ) ```