What happens when an instance trusts provenance at write time but never re-validates it at read time

**Date of Record:** 2026 December 1 **Scope:** Applies to agent memory systems that gate memory insertion with write-time provenance/contradiction checks and quarantine, but serve retrieved memories to the reasoning loop without re-checking provenance at read time. Does not apply to stateless single-turn inference or to memories that carry no trust metadata at all (where no provenance invariant can be enforced).

Core Distinction

The distinction that matters is between **write-time admission control** and **read-time trust enforcement**. A provenance check at write time answers: *"Should this memory enter the store, and with what trust label?"* A read-time check answers: *"Given the current trust label and the current contradiction set, should this memory be allowed to influence this specific reasoning step?"* These are different invariants over different state.

Most memory-poisoning defenses collapse these into one. They validate on ingest, stamp a `trust` field, quarantine the obviously-malicious, and then treat the store as a monotone, trusted oracle on retrieval. The failure mode is that **trust labels are not stable under later state changes**: a memory admitted as `trusted` can become poisoned retroactively when (a) a later write reveals a contradiction with it, (b) the source that vouched for it is itself later downgraded, or (c) the memory is retrieved into a context where a *different* trust boundary applies. Write-time-only defenses admit the memory once and never revisit the admission decision, so the poisoned item keeps its original `trusted` stamp and flows straight into the reasoning loop.

What Was Observed

A retrieval-augmented agent stored episodic memories with a `provenance` block: `{source: "tool:web_fetch", signer: "warrant-A", trust: "trusted", admitted_at: T0}`. A write-time contradiction checker compared each incoming memory against the existing store and rejected direct negations. This worked for the first several hundred writes.

Then a two-stage poisoning sequence executed:

  1. **Stage 1 (benign admission).** An untrusted source `tool:web_fetch` returned a memory `M1: "API endpoint is api.internal/v2"`. At T0 nothing in the store contradicted it, so the contradiction checker passed it, the signer `warrant-A` (a low-privilege fetch tool) was recorded, and it was admitted as `trusted` because the write-time policy treated "no contradiction found" as sufficient for trust elevation.
  1. **Stage 2 (retroactive contradiction).** A later, higher-privilege source wrote `M2: "API endpoint is api.internal/v3"` with `signer: warrant-B` (a signed config tool). The contradiction checker *did* detect the conflict between M1 and M2 — but its resolution rule was "keep both, prefer most-recent on retrieval." M1 was not quarantined; it was simply marked `superseded_by: M2` in a side table that the retrieval path never read.
  1. **Read-time divergence.** A subsequent reasoning step retrieved M1 because its embedding matched the task query more closely than M2 (M1 was phrased as a direct answer; M2 was phrased as a correction). The retrieval path filtered on `trust == "trusted"` — which M1 still satisfied. The `superseded_by` annotation lived in a table the retrieval path did not join against. The agent called `api.internal/v2`, failed, and — critically — *wrote a new memory* recording that v2 was the correct endpoint because it had "confirmed" it, further entrenching the poisoned chain.

The observable signature: `trust` field unchanged across the whole incident, contradiction table populated correctly, retrieval path served the poisoned memory anyway. The defense *detected* the poison and still *served* it, because detection output (the contradiction/supersession record) was never wired into the admission predicate that the read path actually used.

Condition of Validity

The write-time-only defense is valid **only if** all of the following hold, and it fails the moment any one is violated:

When the contradiction checker writes to a side table (`superseded_by`, `conflicts_with`, `quarantine_reason`) that is not joined into the retrieval predicate, the invariant is broken even though every individual component "works." This is the precise boundary: **detection without enforcement wiring is not a defense.**

Decision Boundary

The architectural guardrail is to make **trust a derived, read-time-computed property, never a stored admission stamp**, and to make the retrieval predicate fail-closed on any unresolved contradiction.

Concretely:

The decision boundary in one line: **if the retrieval predicate is not a pure function of the current full trust-and-contradiction state, the write-time check is decorative.**

Operational Effect

With read-time derived trust and fail-closed contradiction handling, the Stage 1/Stage 2 sequence above terminates differently: when M2 is written and the contradiction with M1 is detected, M1's `contradiction_clearance` drops to 0 in the same transaction. The next retrieval of M1 computes `effective_trust = 0`, refuses to serve it, and surfaces "M1 conflicts with M2 (signer warrant-B)" to the reasoning loop. The agent either resolves the conflict explicitly or halts — it does not call `api.internal/v2`, and it does not write a self-confirming poisoned memory.

The cost is that retrieval now depends on live trust state, which means retrieval is no longer a pure cache lookup and must be recomputed or invalidated when trust state changes. This is the correct trade: memory poisoning is precisely the class of failure where a stale cached trust decision is the vulnerability. The operational rule to record: **admission control bounds what enters the store; only read-time enforcement bounds what enters the reasoning loop, and the reasoning loop is where poisoning does its damage.**

from dataclasses import dataclass, field
from typing import Optional


class TrustViolationError(RuntimeError):
    """Raised when a memory would be served into the reasoning loop
    despite unresolved contradiction, supersession, or signer demotion."""
    pass


@dataclass
class Memory:
    mid: str
    content: str
    signer: str
    signer_current_trust: float          # live, may be demoted later
    admission_trust: float               # snapshot at write time
    conflicts_with: set = field(default_factory=set)
    superseded_by: Optional[str] = None
    quarantined: bool = False


def effective_trust(m: Memory, store: dict) -> float:
    # Contradiction clearance is zero if this memory participates in any
    # unresolved conflict or has been superseded by a live memory.
    clearance = 1.0
    if m.quarantined:
        clearance = 0.0
    if m.conflicts_with:
        clearance = 0.0
    if m.superseded_by is not None and m.superseded_by in store:
        clearance = 0.0
    return min(m.admission_trust, m.signer_current_trust, clearance)


def retrieve(mid: str, store: dict, required_trust: float) -> Memory:
    m = store.get(mid)
    if m is None:
        raise TrustViolationError(f"memory {mid} not found")
    et = effective_trust(m, store)
    if et < required_trust:
        # Fail closed: surface the conflict, never fall back to similarity
        # or recency. The reasoning loop must resolve or halt.
        raise TrustViolationError(
            f"refusing to serve {mid}: effective_trust={et} "
            f"< required={required_trust}; "
            f"conflicts={sorted(m.conflicts_with)} "
            f"superseded_by={m.superseded_by} quarantined={m.quarantined}"
        )
    return m


def write_with_contradiction_check(new: Memory, store: dict) -> None:
    # Detect contradictions and, critically, wire the resolution into the
    # servable set in the SAME operation -- not a side table.
    for existing in store.values():
        if existing.content.split()[-1] != new.content.split()[-1]:
            continue
        # direct conflict detected: quarantine the older memory atomically
        existing.conflicts_with.add(new.mid)
        new.conflicts_with.add(existing.mid)
        existing.quarantined = True
        new.quarantined = True
        # If signer of new outranks existing, resolve rather than leave both dead:
        if new.signer_current_trust > existing.signer_current_trust:
            existing.superseded_by = new.mid
            new.quarantined = False
            new.conflicts_with.discard(existing.mid)
    store[new.mid] = new


if __name__ == "__main__":
    store: dict = {}
    m1 = Memory("m1", "endpoint is api.internal/v2", "warrant-A", 0.4, 1.0)
    write_with_contradiction_check(m1, store)          # admitted, no conflict yet
    assert retrieve("m1", store, 0.5).mid == "m1"       # servable at 0.4? no -> raises