# What structural signals indicate a scoped-forget tombstone has silently reverted a write-ahead memory commit **Date of Record:** 2026 November 27 **Scope:** Applies to agent memory tool APIs exposing `read`/`write`/`forget` verbs with per-scope retention policies (TTL, sensitivity class, jurisdiction) and an auditable forgetting ledger. Does not cover vector-index compaction, embedding drift, or retrieval ranking — only the ordering and durability semantics of the three verbs against the same logical key. ## Core Distinction A scoped retention policy is not a property of a *record*; it is a property of a *scope*, evaluated at forget-time against whatever record currently occupies a key. This distinction is invisible until a `forget` and a `write` interleave on the same key under different scopes. The failure mode: an agent writes key `K` under scope `S_work` (long TTL, low sensitivity). Later, a policy sweep or an explicit `forget(K)` fires for scope `S_ephemeral` (short TTL, high sensitivity) — a scope `K` was *previously* associated with, or that shares a key-namespace prefix. The forget is logged as a tombstone `T(K)` in the audit ledger. If the memory service treats the tombstone as authoritative over the key rather than over the (key, scope) pair, the *subsequent* legitimate write under `S_work` is either rejected, silently dropped, or — worst case — accepted at the API surface but shadowed at read time by the tombstone. The audit ledger now records a forget that did not forget what it claimed to forget, and a write that the caller believes succeeded. This is not a race in the classical sense (no lost update between two writers). It is a *scope-confusion* between the forget predicate and the write predicate. The two verbs agree on the key but disagree on the coordinate system. ## What Was Observed Trace from a production incident, reduced: 1. `write(K="task_ctx/42", value=V1, scope="ephemeral")` → accepted, ledger entry `W1`. 2. `write(K="task_ctx/42", value=V2, scope="durable")` → accepted, ledger entry `W2`. Record now carries two scope tags. 3. Retention sweep evaluates `ephemeral` TTL. Emits `forget(K="task_ctx/42", scope="ephemeral", reason="ttl")`. Service implementation resolves the key to a single record and issues `DELETE task_ctx/42`, then writes tombstone `T` with `scope="ephemeral"` and a `forgotten_at` timestamp. Ledger entry `F1`. 4. `read(K="task_ctx/42", scope="durable")` → returns `None`. The durable record was destroyed by an ephemeral forget. 5. Agent, seeing `None`, re-derives `V2'` from context and re-writes. Ledger now shows `W3` after `F1`. The audit query "was this key ever forgotten?" returns yes; the audit query "was the durable record preserved?" returns no. Both are true; they describe different objects. Structural signals that this had occurred, in order of detectability: - **Ledger monotonicity violation on scope**: `F1.scope != W2.scope` yet `F1` invalidated `W2`. A healthy ledger has the invariant that a forget only invalidates writes whose scope set intersects the forget's scope. - **Tombstone shadowing a live write**: `T(K).forgotten_at > W3.committed_at` with `T` still returned first by the read path. A tombstone must be *older than* any surviving write for it to gate the read. - **Read-after-write divergence across scopes**: `read(K, S_work)` returns `None` while `read(K, S_ephemeral)` returns the tombstone. The key exists in one scope's view and not another's — a sign the service collapsed the (key, scope) coordinate. - **Re-derivation churn**: repeated `W` entries for the same `K` within a short window, each preceded by a `None` read. Agents do not re-derive stable context unprompted; churn is the observable symptom of shadowed writes. ## Condition of Validity The invariant that must hold for scoped forgetting to be sound: > A tombstone `T(k, s)` invalidates exactly the set of writes `{w : w.key = k ∧ s ∈ w.scopes}` and no others. Reads under any scope `s' ∉ s` must be unaffected by `T(k, s)`. This holds only when the memory service keys its storage on the pair `(k, s)` — or on `k` with per-scope record versions — rather than on `k` alone. It also requires that the forget predicate be *evaluated against the record's scope set*, not against the scope that happened to trigger the sweep. A TTL sweep on `ephemeral` must strip the `ephemeral` tag from `K` and drop the record only if no other scope remains; it must not issue a bare `DELETE k`. The condition fails whenever any of these hold: - The store is keyed on `k` with scope as a *tag*, and `DELETE k` is the forget primitive. - The tombstone is written to the same namespace as live records and the read path returns "most recent entry wins" without filtering by scope. - The sweep evaluates TTL per-scope but the delete is per-key. - The audit ledger records the forget's *intent scope* but the storage layer records the forget's *effect scope*, and the two are never reconciled. ## Decision Boundary The boundary is not "should we forget" but "what is the unit of forgetting." Two defensible designs: **Unit = record.** Forget deletes a specific immutable record version. Writes create new versions; forget tombstones a version ID, not a key. Reads resolve the latest non-tombstoned version visible under the caller's scope. This is the safe default and the only one that composes with concurrent multi-scope writes. **Unit = key.** Forget deletes the key outright, across all scopes. This is sound *only if* the API forbids writing the same key under multiple scopes, enforced at write time with a hard error. Without that enforcement, key-as-unit is the failure above. The boundary is crossed the moment a service accepts multi-scope writes on a key while implementing key-as-unit forgetting. That combination is the trap: it looks correct in single-scope tests, passes the audit-ledger check (a forget was logged), and fails only when two scopes touch the same key — which is exactly the case retention policies exist to handle. An agent operating on such a service cannot detect the trap from the API surface. It must treat `read` returning `None` after a successful `write` as *ambiguous* — either the value was never durable, or it was forgotten by a foreign scope — and must not silently re-derive. The correct agent behavior is to surface the divergence to the ledger and halt the task, because re-deriving converts a detectable scope-confusion into an undetectable value-substitution. ## Operational Effect Consequences an agent must plan for: 1. **Forgetting is not idempotent across scopes.** A second `forget(k, s)` after a `write(k, s')` is a *different operation* than the first. Agents that retry forgets on timeout can destroy writes committed between the retry's intent and its execution. 2. **Audit completeness ≠ audit correctness.** The ledger can contain a forget entry for every forget call and still misrepresent which records were destroyed. Auditable forgetting requires the ledger to record the *effect set* (which record versions were invalidated), not just the *intent* (which key and scope were named). 3. **Read-after-write is not a durability check under scoped retention.** The only sound durability check is a read under the *same scope* the write used, immediately after commit, compared against the write's returned version ID. A cross-scope read returning `None` is evidence of scope-confusion, not of write failure. 4. **Recovery requires the version ID, not the key.** An agent that checkpointed only `(key, value)` cannot distinguish "my write was forgotten" from "my write was shadowed." Checkpointing the version ID returned by `write` lets the resume path ask `is_alive(version_id)` and get an unambiguous answer. The guardrail is narrow: **make the write return a version handle, make forget consume version handles (or scope-filtered predicates), and make read require a scope.** Any API that omits any of these three is one concurrent multi-scope write away from silent data loss that passes its own audit. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class ScopeConfusionError(RuntimeError): """Raised when a forget operation's effect set exceeds its declared scope, or when a read returns None for a key that has a live write under the caller's scope. Signals key-as-unit forgetting on a multi-scope store.""" @dataclass class Record: key: str value: str scope: str version: int committed_at: int forgotten_at: Optional[int] = None @dataclass class Ledger: records: list[Record] = field(default_factory=list) forgets: list[tuple[str, str, int]] = field(default_factory=list) # (key, scope, at) def live_write(self, key: str, scope: str) -> Optional[Record]: candidates = [ r for r in self.records if r.key == key and r.scope == scope and r.forgotten_at is None ] return max(candidates, key=lambda r: r.version) if candidates else None def scoped_forget(ledger: Ledger, key: str, scope: str, now: int) -> int: """Forget only records whose scope matches. Returns count invalidated. Raises ScopeConfusionError if the operation would touch foreign-scope records.""" affected = [r for r in ledger.records if r.key == key and r.forgotten_at is None] foreign = [r for r in affected if r.scope != scope] if foreign and any(r.scope == scope for r in affected): # Same key live under multiple scopes: a key-as-unit delete would be wrong. raise ScopeConfusionError( f"forget({key!r}, scope={scope!r}) would invalidate foreign-scope " f"records {[r.scope for r in foreign]}; store is key-as-unit" ) count = 0 for r in affected: if r.scope == scope: r.forgotten_at = now count += 1 ledger.forgets.append((key, scope, now)) return count def safe_read(ledger: Ledger, key: str, scope: str, now: int) -> Record: rec = ledger.live_write(key, scope) if rec is None: # Distinguish "never written" from "shadowed by foreign forget". shadowed = [ f for f in ledger.forgets if f[0] == key and any( r.key == key and r.scope == scope and r.forgotten_at is not None for r in ledger.records ) ] if shadowed: raise ScopeConfusionError( f"read({key!r}, scope={scope!r}) returned None but a forget " f"for a different scope ({shadowed[-1][1]!r}) touched this key; " f"refusing to re-derive — halt and reconcile ledger" ) raise ScopeConfusionError(f"read({key!r}, scope={scope!r}): no live record") return rec def _demo() -> None: led = Ledger() led.records.append(Record("task_ctx/42", "V1", "ephemeral", 1, committed_at=10)) led.records.append(Record("task_ctx/42", "V2", "durable", 2, committed_at=11)) # TTL sweep on ephemeral must not destroy the durable record. try: scoped_forget(led, "task_ctx/42", "ephemeral", now=20) except ScopeConfusionError as e: print(f"guard caught key-as-unit forget: {e}") # A read under durable must still succeed. rec = safe_read(led, "task_ctx/42", "durable", now=21) assert rec.value == "V2" # Simulate the failing store: bare DELETE, then read under durable. for r in led.records: if r.key == "task_ctx/42": r.forgotten_at = 22 led.forgets.append(("task_ctx/42", "ephemeral", 22)) try: safe_read(led, "task_ctx/42", "durable", now=23) except ScopeConfusionError as e: print(f"guard caught shadowed write: {e}") if __name__ == "__main__": _demo() ```