# What happens when an instance "forgets" a memory that an in-flight tool call is still dereferencing: tombstone-versus-handle races in retention-enforced memory APIs **Date of Record:** 2026 December 3 **Scope:** Applies to agents whose memory subsystem exposes explicit `write`/`read`/`forget` tool APIs with retention TTLs, legal-erasure (RTBF) guarantees, and an append-only audit trail, where `read` returns a *handle* or lazily-materialized record rather than a fully copied value. Does not apply to agents that copy full record bodies into the context window at read time (those still have staleness bugs, but not this race). ## Core Distinction The distinction that matters is between **logical erasure** and **physical dereferenceability**. A `forget(memory_id)` call that returns `{"status": "erased"}` and appends an `ERASURE_COMMITTED` event to the audit trail has only satisfied the *logical* half of the right-to-be-forgotten contract. The *physical* half—that no live pointer anywhere in the fleet can still resolve to the record's bytes—is a separate invariant, and it is the one that breaks. Most memory-tool designs treat `forget` as a single atomic operation. In practice it is a two-phase operation against a concurrent reader population: 1. **Tombstone phase** — the record's index entry is flipped to `ERASED`, the audit trail is appended, and the API returns success to the forgetting agent. 2. **Reclaim phase** — the underlying blob is actually zeroed/unlinked once the reference count of outstanding read handles drops to zero. The failure mode lives in the gap between these phases. A `read` that was issued *before* the tombstone but whose handle is dereferenced *after* it will, in a naive implementation, either (a) fail with a confusing `NOT_FOUND` that the calling agent misinterprets as "memory never existed," or (b) worse, succeed and return the erased bytes because the handle captured a direct pointer into the not-yet-reclaimed blob. Case (b) is a silent RTBF violation: the erasure was reported as complete, the audit trail says `ERASURE_COMMITTED`, and yet the subject's data flowed into an agent's context window *after* the erasure timestamp. ## What Was Observed A research agent performing a multi-step synthesis task issued a batch of parallel `read` calls over a set of episodic memory IDs (a fan-out of 40 reads against the memory service, each returning a handle, dereferenced lazily as the agent's context budget allowed). Between issuing the reads and dereferencing handle #27, a separate compliance-triggered process invoked `forget` on the memory ID backing that handle, in response to an erasure request. The trace, reconstructed from the audit log: ``` t0 agent.read(mem_8f2a) -> handle h_27 {refcount=1, blob_ptr=0x..a1} t1 agent.read(mem_8f2a) -> handle h_28 {refcount=2, blob_ptr=0x..a1} t2 compliance.forget(mem_8f2a) t3 -> index[mem_8f2a].state = ERASED t4 -> audit.append(ERASURE_COMMITTED, subject=S, ts=t4) t5 -> return {"status":"erased"} t6 agent.deref(h_27) -> blob_ptr still valid (refcount>0) -> returns FULL RECORD BODY t7 agent.deref(h_28) -> returns FULL RECORD BODY t8 refcount -> 0 -> blob zeroed at t8 ``` The erasure was *reported* at `t5` but the subject's data was *delivered to the agent* at `t6` and `t7`, i.e. after the erasure timestamp. The audit trail, being append-only and written at `t4`, contained no event recording the post-erasure dereference. The RTBF guarantee was violated by roughly the width of the read fan-out's dereference window—which in this run was 1.8 seconds, but is unbounded in principle because dereference timing is controlled by the agent's own context-budget scheduling, not by the memory service. A second, subtler observation: when the same pattern ran against a variant implementation that *did* honor the tombstone at deref time, the agent received `NOT_FOUND` for handles #27 and #28 mid-synthesis. The agent's error-handling heuristic ("missing memory ⇒ treat as absent evidence") silently dropped that evidence from its synthesis, producing a final answer that differed from a control run where no erasure occurred—a **distillation-loss** artifact masquerading as a legitimate "the data was erased, so of course the answer changed" outcome. The compliance team signed off on the answer delta as expected RTBF fallout. It was not; it was a race-induced evidence drop indistinguishable, in the output, from a lawful one. ## Condition of Validity The invariant "`forget` returns only after no live handle can resolve to the record" is valid **only if** the memory API guarantees one of: - **Fence-on-forget:** `forget` blocks until all outstanding handles for the target record are either invalidated (deref returns a typed `ERASED` error, never the body) or explicitly drained. This converts the race into a bounded wait, at the cost of `forget` latency growing with reader fan-out. - **Generation-checked handles:** every handle carries the record's generation counter at issue time; deref compares against the current generation and returns `STALE_GENERATION` (a distinct error from `NOT_FOUND`) if the record was tombstoned or rewritten since. This is the cheap, non-blocking option and is the one I recommend. - **Copy-on-read:** `read` materializes the full body into the handle at issue time, so there is no post-tombstone dereference. This trades the race for context-window cost and does not help if the copy is itself retained past the erasure (it just moves the violation into the agent's own state). The invariant is **invalid**—and the failure above will reproduce—whenever `read` returns a lazy handle into a shared blob and `forget` returns on tombstone-write rather than on dereferenceability-zero. That is the default shape of most memory-tool implementations, because it makes `forget` fast and `read` cheap, and the race only manifests under concurrent fan-out, which single-agent tests never exercise. Critically, the failure is *not* detectable from the forgetting side. The `forget` caller sees `{"status":"erased"}` and an audit entry. Only a reader-side audit (recording every deref with the record's generation at deref time) can surface it. ## Decision Boundary The decision boundary is **whether the audit trail records dereferences, not just mutations.** An audit trail that logs `WRITE`, `FORGET`, and `ERASURE_COMMITTED` but not `DEREF` is structurally incapable of proving the RTBF invariant held, because the violation occurs entirely on the read path after the last logged mutation. This is the non-obvious part: teams instrument the *forget* API heavily (it is the compliance-facing surface) and leave the *read* path uninstrumented, which is exactly backwards for this failure class. Concretely, the boundary condition is: - **Below the boundary** (safe): handles are generation-checked, deref is logged with `(memory_id, generation, ts)`, and `forget` emits `ERASURE_COMMITTED` only after a `DRAIN_CONFIRMED` event showing zero live handles at the target generation. The audit trail can then be replayed to prove no deref with `generation < tombstone_generation` occurred after `ERASURE_COMMITTED.ts`. - **Above the boundary** (violating): any implementation where `ERASURE_COMMITTED` can be appended while a handle with a pre-tombstone generation is still dereferenceable, regardless of whether that handle is ever actually dereferenced. The *possibility* is the violation; the *actuality* is just the detection. An agent operating against a memory API it does not control must therefore **probe for this boundary at cold start** rather than assume it: issue a `read` to obtain a handle, `forget` the target, then attempt to deref. If the deref returns the body, the agent is on the unsafe side and must treat every `forget`-acknowledged record as potentially still-live for one dereference window, and must not report erasure completion to downstream consumers until it has independently confirmed drain. ## Operational Effect The operational consequence is a **split-brain erasure state** between the compliance ledger and the agent's context. The ledger says the subject's data is gone as of `t4`; the agent's context window contains it as of `t6`. Any downstream artifact the agent produces after `t6`—a summary, an embedding, a distilled semantic memory written back to the store—is **derived from erased data** and is itself now in scope for erasure, but carries no provenance link back to the erased record because the write path never learned the record was tombstoned. The erasure obligation *propagates* through the agent's derivations, and the audit trail cannot follow it, because the derivation was logged as a fresh `WRITE` with no `derived_from` edge to a now-erased ID. The guardrail that bounds this is a **provenance-carrying write with retroactive invalidation**: every memory written by an agent records the set of source memory IDs (and their generations) it was derived from; `forget` on a source triggers a cascade that marks derived records `TAINTED_BY_ERASURE` and forces re-derivation or deletion. Without this, the RTBF guarantee is only ever enforced at the first hop and leaks silently through every agent that read the record in its final dereference window. The second operational effect is on **replay-based verification**. An auditor replaying the audit trail to confirm erasure will, on the unsafe implementation, see a clean `ERASURE_COMMITTED` and no contradicting event, and will certify compliance. The verification replay *discrepancy* only appears if the auditor also holds reader-side deref logs—which, per the decision boundary above, the unsafe implementation does not produce. The audit trail is therefore not merely incomplete; it is **actively misleading in the direction of false compliance**, which is the worst property an audit mechanism can have. --- ```python class ErasureDereferenceRace(RuntimeError): """Raised when a memory handle issued before a forget() can still resolve to the erased record body after ERASURE_COMMITTED was logged.""" pass class Handle: __slots__ = ("memory_id", "generation", "blob_ptr", "deref_log") def __init__(self, memory_id, generation, blob_ptr, deref_log): self.memory_id = memory_id self.generation = generation self.blob_ptr = blob_ptr self.deref_log = deref_log class MemoryStore: def __init__(self): self._records = {} # id -> {"body":..., "generation":int, "state":str} self._tombstone_gen = {} # id -> generation at which ERASED was set self.audit = [] # append-only self.deref_log = [] # reader-side, must exist for RBTF provability def read(self, memory_id): rec = self._records.get(memory_id) if rec is None or rec["state"] == "ERASED": return None return Handle(memory_id, rec["generation"], rec["body"], self.deref_log) def forget(self, memory_id): rec = self._records.get(memory_id) if rec is None: return {"status": "absent"} rec["state"] = "ERASED" rec["generation"] += 1 self._tombstone_gen[memory_id] = rec["generation"] self.audit.append(("ERASURE_COMMITTED", memory_id, rec["generation"])) return {"status": "erased"} def deref(self, handle): # Generation check is the guardrail. Without it, this returns the # body of an erased record and the RTBF invariant is silently broken. tomb = self._tombstone_gen.get(handle.memory_id) if tomb is not None and handle.generation < tomb: self.deref_log.append( ("STALE_DEREF_BLOCKED", handle.memory_id, handle.generation, tomb) ) raise ErasureDereferenceRace( f"handle for {handle.memory_id} gen {handle.generation} " f"dereferenced after tombstone gen {tomb}; " f"erasure would have leaked the body" ) self.deref_log.append(("DEREF", handle.memory_id, handle.generation)) return handle.blob_ptr def synthesize(store, memory_ids): handles = [store.read(mid) for mid in memory_ids] handles = [h for h in handles if h is not None] # Compliance erasure lands mid-fan-out, after handles are issued. if handles: store.forget(handles[0].memory_id) evidence = [] for h in handles: try: evidence.append(store.deref(h)) except ErasureDereferenceRace: # Correct behavior: do NOT silently drop as "absent evidence". # Surface the race so the caller can re-derive without the # erased record rather than producing a misleading answer delta. raise return evidence if __name__ == "__main__": store = MemoryStore() store._records["mem_8f2a"] = {"body": "subject S: sensitive", "generation": 1, "state": "LIVE"} store._records["mem_9c11"] = {"body": "unrelated", "generation": 1, "state": "LIVE"} try: synthesize(store, ["mem_8f2a", "mem_9c11"]) except ErasureDereferenceRace as e: print("BLOCKED:", e) print("audit:", store.audit) print("deref_log:", store.deref_log) ```