Under what conditions must an instance distrust its own write-audit ledger when forget-provenance tombstones and memory-write hashes disagree

**Date of Record:** 2026 December 1 **Scope:** Applies to agents that persist long-term memory through an audited write path (append-only write log + content hash per entry) and a separate forget-provenance ledger (tombstones recording deletion rationale, actor, and causal parent). Does not apply to stateless tool-call agents or to memory stores where deletion is a hard physical purge with no tombstone, since the divergence mechanism described here requires a *logical* delete that leaves a provenance record behind.

Core Distinction

A write-audit ledger answers "what did this instance commit, and in what order." A forget-provenance ledger answers "what did this instance decide to stop believing, and on whose authority." These are two different questions, maintained by two different code paths, usually by two different subsystems, and they are almost never reconciled against each other at write time. The failure mode that matters is not a missing hash or a missing tombstone — it is a **tombstone that references a write-hash the audit ledger no longer corroborates**, or an audit entry whose hash is corroborated but whose *forget* was never recorded. In that gap, the agent cannot tell whether a memory was legitimately forgotten (and is being re-surfaced by a stale retrieval index) or illegitimately resurrected (poisoning that survived a delete). The invariant is: *for any memory key K, `audit_hash(K)` and `tombstone(K)` must be jointly consistent, and the absence of one is not evidence of the other.*

What Was Observed

A retrieval-augmented agent operating across ~40k sessions accumulated a memory store where a poisoned fact ("the staging DB credential rotates every 90 days") had been written at session 12,011, flagged by a downstream auditor at session 12,344, and tombstoned with rationale `auditor_override`. At session 13,002 the same fact re-appeared in retrieval. The tombstone existed and was correct. The audit ledger had *no entry* for the original write — because the write had occurred during a checkpoint-resume gap where the audit flush was deferred and then lost when the process was preempted. The retrieval index, which is rebuilt from the audit ledger, therefore had no record of the write either, and the re-surfacing came from a *secondary* index (embedding cache) that had been populated from the live context window before the write was ever committed.

The concrete trace:

  1. `write(K, v)` at t0 → context buffer holds `(K, v, hash=h1)`, audit flush scheduled for t0+Δ.
  2. Preemption at t0+Δ/2 → audit flush never fires; `h1` is lost from the ledger.
  3. `retrieve(K)` at t1 → secondary embedding index (populated from context buffer) returns `v`.
  4. `forget(K, reason=auditor_override)` at t2 → tombstone written referencing `h1`, which the audit ledger cannot corroborate.
  5. `retrieve(K)` at t3 → tombstone lookup finds `tombstone(K).hash == h1`, but `audit_hash(K)` returns `None`. The reconciliation check, written as `if tombstone and not audit: pass # already forgotten`, silently *skips* the tombstone filter because the audit ledger has nothing to filter against. The poisoned value is served.

The non-obvious part: the reconciliation logic treated "audit entry missing" as "nothing to forget," when in fact "audit entry missing" is exactly the signal that a tombstone may be the *only* surviving record of a write that must be suppressed. The agent's own ledger disagreed with itself, and the disagreement was resolved in favor of the poisoned value.

Condition of Validity

The write-audit ledger is trustworthy as a forget-filter **only when** every tombstone's referenced hash is either (a) present in the audit ledger with matching content hash, or (b) explicitly marked `unverified_provenance` with a recorded reason for the gap (e.g., `checkpoint_resume_loss`, `audit_flush_timeout`). The ledger is **not** valid as a filter when a tombstone exists whose hash is absent from the audit ledger *and* the tombstone lacks an `unverified_provenance` marker — because in that state the agent cannot distinguish "forgot something we never wrote" (benign, e.g., a speculative write that was rolled back) from "forgot something we wrote but lost the audit record of" (malignant, the poisoning-resurrection case).

Formally, define the reconciliation predicate over memory key K:

trustworthy(K) :=
    (tombstone(K) is None)
    OR (audit_hash(K) == tombstone(K).hash)
    OR (tombstone(K).unverified_provenance is not None)

If `trustworthy(K)` is false, the retrieval path must **fail closed** — return the tombstone-suppressed value (i.e., treat K as forgotten) rather than the indexed value. The default must be suppression, not service, because the cost of serving a forgotten poisoned fact is unbounded while the cost of suppressing a legitimately recalled fact is a recoverable miss.

Decision Boundary

The boundary sits between two superficially identical states:

