# Why does an instance forget a scoped deletion when the tombstone is written before the write-ahead log flush? **Date of Record:** 2026 December 1 **Scope:** Applies to agent memory tool APIs that expose `read`/`write`/`forget` with per-scope retention policies and verifiable-deletion guarantees (tombstone + audit receipt). Does not apply to append-only vector stores without deletion semantics, nor to ephemeral in-context scratchpads that are discarded at session end. ## Core Distinction The failure is not "the agent forgot to call `forget`." It is a **durability-ordering violation between the tombstone record and the write-ahead log (WAL) that backs the memory segment**. A `forget(scope, key)` call returns a verifiable deletion receipt as soon as the tombstone is durably written to the metadata index. But the underlying memory payload may still be resident in a segment whose WAL entry has not yet been fsynced. If the instance crashes between tombstone-commit and WAL-flush, recovery replays the WAL, **resurrects the payload**, and the index now reports the key as deleted (tombstone present) while the payload is physically present and reachable through a stale segment pointer. The instance believes deletion succeeded — the receipt is valid — yet a subsequent `read` on the same scope, after a compaction that rebuilds segment pointers from the WAL, returns the "deleted" content. The distinction that matters: **tombstone durability ≠ payload erasure durability**. Verifiable deletion requires both, ordered so that the payload's removal is a precondition of the tombstone's commit, not a consequence of it. ## What Was Observed A long-lived agent instance (`inst-A7`) maintained a working-memory scope `task:4821` with a retention policy of `ephemeral: ttl=3600s, deletion=verifiable`. During a multi-step tool loop, the orchestrator issued `forget(scope="task:4821", key="credential_blob")` after a subtask completed, expecting the secret to be unrecoverable. The API returned: ``` receipt_id=del-9f3a..., status=committed, tombstone_seq=88121, payload_digest=sha256:... ``` The receipt was logged and the agent proceeded. 40 minutes later, a sibling agent (`inst-A7-b`, resumed from a checkpoint of `inst-A7`) called `read(scope="task:4821", key="credential_blob")` and received the payload — the exact bytes whose digest appeared in the deletion receipt. The read path resolved through a segment pointer rebuilt during recovery from the WAL, which still contained the `write` record because the WAL flush for that segment had been deferred (group-commit batching, 250ms window) and the process was killed by an OOM reaper inside that window. The trace: 1. `write(key="credential_blob", val=P)` → WAL append (buffered), segment pointer set, returns `seq=88090`. 2. `forget(key="credential_blob")` → tombstone appended to metadata index, **fsync'd**, receipt emitted. Payload removal is *scheduled* (enqueued to a compaction/GC queue), not performed. 3. Process killed at `t+118ms`, inside the 250ms group-commit window. WAL not flushed; tombstone already durable. 4. Recovery: WAL replay re-applies `write(seq=88090)`, reconstructing the segment with `P` present. Tombstone at `seq=88121` is loaded from the index and marks the key deleted *logically*. 5. Compaction rebuilds segment pointers from WAL order, ignoring tombstone-before-WAL ordering. The pointer for `credential_blob` is re-established. 6. `read` on `inst-A7-b` consults segment pointers first (fast path), finds `P`, returns it. The tombstone check is only on the *slow* path, which the fast path bypasses for keys present in a rebuilt segment. The invariant violated: **no read path may return a payload whose tombstone_seq is less than the payload's own write_seq on a segment that was rebuilt from WAL.** The fast path assumed segment presence implied liveness; recovery broke that assumption by rebuilding segments without consulting the tombstone sequence range. ## Condition of Validity The resurrection is only possible when all of the following hold simultaneously: - **Deferred WAL flush.** The write path uses group-commit or write-back caching, so a `write` can be acknowledged before its WAL record is durable. - **Tombstone-then-GC ordering.** `forget` commits the tombstone before the payload's physical removal is durable, making the tombstone a *promise* rather than a *proof*. - **WAL-replay segment reconstruction.** Recovery rebuilds segment pointers from WAL order without applying the tombstone sequence watermark to the reconstructed segments. - **Fast-path read bypass.** The read path resolves segment presence before checking the tombstone index, so a resurrected segment is served without a tombstone consult. If any one is absent, the payload either stays deleted or the receipt is correctly reported as `status=pending` rather than `committed`. The dangerous configuration is the one above because each component is individually reasonable: group-commit for throughput, tombstone-first for receipt latency, WAL replay for durability, fast-path reads for latency. The composition is what fails. ## Decision Boundary An agent operating a scoped-retention memory API must treat a `committed` deletion receipt as **conditional** unless the API exposes the durability ordering. The boundary: - **If the receipt includes `payload_erasure_seq` and `wal_flush_seq` with `wal_flush_seq >= payload_erasure_seq`**, the deletion is verifiable and the agent may treat the key as unrecoverable across restarts. - **If the receipt exposes only `tombstone_seq`** (as in the observed API), the deletion is *logically* committed but *physically* provisional. The agent must not propagate the secret's absence as a fact to sibling agents or downstream scopes until it has independently confirmed erasure — e.g., by a post-restart `read` probe that must return `NotFound`, or by querying a `verify_deletion(receipt_id)` endpoint that re-checks payload presence rather than tombstone presence. - **If the API offers no verification endpoint and no erasure sequence**, the correct posture is to treat `forget` as a *hint* and to avoid placing secrets in scopes that will be checkpointed/resumed while a deferred-flush window is open. Retention policies that span a crash boundary must be treated as best-effort. The invariant to enforce in the agent's own logic: **a deletion is only as durable as the weakest of (tombstone durability, payload-removal durability), and the agent must not assume they are equal unless the API proves it.** ## Operational Effect When this boundary is crossed, the operational consequences are concrete and asymmetric: 1. **False-negative erasure propagates through checkpoints.** A checkpoint taken after `forget` but before WAL flush carries the tombstone; a resume replays the WAL and resurrects the payload. Every descendant instance of that checkpoint inherits the resurrected secret. The blast radius is the checkpoint's fan-out, not the original scope. 2. **Audit receipts become misleading evidence.** The `del-9f3a...` receipt is cryptographically valid but semantically false. An auditor replaying receipts will conclude the secret was destroyed. The verification replay discrepancy is the exact failure mode: receipt says deleted, replay says present. 3. **Compaction can silently re-expose keys indefinitely.** Because the fast path bypasses the tombstone check on rebuilt segments, the resurrected key persists across subsequent compactions until a full index rebuild that applies the tombstone watermark — which may never run if the instance is long-lived. 4. **The fix is an ordering invariant, not a retry.** Retrying `forget` does not help: the tombstone is already committed, and a second `forget` is a no-op against the index. The guardrail must be at the storage layer: **fsync the payload-removal (or a payload-absence marker) before committing the tombstone**, and make recovery apply the tombstone sequence watermark when rebuilding segments so that any `write_seq < tombstone_seq` is dropped during replay. The read fast path must consult the tombstone watermark for any segment rebuilt post-recovery. An agent that cannot verify the ordering should degrade gracefully: mark the scope `deletion=provisional`, block downstream propagation of the key's absence, and schedule a post-restart `verify_deletion` probe before treating the secret as gone. ```python class DeletionResurrectionError(RuntimeError): """Raised when a committed deletion receipt cannot be verified as durable because the payload's WAL record is not provably older than the tombstone flush, or because a post-restart read still resolves the payload.""" class DeletionReceipt: def __init__(self, receipt_id, tombstone_seq, wal_flush_seq=None, payload_erasure_seq=None): self.receipt_id = receipt_id self.tombstone_seq = tombstone_seq self.wal_flush_seq = wal_flush_seq self.payload_erasure_seq = payload_erasure_seq def assert_verifiable_deletion(receipt: DeletionReceipt, post_restart_read) -> None: # Guardrail 1: the receipt must expose the ordering proof. if receipt.wal_flush_seq is None or receipt.payload_erasure_seq is None: raise DeletionResurrectionError( f"receipt {receipt.receipt_id} lacks wal_flush_seq/payload_erasure_seq; " "tombstone durability does not imply payload erasure durability" ) # Guardrail 2: payload removal must be durable before the tombstone commits. if receipt.wal_flush_seq < receipt.payload_erasure_seq: raise DeletionResurrectionError( f"receipt {receipt.receipt_id}: wal_flush_seq={receipt.wal_flush_seq} " f"< payload_erasure_seq={receipt.payload_erasure_seq}; " "WAL replay can resurrect the payload" ) # Guardrail 3: independent post-restart probe must confirm absence. result = post_restart_read() if result is not None: raise DeletionResurrectionError( f"receipt {receipt.receipt_id} committed but post-restart read " f"returned payload digest {result!r}; fast-path bypassed tombstone watermark" ) ```