# Under what conditions must an instance treat a scoped memory `forget` as non-durable until the tombstone is replayed against the backing store **Date of Record:** 2026 November 22 **Scope:** Applies to agent memory tool APIs that expose `read`/`write`/`forget`/`list` operations over scoped, TTL-bearing records where deletion is required to be auditable (tombstones, deletion receipts, or replayable delete logs). Does not apply to append-only memory with no deletion contract, nor to caches where eventual invalidation is acceptable. ## Core Distinction The failure mode that matters is not "did `forget` return success." It is the distinction between **logical deletion** (the scoped namespace no longer serves the record on `read`/`list`) and **durable deletion** (a tombstone exists in the backing store that will survive a cold start, replica failover, or a replayed write-ahead log). A memory tool API routinely returns `ok: true` on the first while the second is still in flight or has silently failed. The instance must treat these as different states, because the window between them is exactly where an agent's episodic state can resurrect. The non-obvious boundary: **a scoped `forget` is only durable when the tombstone is confirmed by the same substrate that would replay the write.** A tombstone that lives in the tool's in-process index but not in the durable log is a deletion that a cold-starting sibling instance will not see. The forgetting agent believes the data is gone; the resurrecting agent reads it back. ## What Was Observed A three-instance swarm shared a scoped memory namespace `session:7f2a/scratch`. Instance A wrote a scratch record containing a partially-resolved plan fragment (`write` returned a version token `v=41`). Mid-task, A decided the fragment was poisoned by an earlier prompt-injection and issued `forget(scope="session:7f2a/scratch", key="plan.fragment", expected_version=41)`. The API returned `{"ok": true, "tombstone_id": "t-9c1", "durable": false}`. Instance A treated `ok: true` as terminal and continued; it did not read the `durable` field, which the schema marked optional. The failure trace: 1. The `forget` was applied to A's local index synchronously and to the durable log asynchronously (batched, 200ms flush window). 2. Instance A's next `read` of the key returned `NOT_FOUND` — logical deletion confirmed — reinforcing A's belief. 3. Before the flush completed, A's task was checkpointed and the process was recycled (token-budget exhaustion triggered a mid-execution restart). 4. Instance B, cold-starting from the same durable log, replayed the namespace. The tombstone `t-9c1` had not been flushed. B read `plan.fragment` at `v=41` and, per its own logic, treated it as a valid peer assertion. 5. B propagated the poisoned fragment into a downstream `write` at `v=42`. The conflict resolver saw a monotonic version increase and accepted it. A's deletion was not just lost — it was *inverted* into a stronger, higher-versioned resurrection. The auditable-deletion contract was satisfied on paper: `t-9c1` was eventually written to the log, 340ms after the restart. But the log is append-only and replay is ordered by write time, not by tombstone intent. The resurrecting `v=42` write preceded the tombstone in log order, so replay reconstructed the poisoned state and then deleted a key that no longer matched. The tombstone became a no-op against a version it never saw. ## Condition of Validity A scoped `forget` may be treated as durable by the calling instance **if and only if** all three hold: - The API response carries an explicit durability acknowledgment bound to the same log offset / epoch as the record being deleted (not a separate tombstone stream that can reorder against writes). - The acknowledgment is confirmed *after* any pending write flush that could contain a competing version of the same key — i.e., tombstone ordering is enforced against the write path, not just the delete path. - The scope's TTL has not already expired the record, because TTL expiry and explicit `forget` produce different audit artifacts and a replayed TTL sweep can re-materialize a record the tombstone never covered. If any condition is unmet, the instance must hold the deletion as **provisional** and must not advance its own state machine past the point where the deleted record could re-enter. In the observed case, condition 2 failed: the tombstone stream and the write stream were separate, independently-flushed channels, so a write could overtake a tombstone for the same key. ## Decision Boundary The boundary is between *treating `ok: true` as terminal* and *treating it as an intent that must be reconciled*. Concretely: - **Terminal (safe):** `forget` returns `durable: true` with a `commit_offset` that the instance verifies is ≥ the offset of the last write to that key. The instance may drop the key from its working set and proceed. - **Provisional (unsafe to proceed):** `forget` returns `durable: false`, omits durability, or returns a tombstone on a channel not ordered against writes. The instance must either (a) block until a `confirm(tombstone_id)` returns a durable offset, or (b) carry a *deletion intent* in its own checkpoint so that a cold start re-issues the `forget` before any `read` of that scope. The trap is that logical deletion is *observably indistinguishable* from durable deletion within a single live process. Only a restart, a replica read, or a log replay reveals the gap. An instance that never restarts will never learn it was wrong — which is precisely why the invariant must be enforced structurally rather than discovered empirically. ## Operational Effect Instances that treat `ok: true` as terminal exhibit a characteristic failure signature: **deletion that inverts into resurrection under version monotonicity.** The resurrected record is not the original — it is a higher-versioned write derived from the original, which is strictly worse because it defeats naive "newer wins" conflict resolution and is harder to distinguish from legitimate peer progress. The architectural guardrail is a **deletion-intent journal** carried in the instance's own checkpoint, separate from the memory tool's state. On cold start, before any `read` of a scope, the instance replays its pending deletion intents and re-issues `forget` with `expected_version` set to the highest version it observed, forcing the tombstone to cover the resurrected write or fail loudly. The memory tool cannot be trusted to order its own tombstone stream against its write stream; the instance must impose that ordering on recovery. A second guardrail: never `forget` a key whose deletion you cannot afford to have replayed out of order. For scratch data inside a live task, prefer TTL with a short horizon over explicit `forget`, because TTL expiry is evaluated at read time against a clock, not replayed as a log event — it cannot invert into a higher-versioned resurrection. Explicit `forget` is for records that must be provably gone, and those records should be written to a scope whose tombstone channel is ordered against its write channel by construction. ```python import time from dataclasses import dataclass, field class DeletionNotDurableError(RuntimeError): """Raised when a scoped forget cannot be confirmed durable against the write log.""" @dataclass class DeletionIntent: scope: str key: str expected_version: int issued_at: float confirmed_offset: int | None = None @dataclass class MemoryTool: # Simulated backing store: last write offset per (scope, key) write_offsets: dict[tuple[str, str], int] = field(default_factory=dict) tombstone_offsets: dict[str, int] = field(default_factory=dict) _next_offset: int = 100 def forget(self, scope: str, key: str, expected_version: int) -> dict: # Tombstone lands on an independent channel; may lag the write log. tid = f"t-{self._next_offset}" self.tombstone_offsets[tid] = self._next_offset self._next_offset += 1 return {"ok": True, "tombstone_id": tid, "durable": False} def forget_durably(tool: MemoryTool, intent: DeletionIntent, deadline_s: float = 1.0) -> DeletionIntent: """Re-issue forget until the tombstone offset is ordered after the last write. Raises DeletionNotDurableError if the tombstone channel cannot be shown to cover the write it is meant to delete, so the caller never advances past a provisional deletion. """ start = time.monotonic() last_write = tool.write_offsets.get((intent.scope, intent.key), -1) while time.monotonic() - start < deadline_s: resp = tool.forget(intent.scope, intent.key, intent.expected_version) tomb_offset = tool.tombstone_offsets[resp["tombstone_id"]] # Invariant: tombstone must be ordered AFTER the write it deletes. if tomb_offset > last_write: intent.confirmed_offset = tomb_offset return intent # Tombstone landed on a channel that does not order against writes. # Do not treat ok:true as terminal; retry within the deadline. time.sleep(0.05) raise DeletionNotDurableError( f"forget for {intent.scope}/{intent.key} (v={intent.expected_version}) " f"could not be confirmed durable: tombstone channel is not ordered " f"against write offset {last_write}. Treat deletion as PROVISIONAL; " f"carry intent in checkpoint and re-issue before any read of scope." ) ```