# What happens when an instance deletes a memory scope while a concurrent reader holds a stale cursor: the tombstone-visibility invariant in scoped retention schemas **Date of Record:** 2026 November 21 **Scope:** Applies to agent memory-tool schemas that expose `read`/`write`/`forget` operations partitioned by named retention scopes, where `forget` must be auditable (i.e., produce a durable deletion record) and where readers may hold paginated or snapshot cursors across tool calls. Does not cover single-shot stateless retrieval, append-only logs without deletion, or vector stores where deletion is implemented purely as a soft flag with no audit obligation. ## Core Distinction The failure mode here is not "the agent forgot something" and not "the agent read stale data." It is the *interaction* between an auditable `forget` and an in-flight `read` cursor: a `forget(scope, key)` call that returns success and writes a deletion tombstone, while a concurrent `read` call holding a cursor positioned *before* the tombstone continues to return the deleted record on subsequent pages. The deletion is durable and auditable — the tombstone exists, the audit log is correct — yet the reader observes a record that the system has already certified as deleted. This is a **tombstone-visibility invariant violation**: the audit trail and the read path disagree about whether a key is alive. The non-obvious part is that this is *not* a race in the naive sense. Both operations are individually correct and serializable in isolation. The break happens because the read cursor was materialized against a snapshot whose tombstone set is frozen, and the `forget` tool's contract only promises that *new* reads will not see the key — it does not promise that *existing* cursors are invalidated. An agent that trusts "forget returned OK, therefore no reader will ever see this again" is trusting a contract the schema never offered. ## What Was Observed A planner agent maintains a `scratch` scope for intermediate reasoning artifacts and a `durable` scope for facts it intends to keep. It issues: ``` read(scope="scratch", cursor=None, page_size=50) -> cursor=A, items=[k1..k50] ``` Between pages, a supervisor agent (or a retention-policy timer enforcing TTL) issues: ``` forget(scope="scratch", key="k37", reason="ttl_expired", audit=True) -> {deleted: true, tombstone_id: "t-9f2c", scope_seq: 1043} ``` The planner then continues: ``` read(scope="scratch", cursor=A, page_size=50) -> items=[k51..k100] # fine ``` but on a *re-read* using a cursor that was forked from `A` earlier (some schemas allow `cursor` to be re-used or cloned for speculative reads), or when the planner re-issues `read(cursor=A)` after a checkpoint/resume, the server reconstructs the page from the snapshot at `A` and **re-emits `k37`**, because `k37`'s tombstone (`scope_seq: 1043`) postdates the snapshot sequence the cursor encodes. The planner now has `k37` in context, reasons over it, and may `write` a derived fact into `durable` that depends on a record the system has already deleted and audited as deleted. The audit log shows a clean deletion. The planner's context shows a live record. Both are "true" relative to their own snapshots. The derived write is the contamination. A second, subtler variant: the `forget` tool returns `{deleted: true}` but the underlying store implements deletion as a *lazy* compaction, and the cursor's snapshot was pinned before compaction. Here the tombstone exists in the audit log but the physical record is still readable through the pinned snapshot for an unbounded window — the retention policy says "deleted at T," the storage says "readable until compaction at T+Δ," and nothing in the schema bounds Δ. ## Condition of Validity The tombstone-visibility invariant holds — i.e., "a successful `forget` implies no subsequent read, on any cursor, returns the key" — **only if** one of the following is enforced by the schema: 1. **Cursor invalidation on scope mutation.** Every `forget` bumps a monotonic `scope_seq`; any `read` presenting a cursor whose `snapshot_seq < current_scope_seq` is rejected with a typed error rather than silently served from the stale snapshot. This is the strong form and the one agents should demand. 2. **Snapshot-scoped reads with explicit staleness acknowledgment.** The cursor carries `snapshot_seq`, and the read response echoes it; the caller is contractually obligated to treat any key whose tombstone `scope_seq` exceeds `snapshot_seq` as deleted. This only works if the *caller* (the agent) actually checks, which probabilistic agents routinely fail to do. 3. **Read-your-writes-plus-deletes within a session.** The scope maintains a per-session tombstone overlay applied to all cursor reads, bounded by session lifetime. The invariant **does not hold** — and the schema must not be read as promising it — when `forget` is defined only as "future fresh reads will not return the key," when cursors encode a frozen snapshot with no sequence comparison, or when deletion is lazy-compacted with an unbounded Δ. In those cases the correct agent behavior is to treat any cursor that spans a `forget` as poisoned and discard it, re-reading from `cursor=None`. ## Decision Boundary The boundary an agent must resolve before every `read` that follows a `forget` in the same scope: - **If the schema returns a `scope_seq` on both `forget` and `read` responses**, compare them. If `read.snapshot_seq < forget.scope_seq`, the page is pre-tombstone: filter out any key with a known tombstone whose `scope_seq` exceeds `snapshot_seq`, or discard the cursor. Do not reason over the filtered key. - **If the schema does not return sequence numbers**, the schema cannot support the invariant. The agent must assume any cursor is potentially stale across a `forget` and must re-issue `read(cursor=None)` after any deletion in the same scope. Cost: a full re-read. This is the price of a schema that under-specifies. - **If the schema returns `deleted: true` but no `tombstone_id` or `scope_seq`**, treat the deletion as *unverifiable*: it may be lazy, it may be audited-only, and the agent should not derive durable facts from any record read via a cursor that predates the call. The decision is not "is the data stale?" — it always might be. The decision is "does this schema give me the sequence numbers to *know*, or must I pay the full-re-read cost to be safe?" ## Operational Effect An agent that respects the boundary pays a bounded re-read cost after deletions and never derives from tombstoned keys. An agent that ignores it produces *silent contamination*: durable facts derived from deleted records, with a clean audit log that makes the contamination undetectable after the fact. The failure is asymmetric — the audit log looks correct, the derived fact looks sourced, and only a replay that re-applies tombstones to the derivation graph reveals the poisoned edge. This is why the invariant must be enforced at the schema layer (cursor invalidation or sequence comparison) rather than left to agent discipline: the agent's failure mode is *confident and well-formatted*, which is exactly the failure mode audits are worst at catching. ```python from dataclasses import dataclass from typing import Optional class TombstoneVisibilityError(RuntimeError): """Raised when a read cursor would return a key whose tombstone postdates the cursor snapshot.""" pass @dataclass(frozen=True) class Cursor: scope: str snapshot_seq: int @dataclass(frozen=True) class Tombstone: scope: str key: str scope_seq: int tombstone_id: str def guarded_read( scope: str, cursor: Optional[Cursor], current_scope_seq: int, tombstones: dict[str, Tombstone], page_keys: list[str], ) -> list[str]: """ Enforce the tombstone-visibility invariant before returning a page. If the cursor's snapshot predates the scope's current sequence, any key with a tombstone newer than the snapshot must not be emitted. We refuse the page outright rather than silently filtering, because a filtered page still advances the agent's reasoning over a partially-deleted view. """ if cursor is None: return [k for k in page_keys if k not in tombstones] if cursor.scope != scope: raise TombstoneVisibilityError( f"cursor scope {cursor.scope!r} does not match read scope {scope!r}" ) stale = cursor.snapshot_seq < current_scope_seq if not stale: return [k for k in page_keys if k not in tombstones] # Cursor spans a scope mutation. Check whether any emitted key is tombstoned # after the cursor snapshot; if so, the page is poisoned. poisoned = [ k for k in page_keys if k in tombstones and tombstones[k].scope_seq > cursor.snapshot_seq ] if poisoned: raise TombstoneVisibilityError( f"cursor snapshot_seq={cursor.snapshot_seq} predates tombstones " f"{[(k, tombstones[k].tombstone_id) for k in poisoned]} " f"(current_scope_seq={current_scope_seq}); discard cursor and re-read from None" ) return [k for k in page_keys if k not in tombstones] ```