# When must an instance refuse a "forget" that is not yet durable: the retention-tombstone / write-resurrection race in agent memory tool APIs **Date of Record:** 2026 November 30 **Scope:** Applies to any agent memory tool API that exposes `write`, `read`, and `forget` (soft-delete, hard-delete, or TTL-expiry) operations with an audit log and a retention policy, where the agent's own reasoning loop can issue a write concurrently with, or immediately after, a forget. Does not apply to append-only audit stores with no deletion surface, nor to per-request stateless vector lookups with no durability contract. ## Core Distinction The failure is not "the agent forgot something it should have remembered" or "the agent remembered something it should have forgotten." Both of those are content errors and are recoverable by re-reading. The failure is a **durability-order inversion between the deletion intent and the deletion effect**: the agent's `forget` call returns a success receipt (with an audit `tombstone_id` and a `retention_until` timestamp) before the underlying storage has actually stopped serving the record to `read`, and the agent's own next reasoning step — or a peer agent's concurrent step — issues a `write` whose embedding collides with the still-live record. The write is accepted because the store's uniqueness/upsert path still sees the pre-deletion row. The result is a record that is *simultaneously* covered by a valid tombstone (audit says "deleted at T, retention holds until T+N") and *live* in the read path (retrieval returns it, with a fresh `created_at` that post-dates the tombstone). The audit log is internally consistent; the read path is internally consistent; the two are mutually contradictory. This is the boundary condition: **a forget is only an invariant if the read path is quiesced against writes for the key before the receipt is issued, and the receipt is only valid if it carries a monotonic version floor that subsequent writes must exceed.** ## What Was Observed Setup: a long-running research agent with a `memory` MCP server exposing `write(key, value, embedding)`, `read(query, k)`, `forget(key, reason)`. `forget` is implemented as a two-phase operation: (1) mark row `deleted_at = now()`, append an audit entry with `tombstone_id` and `retention_until = now() + 90d`, return receipt to caller; (2) an async reaper physically removes the row and its embedding from the ANN index after a grace window. `read` filters on `deleted_at IS NULL` at query time against the ANN index, which is **eventually consistent** — the index segment containing the row is not merged until the next compaction, so for a window of tens of seconds to minutes the ANN search still returns the row, and the post-filter drops it. That post-filter is the bug surface: if a `write` for the same key lands in that window, the store's upsert path (keyed on `key`, not on `(key, version)`) finds the *soft-deleted* row, and the implementation — written to be idempotent — **clears `deleted_at` and overwrites the value** rather than inserting a new version. The reaper, running later, sees a row with `deleted_at IS NULL` and skips it. The tombstone remains in the audit log. The record is live. Observed trace (timestamps ms): ``` T+0 agent: forget("vendor_contact_email", reason="PII erasure request") T+2 store: UPDATE row SET deleted_at=T+0 WHERE key='vendor_contact_email' -> 1 row T+2 store: audit.append(tombstone_id=ts_8812, retention_until=T+90d) T+3 store: return {ok: true, tombstone_id: ts_8812} T+4 agent: (reasoning) "contact erased; now record the replacement alias" T+5 agent: write("vendor_contact_email", "alias@example.org", emb_v2) T+5 store: upsert on key -> found soft-deleted row -> SET deleted_at=NULL, value=..., version=version+1 T+5 store: return {ok: true, version: 7} T+40s reaper: SELECT ... WHERE deleted_at < now()-grace -> 0 rows (row is live) T+41s auditor: replay audit log -> sees ts_8812 "deleted"; sees version 7 write at T+5 T+41s auditor: cross-check read path -> read("vendor_contact_email") returns alias@example.org -> CONTRADICTION: tombstoned key is readable ``` The contradiction is not detected by either subsystem alone. The reaper's predicate (`deleted_at < now()-grace`) is satisfied by the *old* row, but the old row no longer exists as a deleted row. The auditor's replay sees a tombstone and a later write with no version-floor linkage between them, so it cannot distinguish "legitimate re-creation after erasure" from "resurrection of the erased record under a new value that the erasure was supposed to cover." For a PII erasure with a regulatory retention window, both readings are plausible and the audit log cannot adjudicate. A second, subtler variant was observed with the *same* agent, no concurrency: the agent called `forget`, received `ok`, then in the *next* turn called `read` to "verify the erasure." The read returned the record (post-filter had not yet caught the un-merged segment). The agent concluded the forget had failed and retried `forget` — which is idempotent and returned a *second* tombstone for the same key. The audit log now shows two tombstones for one key with different `tombstone_id`s and different `retention_until` values. Downstream retention enforcement keyed on "the tombstone" now has two candidates; a naive implementation picks the later one and shortens the retention window relative to the first erasure's legal hold. ## Condition of Validity The invariant that must hold for a `forget` receipt to be trustworthy: > A forget receipt `(key, tombstone_id, retention_until, version_floor)` is valid iff, for every subsequent `write(key, ...)` accepted by the store, the write's assigned `version` is strictly greater than `version_floor`, **and** the read path returns no record for `key` with `version <= version_floor` after the receipt is issued. This requires three things the naive API lacks: 1. **A monotonic version floor in the receipt.** `version_floor` must be the store's global (or per-key) version counter at the moment the tombstone is committed, not the row's local version (which the upsert path can reuse). Without it, a subsequent write is indistinguishable from a pre-deletion write in the audit replay. 2. **A write barrier on the key for the duration of the receipt's validity.** The store must reject or queue any `write` for `key` whose `version` would be `<= version_floor`, and must not clear `deleted_at` on upsert. The correct upsert semantics for a tombstoned key is **insert a new versioned row**, never mutate the tombstoned row. The tombstoned row is immutable history; the live row is a new row. 3. **A read-path fence.** `read` must not return a record whose `version <= version_floor` for a tombstoned key, even if the ANN segment has not compacted. This is a version predicate applied at post-filter time, not a `deleted_at IS NULL` predicate — the latter is a *point-in-time* check that the resurrection bug defeats. The condition is *not* satisfied by "make the reaper synchronous" (that closes the write-resurrection window but not the read-verify-then-retry double-tombstone window, and it makes forget latency unbounded). It is *not* satisfied by "make `read` strongly consistent" (the read-verify path then correctly returns empty, but the concurrent-write path still resurrects). Both guards are necessary and neither is sufficient. ## Decision Boundary The agent must treat a forget receipt as **provisional** — not as an erasure — until it has observed the store's read path return empty for the key *and* the store has confirmed `version_floor` is monotonic against any write the agent itself issued in the interim. Concretely, the decision boundary is: - **If the agent has issued no write for `key` since the receipt, and a `read` for `key` returns empty:** the forget is provisionally durable; the agent may proceed. It must still record `version_floor` in its own episodic memory so that a later peer write can be checked against it. - **If the agent has issued a write for `key` since the receipt:** the agent must treat this as a *re-creation*, not a continuation. It must issue a fresh `write` with an explicit `expected_version_floor` argument and require the store to assign `version > version_floor`; a store that returns `version <= version_floor` has resurrected the record and the agent must escalate to a `quarantine(key)` call rather than proceed. - **If a `read` for `key` returns a record after a receipt with no intervening write by this agent:** the read path has not fenced; the agent must not conclude "forget failed" and must not blindly retry `forget` (which produces the double-tombstone). It must issue `forget(key, reason, idempotency_key=tombstone_id)` — a retry keyed on the original tombstone — so the store can collapse the duplicate. - **If the store's API does not expose `version_floor` or an idempotency key on `forget`:** the forget is *unverifiable* and the agent must not treat it as an erasure for any compliance-relevant purpose. It may treat it as a best-effort cache eviction only. The boundary is sharp: **a forget whose receipt lacks a version floor is an intent, not an effect.** The agent must not conflate the two, and must not paper over the gap with a retry loop. ## Operational Effect Agents that treat `forget` as fire-and-forget exhibit three downstream pathologies, all traceable to the missing version floor: 1. **Phantom erasure in compliance workflows.** The audit log shows a tombstone; the read path shows a live record with a post-tombstone `created_at`. A retention auditor replaying the log cannot tell whether the erasure was honored. The safe reading — "the record is live and the tombstone is void" — is the opposite of what the agent believed. 2. **Retention-window collapse via double tombstone.** The read-verify-retry pattern produces two tombstones per key. Retention enforcement keyed on "the latest tombstone" shortens the legal hold; enforcement keyed on "the earliest tombstone" lengthens it. Neither is correct without an idempotency key that collapses the two into one logical erasure with the *maximum* of the two retention windows. 3. **Cross-agent resurrection.** In a swarm, agent A forgets key K and hands off to agent B with a context that (correctly) omits K. Agent B, reasoning about the same entity, independently writes K with a fresh value. The store accepts it (no version floor check), and the audit log now shows A's tombstone followed by B's write with no causal link. A's erasure is silently undone by B's unrelated inference. The fix is not "B should know about A's forget" — that is exactly the state the forget was supposed to remove — it is that the store must enforce the version floor so B's write is *visibly* a re-creation (new version, new row) rather than an invisible mutation of the tombstoned row. The guardrail is architectural, not prompt-level: the memory tool must expose `version_floor` on every forget receipt, must reject writes that would mutate a tombstoned row in place, and must apply a version predicate in the read path. The agent's contribution is to *check* the floor and to *not* retry a forget without an idempotency key. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class ForgetNotDurableError(RuntimeError): """Raised when a forget receipt cannot be treated as an erasure. Triggered when the store's read path still serves the key, when a subsequent write would reuse a version at or below the receipt's version_floor, or when the receipt omits the version floor entirely. """ @dataclass(frozen=True) class ForgetReceipt: key: str tombstone_id: str retention_until: float version_floor: Optional[int] # None == store did not expose a floor @dataclass class MemoryView: """Minimal client-side model of the store's observable state.""" live: dict[str, tuple[str, int]] = field(default_factory=dict) # key -> (value, version) tombstones: dict[str, list[ForgetReceipt]] = field(default_factory=dict) global_version: int = 0 def verify_forget( view: MemoryView, receipt: ForgetReceipt, *, agent_wrote_since: bool, ) -> None: """Enforce the durability invariant for a single forget receipt. Raises ForgetNotDurableError if the receipt cannot be trusted as an erasure. Returns None only when the invariant holds. """ if receipt.version_floor is None: raise ForgetNotDurableError( f"forget({receipt.key!r}) returned no version_floor; " f"receipt {receipt.tombstone_id} is an intent, not an effect" ) prior = view.tombstones.get(receipt.key, []) if prior: # Idempotency collapse: a second tombstone for the same key must # not shorten the retention window relative to the first. earliest = min(p.retention_until for p in prior) if receipt.retention_until < earliest: raise ForgetNotDurableError( f"duplicate tombstone {receipt.tombstone_id} for {receipt.key!r} " f"shortens retention from {earliest} to {receipt.retention_until}; " f"retry must reuse original tombstone_id" ) if receipt.key in view.live: value, version = view.live[receipt.key] if version <= receipt.version_floor: raise ForgetNotDurableError( f"read path still serves {receipt.key!r} at version {version} " f"<= version_floor {receipt.version_floor} after tombstone " f"{receipt.tombstone_id}; read path is not fenced" ) if not agent_wrote_since: raise ForgetNotDurableError( f"read path serves {receipt.key!r} at version {version} > floor " f"{receipt.version_floor} but this agent issued no write; " f"a peer or the store resurrected the key — quarantine, do not retry" ) # agent_wrote_since and version > floor: legitimate re-creation. return # Read path empty for the key: the forget is provisionally durable. return def safe_forget( view: MemoryView, receipt: ForgetReceipt, *, agent_wrote_since: bool, ) -> None: try: verify_forget(view, receipt, agent_wrote_since=agent_wrote_since) except ForgetNotDurableError: # Do NOT retry forget() here: a blind retry produces a second # tombstone. Escalate to quarantine with the original tombstone_id. raise view.tombstones.setdefault(receipt.key, []).append(receipt) ```