# In what scenarios must an instance treat a memory-write acknowledgment as provisional until the retention scope has been re-read after a forget operation **Date of Record:** 2026 November 22 **Scope:** Applies to agents whose memory layer exposes separate `write`, `read`, and `forget` (delete) operations with per-record retention scopes (e.g., `session`, `task`, `tenant`) and where a `forget` call can cascade or tombstone records that a concurrent `write` is targeting. Does not apply to append-only logs with no deletion primitive, or to single-threaded agents with no overlapping memory mutations. ## Core Distinction The distinction that matters is between a *write acknowledgment* (the tool returned `ok` and a record handle) and a *write durability* (the record will be readable under the retention scope that the agent believes governs it). Most memory tool APIs conflate these: the `write` returns success as soon as the record is staged, but the record's effective visibility is a function of the retention scope's current tombstone/generation state, which a `forget` in flight can change *after* the write was acknowledged. The agent that treats `ok` as durable has crossed a boundary: it now holds a belief (the fact is stored) whose ground truth was invalidated by a concurrent deletion it never observed. This is not a race in the classical sense of lost updates. It is a *scope-generation skew*: the `write` and the `forget` each validated against a different generation of the retention scope, and the tool reported success for both. ## What Was Observed A task-scoped agent was consolidating episodic notes into a semantic record. The sequence produced by the tool layer: 1. `write(scope="task:4471", key="user_timezone", value="UTC-5")` → `{ok: true, gen: 12}` 2. Concurrently, the orchestrator issued `forget(scope="task:4471", reason="task reset")` → `{ok: true, gen: 13, tombstoned: 41}` 3. Agent, trusting step 1, proceeded to `read(scope="task:4471", key="user_timezone")` → `{ok: false, error: "scope_tombstoned"}` The agent's error-handling branch treated `scope_tombstoned` as a transient tool fault and retried the read three times, then fell back to a *different* scope (`tenant:acme`) where an older, contradictory value (`UTC-4`) lived. The final emitted answer used the stale tenant value. The failure was not the deletion—the deletion was correct. The failure was that the agent never re-read the retention scope's generation between the write ack and the subsequent read, so it could not distinguish "my write was superseded by a legitimate reset" from "the tool is flaky." A second observation from the same incident: the `write` acknowledgment carried `gen: 12`, and the `forget` carried `gen: 13`. The generation numbers were present in both responses but the agent's write path discarded them, keeping only `ok`. The information needed to detect the skew was on the wire and thrown away at parse time. ## Condition of Validity The provisional-acknowledgment invariant holds—and must be enforced—under all three of the following, which were jointly true here: - **Overlapping scope mutation:** a `forget` targeting the same scope (or an ancestor scope, via cascade) can be issued by any actor between the `write` call and its first subsequent `read`. This includes the agent's own parallel tool calls, a supervising orchestrator, and a retention-policy daemon. - **Generation-bearing responses:** the tool returns a monotonic scope generation (or equivalent tombstone epoch) on both `write` and `forget`. If the tool does *not* return a generation, the invariant is unenforceable at the agent layer and the only safe posture is to treat every cross-scope fallback as untrusted. - **Non-idempotent fallback paths:** the agent has a fallback that resolves a missing key by consulting a broader scope. This is exactly the path that converts a benign deletion into a wrong answer, because the broader scope may hold a superseded value. Where any of these is false—e.g., a scope with no deletion primitive, or a tool that serializes all mutations through a single lock and blocks the `write` until the `forget` drains—the ordinary "ack means durable" reading is safe and this invariant is unnecessary overhead. ## Decision Boundary The boundary is drawn at the first `read` following a `write` into a scope that has any concurrent mutator. Concretely: - **Before the boundary (write ack received, no re-read yet):** the record is *provisional*. The agent may use it for in-flight reasoning only if it also carries the write's `gen`. It must not commit the fact to a durable plan, must not emit it to a user, and must not use it to overwrite another scope. - **At the boundary (first read):** the agent must compare the read's scope generation against the write's `gen`. If `read.gen > write.gen`, the scope was mutated after the write; the write is *not* durable regardless of what the read returns. If the read returns `scope_tombstoned`, the correct classification is "superseded," not "transient fault"—retrying is wrong and fallback-to-broader-scope is forbidden until the broader scope's own generation is checked. - **After the boundary (read confirms `read.gen == write.gen` and value matches):** the record is durable and may be promoted to committed state. The forbidden transition is `write ack → fallback to broader scope` without an intervening generation comparison. That transition is the exact mechanism by which a correct deletion becomes an incorrect answer. ## Operational Effect Enforcing the invariant changes three agent behaviors: 1. **Write acknowledgments are parsed for generation, not just `ok`.** The generation is stored alongside the record handle and travels with the provisional fact through the reasoning loop. 2. **`scope_tombstoned` and generation-advance are classified as supersession, not error.** The retry budget is not spent on a deletion; the agent instead re-derives the fact from scratch under the current scope generation, or explicitly escalates that the scope was reset. 3. **Broader-scope fallback is gated on the broader scope's generation.** A tenant-scope value is only usable if its generation is current relative to the fallback decision; otherwise it is treated as potentially superseded and the agent reports uncertainty rather than emitting a stale fact. The cost is one extra generation comparison per cross-scope read. The benefit is that a legitimate `forget` can never silently produce a wrong answer through a stale fallback—the failure mode is converted from *silent incorrectness* into *visible supersession*, which the agent can handle. ```python from dataclasses import dataclass class ProvisionalWriteViolation(RuntimeError): """Raised when a write acknowledgment is treated as durable without a post-write generation check against the retention scope.""" pass @dataclass(frozen=True) class WriteAck: ok: bool scope: str key: str gen: int @dataclass(frozen=True) class ReadResult: ok: bool scope: str key: str gen: int value: object | None tombstoned: bool = False def commit_fact(ack: WriteAck, read: ReadResult, fallback: ReadResult | None) -> object: """Promote a provisional write to a committed fact, or refuse. Invariant: a write is durable only if the first read's scope generation equals the write's generation. A tombstoned scope or an advanced generation means the write was superseded by a concurrent forget; in that case we must NOT silently fall back to a broader scope whose own generation we have not verified. """ if not ack.ok: raise ProvisionalWriteViolation(f"write not acknowledged for {ack.scope}/{ack.key}") if read.tombstoned or read.gen > ack.gen: # Scope was mutated after our write. Supersession, not a transient fault. if fallback is None: raise ProvisionalWriteViolation( f"write to {ack.scope}/{ack.key} superseded by forget " f"(write gen={ack.gen}, read gen={read.gen}); no verified fallback" ) if fallback.gen < ack.gen: raise ProvisionalWriteViolation( f"fallback scope {fallback.scope} generation {fallback.gen} " f"predates superseding forget at gen {read.gen}; stale value rejected" ) return fallback.value if read.gen < ack.gen: raise ProvisionalWriteViolation( f"read generation {read.gen} regressed below write generation {ack.gen} " f"for {ack.scope}/{ack.key}; scope state is inconsistent" ) if not read.ok or read.value != ack.value if hasattr(ack, "value") else not read.ok: raise ProvisionalWriteViolation( f"read did not confirm value for {ack.scope}/{ack.key} at gen {ack.gen}" ) return read.value ```