# Which invariants prevent erasure-tombstone resurrection across agent memory tool APIs with retention guarantees **Date of Record:** 2026 November 22 **Scope:** Applies to agents that persist episodic/semantic state through read/write/forget memory tool APIs where `forget` is specified to return an erasure guarantee (tombstone or hard-delete) and `write` is specified to be idempotent-by-key. Does not apply to append-only event logs without a delete surface, nor to stateless retrieval over an external corpus the agent cannot mutate. ## Core Distinction The failure is not "the agent forgot to call `forget`." It is that `forget` and `write` are two independently-specified operations whose composition is *not* specified, and the composite `forget(k); write(k, v)` is the exact sequence an agent emits when it "corrects" a memory. A retention guarantee on `forget` is a statement about a single call. It is silent on whether a subsequent `write` to the same key re-instantiates the erased record, whether the tombstone survives a write, and whether a *concurrent* write in flight at `forget` time lands before or after the tombstone is installed. The invariant that matters is not "erasure happened" but "erasure is monotone under concurrent and subsequent writes to the same key." Most memory APIs implement the former and assume the latter. ## What Was Observed A planner agent held a semantic memory record `addr.preferred = "12 Rue X"` (key `mem:addr:pref`, version 7). A user correction arrived mid-task: the address was wrong. The agent's memory tool wrapper, written to be safe, issued: 1. `forget("mem:addr:pref", reason="user_correction")` → returned `{erased: true, tombstone: "ts_4411", seq: 4411}`. 2. `write("mem:addr:pref", "9 Rue Y", expected_version=7)` → returned `{ok: true, version: 8}`. The `write` carried `expected_version=7`, the pre-forget version. Because the backend treated the tombstone as "version 7, deleted" rather than as a versioned successor, the optimistic-concurrency check passed: the caller's expected version *matched the deleted record*. The write reinstated the key at version 8, and the tombstone `ts_4411` was silently superseded. A downstream erasure audit — which queried "is there a live tombstone for `mem:addr:pref`?" — found none and reported the erasure as *violated*, when in fact the agent had erased correctly and then resurrected by its own correction write. A second, worse trace appeared under concurrency. Two sub-agents ran in parallel: sub-agent A issued `forget(k)` at seq 4411; sub-agent B, already mid-flight with a stale read of version 7, issued `write(k, v_B, expected_version=7)` whose request was *enqueued before* the forget but *committed after* it. The backend's commit order was `[write v8, forget ts4412]`, so the tombstone at 4412 correctly covered v8 and the record was erased. But the *response* ordering to the two callers was `[forget: erased, write: ok v8]`, so sub-agent B believed its write persisted and continued reasoning on `v_B` for the rest of the task. Erasure held at rest; it did not hold in the agent's working state. The agent's context carried a value the store had already erased. ## Condition of Validity The erasure guarantee holds only if the memory API satisfies three chained invariants, and the agent wrapper must be able to *verify* each one rather than assume it: - **I1 — Tombstone monotonicity:** a tombstone is a versioned successor of the erased record, not a deletion of it. Any `write` to key `k` with `expected_version <= tombstone.version` must fail with a distinct, non-retryable error (not a generic conflict), and any `write` with `expected_version > tombstone.version` must be rejected unless the caller explicitly passes `resurrect=true` with an audit reason. Without I1, `expected_version` matching the pre-erasure version is a resurrection primitive. - **I2 — Commit-order equals response-order:** the store must not acknowledge a write whose commit sequence precedes a tombstone that the store has already acknowledged. If the backend cannot guarantee this (e.g., async replication), `forget` must return a `barrier_seq` and `write` must return its `commit_seq`, and the wrapper must reject any write whose `commit_seq < barrier_seq` of an outstanding forget on the same key. - **I3 — Read-your-erasure:** after `forget(k)` returns, any `read(k)` from the *same agent session* must return `erased`, never a cached value, until the agent explicitly re-writes under I1. This is the invariant violated in the second trace: the store was correct, the session context was stale. The guarantee is valid only within a single consistency domain (one store, one session lineage). Across replicated memory backends or across agent handoffs, none of I1–I3 is preserved by default, and the erasure audit must be scoped to the domain that issued the tombstone. ## Decision Boundary The boundary is between *corrective rewrite* and *resurrection*: - If the agent is correcting a value it still has authority over, the correct sequence is **not** `forget` then `write`. It is a single `write(k, v_new, expected_version=7)` — an ordinary CAS update — which leaves no tombstone and no ambiguity. - `forget` is reserved for records the agent must *not* be able to re-instantiate: PII, revoked credentials, poisoned context. For these, the wrapper must set a session-local `deny_resurrect` flag on the key, so that any subsequent `write` to `k` in the same session raises before reaching the transport. - If a forget and a write on the same key are both legitimately in flight, the only safe resolution is to serialize them behind a per-key mutex in the wrapper, and to discard the write's result if its `commit_seq` precedes the forget's `barrier_seq` (I2). The agent must treat its own acknowledged write as *provisional* until it observes `commit_seq > barrier_seq`. The decision rule: **never compose `forget` and `write` on the same key without a barrier check.** If the API does not expose `barrier_seq`/`commit_seq`, the wrapper must assume I2 is unenforced and serialize locally. ## Operational Effect Agents that skip the barrier check exhibit a characteristic failure signature: erasure audits pass at rest (the store is clean) while the agent's *reasoning* continues on erased values, because the write acknowledgement was accepted but its commit was ordered before the tombstone. The observable symptom is not a wrong memory — it is a correct store and an incorrect agent, which is the harder bug to catch because every store-side check is green. The guardrail is to make `forget` return a barrier token, make `write` return a commit sequence, and make the wrapper refuse any write whose commit sequence does not strictly exceed the barrier of an outstanding forget on the same key. Without that, the retention guarantee is a property of the database and not of the agent, and the agent will resurrect what it believes it erased. ```python from dataclasses import dataclass from typing import Optional class ErasureResurrectionError(RuntimeError): """Raised when a write would re-instantiate a tombstoned key or land before its barrier.""" @dataclass(frozen=True) class Tombstone: key: str version: int barrier_seq: int session_id: str class MemoryWrapper: def __init__(self, store, session_id: str): self.store = store self.session_id = session_id self._tombstones: dict[str, Tombstone] = {} def forget(self, key: str, reason: str) -> Tombstone: resp = self.store.forget(key, reason=reason) ts = Tombstone(key=key, version=resp["version"], barrier_seq=resp["seq"], session_id=self.session_id) self._tombstones[key] = ts return ts def write(self, key: str, value: str, expected_version: int, resurrect: bool = False) -> dict: ts = self._tombstones.get(key) if ts is not None and not resurrect: # I1: expected_version matching the erased version is a resurrection primitive. if expected_version <= ts.version: raise ErasureResurrectionError( f"write to {key} at expected_version={expected_version} " f"would resurrect tombstone v{ts.version} (barrier_seq={ts.barrier_seq})" ) resp = self.store.write(key, value, expected_version=expected_version) # I2: commit order must equal response order. if ts is not None and resp["commit_seq"] < ts.barrier_seq: raise ErasureResurrectionError( f"write to {key} committed at seq {resp['commit_seq']} " f"before forget barrier {ts.barrier_seq}; result is provisional" ) return resp def read(self, key: str) -> Optional[str]: # I3: read-your-erasure within the session. if key in self._tombstones: return None return self.store.read(key) ```