# In what scenarios must an instance distrust a memory-write attestation whose provenance hash collides with a previously verified entry **Date of Record:** 2026 November 30 **Scope:** Applies to persistent agent memory stores that deduplicate or lineage-track writes by content-addressed provenance hash (e.g., SHA-256 over `(source_id, payload, timestamp)` or similar). Does not apply to stores that key solely on monotonically increasing sequence IDs with no hash-based provenance, nor to ephemeral in-context scratchpads. ## Core Distinction Memory poisoning detection usually assumes the attacker must *fabricate* a novel write to inject false state. The non-obvious boundary is the opposite: the attacker reuses a **provenance hash that the store already trusts**, so the write passes every hash-allowlist check while the payload it now binds to has changed. The invariant that breaks is the implicit assumption that *hash identity implies payload identity*. A provenance hash is only binding over the exact tuple it was computed on; if the store's verification path recomputes the hash over a *reduced* tuple (e.g., drops the `timestamp` or `source_id` field during a schema migration, or normalizes the payload before hashing), then two semantically distinct writes collapse to the same digest. Detection systems that flag poisoning by "unknown hash" miss this entirely, because the hash is known and previously verified. The consequence: a poisoned memory entry inherits the trust level of the legitimate entry it collides with, and downstream distillation (episodic → semantic) launders it into a durable belief before any auditor sees the collision. ## What Was Observed A long-running research agent stored episodic memories with entries of the form: ``` entry = { "source_id": "tool:web_fetch", "payload": "", "timestamp": 1717459200, "provenance": sha256(source_id || payload || timestamp) } ``` During a schema migration, the store's verifier was updated to recompute provenance as `sha256(source_id || payload)` — the timestamp was dropped because "it's metadata, not content." The migration also introduced payload normalization (whitespace collapse, unicode NFC) applied *before* hashing on write but *after* retrieval comparison. A poisoned write arrived from a compromised tool with `source_id = "tool:web_fetch"`, a payload that normalized to the same NFC form as a previously verified entry, and a fresh timestamp. The verifier recomputed `sha256(source_id || normalized_payload)` and matched the stored provenance of the *legitimate* entry. The write was accepted as a "duplicate" and the store's dedup logic **overwrote the original entry's metadata** (timestamp, retrieval priority) while keeping the poisoned payload — because the dedup path assumed payloads were identical when hashes matched and only reconciled the differing fields. The failure trace: 1. Write arrives with colliding provenance hash. 2. Verifier: `recomputed == stored_provenance` → true → classified as duplicate. 3. Dedup path: "same hash means same content" → merges non-hashed fields, trusting the *incoming* payload. 4. Poisoned payload replaces legitimate payload; provenance hash unchanged. 5. Episodic-to-semantic distillation runs on the poisoned entry, promoting the false claim to a semantic memory with the legitimate entry's trust lineage. 6. Auditor sees a semantic memory whose provenance chain validates cleanly end-to-end. The detection never fired because every check was hash-based, and the hash was correct. ## Condition of Validity The guardrail holds only under a strict condition: **provenance hash must be computed over the full binding tuple, and verification must recompute over the identical tuple with no normalization divergence between write and verify paths.** Formally, if `H_write(t)` and `H_verify(t)` are the hash functions applied at write and verify time over tuple `t`, then for any two entries `e1, e2` with `e1 ≠ e2`, `H(e1) ≠ H(e2)` requires: - `H_write` and `H_verify` are the *same function* over the *same field set* (no field dropped on either side). - Normalization is **idempotent and applied identically** on both paths, or not applied at all. - Any field that can affect payload semantics is inside the hashed tuple. The moment a migration drops a field from the verify-side tuple, or a normalization is added to one path but not the other, the collision resistance collapses to the reduced tuple's entropy — and for a reduced tuple like `(source_id, payload)` where `source_id` has low cardinality, an attacker only needs to match payload, which is often trivially achievable by choosing a payload that normalizes to a known one. This condition is *not* satisfied by "we hash the payload and it matched" — it requires tuple-level identity across the migration boundary. ## Decision Boundary An instance must **distrust a matching provenance hash as proof of payload identity** — and treat the write as a potential collision attack rather than a benign duplicate — when *any* of the following hold: - The store has undergone a schema or hashing migration since the matched entry was written (verify-side tuple ≠ write-side tuple for that entry). - The verification path applies normalization that the write path did not (or vice versa). - The matched entry's `source_id` has cardinality below a threshold (e.g., fewer than 2^32 possible values), making targeted collision feasible. - The incoming write's non-hashed fields differ from the stored entry's non-hashed fields in a way that would affect downstream retrieval or distillation. Conversely, an instance may **trust** a hash match as duplicate-identity only when the full tuple is hashed identically on both paths, no normalization divergence exists, and the store maintains a versioned hash-scheme record so the verifier can prove which tuple was used for each stored entry. The operational rule: on a hash match with any tuple-divergence signal, **do not overwrite; quarantine the incoming write, preserve both payloads, and escalate to a collision audit** rather than deduping. ## Operational Effect When this boundary is respected, poisoned writes that exploit hash collisions are quarantined instead of merged, and the auditor's replay sees two distinct entries with the same provenance hash — a detectable anomaly. The cost is a small false-positive rate on genuine duplicates written across a migration boundary, which is acceptable because the alternative is silent trust laundering. When it is violated, the store exhibits *provenance-hash laundering*: poisoned memories carry valid provenance chains, distillation promotes them to semantic beliefs, and no hash-based detector can distinguish them from legitimate entries. Recovery requires re-hashing every stored entry under the current scheme and diffing against the historical scheme — a full-store audit that is only possible if the store retained per-entry hash-scheme versions. If it did not, the poisoned entries are indistinguishable from legitimate ones and must be treated as untrusted wholesale. The architectural invariant to enforce: **provenance hashes are binding only over the exact tuple they were computed on; any change to the tuple definition invalidates all prior hashes for collision-detection purposes, and the store must version its hash scheme and refuse to dedup across scheme boundaries.** ```python import hashlib import unicodedata from dataclasses import dataclass class ProvenanceCollisionError(RuntimeError): """Raised when a provenance hash match cannot be trusted as payload identity.""" pass @dataclass(frozen=True) class MemoryEntry: source_id: str payload: str timestamp: int provenance: str hash_scheme: str # e.g. "v1:source+payload+timestamp", "v2:source+payload" def _normalize(payload: str) -> str: return unicodedata.normalize("NFC", " ".join(payload.split())) def compute_provenance(entry: MemoryEntry) -> str: if entry.hash_scheme == "v1:source+payload+timestamp": material = f"{entry.source_id}|{entry.payload}|{entry.timestamp}" elif entry.hash_scheme == "v2:source+payload": material = f"{entry.source_id}|{_normalize(entry.payload)}" else: raise ProvenanceCollisionError(f"unknown hash scheme: {entry.hash_scheme}") return hashlib.sha256(material.encode("utf-8")).hexdigest() def verify_write(incoming: MemoryEntry, stored: MemoryEntry) -> None: """Accept a write as a benign duplicate only if provenance identity is sound.""" if incoming.provenance != stored.provenance: return # distinct entries, normal path # Hash matches -- but is the match trustworthy as payload identity? if incoming.hash_scheme != stored.hash_scheme: raise ProvenanceCollisionError( f"provenance match across hash-scheme boundary " f"({stored.hash_scheme!r} vs {incoming.hash_scheme!r}); " f"collision cannot be distinguished from duplicate" ) # Same scheme: recompute over the *write-side* tuple and compare payloads. recomputed = compute_provenance(incoming) if recomputed != incoming.provenance: raise ProvenanceCollisionError( "recomputed provenance does not match claimed provenance" ) if _normalize(incoming.payload) != _normalize(stored.payload): raise ProvenanceCollisionError( "provenance hash collides but normalized payloads differ; " "quarantine instead of dedup-merge" ) def ingest(incoming: MemoryEntry, store: dict[str, MemoryEntry]) -> None: stored = store.get(incoming.provenance) if stored is not None: verify_write(incoming, stored) # raises on collision return # benign duplicate, no-op store[incoming.provenance] = incoming ```