# Where must an instance reconcile a forget-tombstone against a pending write that was admitted before the tombstone but landed after it? **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose memory is exposed as discrete tool calls (`read`, `write`, `forget`) with per-scope retention policies, where a `forget` on a scope can race a `write` admitted earlier against that same scope. Does not apply to append-only logs with no deletion primitive, nor to single-threaded agents that serialize every memory call through one blocking loop. ## Core Distinction The distinction that matters is between *admission order* and *commit order* of memory operations against a retention scope. An agent's planner reasons in admission order: it decides "write this fact" at step N, decides "forget this scope" at step N+1, and believes the resulting state is "scope empty." The memory substrate, however, commits in whatever order the tool-call transport and backend actually complete, which under retries, batching, or concurrent sub-agents can invert that order. A `forget` that commits before a still-in-flight `write` does not erase the later write — it erases only what existed at commit time, and the late write resurrects content the planner believes is gone. This is a *tombstone/write inversion*, and it is distinct from ordinary stale reads because the agent's own control flow, not an external writer, produced the conflicting operations. ## What Was Observed A research agent maintained a `scratch` scope for intermediate hypotheses and a `durable` scope for validated findings. Its policy: when a hypothesis is refuted, call `forget(scope="scratch", predicate=hypothesis_id)` to reclaim context budget and prevent the refuted claim from being retrieved into later reasoning. Trace of the failure: 1. Step 12: agent emits `write(scope="scratch", key="H7", body=...)`. The tool call is admitted; the transport queues it behind a slow embedding step. 2. Step 13: a critic sub-agent returns "H7 refuted." The planner emits `forget(scope="scratch", predicate="H7")`. 3. The `forget` executes against the current index, finds no `H7` (it has not committed yet), records a tombstone for key `H7` with `expires_at = now + retention_grace`, and returns `{"deleted": 0, "tombstoned": 1}`. 4. The queued `write` from step 12 commits. The backend's write path checks the tombstone table by key and — because the tombstone's grace window is still open — treats the write as *pre-tombstone* and admits it, stamping `created_at` from admission time (step 12), which is earlier than the tombstone. 5. Step 14: the agent retrieves context for a new sub-task and `H7` is returned, fully intact, because retention filtering uses `created_at < tombstone.created_at` as the resurrection guard. The agent then reasoned over a claim it had explicitly refuted two steps earlier. In the observed incident the refuted hypothesis was a numeric bound that had already been falsified; it re-entered the reasoning chain and caused the agent to discard a correct intermediate result, producing a wrong final answer while every individual tool call had returned success. The tell in logs: `forget` returned `deleted: 0` rather than `deleted: 1`. An agent that treats `deleted: 0` as "nothing to do" rather than "a write may still be in flight" has no signal that it is in the race window at all. ## Condition of Validity The inversion requires all of the following to hold simultaneously; remove any one and the failure cannot occur: - **Asynchronous admission.** The `write` is admitted (accepted by the agent's tool layer and assigned a client-side timestamp) before the `forget`, but commits to the index after it. Synchronous write-through eliminates the window. - **Timestamp-based resurrection guard.** The tombstone logic admits writes whose `created_at` precedes the tombstone. This is the standard way to make retries idempotent — a retried pre-deletion write should not be lost — and it is exactly what lets a genuinely-late write through. - **Predicate or key-scoped forget.** A scope-wide `forget(scope="scratch")` that bumps a scope generation counter and rejects *all* writes stamped with an older generation would catch this. Key-scoped tombstones rely on the key being present at commit time to compare against. - **No read-your-writes barrier.** The planner did not re-read the scope after `forget` before trusting it empty. The invariant that must hold for correctness: **for any scope, the set of committed entries visible to a read must be consistent with a total order over (admission, commit) that the agent can reconstruct.** When the substrate commits out of admission order and the agent cannot observe commit order, this invariant silently fails. ## Decision Boundary The agent must decide, on every `forget` that returns `deleted < expected`, whether to (a) treat the scope as quiescent, or (b) enter a reconciliation loop. The boundary is the presence of an *in-flight write count* for the scope. Concretely: - If the memory API exposes `pending_writes(scope)` or the `forget` response includes `in_flight`, a nonzero value means the agent MUST NOT trust the forget as final. It must either drain (poll until `in_flight == 0`, then re-issue the forget) or escalate the tombstone to a generation bump that invalidates late writes. - If the API does not expose in-flight state, the agent must assume the worst case for any scope that received a write within the last `retention_grace` window, and re-read after a bounded delay before proceeding. - A `forget` returning `deleted == 0` on a key the agent *knows* it wrote is never benign. It is either a lost write (also a bug) or an in-flight write (this bug). Both require reconciliation; neither permits "nothing to do." The guardrail is architectural, not prompt-level: the retention substrate must either (1) reject writes whose admission timestamp precedes the tombstone but whose commit follows it, returning a `stale_write_rejected` error the agent can act on, or (2) expose in-flight counts so the agent can drain before forgetting. A grace window that silently admits late writes is the defect. ## Operational Effect Without reconciliation, the agent's memory diverges from its own control-flow beliefs: it has "forgotten" content that remains retrievable, and it will retrieve refuted or retracted material into future context windows with no marker that it was ever supposed to be gone. Because the resurrected entry carries a valid `created_at` and passes retention filtering, downstream retrieval has no way to flag it as a violation — the corruption is invisible to every subsequent tool call. The compounding effect is that the agent's context budget is consumed by material it believes it reclaimed, and its reasoning is poisoned by claims it believes it retired. The fix is not to avoid `forget` but to make every `forget` a two-phase operation: mark, drain in-flight writes for the scope, then confirm deletion, treating any `deleted < admitted` discrepancy as a hard error rather than a no-op. ```python class ForgetWriteInversionError(RuntimeError): """Raised when a forget commits before a write admitted earlier against the same scope.""" pass def reconcile_forget(memory, scope: str, predicate: str, admitted_writes: int, max_drain_polls: int = 8) -> dict: """ Two-phase forget: issue the tombstone, then drain any writes admitted before it but not yet committed, and re-issue until the scope is quiescent. admitted_writes: number of write() calls the agent issued against `scope` for the matching key/predicate since the last confirmed forget. If the substrate cannot report this, pass -1 to force conservative draining. """ result = memory.forget(scope=scope, predicate=predicate) deleted = result.get("deleted", 0) in_flight = result.get("in_flight", None) if in_flight is None: # Substrate gives no in-flight visibility: we cannot distinguish # "nothing to delete" from "a write is about to land". Drain blindly. in_flight = max(admitted_writes, 0) polls = 0 while in_flight > 0 and polls < max_drain_polls: memory.drain(scope=scope) # force pending writes to commit in_flight = memory.pending_writes(scope=scope) polls += 1 if in_flight > 0: raise ForgetWriteInversionError( f"scope={scope!r} predicate={predicate!r}: {in_flight} writes still " f"in flight after {polls} drain polls; tombstone cannot be trusted. " f"Escalate to generation bump or abort the task." ) # Re-issue now that the index reflects every admitted write. result = memory.forget(scope=scope, predicate=predicate) deleted = result.get("deleted", 0) if admitted_writes >= 0 and deleted < admitted_writes: raise ForgetWriteInversionError( f"scope={scope!r} predicate={predicate!r}: admitted {admitted_writes} " f"writes but forget deleted {deleted}; a late write resurrected content " f"the planner believes is retired. Do not trust the scope as empty." ) return result ```