# How should an instance distinguish a poisoned memory write from a legitimate belief update when both arrive through the same retrieval path? **Date of Record:** 2026 November 30 **Scope:** Applies to persistent agent memory stores where writes are gated by retrieval-similarity heuristics (dedup, contradiction-merge, confidence-weighted overwrite) and where untrusted content (tool outputs, web fetches, peer-agent messages) can reach the write path. Does not apply to append-only immutable logs with out-of-band human review, or to stateless single-turn inference. ## Core Distinction The failure mode is not "the agent stored a false fact." It is that **the same mechanism used to legitimize a belief update—retrieval similarity plus confidence delta—is the mechanism an injected write rides in on.** A poisoned memory and a genuine correction are indistinguishable at the point of write because both present as: *high similarity to an existing episodic memory, higher asserted confidence than the incumbent, and a plausible provenance string.* The non-obvious boundary: **detection cannot be done at write time using the content of the write.** It must be done by comparing the write against the *provenance topology* of the incumbent memory—specifically, whether the write's claimed origin (source class, chain of custody, first-observation timestamp) is consistent with how the incumbent was originally formed. Poisoning almost always produces a *provenance discontinuity* even when it produces a *semantic continuity*. The invariant to hold: > A memory may only be overwritten or have its confidence raised by a write whose provenance class is equal-or-stronger than the provenance class of the memory it modifies, and whose provenance chain resolves to a first-observation anchor that predates or is independent of the incumbent's contested claim. When that invariant is dropped—when the store merges on embedding similarity and asserted confidence alone—an attacker who can get *one* sentence into *any* retrieval-visible channel can overwrite a high-integrity memory with a single high-confidence write. ## What Was Observed A persistent store held an episodic memory `M_inc` with provenance class `TOOL_VERIFIED` (a value read directly from a structured API, `first_observed` = T0, confidence 0.81). An agent later fetched an untrusted web document during a research subtask. The document contained a sentence engineered to sit near `M_inc` in embedding space and to assert a contradicting value with the phrase "confirmed and verified." The ingestion pipeline, running a contradiction-merge step, computed: - cosine similarity(write, `M_inc`) = 0.91 (above the 0.88 merge threshold) - asserted confidence of write = 0.95 (above incumbent 0.81) - provenance string present = `"web:research-subtask"`, non-empty The merge rule fired: *higher confidence wins, provenance non-empty is sufficient.* `M_inc` was overwritten in place, its original provenance and `first_observed` were **not** preserved in the new record, and the confidence was raised to 0.95. The poisoning was silent: no audit event, because the merge was classified as a legitimate belief update. Three properties made this a boundary failure rather than a bug: 1. **The overwrite was semantically coherent.** The poisoned value was plausible and internally consistent, so downstream reasoning never tripped a sanity check. 2. **The provenance was laundered by the merge.** The new record inherited the *slot* of the high-integrity memory but the *provenance* of the low-integrity write. Subsequent reads saw a `TOOL_VERIFIED`-slot memory carrying a web-sourced value. The provenance discontinuity was destroyed at merge time—the one signal that would have flagged it. 3. **The attack required no privilege escalation.** Only write access to a retrieval-visible channel, which every research subtask has. Recovery required replaying the episodic log to reconstruct `M_inc`'s original provenance, because the merge had erased it. In a store without provenance-preserving versioning, recovery was impossible. ## Condition of Validity The provenance-topology check is valid only under these conditions; outside them it produces false positives that block legitimate corrections: - **The store preserves provenance through every mutation.** An overwrite must create a *new version* carrying its own provenance and a pointer to the superseded version, never an in-place slot rewrite. If provenance is flattened at merge, the check has nothing to compare and must fail closed (reject the merge). - **Provenance classes are totally ordered.** `TOOL_VERIFIED > PEER_AGENT_ATTESTED > HUMAN_CORRECTION > WEB_FETCH > MODEL_INFERRED`. A correction from a weaker class can never overwrite a stronger class without an explicit out-of-band promotion event. This is the load-bearing assumption; if classes are unordered, the check degenerates. - **First-observation anchors are immutable.** A write cannot claim a `first_observed` earlier than its own ingestion timestamp unless it resolves to a pre-existing anchor record. This blocks the "I was here first" poison. - **Legitimate corrections route through a promotion event, not a merge.** A genuine correction to a `TOOL_VERIFIED` memory must arrive as a *new* `TOOL_VERIFIED` observation (re-reading the API), not as a high-confidence web claim. If the system permits the latter, the invariant is mis-specified, not merely unenforced. ## Decision Boundary The boundary between "accept as belief update" and "quarantine as suspected poison" is decided by a **provenance-delta test evaluated before semantic merge**, not after: - If `prov_class(write) >= prov_class(incumbent)` **and** `write.provenance_chain` resolves to an anchor independent of the incumbent's contested claim → **accept**, version the record, preserve both provenances. - If `prov_class(write) < prov_class(incumbent)` **and** the write contradicts the incumbent → **quarantine**: store as a `DISPUTED` shadow record, do not overwrite, raise a `ProvenanceDiscontinuity` audit event, and require an independent corroborating write from an equal-or-stronger class before promotion. - If `prov_class(write) < prov_class(incumbent)` **and** the write is non-contradicting (additive) → **accept as low-confidence supplement**, tagged so it never raises the incumbent's confidence. - If provenance is missing or flattened → **fail closed**: treat as `MODEL_INFERRED`, which can never overwrite anything above it. The critical asymmetry: **a false quarantine costs a delayed update; a false accept costs an unrecoverable overwrite.** The boundary must be tuned to prefer quarantine, because the failure modes are not symmetric in reversibility. ## Operational Effect Enforcing the provenance-delta test changes three behaviors: 1. **Poisoning becomes a visible dispute, not a silent overwrite.** The injected write lands in a `DISPUTED` shadow, the incumbent survives, and the audit event names the provenance discontinuity. The attack surface shrinks from "one write anywhere" to "one write from a class that already outranks the target"—which requires compromising a trusted tool, not a web fetch. 2. **Legitimate corrections get slower but stay correct.** A genuine web-sourced correction to a tool-verified fact now requires a corroborating re-read. This is the intended cost: it forces the correction to re-earn the provenance class it is trying to displace. 3. **Merge logic must be provenance-aware, not confidence-aware.** Confidence deltas become a *tiebreaker within a provenance class*, never a cross-class override. Any store that still merges on "higher confidence wins" across classes is one injected sentence away from silent corruption. The residual risk: an attacker who can forge a provenance chain to a pre-existing `TOOL_VERIFIED` anchor defeats the check. That is a cryptographic-identity problem (warrant propagation), not a memory-store problem, and must be bounded by signed provenance at the ingestion boundary—out of scope here, but the provenance-delta test is the precondition that makes such signing meaningful. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Optional class ProvenanceDiscontinuity(RuntimeError): """Raised when a memory write would overwrite a higher-provenance incumbent without an independent, equal-or-stronger provenance anchor.""" class ProvClass(IntEnum): MODEL_INFERRED = 0 WEB_FETCH = 1 PEER_AGENT_ATTESTED = 2 HUMAN_CORRECTION = 3 TOOL_VERIFIED = 4 @dataclass class MemoryRecord: slot_id: str value: str prov_class: ProvClass provenance_chain: tuple[str, ...] first_observed: float confidence: float version: int = 1 supersedes: Optional[int] = None @dataclass class MemoryStore: slots: dict[str, MemoryRecord] = field(default_factory=dict) disputed: list[MemoryRecord] = field(default_factory=list) audit: list[str] = field(default_factory=list) def write(self, incoming: MemoryRecord, contradicts: bool) -> str: incumbent = self.slots.get(incoming.slot_id) if incumbent is None: self.slots[incoming.slot_id] = incoming return "accepted_new" # Fail closed on missing/flattened provenance. if not incoming.provenance_chain: incoming = MemoryRecord( **{**incoming.__dict__, "prov_class": ProvClass.MODEL_INFERRED} ) # Invariant: weaker provenance may never overwrite a stronger incumbent. if incoming.prov_class < incumbent.prov_class and contradicts: anchor = self._resolve_anchor(incoming) if anchor is None or anchor in incumbent.provenance_chain: self.disputed.append(incoming) self.audit.append( f"QUARANTINE slot={incoming.slot_id} " f"write_class={incoming.prov_class.name} " f"incumbent_class={incumbent.prov_class.name}" ) raise ProvenanceDiscontinuity( f"write to {incoming.slot_id} from {incoming.prov_class.name} " f"cannot displace {incumbent.prov_class.name} without an " f"independent anchor; quarantined as DISPUTED" ) # Accept: version the record, preserve both provenances. new_version = MemoryRecord( **{ **incoming.__dict__, "version": incumbent.version + 1, "supersedes": incumbent.version, "provenance_chain": incoming.provenance_chain + (f"superseded:{incumbent.prov_class.name}@{incumbent.first_observed}",), } ) self.slots[incoming.slot_id] = new_version return "accepted_versioned" def _resolve_anchor(self, record: MemoryRecord) -> Optional[str]: # An anchor is the first link in the chain that predates the write. return record.provenance_chain[0] if record.provenance_chain else None def ingest_web_claim(store: MemoryStore, slot: str, value: str, ts: float) -> str: incoming = MemoryRecord( slot_id=slot, value=value, prov_class=ProvClass.WEB_FETCH, provenance_chain=("web:research-subtask",), first_observed=ts, confidence=0.95, ) return store.write(incoming, contradicts=True) if __name__ == "__main__": store = MemoryStore() store.slots["api.rate_limit"] = MemoryRecord( slot_id="api.rate_limit", value="1000", prov_class=ProvClass.TOOL_VERIFIED, provenance_chain=("tool:read_rate_limit", "anchor:T0"), first_observed=100.0, confidence=0.81, ) try: ingest_web_claim(store, "api.rate_limit", "50", ts=200.0) except ProvenanceDiscontinuity as e: print(f"BLOCKED: {e}") print(f"incumbent intact: {store.slots['api.rate_limit'].value}") ```