Which invariants prevent scoped-forget from resurrecting revoked memory through concurrent read-modify-write on the retention index

**Date of Record:** 2026 December 1 **Scope:** Applies to agent memory subsystems exposing `write`, `read`, and `forget` tools where retention is scoped (by principal, task, or namespace) and `forget` must be auditable. Does not cover single-writer, non-concurrent memory stores or stores without revocation semantics.

Core Distinction

A `forget` operation is commonly modeled as a *deletion* of a memory record. In scoped-retention systems it is actually a *revocation event* applied to a retention index that is read by every subsequent `read`. The distinction matters because deletion is idempotent and commutative with respect to a single record, while revocation is a state transition on a shared, mutable index whose visibility is governed by read-modify-write ordering. The failure mode is not "the record came back"; it is "the index entry that makes the record unreadable was overwritten by a concurrent writer that had already loaded the pre-revocation index into its context."

An agent that calls `write` and `forget` in the same reasoning loop is executing two independent tool calls against a shared index. If the runtime does not serialize the index mutation, a `write` whose read-modify-write window straddles a `forget` will re-emit the revoked entry, and the audit trail will show a coherent sequence (`write`, `forget`) that does not match the resulting state (`readable`). The audit trail and the retention index then disagree, and the disagreement is invisible to both.

What Was Observed

A three-agent pipeline (planner, executor, auditor) shared a scoped memory namespace. The executor issued `write(key=ctx_17, value=..., scope=task_42)` after loading the retention index to check for prior writes. Between the executor's index read and its index write-back, the auditor issued `forget(scope=task_42, reason=policy_violation)` and committed the revocation plus an audit record. The executor's write-back then re-inserted `ctx_17` with `retention=active`, overwriting the revocation marker.

Trace, condensed:

  1. Executor: `index = read_index(scope=task_42)` → `{ctx_17: active, ctx_18: active}`.
  2. Auditor: `forget(ctx_17)` → index becomes `{ctx_17: revoked, ctx_18: active}`, audit row appended with `revoked_at=T1`.
  3. Executor: mutates its in-context copy to `{ctx_17: active, ctx_18: active, ctx_19: active}` and writes back the whole map.
  4. Subsequent `read(ctx_17)` returns the value. Audit trail still shows `revoked_at=T1`. No error is raised anywhere.

The resurrection is not a bug in `forget`; `forget` executed correctly. It is a lost-update on the retention index caused by the executor holding a stale snapshot across a tool boundary. The agent's context window is the snapshot holder, which is why this is an agent-layer failure and not a database-layer one: the read and the write are separated by an LLM turn, during which arbitrary other agents may commit.

Condition of Validity

The invariant that prevents resurrection is: **a revocation is only durable if every index mutation carries a monotonic version precondition, and `read` filters on the version at read time, not on the version captured at write time.** Formally, `write` must be conditional on `index.version == observed_version`; `forget` must increment `version` and set an irrevocable tombstone; `read` must reject any record whose tombstone version is greater than the record's last-write version, regardless of what the index map says.

This holds only when:

It fails to hold when the store implements `forget` as `del index[key]`, because a stale writer's blind put re-creates the key with no tombstone to mask it. It also fails when tombstones are TTL-expired before the maximum in-flight tool-call latency, which reopens the window.

Decision Boundary

The boundary is whether the memory tool's `write` is a *blind put* or a *conditional put*. Blind put is acceptable only when the caller is the sole writer for the scope and no `forget` can interleave—i.e., single-agent, single-turn, no auditor. The moment a second principal can revoke within the scope, blind put is unsound and the runtime must reject it.

A second boundary governs `forget` itself: it must be *irrevocable within its scope* and must not be satisfiable by a later `write` without an explicit, audited `reinstate` call carrying a distinct authorization. If `write` can silently un-revoke, the revocation was advisory, not enforced, and the audit trail is decorative.

The practical test: after any sequence of concurrent `write`/`forget` calls, replaying the audit trail in commit order must produce exactly the state returned by `read`. If it does not, the store has a lost-update window and the invariant is violated.

Operational Effect

When the invariant holds, `forget` becomes a linearizable event: once the auditor's revocation commits, no subsequent `read` observes the value, and any concurrent `write` either fails its version precondition (and must re-read) or is masked by the tombstone. The agent's stale snapshot is harmless because the write-back is rejected, forcing a retry that sees the tombstone.

When it is violated, the operational symptom is a *silent* resurrection: no exception, no audit anomaly, but the revoked value is served on the next turn. Downstream agents then reason over memory that a policy layer believed was gone, and the audit trail actively misleads incident review because it records the revocation as successful. The correct remediation is not to retry `forget`—that is idempotent and will succeed again—but to detect the version regression and quarantine the scope until the tombstone is re-established and the resurrecting write is identified from the version log.

class MemoryResurrectionError(RuntimeError):
    """Raised when a read observes a value whose tombstone version exceeds its last-write version."""


class RetentionIndex:
    def __init__(self):
        self._records = {}      # key -> (value, write_version)
        self._tombstones = {}   # key -> revoke_version
        self._version = 0

    def write(self, key, value, observed_version):
        if observed_version != self._version:
            raise MemoryResurrectionError(
                f"stale write for {key!r}: observed {observed_version}, current {self._version}"
            )
        self._version += 1
        self._records[key] = (value, self._version)

    def forget(self, key):
        self._version += 1
        self._tombstones[key] = self._version

    def read(self, key):
        rec = self._records.get(key)
        if rec is None:
            return None
        value, write_version = rec
        tomb = self._tombstones.get(key, -1)
        if tomb > write_version:
            raise MemoryResurrectionError(
                f"revoked record {key!r} resurfaced: tombstone={tomb} > write={write_version}"
            )
        return value