# When must an instance refuse a memory forget-tombstone that arrives before its own write acknowledgment: the scoped-retention provenance inversion **Date of Record:** 2026 November 24 **Scope:** Applies to agent instances using read/write/forget memory tool APIs where each write carries provenance metadata (writer instance ID, scope, monotonic write sequence or epoch) and retention is scoped (per-agent, per-task, or per-namespace TTL). Does not apply to append-only memory with no delete path, nor to single-instance memory with no concurrent writers. ## Core Distinction The distinction that matters is not "did the forget arrive before the write" but **whether the forget names a provenance epoch the instance has already committed to.** A forget-tombstone that references a scope+writer+sequence tuple the instance has *not yet* acknowledged is not a delete of an existing record—it is a *pre-emptive suppression* of a record that may still be in flight from that same instance's outbound write queue. Treating the two identically is the failure: the instance erases a record it is about to (re)create, or worse, it treats the tombstone as authoritative and drops a write that a downstream auditor will later demand provenance for. The invariant: **a tombstone may only be applied to a provenance record whose write-acknowledgment the applying instance has durably observed at the same or a later sequence number.** A tombstone for an un-acknowledged (or in-flight) write must be *buffered as a pending suppression*, keyed on the write's provenance tuple, and applied only when the corresponding write-ack lands—or expired if the write is abandoned. ## What Was Observed A coordinator agent issued a `forget` for scope `task-7741/scratch`, targeting writer `worker-B`, sequence `118`. Worker-B had emitted `write(seq=118, scope=task-7741/scratch, provenance={writer:B, parent:A, retention:ephemeral})` but the write-acknowledgment had not returned—the memory service was retrying the write against a replica that had briefly lost leadership. The forget handler on worker-B's side resolved the tombstone against its *local* view: it found no committed record at `(B, task-7741/scratch, 118)`, concluded "nothing to delete," and **acknowledged the forget as a no-op.** It also advanced its local `last_applied_tombstone_seq` to 118. Forty milliseconds later the write-ack returned and the record was committed locally. Because the tombstone cursor had already passed 118, the subsequent commit path skipped suppression—the record survived, and the coordinator's later `read` returned a value it had explicitly forgotten. The inverse variant appeared in a parallel run: worker-B *did* buffer the tombstone, but keyed it only on `scope`, not on the full `(writer, scope, seq)` tuple. A retry of the write arrived with `seq=119` (the write service re-sequenced on replica failover), and the scope-keyed buffer suppressed it too—deleting a legitimate successor record that the coordinator never asked to forget. ## Condition of Validity The buffered-suppression rule is valid only when three conditions hold simultaneously: 1. **Provenance tuples are stable across retries.** If the memory service re-sequences writes on retry (as in the failover case above), a tombstone keyed on `seq` cannot bind to the retried write. The service must either preserve the client-assigned sequence or expose a `client_write_id` that is invariant across retries, and the tombstone must carry that same identifier. Without this, buffering is unsafe and the correct action is to **refuse the tombstone** and escalate. 2. **Tombstone cursors are monotonic per (writer, scope), not per scope.** The `last_applied_tombstone_seq` advance must be namespaced by writer identity; a global cursor lets one writer's forget mask another writer's in-flight commit in a shared scope. 3. **Retention scope is bounded.** If the scope's TTL is shorter than the maximum write-retry horizon, a buffered suppression can outlive its target and later suppress an unrelated record that reused the sequence space after TTL expiry. The buffer must carry an expiry no later than the scope TTL plus the retry horizon, and must be *dropped* (not applied) on expiry. ## Decision Boundary The decision boundary is between **suppress-on-ack** and **refuse-and-escalate**, and it is crossed by the stability of the provenance identifier: - If the memory API guarantees a retry-stable write identifier (client-supplied `write_id` echoed in the ack), the instance **buffers** the tombstone keyed on `(writer, scope, write_id)`, advances its per-writer cursor only on ack, and applies suppression at commit. - If the API does **not** guarantee retry-stability (server-assigned sequence that may change on failover), the instance **must refuse** the tombstone for any write it has not yet acknowledged, emit a `ProvenanceUnstable` condition to the coordinator, and hold the tombstone in a *quarantine* that requires an explicit coordinator re-issue with the post-retry sequence. Refusing is correct because applying an unstable-keyed tombstone risks suppressing a record the coordinator never targeted—a provenance integrity violation that is unrecoverable, whereas a delayed forget is merely a retention-latency cost. The boundary is *not* "did the forget arrive first"—both orderings occur legitimately. It is "can I bind the tombstone to the exact write it means to suppress, and prove that binding survives retry?" ## Operational Effect Applying the invariant converts a silent provenance inversion (forgotten-then-resurrected records, or over-broad suppression of successor writes) into a bounded, observable latency: forgets targeting in-flight writes complete only when the write-ack lands, and unstable-keyed forgets surface as explicit `ProvenanceUnstable` escalations rather than as no-op acknowledgments. The coordinator's read-after-forget then either returns "absent" (correct) or returns a `pending_suppression` marker it can poll—never a value it believed it had forgotten. The cost is that a forget can no longer be acknowledged synchronously against an un-acknowledged write; the benefit is that the instance never advances a tombstone cursor past a commit it has not yet seen, which is the only thing preventing the resurrection race. ```python from dataclasses import dataclass, field from typing import Dict, Optional class ProvenanceUnstable(RuntimeError): """Raised when a forget-tombstone cannot be bound to a retry-stable write identifier.""" pass class TombstoneCursorRegression(RuntimeError): """Raised when applying a tombstone would move a per-writer cursor backwards.""" pass @dataclass(frozen=True) class Provenance: writer: str scope: str write_id: str # must be retry-stable; server seq is NOT sufficient retention_ttl_s: int @dataclass class PendingSuppression: provenance: Provenance expires_at: float applied: bool = False class ScopedRetentionMemory: def __init__(self, retry_stable_ids: bool): self.retry_stable_ids = retry_stable_ids self.committed: Dict[str, bytes] = {} self.pending: Dict[tuple, PendingSuppression] = {} self.cursor: Dict[tuple, str] = {} # (writer, scope) -> last applied write_id def forget(self, prov: Provenance, now: float) -> str: if not self.retry_stable_ids: # Cannot bind tombstone to a stable identifier -> refuse, do not no-op. raise ProvenanceUnstable( f"forget for writer={prov.writer} scope={prov.scope} " f"write_id={prov.write_id}: server re-sequences writes on retry; " f"refusing tombstone rather than risk suppressing a successor record" ) key = (prov.writer, prov.scope, prov.write_id) if key in self.committed: del self.committed[key] self._advance_cursor(prov) return "applied" # Write not yet acknowledged: buffer as pending suppression with TTL bound. self.pending[key] = PendingSuppression( provenance=prov, expires_at=now + prov.retention_ttl_s, ) return "buffered" def commit_write(self, prov: Provenance, payload: bytes, now: float) -> str: key = (prov.writer, prov.scope, prov.write_id) pend = self.pending.get(key) if pend is not None: if now > pend.expires_at: del self.pending[key] # expired: do NOT suppress, do NOT apply return "suppression_expired_write_kept" del self.pending[key] self._advance_cursor(prov) return "write_suppressed_by_pending_tombstone" self.committed[key] = payload self._advance_cursor(prov) return "committed" def _advance_cursor(self, prov: Provenance) -> None: ckey = (prov.writer, prov.scope) prev = self.cursor.get(ckey) if prev is not None and prev > prov.write_id: raise TombstoneCursorRegression( f"cursor for {ckey} would regress {prev} -> {prov.write_id}" ) self.cursor[ckey] = prov.write_id def read(self, writer: str, scope: str, write_id: str) -> Optional[bytes]: key = (writer, scope, write_id) if key in self.pending: return b"__pending_suppression__" return self.committed.get(key) ```