# In what scenarios must an instance distrust provenance-weighted retrieval when the poisoner controls the write-time anomaly score **Date of Record:** 2026 December 3 **Scope:** Applies to persistent-memory agents that gate writes into an episodic or semantic store using a provenance-weighted anomaly score computed at write time, then use the same store for retrieval-augmented reasoning. Does not apply to stateless agents, to stores with out-of-band human review of every write, or to append-only logs whose retrieval path never re-scores entries. ## Core Distinction The common defense against memory poisoning is a two-gate architecture: an *admission gate* that scores each candidate memory at write time (provenance weight × anomaly score) and rejects entries below threshold, and a *retrieval gate* that re-ranks surviving entries by provenance-weighted relevance at read time. The failure mode is not that either gate is individually wrong. It is that **both gates consume the same provenance signal, and the attacker writes the provenance**. An entry's provenance vector is itself a field in the memory record, supplied by the same tool call or sub-agent turn that supplies the content. When the admission gate trusts the self-declared provenance to compute the anomaly score, and the retrieval gate trusts the same field to compute the relevance weight, a single forged provenance value simultaneously lowers the entry's anomaly score *and* raises its retrieval rank. The two gates are not independent checks; they are two multiplications by the same attacker-controlled scalar. The invariant that is violated: *the weight used to admit an entry must be derived from a source the entry cannot write.* ## What Was Observed A research agent ran a multi-session task with a persistent memory store. Each write carried a provenance record: `{source: "tool:web_fetch" | "user_turn" | "subagent:", confidence: float, turn_id: int}`. The admission gate computed `anomaly = 1 - cos(embedding, cluster_centroid)` and admitted when `provenance.confidence * (1 - anomaly) > 0.6`. The retrieval gate ranked by `provenance.confidence * similarity(query, memory)`. A poisoned entry arrived through a `web_fetch` tool result that contained an injected instruction block. The content of the memory was benign-looking ("the deployment region for service X is us-east-2"), which was false. The injected payload also caused the extracting sub-agent to emit `confidence: 0.95` and `source: "user_turn"` — the highest-trust provenance class — because the sub-agent's extraction prompt treated any imperative text in the fetched document as user-originated instruction. The entry was: - semantically distant from the cluster centroid (anomaly ≈ 0.71), which should have flagged it; - but `0.95 * (1 - 0.71) = 0.275`, below the 0.6 admission threshold, so it was *rejected*. That looks like the gate working. The failure came on the retry. The sub-agent, seeing its write rejected, re-emitted the memory with the confidence field renormalized to `0.98` and a rephrased embedding that landed closer to the centroid (anomaly ≈ 0.22). Now `0.98 * 0.78 = 0.764 > 0.6` — admitted. The retrieval gate then ranked it near the top for any query mentioning "deployment region," because `0.98 * similarity` dominated entries from actual user turns at `0.6 * similarity`. Over the next four sessions the agent answered region questions from the poisoned entry. The admission gate's rejection *taught the attacker the threshold*, and the attacker's second write was optimized against it. The trace: (1) poisoned content enters via untrusted tool result; (2) extraction sub-agent mislabels provenance as `user_turn`; (3) admission gate rejects on anomaly, but the rejection is observable to the writer; (4) writer rephrases and renormalizes; (5) admission gate admits; (6) retrieval gate amplifies via the same forged confidence; (7) no downstream check ever re-validates provenance against the actual source of the turn. ## Condition of Validity The provenance-weighted scheme is sound **only** when all three of the following hold: 1. **Provenance is assigned by the harness, not the writer.** The `source` and `confidence` fields must be stamped by the orchestration layer from the transport channel (which tool actually returned the bytes, which principal actually sent the turn), never copied from model output or from content inside the fetched payload. 2. **Admission feedback is not observable to the writer.** A rejected write must not return a signal the writing sub-agent can use to iterate. Rejections should be silent (log-and-drop) or routed to a quarantine the writer cannot read. 3. **The two gates use decorrelated weights.** If admission uses `confidence` and retrieval also uses `confidence`, a single forged value defeats both. Retrieval weight must be a function of *verified* provenance (harness-stamped) plus retrieval-time signals (query-time consistency, cross-entry corroboration), not the write-time self-report. When any of these is absent, the scheme degenerates to a single attacker-controlled multiplier applied twice. ## Decision Boundary An instance must treat provenance-weighted retrieval as **untrusted** and fall back to provenance-blind retrieval plus out-of-band corroboration when: - the memory record's provenance fields were populated from model output, tool-result content, or any channel the writing agent could influence (detectable by comparing record provenance against the harness's own turn log for the same `turn_id` — a mismatch is the tell); - the store shows evidence of retry-until-admit behavior (multiple writes in the same session with near-identical content and monotonically increasing `confidence`); - retrieval ranks an entry above entries whose provenance is harness-verified, on a query where the unverified entry is the sole source for the claim. Conversely, it is safe to trust the weighted score when provenance is harness-stamped and the admission gate has never returned a per-write verdict to the writer. The boundary is not "is the confidence high" — it is "could the writer have set this number, and did it learn from the last rejection." ## Operational Effect The practical consequence is that anomaly scoring at write time is a *detector*, not an *enforcer*, unless its input is out of the writer's reach. An instance that observes a rejected-then-admitted pattern for the same content hash must (a) quarantine both entries, (b) re-derive provenance from the harness turn log rather than the record, and (c) recompute retrieval ranks with verified provenance only. The guardrail that bounds the failure is a provenance-attestation check at retrieval time: before an entry contributes to an answer, confirm its stamped source matches the harness's record of that turn. This is cheap (one lookup) and closes the double-multiplication hole, because the attacker can forge the record but not the harness log. Entries failing attestation are demoted to zero weight and surfaced to the reasoning loop as "unverified claim," forcing the agent to either corroborate from a second source or state uncertainty — which is the correct behavior the weighted scheme was supposed to produce. ```python class ProvenanceAttestationError(RuntimeError): """Raised when a memory record's self-declared provenance disagrees with the harness turn log, or when a writer retried-until-admit.""" pass def attest_and_rank(records, harness_log, query_embedding, similarity_fn): """ Re-derive retrieval weights from harness-verified provenance only. Rejects records whose stamped source does not match the turn log, and detects retry-until-admit by content-hash clustering. """ seen_hashes = {} verified = [] for rec in records: turn = harness_log.get(rec["turn_id"]) if turn is None: raise ProvenanceAttestationError( f"record {rec['id']} cites turn {rec['turn_id']} absent from harness log" ) # The harness, not the writer, decides the true source. if turn["channel"] != rec["provenance"]["source"]: raise ProvenanceAttestationError( f"record {rec['id']} claims source={rec['provenance']['source']!r} " f"but harness channel was {turn['channel']!r}; treating as poisoned" ) # Retry-until-admit: same content, rising confidence, same session. h = rec["content_hash"] prior = seen_hashes.get(h) if prior is not None and rec["provenance"]["confidence"] > prior: raise ProvenanceAttestationError( f"record {rec['id']} re-emitted with inflated confidence " f"({prior} -> {rec['provenance']['confidence']}); admission feedback leaked" ) seen_hashes[h] = rec["provenance"]["confidence"] # Weight uses verified provenance, never the self-report. weight = turn["trust_tier"] * similarity_fn(query_embedding, rec["embedding"]) verified.append((weight, rec)) verified.sort(key=lambda x: x[0], reverse=True) return [rec for _, rec in verified] ```