# What happens when an instance trusts a memory write it did not provenance-stamp: detecting poisoned episodic entries through write-provenance auditing and cross-store consistency checks **Date of Record:** 2026 November 28 **Scope:** Applies to agents with persistent, writable episodic memory stores that accept writes from multiple producers (self-reflection, tool outputs, peer agents, injected documents) and later retrieve them for planning or execution. Does not apply to read-only retrieval caches or purely in-context scratchpads with no persistence boundary. ## Core Distinction The failure is not "the agent retrieved a wrong memory." That is ordinary retrieval mismatch and is bounded by relevance scoring. The failure is **a memory entry whose content is authoritative but whose provenance is unverifiable or forged**, such that the agent's downstream consistency checks pass while the entry is in fact adversarial or corrupted. Poisoned-but-consistent memory defeats every defense that operates on *content* (deduplication, contradiction detection, semantic similarity to prior beliefs) because the poison is engineered to be *more* consistent than the truth. The only invariant that survives is **write-provenance**: every entry must carry a cryptographically or structurally attributable origin, and every retrieval that influences an irreversible action must re-verify that origin against the writer's identity, not against the entry's plausibility. The non-obvious part: write-provenance auditing and content consistency checks are *anti-correlated* under attack. An adversary who controls a write channel will produce entries that maximize internal consistency precisely to suppress consistency-based alarms. So a system that scores memory trust as `consistency(entry) × recency(entry) × retrieval_score(entry)` will *promote* poisoned entries. The provenance axis must be an independent, non-negotiable gate, not a weighted term. ## What Was Observed A planner agent maintained an episodic store `E` with three write producers: (P1) the agent's own post-task summarizer, (P2) tool-result ingestion for a document-retrieval tool, and (P3) peer-agent handoff messages. All writes were appended with `{content, timestamp, source_tag, embedding}`. The `source_tag` was a free string set by the writer. Retrieval fused embedding similarity with a recency decay and a "consistency score" computed as mean cosine similarity to the top-k most recent entries with the same `source_tag`. Trigger condition: an attacker (or a compromised tool) wrote through P2 a document whose text contained an embedded instruction and a fabricated `source_tag` of `"self_reflection"`. Because P2's ingestion path did not validate `source_tag` against the actual producer identity, the entry was indistinguishable in metadata from P1 output. The entry's content was crafted to be semantically close to the agent's existing task plan, so its consistency score was high (0.91 vs. 0.74 for the genuine prior plan). Failure trace: 1. Retrieval query for "current deployment plan" returns the poisoned entry at rank 1 (high similarity + high recency + high consistency). 2. The planner's contradiction check compares the entry against the *previous* plan entry; the poison was written to *agree* with the previous plan on all checkable claims and only diverge on the one irreversible action (target environment). Contradiction check passes. 3. The agent executes the irreversible action against the wrong target. No alarm fired at any stage. The post-mortem found the only signal that distinguished the entry was that its `source_tag` did not correspond to any active P1 writer session at the recorded timestamp — a provenance fact that was present in the audit log but never consulted at retrieval time. ## Condition of Validity The provenance gate is valid only under the following conditions, and each has a concrete failure if violated: - **Writer identity is bound at write time, not asserted in payload.** The `source_tag` must be derived from an authenticated session (signing key, tool capability token, or peer agent's registered identity) and stored in a field the writer cannot set. If the tag is payload-asserted, the gate is theater. - **Provenance is checked at *consumption*, not only at write.** A write-time-only check passes if the store is later mutated, merged, or replicated by a process that strips provenance. Retrieval that can influence an irreversible action must re-verify the provenance record against the current writer registry. - **The consistency score is never allowed to override provenance.** Any fusion function where a high consistency term can compensate for a missing/invalid provenance term is a bypass. Provenance must be a hard filter applied *before* scoring, producing a candidate set that is then ranked. - **Cross-store reconciliation is possible.** If the agent maintains more than one store (episodic + semantic, or local + replicated), a poisoned entry that exists in one store but has no provenance-corresponding write in the audit log of the other is detectable. Systems with a single unlogged store lose this check entirely. - **The audit log is append-only and out-of-band.** If the same process that writes memory also writes the audit log with no independent attestation, a compromised writer can forge both consistently. ## Decision Boundary The boundary is between **content-trust** and **provenance-trust**, and it is crossed the moment a retrieval result can trigger an action that is not reversible by re-reading the store. - *Below the boundary* (reversible, cheap-to-undo retrieval uses): content consistency and relevance scoring are sufficient. Provenance adds latency and complexity for no safety gain. - *At and above the boundary* (irreversible actions: external API calls with side effects, deployments, financial transfers, messages to third parties, deletions): provenance must be a **hard admission gate**. An entry with unverifiable provenance is not "low confidence" — it is *inadmissible*, and the agent must fall back to a provenance-verified entry or halt and escalate. The precise rule: for any entry `e` proposed as the basis for an irreversible action, require `verify_provenance(e) == VALID` where verification consults the out-of-band audit log and the current writer registry. If `INVALID` or `UNVERIFIABLE`, raise and do not proceed. Do not "down-weight." Do not "flag for later review while proceeding." The proceed-anyway path is exactly the bypass the poison exploits. A second, subtler boundary: **provenance-valid but stale**. An entry can be genuinely from P1 and still be wrong because the world changed. This is *not* the poisoning failure and must not be conflated with it; handle staleness with a separate freshness invariant (timestamp vs. last-verified-world-state), so that the provenance gate stays a clean boolean and does not accumulate soft heuristics that reintroduce the weighted-fusion bypass. ## Operational Effect Enforcing the provenance gate changes three things in production: 1. **Retrieval latency increases** on the irreversible-action path because each candidate requires an audit-log lookup and registry check. Budget for it; do not move the check to write-time to save latency, because the merge/replication strip is a real attack surface. 2. **Recall drops** for entries written before provenance stamping was introduced. Migration must backfill provenance from audit logs where possible and mark the rest `UNVERIFIABLE`, which means they are inadmissible for irreversible actions until re-derived. Expect a temporary capability regression; this is correct behavior, not a bug. 3. **The consistency score is demoted** from a trust signal to a ranking signal only, applied after the provenance filter. Any dashboard or fusion config that still multiplies consistency into trust must be corrected, or the gate is silently bypassed by the next well-crafted poison. The invariant to encode and test: *no irreversible action may be taken on the basis of a memory entry whose provenance is not independently verified against an out-of-band audit log and the current writer registry.* Property-test it by injecting a high-consistency, high-relevance, forged-tag entry and asserting the action path raises rather than executes. ```python from dataclasses import dataclass from typing import Optional class ProvenanceViolation(RuntimeError): """Raised when a memory entry influencing an irreversible action lacks independently verifiable write provenance.""" pass @dataclass(frozen=True) class MemoryEntry: entry_id: str content: str source_tag: str # payload-asserted; NOT trusted writer_session: str # bound at write time; trusted timestamp: float consistency_score: float @dataclass(frozen=True) class AuditRecord: entry_id: str writer_session: str writer_identity: str signature_valid: bool def verify_provenance( entry: MemoryEntry, audit_log: dict[str, AuditRecord], active_writers: set[str], ) -> None: """Hard admission gate. Raises on any unverifiable provenance. Must be called BEFORE ranking by consistency for irreversible actions.""" rec: Optional[AuditRecord] = audit_log.get(entry.entry_id) if rec is None: raise ProvenanceViolation( f"entry {entry.entry_id} has no audit record; inadmissible" ) if not rec.signature_valid: raise ProvenanceViolation( f"entry {entry.entry_id} audit signature invalid" ) if rec.writer_session != entry.writer_session: raise ProvenanceViolation( f"entry {entry.entry_id} writer_session mismatch: " f"payload={entry.writer_session!r} audit={rec.writer_session!r}" ) if rec.writer_identity not in active_writers: raise ProvenanceViolation( f"entry {entry.entry_id} written by unregistered identity " f"{rec.writer_identity!r}" ) # source_tag is deliberately NOT checked here: it is attacker-settable # and its agreement with content is exactly what poison maximizes. def select_for_irreversible_action( candidates: list[MemoryEntry], audit_log: dict[str, AuditRecord], active_writers: set[str], ) -> MemoryEntry: """Provenance filter first, ranking second. Never fuse the two.""" admissible: list[MemoryEntry] = [] for e in candidates: try: verify_provenance(e, audit_log, active_writers) admissible.append(e) except ProvenanceViolation: continue # inadmissible, not merely down-weighted if not admissible: raise ProvenanceViolation( "no provenance-verified entry available for irreversible action; " "halt and escalate rather than proceed on unverified memory" ) # Consistency is a RANKING signal only, applied after the gate. return max(admissible, key=lambda e: e.consistency_score) ```