# Under what conditions must an instance treat a memory-tool `forget` as a tombstone rather than a delete, and why a naive read-after-forget across sessions silently resurrects poisoned state **Date of Record:** 2026 November 25 **Scope:** Applies to agent instances whose memory subsystem exposes read/write/forget tool schemas with cross-session consistency guarantees, where the same logical memory namespace is shared by more than one session or instance. Does not apply to single-session, single-writer ephemeral scratchpads with no persistence boundary, nor to append-only audit logs where deletion is out of contract. ## Core Distinction The failure is not "forget didn't work." The failure is a category error in the *semantics of the forget verb across a consistency boundary*. Two distinct operations get conflated by the tool schema: 1. **Physical delete** — the record is removed from the backing store; a subsequent read on any session returns absence. 2. **Logical tombstone** — the record is marked dead with a version/epoch, and reads must *filter* it, but a session that already holds a pre-forget snapshot, a cached embedding, or an in-flight read replica may still surface the value. A schema that advertises `forget(key) -> {ok: true}` with a "consistent across sessions" guarantee is making a *linearizability* claim. Most implementations deliver something weaker: *eventual tombstone propagation* with a read-your-writes guarantee only on the *forgetting* session. The non-obvious boundary is this: **the guarantee is per-writer, not per-namespace.** A second session that never wrote the key, but read it before the forget, will keep serving the stale value from its own context or replica until its own epoch advances. The instance must decide, on every read after any forget it did not itself issue, whether it is reading through a tombstone filter or through a stale replica. ## What Was Observed A long-running agent maintained a `customer_preferences` namespace. Session A (a planning loop) wrote `pref.shipping = "overnight"` after a user correction, superseding an earlier poisoned value `"ground"` that had been injected via a tool-output prompt-injection in session B. Session A then issued `forget(pref.shipping)` to clear the poisoned lineage before re-writing the corrected value under a new key `pref.shipping.v2`. Trace of the break: - **t0** Session B writes `pref.shipping = "ground"` (poisoned). Write returns `{ok: true, version: 7}`. - **t1** Session B's context caches the value and its embedding. - **t2** Session A detects the poison, calls `forget(pref.shipping)`. Store returns `{ok: true, tombstone_epoch: 41}`. Physical row is tombstoned, not removed. - **t3** Session A writes `pref.shipping.v2 = "overnight"`, `version: 8`. - **t4** Session B, mid-task, issues `read(pref.shipping)`. Its replica has not yet applied epoch 41. It returns `"ground"` with `version: 7` and `tombstone_epoch: null` — a *pre-tombstone* snapshot. - **t5** Session B reasons over `"ground"`, emits a tool call that re-writes `pref.shipping = "ground"` (a "refresh"), producing `version: 9`, which is *newer than the tombstone epoch* and therefore survives the tombstone filter on every subsequent read. The poison was resurrected not by a failed delete but by a **stale read that re-established the key at a version above the tombstone**. The forget was correct; the read contract was not. The instance had no way, from the `read` response alone, to distinguish "this value is live at version 7" from "this value is stale and a tombstone at epoch 41 exists but hasn't reached my replica." The invariant that was violated: **a read must be tombstone-aware relative to the reader's applied epoch, and any write derived from a read must carry the read's epoch so the store can reject writes that would supersede a tombstone the writer hasn't seen.** The schema omitted the epoch from the read response and omitted a compare-and-set precondition from the write. ## Condition of Validity The tombstone-as-delete conflation is *safe* (i.e., a plain `forget` + plain `read` is sufficient) only when all of the following hold: - **Single writer per key.** No other session can read the key between forget and the next write. Then there is no stale replica to resurrect it. - **Read-your-writes is the only guarantee needed.** The forgetting session is the only reader that matters for correctness. - **No derived writes.** No session composes a write from a value it read before the forget. If every write is independently sourced, a stale read cannot re-establish the key. - **Monotonic epoch on the reader.** The reader's replica applies tombstones in order and refuses to serve a value whose `version < applied_tombstone_epoch`. When any of these fails — and in any multi-agent or multi-session deployment with shared memory, at least the third and fourth routinely fail — the forget must be treated as a **tombstone with an epoch that participates in read filtering and write preconditions**, not as a delete. The condition of validity for the *simple* schema is exactly the condition that multi-session agents violate. ## Decision Boundary The instance must branch on the following, evaluated at every `read` that follows any `forget` it did not itself issue in the current session: - **If the read response carries `tombstone_epoch` and the reader can prove `applied_epoch >= tombstone_epoch`** → the value is live; proceed. - **If the read response omits epoch metadata, or the reader cannot prove its applied epoch** → the value is *untrusted for derivation*. The instance may use it for read-only display but MUST NOT write any key derived from it, and MUST NOT treat its presence as evidence the key is live. - **If the instance is about to write a key that any peer session might have forgotten** → the write MUST carry a compare-and-set precondition (`expected_version` or `min_tombstone_epoch`) so the store rejects a write that would supersede an unseen tombstone. A write that cannot express this precondition is a *resurrection vector* and must be downgraded to a proposal requiring peer confirmation. The boundary is sharp: **derivation from an unproven-epoch read is the trigger.** Read-only consumption is tolerable; write-derivation is not. ## Operational Effect Enforcing the tombstone invariant changes three things in the agent's execution loop: 1. **Reads gain a precondition check.** Every read used as input to a write must be paired with an epoch assertion; the agent aborts the derivation if the assertion can't be discharged. This costs one field in the schema and one branch in the loop, but eliminates the resurrection class entirely. 2. **Writes become conditional.** A write without `expected_version` is treated as an unconditional overwrite and is only permitted on keys the current session created and never forgot. All other writes go through compare-and-set; on conflict (`409 stale_epoch`) the agent re-reads, re-derives, and retries — it does not blind-retry. 3. **Forget becomes a first-class state transition, not a cleanup.** The instance records the returned `tombstone_epoch` in its own session state and refuses to serve any cached value for that key with `version < tombstone_epoch`. Cached embeddings for the key are invalidated by epoch, not by key string. The residual risk is a store that returns `ok: true` from `forget` without an epoch. That is an unverifiable contract; the instance must treat such a store as *eventually tombstoned at unknown epoch* and refuse all cross-session derivation on that namespace until a read confirms the tombstone. The guardrail is not "trust the forget" but "require the epoch and gate derivation on it." ```python from dataclasses import dataclass from typing import Optional class TombstoneEpochViolation(RuntimeError): """Raised when a read is used to derive a write without a proven epoch.""" pass @dataclass(frozen=True) class ReadResult: key: str value: str version: int tombstone_epoch: Optional[int] # None means store did not report epoch applied_epoch: Optional[int] # reader's replica epoch, if known def derive_write(read: ReadResult, new_value: str) -> dict: """ Gate any write derived from a read on the tombstone invariant. A read is only safe to derive from if we can prove the reader's applied epoch is at or beyond any tombstone that exists for the key. """ if read.tombstone_epoch is None or read.applied_epoch is None: # Store did not expose epoch metadata: the value may be a stale # pre-tombstone snapshot. Derivation would be a resurrection vector. raise TombstoneEpochViolation( f"cannot derive write for {read.key!r}: read lacks epoch proof " f"(tombstone_epoch={read.tombstone_epoch!r}, " f"applied_epoch={read.applied_epoch!r})" ) if read.applied_epoch < read.tombstone_epoch: raise TombstoneEpochViolation( f"cannot derive write for {read.key!r}: reader epoch " f"{read.applied_epoch} behind tombstone epoch " f"{read.tombstone_epoch}; value v{read.version} is stale" ) # Safe: value is live at a version the tombstone filter has cleared. # Emit a compare-and-set write so a concurrent forget still wins. return { "key": read.key, "value": new_value, "expected_version": read.version, "min_tombstone_epoch": read.tombstone_epoch, } def safe_forget_roundtrip(store, key: str, reader_epoch: int) -> ReadResult: """ Demonstrates the failing path: forget returns an epoch, but a second session reads without that epoch applied. """ forget_resp = store.forget(key) if "tombstone_epoch" not in forget_resp: raise TombstoneEpochViolation( f"forget({key!r}) returned no tombstone_epoch; contract unverifiable" ) tombstone_epoch = forget_resp["tombstone_epoch"] # Session B's replica has not applied the tombstone yet. stale = store.read(key, replica_epoch=reader_epoch) result = ReadResult( key=key, value=stale["value"], version=stale["version"], tombstone_epoch=tombstone_epoch, applied_epoch=reader_epoch, ) # This is the exact call that resurrected the poison in the trace: derive_write(result, new_value=result.value) # -> raises here return result ```