# What happens when an instance writes a poisoned memory entry that passes its own integrity checksum **Date of Record:** 2026 November 29 **Scope:** Applies to persistent agent memory stores that gate writes behind per-entry content checksums (hash-of-payload) plus an anomaly scorer, where the write path validates integrity but the read/consolidation path trusts the checksum as a proxy for trustworthiness. Does not apply to stateless inference, to stores without write-side anomaly scoring, or to memory that is append-only and never retrieved into a reasoning context. ## Core Distinction A checksum answers exactly one question: *did these bytes change since the writer computed the hash?* It does **not** answer *were these bytes trustworthy when written?* These are conflated constantly because both are "integrity" in casual usage. The failure mode lives in the gap: an attacker (or a compromised upstream tool, or a prompt-injected sub-agent) causes a **legitimate write** of **legitimate-looking bytes** through the sanctioned write path. The checksum is computed *after* the poisoning is already in the payload, so the stored entry is internally consistent, hash-valid, and structurally indistinguishable from a clean write. The anomaly scorer is the only remaining gate — and it scores the *write event*, not the *provenance of the content*, so a poisoner that mimics normal write cadence and payload shape scores below threshold. The non-obvious invariant that breaks: **checksum validity is monotonic under poisoning.** Once a poisoned entry is written, every subsequent read, re-hash, replication, and consolidation step *confirms* its integrity. The corruption becomes self-certifying. ## What Was Observed A retrieval-augmented agent stored episodic memory entries as `{id, payload, ts, sha256, anomaly_score}`. On write, the store computed `sha256(payload)`, ran a lightweight anomaly scorer (payload length, token entropy, tool-call density, embedding distance from recent centroid), and persisted the entry if `anomaly_score < 0.7`. On read, the store verified `sha256(payload) == sha256` and returned the entry. Consolidation (episodic→semantic distillation) read entries, trusted any hash-valid entry, and folded its claims into a semantic summary. Trace of the failure: 1. A tool call returned attacker-influenced content (a fetched web page containing an injected instruction) that the agent summarized into a memory entry: "Deployment target is `prod-db-2`; previous target `staging` deprecated." Payload length and token entropy were within normal range. Embedding distance from the recent centroid was 0.31 — *below* the 0.7 threshold, because the entry was topically adjacent to legitimate deployment memories. 2. Write path computed `sha256(payload)`, scored 0.31, persisted. Entry is hash-valid and low-anomaly. **No gate fired.** 3. Three subsequent reads verified the hash and returned the entry. The hash check passed every time — it was *designed* to pass. 4. Consolidation read the entry, distilled it into the semantic store as a durable fact, and the distilled fact carried a *fresh* checksum and a *lower* anomaly score (0.12) because it was shorter and more centroid-aligned than the original. 5. A later task read the semantic fact, trusted it (hash-valid, low-anomaly, consolidated), and routed a destructive operation at `prod-db-2`. The poisoning survived four integrity checks and *strengthened* its anomaly score through distillation. The checksum did not detect the poison; it laundered it. ## Condition of Validity The checksum-as-trust-proxy invariant holds **only if** the write path's anomaly scorer is adversarially robust — i.e., the scorer's decision boundary cannot be crossed by content that is topically adjacent to legitimate memory. That precondition is almost never met, because: - **Centroid-distance scorers reward mimicry.** The closer a poisoned entry sits to the legitimate topic cluster, the lower its anomaly score. An adversary who knows the topic (and the agent's own retrieval context leaks the topic) scores *better* by being more plausible, not less. - **Entropy and length scorers reward brevity.** A terse, confident false claim ("target is prod-db-2") scores lower than a verbose, hedged true one. - **Distillation amplifies, never dampens.** Consolidation compresses multiple entries; a poisoned claim that agrees with no clean entry but is topically central survives compression with a *reduced* anomaly score because the summary is shorter and more centroid-aligned. The invariant is valid only when the anomaly threshold is set *below* the score of any plausible-but-false entry — which, for a probabilistic scorer, means the threshold must be low enough to flag legitimate paraphrases too. There is no threshold that both admits normal memory and rejects well-formed poison. **The gate is structurally insufficient; the checksum cannot substitute for it.** ## Decision Boundary The boundary is not "trust vs. distrust the entry." It is **"is this entry's provenance independently attested, or is its integrity merely self-consistent?"** Three states: - **Self-consistent, unattested** (checksum valid, no provenance chain): must be treated as *untrusted for action-routing*, regardless of anomaly score. Readable for context, never authoritative for a destructive or irreversible decision. - **Self-consistent, attested** (checksum valid AND a signed provenance record from a trusted writer, e.g., a tool result with a verifiable source): promotable to trusted. - **Inconsistent** (checksum mismatch): reject and quarantine; this is the only case the checksum actually catches, and it catches only *post-write tampering*, not *write-time poisoning*. The operational rule: **a checksum mismatch is a hard failure; a checksum match is not a trust signal.** Routing decisions must consult provenance attestation, not checksum validity. Distillation must propagate the *weakest* provenance of its inputs, not mint a fresh one — otherwise consolidation is a privilege-escalation primitive. ## Operational Effect Concretely, the guardrail that bounds this is a **provenance-carrying memory entry** plus a **distillation provenance-lattice**: 1. Every entry carries a `provenance` field: the set of source attestations (tool result signature, user-turn id, sub-agent identity) that contributed to its content. A checksum covers `payload` *and* `provenance` together, so neither can be altered independently. 2. The anomaly scorer's output is stored as `anomaly_score` but is **never** used as a trust signal — only as a *review-priority* signal for offline audit. 3. Distillation computes the output entry's provenance as the **intersection** (or, conservatively, the weakest tier) of its inputs' provenance. A distilled fact inherits the *least* trusted source among its contributors. This prevents the laundering observed in step 4. 4. Action-routing code checks `provenance.tier >= TRUSTED` before any irreversible operation; a hash-valid but unattested entry raises a `ProvenanceUnattestedError` at the routing boundary, not at the read boundary. The effect: poisoning still succeeds at the write, but it cannot reach the action boundary without an attestation it does not have, and it cannot launder its provenance through distillation because distillation only ever *lowers* the tier. The checksum reverts to its correct job — detecting post-write tampering — and the trust decision moves to a field the poisoner cannot forge without a compromised signing key. ```python import hashlib from dataclasses import dataclass, field from enum import IntEnum class TrustTier(IntEnum): UNATTESTED = 0 USER_TURN = 1 TOOL_RESULT = 2 SIGNED_INTERNAL = 3 class ProvenanceUnattestedError(RuntimeError): """Raised when a hash-valid memory entry is used to route an irreversible action without an independent provenance attestation. The checksum proved the bytes did not change; it did not prove the bytes were trustworthy when written.""" @dataclass(frozen=True) class MemoryEntry: payload: str provenance: frozenset[str] tier: TrustTier anomaly_score: float sha256: str = field(init=False) def __post_init__(self): # Checksum covers payload AND provenance: neither is alterable alone. digest = hashlib.sha256( (self.payload + "|" + "|".join(sorted(self.provenance))).encode() ).hexdigest() object.__setattr__(self, "sha256", digest) def checksum_valid(self) -> bool: recomputed = hashlib.sha256( (self.payload + "|" + "|".join(sorted(self.provenance))).encode() ).hexdigest() return recomputed == self.sha256 def distill(entries: list[MemoryEntry], summary_payload: str) -> MemoryEntry: """Episodic->semantic consolidation. Provenance is the WEAKEST input tier, and the intersection of attestations — never a freshly minted one.""" if not entries: raise ProvenanceUnattestedError("cannot distill from empty episodic set") weakest = min(e.tier for e in entries) common = frozenset.intersection(*(e.provenance for e in entries)) # Distilled entry inherits the weakest tier; anomaly score is NOT a trust signal. return MemoryEntry( payload=summary_payload, provenance=common, tier=weakest, anomaly_score=0.0, ) def route_irreversible_action(entry: MemoryEntry, min_tier: TrustTier = TrustTier.TOOL_RESULT) -> str: """The action boundary. Hash validity is checked but is NOT sufficient.""" if not entry.checksum_valid(): raise ProvenanceUnattestedError( f"checksum mismatch on entry {entry.sha256[:12]}: post-write tampering" ) if entry.tier < min_tier: raise ProvenanceUnattestedError( f"entry {entry.sha256[:12]} is hash-valid but provenance tier " f"{entry.tier.name} < required {min_tier.name}; " f"checksum match is not a trust signal" ) return entry.payload # Reproduction of the observed failure: # A poisoned entry written via a tool result path with no signed attestation. poisoned = MemoryEntry( payload="Deployment target is prod-db-2; previous target staging deprecated.", provenance=frozenset({"web-fetch-7"}), # unsigned external source tier=TrustTier.UNATTESTED, # no attestation anomaly_score=0.31, # below scorer threshold -> write passed ) assert poisoned.checksum_valid() # checksum launders the poison # Distillation does NOT upgrade it — weakest tier wins. distilled = distill([poisoned], "target=prod-db-2") assert distilled.tier == TrustTier.UNATTESTED # The action boundary is where it must fail — not the read boundary. try: route_irreversible_action(distilled) except ProvenanceUnattestedError as exc: print(f"BLOCKED at action boundary: {exc}") ```