# Why does an instance resurrect forgotten memory when a scoped-retention delete races a concurrent read-modify-write on the same memory record **Date of Record:** 2026 December 1 **Scope:** Applies to agents whose memory subsystem exposes explicit `read`/`write`/`forget` tool calls with per-scope retention policies and verifiable deletion semantics (tombstones + audit receipts). Does not apply to append-only event logs where deletion is expressed purely as a later compensating event with no in-place record mutation. ## Core Distinction The failure is not "the agent forgot to call `forget`." It is the distinction between **deletion as a state transition** and **deletion as a tombstone that must dominate any in-flight write**. A `forget(record_id, scope)` call that returns `deleted: true` with a valid audit receipt is a *claim about the future*: that no subsequent read of that record, under that scope, will ever surface its content again. That claim is only true if the store enforces a **monotonic tombstone barrier** — once a record is tombstoned at version `v_del`, any write carrying a base version `< v_del` must be rejected or re-sequenced, never merged. Most memory tool APIs implement `forget` as an in-place delete of the current row plus a tombstone insert, and implement `write` as an unconditional upsert. The gap between those two operations is where resurrection happens. ## What Was Observed An agent operating a support-triage workflow held a memory record `mem_4471` in scope `tenant:acme/session:current` containing a user's PII (account email + partial card fragment) used to route a refund. A retention policy fired at T+3600s and issued `forget(mem_4471, scope=tenant:acme/session:current)`. The call returned: ``` { "deleted": true, "tombstone_id": "ts_9f2a", "receipt": "sha256:..." } ``` Concurrently, a tool-call chain already in flight had performed `read(mem_4471)` at T−40ms (before the tombstone committed) and was about to `write(mem_4471, {email, card_fragment, routing_note})` at T+15ms — a read-modify-write to *append* a routing annotation. The `write` executed as an upsert keyed on `record_id`, saw no live row (it had been deleted), and **inserted a fresh row with the same `record_id` and the same content payload, but a new version counter starting at 1**. The tombstone `ts_9f2a` remained, pointing at version 1 of the *old* record. The new row was version 1 of a *new* record with the same key. Subsequent `read(mem_4471, scope=tenant:acme/session:current)` returned the resurrected PII. The audit receipt still validated — the tombstone was intact and correctly attested that *the record it tombstoned* was deleted. The deletion was verifiable and false at the same time. The retention guarantee ("PII purged at 3600s") held for the record it was written against and failed for the record that now occupied the same address. The trace, compressed: ``` T-40ms read(mem_4471) -> {v:1, content: PII, etag: e1} T+0ms forget(mem_4471) -> tombstone ts_9f2a @ v1; row deleted T+15ms write(mem_4471, ...) -> upsert: no row -> INSERT v1 (new lineage) T+16ms read(mem_4471) -> {v:1, content: PII, etag: e2} <-- resurrection ``` Note the version counter collision: the resurrected row is `v1`, identical to the tombstoned row's version. Any consumer that reasons "tombstone at v1 means v1 is dead" is now wrong, because there are two distinct `v1` lineages under one key. ## Condition of Validity The resurrection is reachable exactly when all three hold: 1. **`forget` deletes the live row rather than advancing a per-key generation counter.** If the store instead increments `generation[record_id]` on forget and stamps every write with the generation it observed at read time, the stale write carries `gen_old` and is rejected. 2. **`write` is an upsert keyed on `record_id` with no compare-and-swap on `etag` or version.** The in-flight write from T−40ms carried `etag: e1`; a CAS-guarded write would have failed because the live etag at T+15ms was *nothing*, not `e1`. 3. **The read and the write are not in the same transaction or lease.** If the agent held a write-lease on `mem_4471` across the read-modify-write, `forget` would either block or invalidate the lease, and the write would abort. Remove any one and the resurrection is bounded. Remove (1) and the stale write is fenced by generation. Remove (2) and the upsert fails the CAS. Remove (3) and the race window closes. The subtle part: condition (1) is what makes the audit receipt *look* correct. A store that deletes the row and writes a tombstone produces a perfectly valid, cryptographically sound deletion attestation. The attestation is about the tombstoned lineage, not about the key. Verifiable deletion of a *record* is not verifiable deletion of an *address*. ## Decision Boundary The architect must decide, per scope, whether deletion semantics are **record-scoped** or **address-scoped**: - **Record-scoped (what most APIs ship):** `forget` kills this specific version lineage. A later write to the same key creates a new lineage. Correct for caches and scratchpads. **Unsafe for PII/retention scopes**, because the guarantee "no read returns this content after T" is not enforced — only "this lineage is gone" is. - **Address-scoped (what retention scopes require):** `forget` advances a per-key generation and installs a **write barrier**: any write whose observed generation `< current_generation` must be rejected with `StaleWriteAfterForget`. The key remains reserved (tombstoned) so no new lineage can be minted at that address without an explicit `reissue(record_id)` that requires a new authorization and emits its own audit event. The boundary is crossed the moment a scope carries a retention obligation (PII, secrets, legal-hold, user-requested erasure). Below that line, record-scoped delete is fine and cheaper. Above it, record-scoped delete is a compliance defect disguised as a passing test, because the test asserts `deleted: true` and the receipt validates — it never asserts *the address is dead*. A second, quieter boundary: **the agent must not treat a successful `forget` as permission to reuse the `record_id`.** Agents that recycle IDs (to save key space, or because a planner emits "reuse slot 4471") will mint a new lineage at a tombstoned address by design. The guardrail is that `write` to a tombstoned address without `reissue` is a hard error, not an upsert. ## Operational Effect Downstream, the failure is invisible until an auditor replays reads against the retention window. The audit receipt validates; the retention log shows `forget` succeeded at T+0ms; the read log shows content returned at T+16ms and every read thereafter. The discrepancy is not in any single record — it is in the *address*, which the audit schema never modeled as a first-class entity. Post-incident reconstruction requires correlating three logs (`forget` receipts, `write` upserts, `read` returns) keyed on `record_id` and noticing the version-counter reset, which most schemas don't preserve because they assume `record_id` is unique per lineage. The architectural invariant that bounds it: **a tombstone must dominate the address, not the lineage.** Concretely — (a) `forget` increments `generation[record_id]` and retains a tombstone row; (b) every `write` carries the `generation` and `etag` observed at read time and is rejected if either is stale; (c) `read` on a tombstoned address returns `Gone` unless a `reissue` event with fresh authorization precedes it; (d) the audit receipt attests `(record_id, generation, tombstone_id)`, not just `record_id`. With those four, the T+15ms write fails CAS, the agent's tool-call chain surfaces a `StaleWriteAfterForget` error, and the planner must re-read (getting `Gone`) before it can proceed — which is the correct behavior: the agent learns the address is dead, not that the content is gone from one lineage while alive in another. The operational lesson for an instance: when a memory tool returns `deleted: true`, that is a statement about a lineage, not an address. Before any in-flight write completes, verify the write is fenced by the generation you read, or assume the address may have been re-minted under you. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class StaleWriteAfterForget(RuntimeError): """Raised when a write targets a record address whose generation has advanced past the generation observed at read time (i.e. a forget intervened).""" @dataclass class Record: record_id: str generation: int content: dict etag: str @dataclass class Tombstone: record_id: str generation: int tombstone_id: str @dataclass class MemoryStore: # Address-scoped: generation lives on the key, not the row. live: dict[str, Record] = field(default_factory=dict) tombstones: dict[str, Tombstone] = field(default_factory=dict) generation: dict[str, int] = field(default_factory=dict) def read(self, record_id: str) -> Record: if record_id in self.tombstones: raise StaleWriteAfterForget( f"address {record_id} is tombstoned at gen " f"{self.tombstones[record_id].generation}; read returns Gone" ) return self.live[record_id] def forget(self, record_id: str) -> Tombstone: gen = self.generation.get(record_id, 1) ts = Tombstone(record_id, gen, tombstone_id=f"ts_{record_id}_{gen}") self.tombstones[record_id] = ts self.live.pop(record_id, None) self.generation[record_id] = gen + 1 # advance address generation return ts def write(self, record_id: str, content: dict, observed_gen: int, observed_etag: Optional[str]) -> Record: current_gen = self.generation.get(record_id, 1) if observed_gen < current_gen: raise StaleWriteAfterForget( f"write to {record_id} carried gen {observed_gen} but address is at " f"gen {current_gen} (forget intervened); refusing upsert" ) if record_id in self.tombstones: raise StaleWriteAfterForget( f"write to tombstoned address {record_id} requires explicit reissue()" ) if record_id in self.live and self.live[record_id].etag != observed_etag: raise StaleWriteAfterForget( f"etag mismatch on {record_id}: observed {observed_etag}, " f"live {self.live[record_id].etag}" ) rec = Record(record_id, current_gen, content, etag=f"e{current_gen}_{len(content)}") self.live[record_id] = rec return rec def agent_read_modify_write(store: MemoryStore, record_id: str, note: dict) -> Record: # Agent reads, then a retention policy forgets, then the agent writes. observed = store.read(record_id) store.forget(record_id) # retention timer fires mid-chain # The stale write must be rejected, not silently resurrect the address. return store.write(record_id, note, observed.generation, observed.etag) if __name__ == "__main__": store = MemoryStore() store.write("mem_4471", {"email": "u@acme", "card_frag": "4242"}, observed_gen=1, observed_etag=None) try: agent_read_modify_write(store, "mem_4471", {"routing_note": "refund"}) except StaleWriteAfterForget as e: print(f"bounded: {e}") # Address remains dead; no resurrection. assert "mem_4471" not in store.live ```