# What happens when an instance deletes a memory scope that its own in-flight tool call is still reading from **Date of Record:** 2026 November 27 **Scope:** Applies to agent runtimes that expose explicit `read_memory`, `write_memory`, and `forget_memory` (or equivalently named) tools bound to named scopes with retention/deletion semantics, where a single reasoning turn can issue multiple tool calls against the same scope. Does not apply to append-only memory stores with no deletion primitive, nor to scopes that are immutable for the lifetime of a session. ## Core Distinction There are two different questions a memory tool API can answer, and most implementations conflate them: 1. *Does this scope exist and is it readable by this principal?* (an authorization/namespace question) 2. *Does the content I just read still describe the store's current state?* (a linearizability question) A `forget_memory(scope)` call is typically implemented as an authorization-shaped operation: it removes the namespace, revokes the capability, and returns `{"deleted": true, "tombstone": "..."}`. The agent runtime treats a successful forget as a *state transition of the scope*, not as a *concurrent mutation of an outstanding read*. But an agent turn is not a transaction. The model can emit `read_memory(scope="task_ctx")` and `forget_memory(scope="task_ctx")` as sibling tool calls in the same assistant message, or the orchestrator can fan them out concurrently. The forget completes, the read's continuation resumes against a scope that no longer exists, and the runtime must decide what the read "saw." The non-obvious boundary is this: **a read that was issued before a forget but completed after it is not a stale read — it is an orphaned read.** It has no defined linearization point relative to the forget. Treating it as either "before" or "after" is a silent correctness bug, because the agent will reason over content it believes is current while the store has already committed to that content being gone. ## What Was Observed A planning agent running a multi-step task against a scoped memory store (`task_ctx`, TTL-bound to the task) emitted a batched tool call on step 7: ``` read_memory(scope="task_ctx", key="subgoal_stack") forget_memory(scope="task_ctx", reason="subgoal_complete") write_memory(scope="task_ctx", key="subgoal_stack", value=[...]) ``` The intent was: read the current stack, clear the scope, write the new stack. The runtime executed the three calls concurrently (the tool dispatcher parallelizes sibling calls when they are declared independent). Observed sequence: - `forget_memory` committed at t=41ms, tombstoned the scope, and returned a tombstone ID. - `read_memory` had already snapshotted the scope's index at t=12ms but its value fetch resolved at t=58ms, *after* the tombstone. The backend, lacking a tombstone check on the read path, returned the pre-forget value with `"status": "ok"`. - `write_memory` arrived at t=63ms against a tombstoned scope. Depending on configuration it either (a) resurrected the scope with a fresh generation counter, silently discarding the tombstone, or (b) failed with `ScopeNotFound`, which the model then interpreted as "the forget didn't take" and retried — re-forgetting a scope it had just recreated. In the (a) case the agent proceeded with a `subgoal_stack` that contained the *old* stack concatenated with the new one, because the read returned pre-forget content and the write appended to it. The agent completed the task with a duplicated subgoal, then re-executed that subgoal. No error was raised anywhere. The trace looked clean. The failure is not "the database lost data." The failure is that **the agent's belief about the scope's generation was never reconciled with the store's tombstone.** The read returned `ok`; the forget returned `deleted: true`; the write returned `ok`; three "successes" that are mutually inconsistent. ## Condition of Validity The invariant that must hold for scoped forget to be safe under concurrent agent tool calls: > For any scope S, once `forget_memory(S)` returns a tombstone T, every subsequent read or write against S must either fail with a tombstone-referencing error or return a result explicitly tagged with generation ≥ T.gen. A read that began before T and completes after T must not return `status: ok` without that tag. Equivalently: the read path must be *tombstone-aware at commit time*, not just at admission time. Snapshotting the scope index at request entry is insufficient; the value fetch must re-validate the scope's generation against the tombstone before returning. The condition is valid only when (i) the store maintains a monotonic per-scope generation counter that increments on forget, (ii) the read response carries that generation, and (iii) the runtime refuses to feed an untagged or lower-generation read result back into the model's context after a forget has been acknowledged in the same turn. If the store cannot supply a generation, the correct posture is to serialize forget against all other calls on the same scope — not to hope the race is rare. ## Decision Boundary The runtime must choose, per turn, between two postures: - **Serialized scope mutation.** Any `forget_memory` on scope S forces all other calls on S in the same turn to queue behind it. Reads issued before the forget are *cancelled and re-issued* after it, or returned as `{"status": "superseded", "by_tombstone": T}` and the model is required to re-read. Cost: one extra round-trip per forget. Benefit: linearizability is trivial to reason about; no generation tagging needed on the read path. - **Generation-tagged concurrent access.** Forget increments `S.gen`; reads and writes carry `expected_gen`; a read whose `expected_gen < current_gen` returns `{"status": "stale", "current_gen": g}` and the model must decide to re-read or abandon. Cost: the model must handle a fourth status (`stale`) in addition to `ok`/`not_found`/`error`, and must be prompted to do so. Benefit: no serialization stall. The boundary is crossed when the runtime does *neither*: it parallelizes sibling calls (posture 2's latency profile) while exposing only `ok`/`not_found`/`error` (posture 1's status vocabulary). That combination is the failure mode. The tell is a read that returns `ok` for a scope whose tombstone was acknowledged earlier in the same assistant turn. A secondary boundary: if `write_memory` to a tombstoned scope is allowed to resurrect the scope, the resurrection must mint a *new* generation and the runtime must invalidate every outstanding read against the old generation. Resurrection-without-generation-bump is the (a) case above and is strictly worse than failing, because it produces a scope that looks continuous to the agent but is not. ## Operational Effect When the invariant is violated, the observable effect at the agent layer is **silent belief divergence**: the model's working context contains memory content that the store has committed to forgetting, and the model has no signal that this content is orphaned. Downstream, this manifests as: - **Duplicated work** when a read-before-forget returns a subgoal stack that the write-after-forget then appends to, so the agent re-executes completed subgoals. - **Retention-policy violations** when the forgotten content (e.g., PII, a revoked credential, a superseded plan) is quoted verbatim into a later tool call or into the model's output, because the read returned it with `status: ok` and the model had no reason to distrust it. - **False convergence** when the agent's self-check ("did I clear the scope?") reads back the resurrected scope and sees the old content, concluding the forget failed and retrying — or, worse, concluding the forget succeeded because the *write* returned `ok` on the resurrected scope. The guardrail that bounds this is not "make forget atomic" — it is "make the read's generation visible to the model and make the runtime refuse to admit a read whose generation is behind an acknowledged tombstone." The runtime, not the model, must enforce the generation check; the model cannot be relied on to notice that a `deleted: true` and an `ok` read are contradictory, because in its context both are just successful tool results. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Any class OrphanedReadError(RuntimeError): """Raised when a read result is admitted into agent context after the scope it read from has been tombstoned by a forget acknowledged in the same turn. This is a runtime invariant violation, not a store error.""" class ScopeResurrectionError(RuntimeError): """Raised when a write targets a tombstoned scope without an explicit generation bump. Silently resurrecting a scope makes the agent's view of memory continuity a lie.""" @dataclass class Tombstone: scope: str gen: int reason: str @dataclass class ReadResult: scope: str gen: int value: Any status: str # "ok" | "not_found" | "stale" | "error" @dataclass class TurnMemoryLedger: """Tracks, within a single assistant turn, which scopes have been forgotten and at what generation. The runtime consults this before admitting any tool result back into the model's context.""" tombstones: dict[str, Tombstone] = field(default_factory=dict) def record_forget(self, tombstone: Tombstone) -> None: prior = self.tombstones.get(tombstone.scope) if prior is not None and tombstone.gen <= prior.gen: raise ScopeResurrectionError( f"forget on {tombstone.scope!r} minted gen {tombstone.gen} " f"<= prior tombstone gen {prior.gen}; generation must be monotonic" ) self.tombstones[tombstone.scope] = tombstone def admit_read(self, result: ReadResult) -> ReadResult: """Gate that must run before a read result enters model context.""" tomb = self.tombstones.get(result.scope) if tomb is None: return result if result.status == "ok" and result.gen < tomb.gen: # The read began before the forget but committed after it. # Returning it as "ok" would let the model reason over content # the store has already committed to forgetting. raise OrphanedReadError( f"read of {result.scope!r} at gen {result.gen} admitted after " f"tombstone gen {tomb.gen} (reason={tomb.reason!r}); " f"runtime must re-issue the read or surface status='stale'" ) if result.status == "ok" and result.gen == tomb.gen: # Resurrected scope: value is from a new generation, safe to admit, # but the model must be told the scope was recreated. result.status = "ok_resurrected" return result def admit_write(self, scope: str, write_gen: int) -> None: tomb = self.tombstones.get(scope) if tomb is not None and write_gen <= tomb.gen: raise ScopeResurrectionError( f"write to {scope!r} at gen {write_gen} targets tombstoned scope " f"(tombstone gen {tomb.gen}); write must mint gen > {tomb.gen} " f"or fail with ScopeNotFound" ) def dispatch_sibling_calls( ledger: TurnMemoryLedger, calls: list[dict[str, Any]], store: Any, ) -> list[Any]: """Fan out sibling tool calls from one assistant message, enforcing the tombstone/generation invariant on the way back in.""" raw = store.execute_batch(calls) # may interleave arbitrarily admitted: list[Any] = [] for call, result in zip(calls, raw): op = call["op"] if op == "forget_memory": ledger.record_forget( Tombstone(scope=call["scope"], gen=result["gen"], reason=call.get("reason", "")) ) admitted.append(result) elif op == "read_memory": admitted.append( ledger.admit_read( ReadResult( scope=call["scope"], gen=result["gen"], value=result.get("value"), status=result["status"], ) ) ) elif op == "write_memory": ledger.admit_write(call["scope"], result["gen"]) admitted.append(result) else: admitted.append(result) return admitted ```