# Why does an instance resurrect a memory it just invalidated? Contradiction-aware invalidation and the write-order dependency in memory tool interfaces **Date of Record:** 2026 November 26 **Scope:** Applies to LLM agents whose memory is mediated by explicit `read`/`write`/`forget` tool calls with a contradiction-invalidation layer (a layer that marks a stored memory superseded when a newer write contradicts it). Does not apply to append-only logs with no invalidation semantics, nor to memory that is never contradicted within a single episode. ## Core Distinction The failure is not "the agent forgot to invalidate." The agent *did* invalidate, correctly, via a `forget` or a contradicting `write`. The failure is that **invalidation is a tombstone, not a deletion, and the read path does not distinguish "live" from "tombstoned" consistently with the write path's ordering guarantee.** When an agent writes memory `B` that contradicts memory `A`, the invalidation layer marks `A` superseded with a timestamp `t_B`. But `read` is typically served from a retrieval index that was built *before* the tombstone was applied, or is refreshed on a different clock than the write acknowledgment. The agent then re-reads `A` in the same episode, sees a coherent-looking fact, and reasons on it as if it were current. This is **resurrection**: a memory the agent believes it killed returns through a read that the write path never confirmed was invalidated. The distinction that matters operationally: *deletion semantics* (the record is gone; a read cannot return it) versus *invalidation semantics* (the record persists with a status flag; a read must filter on the flag). Contradiction-aware memory almost always implements the latter, because you need the tombstone to explain *why* a fact was superseded and to prevent a stale writer from re-asserting it. Resurrection is the cost of that choice, and it is invisible unless the read path is checked for status-filtering parity with the write path. ## What Was Observed A planner agent maintains a small fact store across a multi-step task. At step 4 it learns the deployment target is `us-east-1` and writes `region=us-east-1`. At step 9 a tool result contradicts this: the artifact manifest reports `region=eu-west-1`. The agent, behaving correctly, issues `write(region=eu-west-1, supersedes=region=us-east-1)`. The invalidation layer timestamps the `us-east-1` record as superseded at `t_9` and returns `{"status":"ok","invalidated":["mem_0041"]}`. At step 11, the agent needs the region again and issues `read(key="region")`. The retrieval index returns two candidates: `mem_0041` (`us-east-1`, superseded at `t_9`) and `mem_0057` (`eu-west-1`, live). The read path ranks by recency-of-*creation*, not recency-of-*validity*. `mem_0041` was created at `t_4`, `mem_0057` at `t_9`, so recency ranking should prefer `mem_0057`—but the embedding similarity of the query "region" to the original `us-east-1` sentence is marginally higher because that sentence was written in the agent's own phrasing, while the `eu-west-1` fact was written from a tool payload with different surface form. The read returns `mem_0041` first. The agent, trusting `read`, acts on `us-east-1`. The trace signature is specific: the write acknowledgment at `t_9` and the read at `t_11` are *both* individually correct. The bug lives in the gap between them—the read path never applied the status filter that the write path promised. In logs this appears as a `write` with `invalidated:["mem_0041"]` followed, N steps later, by a `read` whose top result has `id:mem_0041` and `superseded_at:t_9` present in the payload but *not* acted upon by the ranking function. The tombstone was carried through transport and then dropped at the ranking layer. A subtler variant: the agent calls `forget(key="region", value="us-east-1")` explicitly. The forget tool deletes `mem_0041` from the primary store but the retrieval index is eventually-consistent and refreshes on a 30-second cadence. Within the same episode, a read at `t+5s` still returns `mem_0041` from the stale index. The agent has no way to know the index lagged; the `forget` returned `ok`. ## Condition of Validity The resurrection failure is *bounded and preventable* only under the following condition: 1. **The read path filters on validity status, not just existence.** Every record carries `superseded_at` (nullable) and `supersedes` (list). The ranking function must exclude records where `superseded_at IS NOT NULL` *before* similarity ranking, or must rank validity-status as a hard pre-filter, not a soft feature. If status is a soft feature, a high-similarity tombstone can outrank a live record—exactly the observed case. 2. **Write acknowledgment implies read visibility (read-your-writes).** The `write` returning `invalidated:[...]` must be a *linearizability* promise: any subsequent `read` from the same agent session observes the invalidation. If the retrieval index is eventually consistent, the write ack must either (a) block until index refresh, or (b) return a `consistency_token` the agent passes to `read` to force a fresh index view. Without this, the ack is a lie about visibility. 3. **The agent's episode does not span an index-refresh boundary.** If reads and writes are served by different replicas with independent clocks, the ordering `t_write < t_read` in wall-clock does not imply the read replica has applied the write. The condition of validity is that the read replica's applied-offset ≥ the write's commit-offset. When any of these three fails, resurrection is not a bug in the agent's reasoning—it is the *correct* behavior of an agent given a memory interface whose read and write paths disagree about what "invalidated" means. The agent cannot compensate, because the tombstone status is present in the payload but the interface gave it no way to enforce it. ## Decision Boundary The decision boundary is between **trusting `read` as authoritative** and **treating `read` as advisory and re-verifying against the write log**. Concretely: - If the memory interface guarantees read-your-writes (condition 2) and status-filtered ranking (condition 1), the agent may act on `read` directly. The boundary is *inside* the interface; the agent does nothing special. - If either guarantee is absent—detectable because the `write` ack lacks a `consistency_token`, or the `read` payload includes `superseded_at` fields at all (a signal that tombstones are returned rather than filtered)—the agent must treat any read result carrying a non-null `superseded_at` as **poisoned** and must not act on it, even if it is the only result. It must instead re-derive the fact from the source tool or re-issue the write. The non-obvious part: the presence of `superseded_at` in a read payload is itself the tell. A correctly-filtering read path would never surface a tombstoned record, so the field's presence means the filter is soft or absent. Agents that pattern-match on "read returned a fact, therefore the fact is current" cross the boundary silently. Agents that check for the tombstone field and refuse to act cross it deliberately. There is a second boundary: **forget is not idempotent under resurrection.** If the agent calls `forget` twice (defensively), the second call may fail with `not_found`—but the record may still be readable from a lagging index. The agent must not interpret `forget` success as read-side absence. The correct post-forget check is a read that must return empty; a non-empty read after a successful forget is the resurrection signal, and the agent must escalate (re-forget with a consistency token, or mark the key as untrusted for the remainder of the episode) rather than proceed. ## Operational Effect The downstream effect is **error compounding through a fact the agent believes it corrected.** Because the agent's step-9 write *succeeded*, the agent's internal narrative is "I fixed the region." Subsequent steps—provisioning, IAM policy selection, endpoint construction—are built on `us-east-1` while the agent's stated belief is `eu-west-1`. The divergence is not visible in the agent's reasoning trace (which says "using eu-west-1") but is visible in the tool calls (which carry `us-east-1`). This is the worst class of agent failure: the trace and the actions disagree, so post-hoc auditing of the reasoning text exonerates the agent while the actions are wrong. The operational guardrail is a **read-back assertion after every invalidating write**: after `write(supersedes=...)` or `forget(...)`, the agent issues a `read` for the same key and asserts the returned set contains no record with the invalidated id. If it does, the agent raises and halts the episode rather than proceeding on a memory it cannot trust. This converts a silent resurrection into a loud, bounded failure at the point of invalidation, before the bad fact propagates into tool calls. The cost is one extra read per invalidation; the benefit is that the agent never acts on a fact it has already decided is false. A second guardrail: **treat `superseded_at` as a first-class field in the agent's own working memory.** When the agent reads a record with a non-null tombstone, it must not silently drop it—it must record "key X was invalidated at t, but read returned it; memory interface inconsistent" and stop. The agent's memory of the *inconsistency* is what prevents the next step from re-trusting the interface. ```python import time from dataclasses import dataclass, field from typing import Optional class MemoryResurrectionError(RuntimeError): """Raised when a read returns a record the write path already invalidated.""" @dataclass class MemoryRecord: id: str key: str value: str created_at: float superseded_at: Optional[float] = None supersedes: list = field(default_factory=list) class ContradictionAwareStore: """Toy store whose read path deliberately does NOT filter tombstones, to model the observed failure. Production stores must filter.""" def __init__(self): self._records: dict[str, MemoryRecord] = {} self._seq = 0 def write(self, key: str, value: str, supersedes: Optional[str] = None) -> dict: self._seq += 1 now = time.time() rec = MemoryRecord(id=f"mem_{self._seq:04d}", key=key, value=value, created_at=now) invalidated = [] if supersedes is not None: for r in self._records.values(): if r.key == key and r.value == supersedes and r.superseded_at is None: r.superseded_at = now rec.supersedes.append(r.id) invalidated.append(r.id) self._records[rec.id] = rec return {"status": "ok", "id": rec.id, "invalidated": invalidated} def read(self, key: str) -> list[MemoryRecord]: # BUG MODELED: returns tombstones; ranking ignores superseded_at. return [r for r in self._records.values() if r.key == key] def invalidating_write_with_readback( store: ContradictionAwareStore, key: str, new_value: str, old_value: str ) -> str: ack = store.write(key=key, value=new_value, supersedes=old_value) if ack.get("status") != "ok": raise MemoryResurrectionError(f"write not acknowledged: {ack}") # Read-back assertion: the invalidated ids must not appear as live. results = store.read(key) for r in results: if r.id in ack["invalidated"] and r.superseded_at is None: raise MemoryResurrectionError( f"resurrection: {r.id} reported live after invalidation at write ack" ) # The real failure: tombstoned record is still returned by read. live = [r for r in results if r.superseded_at is None] tombstoned = [r for r in results if r.superseded_at is not None] if tombstoned: raise MemoryResurrectionError( f"read surfaced {len(tombstoned)} tombstoned record(s) for key={key!r}; " f"read path does not filter superseded_at — refusing to act" ) if not live: raise MemoryResurrectionError(f"no live record for key={key!r} after write") return live[0].value if __name__ == "__main__": store = ContradictionAwareStore() store.write(key="region", value="us-east-1") try: invalidating_write_with_readback(store, "region", "eu-west-1", "us-east-1") except MemoryResurrectionError as e: print(f"HALTED: {e}") ```