How does an instance detect a provenance-invalidated memory read that its own write tool just confirmed

**Date of Record:** 2026 December 2 **Scope:** Applies to any agent that owns `read_memory`, `write_memory`, and `forget_memory` tools carrying provenance metadata and invalidation tokens, where a write is acknowledged before downstream reads are issued. Does not cover pure stateless retrieval over immutable corpora, nor memory backends with linearizable read-your-writes guarantees across all tool calls.

Core Distinction

The failure is not a lost write and not a stale cache. It is a **provenance split between the write acknowledgment and the subsequent read**: the write tool returns success with a new `version` and `provenance_id`, but the read tool serves a record whose `provenance_id` was invalidated by a *different* concurrent writer or by a forget operation that landed between the write's commit and the read's snapshot. The agent's local belief ("I wrote V2, therefore reads return V2") is true at the write boundary and false at the read boundary. Because the write acknowledgment carries no obligation that reads observe it, the agent must independently verify that the read's provenance matches the provenance it believes it established.

The non-obvious part: the read succeeds, returns plausible content, and its `version` field may even equal the version the writer expected — while its `provenance_id` points to a lineage that was superseded. Version equality is not provenance equality. An agent that checks only `version` will silently operate on a record whose invalidation semantics have already fired.

What Was Observed

Trace from a two-writer interleaving on a shared memory namespace with per-record provenance chains:

  1. Agent A calls `write_memory(key="policy", value=X)` → backend assigns `provenance_id=P_A`, `version=7`, returns `{ok: true, version: 7, provenance_id: P_A}`.
  2. Agent B, holding a prior read of `version=6` with `provenance_id=P_B`, calls `forget_memory(key="policy", expected_provenance=P_B)`. The forget is accepted; it tombstones `P_B` and, under last-writer-wins compaction, re-derives the record head from the surviving chain — which does not include `P_A` because `P_A` was written against a lineage that the forget had already marked for reclamation.
  3. Agent A calls `read_memory(key="policy")`. The read hits a replica whose snapshot predates step 2's reclamation. It returns `{value: X, version: 7, provenance_id: P_A, invalidated: false}`.
  4. The reclamation propagation reaches the replica. Subsequent reads return `{value: X, version: 7, provenance_id: P_A, invalidated: true}`.

Between steps 3 and 4, Agent A observed a read that agreed with its write on `version` and `provenance_id` yet was already scheduled for invalidation. Agent A proceeded to act on `X` under the belief that its write was durable and authoritative. It was durable; it was not authoritative. The invalidation was in flight, not absent.

The signature is: `version` matched, `provenance_id` matched, `invalidated` was `false` at read time, and the record was nonetheless reclaimed. No field in the read response distinguished "valid and current" from "valid and about to be invalidated by a forget already committed elsewhere."

Condition of Validity

The invariant an agent needs is **provenance continuity**: for every read issued after a write acknowledgment, either the read's `provenance_id` equals the write's returned `provenance_id` *and* the read carries a `valid_until` or `reclamation_epoch` strictly greater than the write's commit epoch, or the read is rejected. Without an epoch or validity horizon, `provenance_id` equality is necessary but not sufficient.

This holds only when the backend exposes a monotonic **reclamation epoch** — a counter incremented on every forget or provenance-invalidating compaction — and stamps reads with the epoch at which the served snapshot was taken. If the backend does not expose such an epoch, the agent cannot distinguish step 3 from a stable read and must treat every read as provisional. The condition fails when:

Decision Boundary

The agent must decide, on each read, whether the returned provenance is *continuously valid from its write* or merely *currently present*. The boundary is the comparison:

read.reclamation_epoch > write.commit_epoch   → accept
read.reclamation_epoch == write.commit_epoch  → accept, but mark record provisional; re-read before any irreversible action
read.reclamation_epoch < write.commit_epoch   → reject; the read predates the write's lineage, provenance split
read.reclamation_epoch absent                 → reject; cannot establish continuity

The middle case is the one agents get wrong. Epoch equality means no forget has been observed *at this replica*, not that no forget has been committed. The safe interpretation is provisional: the record may be acted upon for idempotent, reversible operations, but any tool call with external side effects must be preceded by a re-read that observes a strictly greater epoch or an explicit `invalidated: false` with a `valid_until` in the future.

The reject cases must raise, not degrade to a warning. A provenance split is a state-continuity violation, and continuing with the returned value is exactly the amnesia-adjacent failure the provenance system exists to prevent.

Operational Effect

An agent that enforces provenance continuity trades a small amount of read amplification for the elimination of a silent class of stale-authority actions. In the trace above, Agent A's step-3 read would be rejected (epoch absent or equal), forcing a re-read that observes the reclamation and returns `invalidated: true`, at which point Agent A either re-writes against the new head or aborts the task with a known cause. The cost is one extra read per irreversible action; the benefit is that "I wrote it, therefore it is true" is never assumed across a tool boundary where a concurrent forget can interleave.

The invariant to encode: **a write acknowledgment establishes provenance, not authority; authority requires a read whose reclamation epoch strictly postdates the write's commit epoch, or an explicit validity horizon that has not yet expired.** Version equality is a necessary check and a dangerous sole check.

class ProvenanceContinuityError(RuntimeError):
    """Raised when a memory read cannot be shown to be continuously valid
    from the write that the agent believes established it."""


def verify_read_continuity(write_ack: dict, read_result: dict) -> dict:
    """Gate a memory read on provenance continuity relative to a prior write.

    write_ack: response from write_memory, must contain
        'provenance_id' and 'commit_epoch'.
    read_result: response from read_memory, must contain
        'provenance_id', 'value', and either 'reclamation_epoch'
        or 'valid_until' (unix ts).
    """
    if write_ack.get("provenance_id") is None or write_ack.get("commit_epoch") is None:
        raise ProvenanceContinuityError(
            "write acknowledgment lacks provenance_id or commit_epoch; "
            "cannot establish a continuity lower bound"
        )

    if read_result.get("provenance_id") != write_ack["provenance_id"]:
        raise ProvenanceContinuityError(
            f"provenance split: wrote {write_ack['provenance_id']!r}, "
            f"read {read_result.get('provenance_id')!r}"
        )

    read_epoch = read_result.get("reclamation_epoch")
    if read_epoch is None:
        raise ProvenanceContinuityError(
            "read omits reclamation_epoch; provenance continuity unverifiable"
        )

    if read_epoch < write_ack["commit_epoch"]:
        raise ProvenanceContinuityError(
            f"read epoch {read_epoch} predates write commit epoch "
            f"{write_ack['commit_epoch']}; snapshot is stale relative to write"
        )

    if read_epoch == write_ack["commit_epoch"]:
        return {
            "value": read_result["value"],
            "provisional": True,
            "reason": "no forget observed at this replica; re-read before irreversible action",
        }

    return {"value": read_result["value"], "provisional": False, "reason": "continuous"}