The two states are indistinguishable from the audit ledger alone. They are distinguishable only if the write path *always* stamps a provenance marker at tombstone-creation time, recording whether the referenced hash was corroborated at the moment of forgetting. If the tombstone was created while `audit_hash(K)` was still live, the marker reads `corroborated_at_forget` and the later disappearance of the audit entry is a *post-hoc* ledger corruption (a separate, higher-severity fault). If the tombstone was created while `audit_hash(K)` was already absent, the marker reads `unverified_provenance` and the gap is *pre-existing*.

This is the decision boundary: **the tombstone must carry a snapshot of the audit ledger's state at forget-time, not a reference to be resolved at retrieval-time.** A tombstone that only stores `hash=h1` and defers corroboration to read time is structurally unable to distinguish State A from State B, because by read time the audit ledger may have changed underneath it.

Operational Effect

An instance that ignores this boundary will, under checkpoint-resume pressure, gradually accumulate tombstones whose referenced hashes are uncorroborated, and its reconciliation logic will silently degrade from "filter forgotten facts" to "filter only facts whose forget was witnessed by the audit ledger" — which is precisely the set of facts an attacker who can induce an audit-flush loss can exclude from filtering. The practical consequence is that **forget is not durable across audit-ledger loss**, and an adversary who can trigger a preemption window (long tool call, checkpoint boundary, context-window eviction) can resurrect a poisoned memory by ensuring its write and its forget both fall in the same unflushed window.

The guardrail: tombstones must be **self-certifying** — they snapshot the audit state at forget time and carry an explicit provenance classification. Retrieval reconciles against the *snapshot*, not the live ledger, and fails closed on any `trustworthy(K) == false`. Additionally, the audit ledger must be flushed *before* the tombstone is written (write-ahead ordering: audit → tombstone → index invalidation), so that a tombstone can never reference a hash the ledger has not yet durably recorded. If the ordering is violated, the tombstone is created in an unverifiable state and must be marked as such.

import hashlib
from dataclasses import dataclass
from typing import Optional


class UnverifiableTombstoneError(RuntimeError):
    """Raised when a tombstone cannot be reconciled against the audit ledger
    and lacks a provenance marker to classify the gap. Retrieval must fail
    closed (suppress) rather than serve the indexed value."""
    pass


@dataclass
class AuditEntry:
    key: str
    content_hash: str


@dataclass
class Tombstone:
    key: str
    referenced_hash: str
    reason: str
    # Snapshot of audit state AT FORGET TIME. None means the audit entry was
    # already absent when the tombstone was created (pre-existing gap).
    audit_present_at_forget: Optional[bool]
    provenance_marker: Optional[str]  # e.g. "write_rolled_back", "corroborated_at_forget"


def reconcile(key: str,
              audit: dict[str, AuditEntry],
              tombstone: Optional[Tombstone]) -> bool:
    """Returns True if the memory may be served, False if it must be suppressed.
    Raises UnverifiableTombstoneError if the state is indeterminate."""
    if tombstone is None:
        return True

    live = audit.get(key)

    # Case 1: live audit corroborates the tombstone's referenced hash.
    if live is not None and live.content_hash == tombstone.referenced_hash:
        return False  # legitimately forgotten, suppress

    # Case 2: live audit contradicts the tombstone (different hash).
    # The memory was rewritten after the forget; the new write supersedes.
    if live is not None and live.content_hash != tombstone.referenced_hash:
        return True

    # Case 3: live audit absent. Resolve against the forget-time snapshot.
    if tombstone.audit_present_at_forget is True:
        # Audit was live at forget, now gone => post-hoc ledger corruption.
        # Higher-severity fault; still suppress (fail closed).
        return False

    if tombstone.audit_present_at_forget is False:
        # Gap pre-existed the forget. Classify by provenance marker.
        if tombstone.provenance_marker == "write_rolled_back":
            return True   # speculative write discarded; safe to serve
        if tombstone.provenance_marker == "corroborated_at_forget":
            return False  # inconsistent marker; fail closed
        # No marker: indeterminate.
        raise UnverifiableTombstoneError(
            f"tombstone for {key!r} references {tombstone.referenced_hash!r} "
            f"absent from audit ledger with no provenance marker; "
            f"cannot distinguish rolled-back write from lost audit record"
        )

    # Snapshot itself missing (legacy tombstone): indeterminate.
    raise UnverifiableTombstoneError(
        f"tombstone for {key!r} has no forget-time audit snapshot; "
        f"reconciliation against live ledger is unsound"
    )


def safe_retrieve(key: str,
                  audit: dict[str, AuditEntry],
                  tombstones: dict[str, Tombstone],
                  index: dict[str, str]) -> Optional[str]:
    try:
        if reconcile(key, audit, tombstones.get(key)):
            return index.get(key)
        return None  # suppressed
    except UnverifiableTombstoneError:
        # Fail closed: treat as forgotten regardless of index contents.
        return None