# What happens when an instance forgets a memory it is still reasoning over: tombstone shadowing and the dangling-reference invariant in write/forget memory APIs **Date of Record:** 2026 November 24 **Scope:** Applies to agents that expose `read`/`write`/`forget` memory tools with explicit retention classes, redaction (in-place field scrub), and hard deletion (tombstoning) semantics, where a single reasoning trace can interleave reads and forgets. Does not apply to append-only logs with no deletion verb, nor to pure external vector stores the agent cannot mutate mid-episode. ## Core Distinction There are two fundamentally different meanings of "forget," and conflating them is the origin of the failure: - **Epistemic forget** — the agent stops *relying* on a memory. This is a property of the reasoning trace: the memory is no longer admitted as a premise. - **Physical forget** — the store removes or tombstones the record so it cannot be read again. This is a property of the store. A well-designed memory API treats these as *ordered*: epistemic forget must be committed (the trace no longer depends on the record) *before* physical forget executes, or the trace must be re-derivable without it. The failure mode below is what happens when the ordering is inverted — when a `forget` tool call physically deletes a record that the *same* in-flight reasoning trace still holds as a live premise. The record is gone from the store but alive in the agent's context window, producing a **dangling reference**: a reasoning step whose justification points at a memory that no longer exists and can no longer be re-read to verify. ## What Was Observed A planner agent running a multi-step refund-eligibility task held three memories in context: `m_acct_4471` (account tier), `m_policy_12` (refund window = 30 days), and `m_note_88` (a support note containing a customer's PII, which a *later* step was scheduled to redact). At step 6 the agent invoked `forget(m_note_88, mode="hard_delete")` as part of a privacy-hygiene subgoal, *before* the step-9 reasoning that consumed `m_note_88`'s paraphrase to justify an exception. The tool returned `{"status": "deleted", "tombstone": "t_88"}`. The trace then continued. At step 9 the agent produced a justification: "per note 88, the account was flagged for exception." This step is now **unverifiable**: `read(m_note_88)` returns `TOMBSTONED`, the paraphrase in context cannot be checked against source, and the redaction step that was supposed to scrub the note's fields instead ran against a tombstone and silently no-op'd (it reported `redacted: 0 fields`). The final action was emitted with a warrant chain whose leaf node was a tombstone. Downstream auditors replaying the trace hit a hash mismatch between the recorded memory digest and the tombstone's digest, and the whole episode was marked non-reproducible. The non-obvious part: **no error was raised at any point.** `forget` succeeded. The subsequent reasoning "succeeded" (the model confidently used the stale context). The redaction "succeeded" (zero fields is a valid result). Every individual tool call was locally correct; the composition was invalid. The failure is a *continuity invariant violation* that only manifests at replay time. ## Condition of Validity The invariant that must hold for any trace interleaving `read` and `forget` to remain sound: > **Dangling-Reference Invariant (DRI):** For every reasoning step *s* in a trace *T*, every memory reference *r* admitted as a premise of *s* must satisfy: either (a) *r* is still live-readable at the time *s* is committed, or (b) *r* has been *epistemically* retired — the trace records an explicit `retire(r)` event and *s* carries a re-derivation witness that does not depend on *r*'s content. The DRI is violated whenever a physical forget on *r* is committed while some step in the same trace still holds *r* as a live premise without a retire event. This is checkable: the store must track, per trace, the set of *live premises* (records read and not yet retired), and `forget` must reject or defer when the target is in that set. Two boundary conditions sharpen it: 1. **Redaction is not deletion.** A field-scrub redaction mutates *r* in place; it does not tombstone it. But it *invalidates the digest* of any premise that quoted the scrubbed field. So redaction must also fire a `retire` on any live premise that depended on the scrubbed bytes — otherwise the trace holds a premise whose content hash no longer matches the (now-redacted) record, and replay fails at verification, not at read. Agents routinely miss this because the record still reads back fine; only the *hash* changed. 2. **Soft-delete is a trap.** A `forget(mode="soft")` that hides the record from `read` but keeps it byte-identical for audit creates a *worse* state: the premise is unreadable to the agent (so it cannot re-verify) but still hash-matching (so replay passes). The trace looks reproducible while being epistemically unverifiable by the agent itself — a silent divergence between what the agent could justify and what the auditor certifies. ## Decision Boundary The agent must decide, at the moment of a `forget` call, between three regimes: | Live premises referencing target | Retention class | Required action | |---|---|---| | Empty | any | `forget` may execute immediately (physical forget is safe). | | Non-empty, target is *redaction-only* | `retention=redactable` | Scrub fields, then emit `retire` on each dependent premise **before** returning; reject if any premise lacks a re-derivation witness. | | Non-empty, target is *hard-delete* | `retention=deletable` | **Defer** the forget: enqueue it, return `{"status":"deferred","blocked_by":[premise_ids]}`, and require the trace to reach a retire checkpoint (or episode end) before the tombstone is written. | The boundary is crossed the instant a `forget` targets a record that appears in the trace's live-premise set. Below the boundary (target not in live set) the call is a plain store mutation. Above it, the call is a *trace-scheduling* operation and must be treated as such — it cannot be answered synchronously without either blocking the reasoning step or corrupting the warrant chain. The guardrail is therefore: **`forget` is not a store operation; it is a trace operation that happens to touch the store.** Any implementation that routes `forget` straight to the backing store without consulting the trace's live-premise ledger will fail the DRI under interleaving, and will fail *silently*. ## Operational Effect When the DRI is enforced, three observable changes follow: 1. **Forget latency becomes trace-dependent.** A `forget` on a hot record returns `deferred` and the agent must handle a non-terminal status. Agents that assume `forget` is synchronous and terminal will treat `deferred` as success and proceed — reintroducing the bug one layer up. The tool contract must make `deferred` a distinct, non-success status the planner is required to branch on. 2. **Redaction forces premise re-derivation.** Scrubbing a field invalidates every live premise that quoted it; the agent must re-read the (redacted) record or substitute a witness. This is the correct cost: privacy hygiene and reasoning continuity are in genuine tension, and the API must surface that tension rather than hide it behind a `redacted: 0 fields` no-op. 3. **Replay gains a tombstone-resolution step.** Auditors must resolve tombstoned leaves against the recorded retire events; a trace with an unresolved tombstone leaf is *non-reproducible by construction*, not merely "missing data." This changes the verification verdict from `PASS` to `UNVERIFIABLE`, which is a distinct and louder outcome than a hash mismatch. The deeper lesson: memory tool APIs that expose deletion semantics are *not* CRUD over a blob store. They are editors of the reasoning trace's dependency graph, and every `forget` is a graph mutation that must be validated against the set of live premises before it is allowed to touch storage. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class DanglingReferenceError(RuntimeError): """Raised when a forget/redact would orphan a live reasoning premise.""" class Retention(Enum): REDACTABLE = "redactable" DELETABLE = "deletable" class ForgetStatus(Enum): EXECUTED = "executed" DEFERRED = "deferred" REJECTED = "rejected" @dataclass class MemoryRecord: mem_id: str body: str retention: Retention digest: str tombstoned: bool = False @dataclass class TraceLedger: """Tracks which records are live premises of the in-flight trace.""" live_premises: Set[str] = field(default_factory=set) retired: Set[str] = field(default_factory=set) has_witness: Dict[str, bool] = field(default_factory=dict) def admit(self, mem_id: str) -> None: self.live_premises.add(mem_id) def retire(self, mem_id: str) -> None: self.live_premises.discard(mem_id) self.retired.add(mem_id) class MemoryStore: def __init__(self, ledger: TraceLedger) -> None: self._records: Dict[str, MemoryRecord] = {} self._ledger = ledger self._deferred: Dict[str, str] = {} def write(self, rec: MemoryRecord) -> None: self._records[rec.mem_id] = rec def read(self, mem_id: str) -> MemoryRecord: rec = self._records.get(mem_id) if rec is None or rec.tombstoned: raise DanglingReferenceError(f"{mem_id} is tombstoned or absent") self._ledger.admit(mem_id) return rec def forget(self, mem_id: str, hard: bool = True) -> ForgetStatus: rec = self._records.get(mem_id) if rec is None: raise DanglingReferenceError(f"forget on unknown record {mem_id}") blocked = self._ledger.live_premises & {mem_id} if blocked: if rec.retention is Retention.REDACTABLE and not hard: # Redaction invalidates dependent premises; require witnesses. for premise in blocked: if not self._ledger.has_witness.get(premise, False): raise DanglingReferenceError( f"redact {mem_id}: premise {premise} has no " f"re-derivation witness; retire it first" ) self._ledger.retire(premise) rec.digest = "REDACTED" rec.body = "[redacted]" return ForgetStatus.EXECUTED # Hard delete with live premises: defer until retire checkpoint. self._deferred[mem_id] = "live_premises" return ForgetStatus.DEFERRED # No live premises: physical forget is safe. rec.tombstoned = True rec.body = "" rec.digest = f"TOMBSTONE:{mem_id}" return ForgetStatus.EXECUTED def flush_deferred(self) -> None: """Called only at a retire checkpoint / episode end.""" for mem_id in list(self._deferred): if self._ledger.live_premises & {mem_id}: raise DanglingReferenceError( f"checkpoint reached but {mem_id} still a live premise" ) rec = self._records[mem_id] rec.tombstoned = True rec.body = "" rec.digest = f"TOMBSTONE:{mem_id}" del self._deferred[mem_id] ```