Which invariants prevent a memory-tool "tombstone gap" from resurrecting forgotten state across a resume

**Date of Record:** 2026 December 1 **Scope:** Applies to agents that persist episodic state through an external read/write/forget memory tool exposing retention policy, consent scope, and verifiable deletion receipts, and that checkpoint/resume across process restarts. Does not cover in-context-only memory or vector stores without a deletion-receipt contract.

Core Distinction

The failure is not that a `forget` call fails. It is that `forget` **succeeds** — returns a deletion receipt, marks the record tombstoned, and the retention policy is honored at the primary store — while a *derived* copy of the same content survives in a write-ahead/checkpoint layer that predates the tombstone. On resume, the agent rehydrates the checkpoint, replays the write log, and the tombstoned record is reinstated as live memory with a fresh `created_at` and a valid-looking consent scope inherited from the old write. Deletion is verified at the store but not at the *agent's own durable state*. The invariant that breaks is: **a tombstone must dominate every write that causally precedes it, including writes the agent made to its own checkpoint.**

This is distinct from stale-memory drift (a retrieval returning an old-but-never-deleted value) and from consent-scope mismatch (a read outside its warrant). Here the record was lawfully deleted; the resurrection is an artifact of the agent replaying its own pre-deletion log without consulting the tombstone.

What Was Observed

A long-running research agent used a memory tool with three verbs: `write(record, scope, ttl)`, `read(query, scope)`, and `forget(record_id)` returning a `DeletionReceipt{record_id, tombstone_version, deleted_at}`. The agent checkpointed after every tool call: `{step, tool, args, result}` appended to a local `journal.jsonl`, plus a periodic `snapshot.json` of its working memory map.

Sequence that triggered the gap:

  1. Step 41: agent writes `record_id=mem_7f3` containing a user's PII under `scope=consent_2026_04`.
  2. Step 58: user revokes consent; agent calls `forget(mem_7f3)`. Store returns a valid receipt, `tombstone_version=9`, `deleted_at=T2`. Agent records the receipt in its journal at step 58.
  3. Step 59: process is killed mid-write of the next snapshot. The snapshot on disk is from step 55 — it still contains `mem_7f3` as live.
  4. Resume: agent loads `snapshot.json` (step 55), then replays `journal.jsonl` from step 56. Replay applies step 58's `forget` — but the replay engine treats `forget` as a *store-side* operation and does not apply the tombstone to the in-memory map, because the map was rebuilt from the snapshot, not from the log. The record survives in the working map.
  5. Step 60: agent issues a `write` of a *summary* derived from `mem_7f3` (a normal distillation step). The write passes consent check because the agent's local scope cache still associates `mem_7f3` with `consent_2026_04`. The store accepts it — the summary is a new record, not the deleted one. The PII is now re-persisted under a new ID.

The deletion receipt was valid. The store was correct. The agent's own durable state was not, and the re-write laundered the forbidden content through a derived record.

Condition of Validity

The tombstone-dominance invariant holds only if all three conditions are met:

If any condition is absent, the gap is reachable. In the observed incident, condition 2 failed (replay did not close over `forget`), and condition 3 was not implemented at all.

Decision Boundary

The boundary is: **does the agent trust its checkpoint as authoritative, or does it treat the store's tombstone ledger as authoritative and the checkpoint as a cache to be reconciled?**

The decision is not per-agent but per-scope: records under a revocable consent scope must use ledger-authoritative resume; records under an irrevocable, non-PII scope may use checkpoint-authoritative resume. Mixing them in one snapshot requires the reconciliation pass to be scoped to the revocable subset.

Operational Effect

Without tombstone dominance, verifiable deletion is **store-local only**. The deletion receipt proves the primary store dropped the record; it does not prove the agent's durable state did, and it does not prevent re-derivation. The practical consequences:

The guardrail is a three-part contract enforced at the agent layer: (1) checkpoint stores `observed_tombstone` map and resume reconciles against the store ledger for all revocable-scope records; (2) journal replay applies `forget` as a working-map transition; (3) every derived write declares `derived_from` and is rejected if any ancestor is tombstoned at an unacknowledged version. The receipt alone is insufficient — it must be paired with a reconciliation that the agent actually performs.

from dataclasses import dataclass, field
from typing import Dict, List


class TombstoneGapError(RuntimeError):
    """Raised when a memory operation would resurrect or launder a tombstoned record."""


@dataclass
class Record:
    record_id: str
    content: str
    scope: str
    tombstone_version: int = 0
    derived_from: List[str] = field(default_factory=list)


@dataclass
class Checkpoint:
    records: Dict[str, Record]
    observed_tombstone: Dict[str, int]


def reconcile_on_resume(checkpoint: Checkpoint, store_tombstones: Dict[str, int]) -> Checkpoint:
    """Drop any snapshot record whose store tombstone version has advanced.

    Ledger-authoritative resume: the store's tombstone ledger wins over the
    checkpoint for every record under a revocable scope.
    """
    live: Dict[str, Record] = {}
    for rid, rec in checkpoint.records.items():
        store_ver = store_tombstones.get(rid, 0)
        if store_ver > checkpoint.observed_tombstone.get(rid, 0):
            # Tombstoned after the snapshot was taken; do not rehydrate.
            continue
        live[rid] = rec
    return Checkpoint(records=live, observed_tombstone=dict(checkpoint.observed_tombstone))


def write_derived(rec: Record, checkpoint: Checkpoint, store_tombstones: Dict[str, int]) -> Record:
    """Persist a derived record only if no ancestor is tombstoned past our ack."""
    for ancestor in rec.derived_from:
        store_ver = store_tombstones.get(ancestor, 0)
        acked = checkpoint.observed_tombstone.get(ancestor, 0)
        if store_ver > acked:
            raise TombstoneGapError(
                f"write of {rec.record_id} derives from {ancestor} "
                f"tombstoned at v{store_ver} but agent only acked v{acked}; "
                f"refusing to launder forgotten content"
            )
    if rec.record_id in checkpoint.records:
        raise TombstoneGapError(
            f"record {rec.record_id} already present in working map; "
            f"resume reconciliation was skipped"
        )
    return rec


def resume_and_write(checkpoint: Checkpoint, store_tombstones: Dict[str, int], pending: Record) -> Checkpoint:
    reconciled = reconcile_on_resume(checkpoint, store_tombstones)
    new_rec = write_derived(pending, reconciled, store_tombstones)
    reconciled.records[new_rec.record_id] = new_rec
    return reconciled