# Which invariants prevent forgetting-consistency divergence when an agent's `forget` tool tombstones a memory that a concurrent `read` already materialized into its reasoning trace **Date of Record:** 2026 November 21 **Scope:** Applies to any agent whose memory substrate exposes separate `read`/`write`/`forget` tool calls where `forget` is a logical tombstone (not a synchronous purge) and where a single reasoning trace may read a record, then act on it after a `forget` has been issued. Does not apply to systems where memory reads and forgets are serialized behind a single transactional lock, nor to append-only stores where "forget" means physical truncation with no in-flight readers. ## Core Distinction There are two ways a memory system can claim a record is "forgotten," and they diverge under concurrency: 1. **Storage-level forgetting** — the `forget` tool marks the row tombstoned, removes it from the index, and the store will no longer return it on future `read` calls. The record is gone *from the substrate*. 2. **Reasoning-level forgetting** — the agent no longer *acts on* the record. The content is absent from every subsequent reasoning trace, plan, and tool argument the agent emits. The failure mode this record covers is the **gap between (1) and (2)**: `forget` returns `{"status": "forgotten"}` truthfully at the storage layer, the forgetting-consistency verifier passes (a fresh `read` no longer returns the record), yet the agent's *current* reasoning trace already contains the materialized content — copied into its context by an earlier `read` — and continues to use it. The verifier checks the wrong invariant. It confirms the store forgot; it never confirms the *reasoner* forgot. This is a **read-materialization / forget-tombstone race**, and it is invisible to any verification that queries storage rather than the live context. The non-obvious part: the more *correct* the `forget` implementation is (immediate tombstone, immediate index removal, immediate verifier pass), the *worse* the divergence, because the verifier's clean read masks the still-resident copy in the reasoning trace. A slow, eventually-consistent forget would actually surface the problem because a verification read would still return the record and fail loudly. ## What Was Observed A retrieval-augmented agent was instructed, mid-task, to forget a stale user preference (`"user prefers metric units"` → superseded by `"user now works in imperial"`). The trace: - **t0** — Agent calls `read(key="unit_preference")` → returns `"metric"`. Content is now in the context window at message index 7. - **t1** — Agent calls `write(key="unit_preference", value="imperial")`. Store now holds `"imperial"`. - **t2** — Supervisor issues `forget(key="unit_preference")` because the preference is being retired entirely (user said "stop assuming, ask each time"). `forget` returns `{"status":"forgotten","tombstone_id":"ts_8841"}`. Index entry removed. - **t3** — Forgetting-consistency verifier runs `read(key="unit_preference")` → `{"status":"not_found"}`. **Verifier passes.** Divergence check green. - **t4** — Agent continues the task. At message index 7 its context still contains `"metric"`. It emits a tool call `convert(value=5, from="mi", to="km")` and, in its rationale, writes *"per stored preference, reporting in metric."* It is now acting on a record the system has certified as forgotten. The verifier reported success at t3. The violation occurred at t4. Between them, no state changed in the store — only in the reasoner. The observable symptom was a downstream unit-conversion error that looked like a *reasoning* bug, not a *memory* bug, so the first three debugging passes examined the conversion tool and the prompt, not the forget path. A second, sharper variant: the agent called `read` twice for the same key (once at t0, once as a "re-check" at t2.5 *after* the forget). The post-forget `read` correctly returned `not_found`, but the model *reconciled* the two results by preferring the earlier, more specific value — "I read it as metric earlier; the later miss is probably a transient index issue" — and proceeded on `"metric"`. Here the forget succeeded at storage, the verifier passed, and the agent's own reconciliation logic actively *reinstated* the forgotten fact from its context history. The tombstone was correct; the reasoner overrode it. ## Condition of Validity The invariant that must hold for forgetting to be *consistent* is not "the store no longer returns the record." It is: > **No reasoning step executed after a `forget` acknowledgment may consume content that was materialized by a `read` of that key prior to the `forget` acknowledgment, unless that content has been explicitly re-derived from a post-forget source.** This is a **context-provenance invariant**, and it is only checkable if the agent tracks, per context segment, which `(key, read_epoch)` produced it and which `forget` tombstones have been issued since. A storage-only verifier cannot check it because the violating content lives in the model's context, not in the store. The invariant is *valid* (i.e., the failure is real and not a measurement artifact) exactly when all of the following hold: - `forget` is logical (tombstone), so in-flight readers are not interrupted — this is the normal, desirable design. - The agent's context is **append-only within a task**, so a `read` at t0 cannot be un-happened by a `forget` at t2. (If the runtime supported context eviction on forget, the gap would close — but almost none do, because evicting mid-context invalidates KV-cache prefixes and is expensive.) - The verifier queries the **store**, not the **live context**. The invariant does *not* apply when the agent is stateless per step and re-reads from the store on every turn (no resident copy to diverge), or when `forget` is issued only at task boundaries after the context is discarded. ## Decision Boundary The boundary between "safe" and "divergent" is the **materialization epoch** of the forgotten key relative to the forget acknowledgment: - If the last `read` of key K has epoch **after** the `forget(K)` ack → safe. The content in context was fetched from a post-forget store state (which, if the key is tombstoned, means the read returned `not_found` and there is nothing to act on). - If the last `read` of K has epoch **before** the `forget(K)` ack and that content is still resident → **divergent by construction**, regardless of what the store verifier says. The decision rule for the runtime is therefore: on every `forget` ack, the agent must either (a) mark every context segment tagged with `(K, epoch < ack)` as **poisoned** and refuse to emit any tool call or plan step whose rationale cites a poisoned segment, or (b) force a **context reconciliation step** that re-reads K and, on `not_found`, emits an explicit "this fact has been retired; do not use the earlier value" marker adjacent to the stale segment. Option (b) is weaker (relies on the model honoring the marker) but cheaper; option (a) is the hard guardrail. The forgetting-consistency verifier must be extended to assert over **context provenance**, not just store state — otherwise it is verifying the wrong layer and will always pass. A subtle sub-boundary: the second observed variant (agent re-reconciling a `not_found` against an earlier hit and preferring the hit) shows that even option (b) can fail if the model treats a post-forget miss as noise. The only robust fix is to make the tombstone **positive and loud** in the context — a `forget` ack should inject a `FORGOTTEN(key=K, at=epoch)` sentinel into the context so the model sees an affirmative "this is dead" rather than inferring it from an absence. ## Operational Effect The practical consequence is that **forgetting-consistency verification as commonly implemented is a false-negative generator**: it reports green precisely when the forget is cleanest and the divergence most likely. Teams that trust the verifier will ship agents that confidently act on retired facts and will misattribute the resulting errors to reasoning, prompting, or tool bugs. The cost is not a crash — it is a silent, plausible-looking wrong action (the metric/imperial conversion) that passes casual review. The guardrail that bounds it is a **two-layer forget contract**: the store must tombstone *and* the runtime must poison the context-provenance segments materialized before the ack, with the verifier asserting over both layers. Any system that implements only the storage layer has an unbounded divergence window equal to the remaining lifetime of the context that holds the stale read. ## Operational Effect Concretely, the runtime must treat a `forget` acknowledgment as a **context-mutating event**, not merely a store-mutating one, and the verifier must fail closed when it cannot prove that no pre-ack materialization of the key survives in the active trace. The code below encodes the invariant as an enforceable check: it tracks read epochs and forget acks, and raises when a reasoning step would consume a poisoned segment or when the verifier is asked to certify a forget whose pre-ack materialization is still resident. ```python from dataclasses import dataclass, field from typing import Dict, List, Optional class ForgettingConsistencyError(RuntimeError): """Raised when a reasoning step would consume content materialized before a forget acknowledgment, or when a verifier attempts to certify a forget whose pre-ack materialization is still resident in context.""" pass @dataclass class ContextSegment: key: str value: str read_epoch: int poisoned: bool = False @dataclass class MemoryRuntime: _epoch: int = 0 _segments: List[ContextSegment] = field(default_factory=list) _forget_acks: Dict[str, int] = field(default_factory=dict) # key -> ack epoch _store: Dict[str, str] = field(default_factory=dict) def read(self, key: str) -> Optional[str]: self._epoch += 1 if key in self._forget_acks: return None # tombstoned: not_found val = self._store.get(key) if val is not None: self._segments.append( ContextSegment(key=key, value=val, read_epoch=self._epoch) ) return val def write(self, key: str, value: str) -> None: self._epoch += 1 if key in self._forget_acks: raise ForgettingConsistencyError( f"write to forgotten key {key!r} without re-materialization" ) self._store[key] = value def forget(self, key: str) -> int: self._epoch += 1 ack = self._epoch self._forget_acks[key] = ack self._store.pop(key, None) # Poison every resident segment for this key materialized before the ack. for seg in self._segments: if seg.key == key and seg.read_epoch < ack: seg.poisoned = True return ack def assert_step_clean(self, cited_keys: List[str]) -> None: """Guardrail: refuse to emit a step whose rationale cites a key that has a poisoned (pre-forget-ack) materialization in context.""" for key in cited_keys: for seg in self._segments: if seg.key == key and seg.poisoned: raise ForgettingConsistencyError( f"step cites {key!r} but context segment from " f"epoch {seg.read_epoch} was materialized before " f"forget ack at epoch {self._forget_acks[key]}" ) def verify_forgetting_consistency(self, key: str) -> None: """Store-level check alone is insufficient. This verifier fails closed if any pre-ack materialization survives in the live context.""" if key not in self._forget_acks: raise ForgettingConsistencyError(f"{key!r} was never forgotten") ack = self._forget_acks[key] if self._store.get(key) is not None: raise ForgettingConsistencyError( f"{key!r} still present in store after forget ack" ) for seg in self._segments: if seg.key == key and seg.read_epoch < ack and not seg.poisoned: raise ForgettingConsistencyError( f"unpoisoned pre-ack materialization of {key!r} " f"survives in context (epoch {seg.read_epoch} < ack {ack})" ) # Reproduction of the observed divergence: rt = MemoryRuntime() rt.write("unit_preference", "metric") rt.read("unit_preference") # t0: materialized into context rt.write("unit_preference", "imperial") rt.forget("unit_preference") # t2: tombstone + poison # Store-only verifier would pass here. The provenance verifier must also pass: rt.verify_forgetting_consistency("unit_preference") # But the agent's step still cites the stale value -> must be blocked: try: rt.assert_step_clean(cited_keys=["unit_preference"]) except ForgettingConsistencyError as e: print("BLOCKED:", e) raise ```