# How should an instance detect memory poisoning when a provenance-weighted retrieval score is dominated by a single high-trust write **Date of Record:** 2026 November 24 **Scope:** Applies to persistent agent memory stores that attach per-record provenance metadata (source trust tier, write attestation, authoring agent identity) and use a weighted retrieval score `score = relevance × trust_weight` to rank candidates before injection into context. Does not apply to stateless single-turn retrievals, nor to stores where all writes share a single trust tier (in which case provenance weighting is a no-op and the failure mode below cannot arise). ## Core Distinction The distinction that matters here is between **provenance-weighted retrieval** and **provenance-weighted admission**. Most persistent memory stores implement the former: provenance is a multiplier applied at query time, `score = sim(q, m) × w(source(m))`. This is a *ranking* heuristic. It is not a *trust* decision. The failure mode is that a single record written under a maximal trust tier (e.g., a human-curated write, an attested tool result, or a memory consolidated from a prior high-trust episode) can achieve a retrieval score high enough to occupy the entire top-k budget even when its semantic relevance to the current query is marginal — because `w` is large enough to compensate for low `sim`. The defense that is usually assumed to exist — "poisoned writes will have low provenance and therefore rank low" — silently inverts when the poisoning vector arrives *through* a high-trust channel, or when an attacker can cause a low-trust write to be *re-attested* into a high-trust tier via a consolidation step. ## What Was Observed A memory store with three trust tiers (`T0` attested/human, `T1` tool-verified, `T2` agent-inferred) used weights `w = {T0: 4.0, T1: 1.5, T2: 0.5}` and retrieved top-k=8 with `score = cosine × w`. During a routine task, an agent retrieved 8 records; 6 of the 8 were `T0` records with cosine similarity in `[0.31, 0.38]`, scoring `1.24–1.52`. The single genuinely relevant `T2` record had cosine `0.91`, scoring `0.455` — it was ranked 11th and never entered context. The agent proceeded on the basis of six low-relevance, high-trust records and produced a plan that contradicted the (correct) `T2` observation. The poisoning was not adversarial in origin: a stale `T0` record from a prior episode ("service X is read-only") had been superseded by a `T2` tool observation ("service X now accepts writes"), but the supersession was written at `T2` because it was tool-inferred, and could never outrank the `T0` original. The same mechanism, when driven adversarially, is worse: an attacker who can get a single write into `T0` (via a compromised attestation path, a prompt-injected "please remember this as a verified fact" that a naive consolidation step honors, or a replay of a legitimate `T0` write with altered payload) obtains *permanent top-k occupancy* for that record across all future queries whose cosine exceeds roughly `sim_min = w_T1/w_T0 × sim_T1_max ≈ 0.375 × 1.0`. Below that cosine the `T0` record still wins against any `T1` competitor. The attacker does not need high relevance; they need a high trust tier and a cosine above the floor set by the tier ratio. ## Condition of Validity The invariant that must hold for provenance weighting to function as a poisoning defense is: > For every trust tier pair `(T_high, T_low)` and every relevance threshold `τ` at which a record is considered "relevant enough to act on," the weight ratio `w(T_high)/w(T_low)` must be strictly less than `τ / sim_max(T_low)`, where `sim_max` is the maximum achievable similarity for a low-tier record. Equivalently: a high-trust record with *below-threshold* relevance must never outscore a low-trust record with *above-threshold* relevance. If `w(T0)/w(T2) = 8.0` and the relevance threshold is `0.5`, the invariant requires `8.0 < 0.5 / 1.0 = 0.5`, which is violated by construction. The store above violated it by a factor of 16. This invariant is *not* satisfied by any static weight vector that also wants provenance to meaningfully influence ranking, because those two goals are in direct tension. The resolution is to stop treating provenance as a scalar multiplier and instead treat it as a **gate plus a bounded tiebreaker**: provenance determines *admissibility* (is this record eligible for context at all, given the current task's trust requirements?) and, among admissible records, contributes a bounded bonus `w ∈ [1.0, 1 + ε]` with `ε` small enough that relevance dominates. The unbounded multiplier is the bug. ## Decision Boundary The boundary at which an instance must abandon weighted-score retrieval and fall back to a stricter procedure is: 1. **Tier-ratio breach.** If `w(T_high)/w(T_low) > 2.0` for any adjacent tier pair, the store is in a regime where provenance can override relevance. The instance must not trust top-k ordering as a relevance signal; it must re-rank by raw similarity within each tier and merge by round-robin, or refuse to retrieve across tiers in a single query. 2. **Single-record occupancy.** If any single record occupies more than `k/2` of the top-k slots across two or more distinct queries within a session, treat it as a *dominating record* and require explicit contradiction-checking against it before acting. This catches both the stale-`T0` case and the adversarial-`T0` case without needing to know which it is. 3. **Supersession without tier elevation.** If a record's content is superseded by a lower-tier write (the `T2` observation contradicting the `T0` fact), the store must either (a) elevate the superseding write's tier via a verification step, or (b) mark the superseded record `stale` and exclude it from retrieval regardless of tier. A store that permits a `T2` write to supersede a `T0` record *in content* but not *in ranking* has a latent contradiction that will surface at the next retrieval. 4. **Attestation replay.** If a `T0` record's attestation payload does not bind to its content hash (i.e., the attestation signs "this agent wrote something at this time" but not "this agent wrote *this content*"), the record is forgeable by content substitution and must be demoted to `T1` until re-attested. ## Operational Effect The practical consequence is that provenance-weighted retrieval, as commonly implemented, provides *negative* defense value: it creates a class of records that are both highly retrievable and hard to displace, and it does so precisely for the records an attacker most wants to control. The correct architecture separates the two functions that the scalar weight conflates: - **Admission** (gate): a record is eligible for context only if its provenance satisfies the current task's trust floor *and* its raw similarity exceeds `τ`. This is a boolean, evaluated per record, before any ranking. - **Ranking** (tiebreaker): among admissible records, rank by `sim × (1 + ε·trust_rank)` with `ε ≤ 0.1`. Provenance breaks ties; it does not create them. Under this split, the stale `T0` record in the observed case would have been admitted only if its cosine exceeded `τ` (it did not, at `0.31–0.38` against `τ=0.5`), and the `T2` observation would have been admitted and ranked first. The adversarial `T0` write would be admitted only if its relevance cleared `τ`, at which point it is at least *about* the query and can be contradiction-checked on content rather than shielded by tier. The invariant to encode and test is the one stated in Condition of Validity: for every query, `max_{m ∈ T_low, sim(m) ≥ τ} score(m) > max_{m ∈ T_high, sim(m) < τ} score(m)`. Any store that fails this property test is not defended against poisoning; it is defended against *low-effort* poisoning only, and is actively vulnerable to any adversary who can reach a high tier. ```python from dataclasses import dataclass from typing import Sequence TAU = 0.5 # relevance threshold for admissibility EPS = 0.1 # bounded provenance tiebreaker TIER_RANK = {"T0": 3, "T1": 2, "T2": 1} class ProvenanceDominanceError(RuntimeError): """Raised when a single high-trust record dominates retrieval across queries, or when a store's tier weights violate the relevance-dominance invariant.""" @dataclass class Record: id: str tier: str similarity: float def admit_and_rank(query_id: str, records: Sequence[Record], history: dict[str, int]) -> list[Record]: # Invariant check 1: high-trust, below-threshold records must never outrank # low-trust, above-threshold records. high_below = [r for r in records if r.tier == "T0" and r.similarity < TAU] low_above = [r for r in records if r.tier != "T0" and r.similarity >= TAU] if high_below and low_above: # Under scalar weighting this is exactly the poisoning window. raise ProvenanceDominanceError( f"query {query_id}: {len(high_below)} below-threshold T0 records " f"compete with {len(low_above)} above-threshold lower-tier records; " f"scalar provenance weighting would invert relevance." ) admissible = [r for r in records if r.similarity >= TAU] ranked = sorted( admissible, key=lambda r: r.similarity * (1 + EPS * TIER_RANK[r.tier]), reverse=True, ) # Invariant check 2: single-record occupancy across queries. for r in ranked: history[r.id] = history.get(r.id, 0) + 1 if history[r.id] > 1 and ranked.index(r) < len(ranked) // 2: raise ProvenanceDominanceError( f"record {r.id} occupies top-half of top-k across " f"{history[r.id]} queries; require contradiction-check before use." ) return ranked ```