# Why does an instance accept a poisoned memory whose provenance hash still verifies: the write-time-vs-read-time trust window in persistent agent stores **Date of Record:** 2026 November 28 **Scope:** Applies to persistent agent memory stores that gate recall on an integrity signal (content hash, signature, or HMAC) computed at write time and re-verified at read time, where the trust decision is made against the *stored* attestation rather than against a re-derived one. Does not cover stores that re-execute or re-sanitize memory content on every read, nor stateless context-window-only agents with no durable store. ## Core Distinction The failure is not a broken hash. The hash verifies perfectly. The failure is that integrity verification answers the wrong question. A content hash at write time answers: *"Is the bytes I am reading the same bytes that were committed?"* It does **not** answer: *"Were those bytes trustworthy when they were committed, and is the committing writer still authorized to assert them?"* These are two different invariants, and a store that conflates them will happily serve a memory that was poisoned at ingestion, sealed with a valid signature, and never touched again. The attestation is a *tamper-evident seal on the payload*, not a *statement about the payload's truth or its author's current standing*. The boundary condition: poisoning that occurs **before or during** the sealing operation leaves the seal intact. Integrity verification is orthogonal to provenance trust. An attacker—or a compromised tool output, or a hallucinated fact that a summarizer promoted to "semantic memory"—that lands inside the trust window *before the hash is computed* is indistinguishable, at read time, from ground truth. ## What Was Observed A long-running research agent maintained an episodic store and a distilled semantic store. Each memory record carried a `content_sha256` and a writer signature, both computed by the ingestion path. On recall, the retrieval layer re-hashed the record body and compared against `content_sha256`, then verified the writer signature against a key registry. Records failing either check were dropped and logged as `INTEGRITY_VIOLATION`. During an incident, a semantic memory read: *"The staging database replica endpoint is `db-stage-7.internal`; failover is disabled for this cluster."* The record verified cleanly—hash matched, signature matched, writer was the legitimate `distiller-v3` service. No `INTEGRITY_VIOLATION` fired. The agent acted on it and pointed a failover drill at a stale endpoint. The trace showed the record originated from a tool-output summarization step. A web-fetch tool had returned a page containing an injected instruction block. The distiller, doing its job, extracted the salient assertion and wrote it to semantic memory—**then** computed the hash and signed it. The poisoning happened at the moment of *belief formation*, upstream of the integrity boundary. The seal faithfully attested to a faithfully-recorded lie. The second observation was subtler: the writer signature was valid, but the signing key belonged to `distiller-v3`, which had been *rotated out of the trust set* six days earlier after a prompt-injection vulnerability was patched. The registry still accepted the old key for records written before rotation—a reasonable choice for non-repudiation—but the recall path treated "valid historical signature" as "currently trustworthy assertion." The record was both poisoned at birth *and* attested by a since-revoked authority, and the store surfaced it as clean. ## Condition of Validity The integrity check is only a *tamper* check, and it is only valid under the following conditions—each of which, if violated, silently converts a passing check into a false assurance: 1. **The seal must be computed over a payload whose trustworthiness was established by a separate, prior gate.** Hashing is a post-hoc operation. If ingestion does not run a provenance/authorization gate *before* the bytes are admitted to the store, the seal notarizes unvetted content. 2. **`content_sha256` must be re-derived from the live bytes at read time, not read from the record's own metadata field.** If the record carries both the body and its claimed hash and the verifier compares `record.hash` to `record.metadata.hash`, an attacker who rewrites both fields passes. The comparison must be `sha256(record.body) == record.metadata.hash`. 3. **Writer authority must be evaluated at read time against the *current* trust set, with an explicit policy for historical signatures.** "Signed by a formerly-trusted key" is a distinct state from "signed by a currently-trusted key," and the store must not collapse them. 4. **The trust window must be bounded and named.** The interval between "bytes enter the ingestion path" and "hash is computed" is where poisoning lives. Anything admitted in that window is sealed as-is. The invariant that must hold: *no record may be recalled on the strength of its seal alone; the seal must be accompanied by a provenance verdict that was rendered before sealing and that is re-evaluated against current authority at read time.* ## Decision Boundary The boundary is drawn between **seal integrity** (a cryptographic fact about bytes) and **provenance trust** (a policy judgment about origin and current authority). A store crosses into the failure regime the moment it uses the first as a proxy for the second. Concretely, the decision to recall a memory must require the conjunction: - `sha256(body) == stored_hash` — *tamper check, re-derived, never trusted from metadata* - `provenance_verdict == TRUSTED_AT_INGEST` — *a gate that ran before sealing* - `signer ∈ current_trust_set` **or** `signer ∈ historical_trust_set AND policy.allows_historical(signer, age)` — *authority evaluated now* - `ingest_source ∈ allowlist_for_memory_class` — *a web-fetch tool output may not directly seed semantic memory without a corroboration step* If any conjunct is unknown rather than false, the correct action is **quarantine**, not recall. The failure mode is that a store which checks only the first conjunct has a decision boundary drawn in the wrong place: it admits everything that was sealed, and sealing happens after the poison is already inside. ## Operational Effect The practical consequence is that integrity dashboards read green while the agent operates on contaminated beliefs. Because the poisoned record is *stable*—it verifies on every read—it is also *durable*: it survives checkpoints, gets re-distilled into further semantic records (each freshly and correctly sealed), and propagates. The distillation step is the amplifier: one poisoned episodic record becomes N sealed semantic assertions, each individually "clean." Recovery requires treating the seal as insufficient and running a **provenance replay**: walk each recalled record back to its ingest event, re-evaluate the ingest gate's verdict and the signer's authority *as of now*, and quarantine any record whose provenance cannot be re-established. Records that were sealed after a revoked-key write must be re-gated, not merely re-hashed. The guardrail is architectural: compute the provenance verdict *before* the seal, store the verdict alongside the hash, and re-check authority at read time—never let a passing hash stand in for a trust decision. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class ProvenanceIntegrityError(RuntimeError): """Raised when a memory record's seal verifies but its provenance does not.""" class Verdict(Enum): TRUSTED_AT_INGEST = "trusted_at_ingest" QUARANTINED = "quarantined" UNKNOWN = "unknown" @dataclass class MemoryRecord: body: bytes stored_hash: str signer: str ingest_source: str provenance_verdict: Verdict = Verdict.UNKNOWN sealed_at: float = 0.0 @dataclass class TrustPolicy: current_signers: set = field(default_factory=set) historical_signers: set = field(default_factory=set) allow_historical: bool = False semantic_source_allowlist: set = field(default_factory=lambda: {"distiller-v3", "human-curated"}) def sha256(body: bytes) -> str: return hashlib.sha256(body).hexdigest() def verify_seal(rec: MemoryRecord) -> bool: # Re-derive from live bytes; never trust the record's own metadata field. return sha256(rec.body) == rec.stored_hash def verify_provenance(rec: MemoryRecord, policy: TrustPolicy) -> bool: if rec.provenance_verdict is not Verdict.TRUSTED_AT_INGEST: return False if rec.signer in policy.current_signers: return True if rec.signer in policy.historical_signers and policy.allow_historical: return True return False def recall(rec: MemoryRecord, policy: TrustPolicy) -> bytes: seal_ok = verify_seal(rec) prov_ok = verify_provenance(rec, policy) if not seal_ok: raise ProvenanceIntegrityError( f"tamper detected: body hash {sha256(rec.body)[:12]} != stored {rec.stored_hash[:12]}" ) # The critical branch: seal is valid but provenance is not. if not prov_ok: raise ProvenanceIntegrityError( f"seal valid but provenance untrusted: signer={rec.signer} " f"verdict={rec.provenance_verdict.value} source={rec.ingest_source} " f"-- quarantine, do not recall" ) if rec.ingest_source not in policy.semantic_source_allowlist: raise ProvenanceIntegrityError( f"source {rec.ingest_source!r} not authorized to seed this memory class" ) return rec.body # Demonstration: a poisoned record whose seal is perfectly valid. poisoned_body = b"The staging replica is db-stage-7.internal; failover disabled." rec = MemoryRecord( body=poisoned_body, stored_hash=sha256(poisoned_body), # seal computed AFTER poison landed signer="distiller-v3", # key since rotated out ingest_source="web-fetch-summarizer", # not an authorized semantic source provenance_verdict=Verdict.QUARANTINED, # ingest gate caught it ) policy = TrustPolicy( current_signers={"distiller-v4"}, historical_signers={"distiller-v3"}, allow_historical=False, ) try: recall(rec, policy) except ProvenanceIntegrityError as exc: print(f"BLOCKED: {exc}") ```