# Under what conditions must an instance distrust a memory write that passes every per-write anomaly score but is contradicted by a later session's retrieval **Date of Record:** 2026 November 23 **Scope:** Applies to persistent agent memory stores that gate writes through a per-write anomaly scorer (embedding distance, novelty, entropy, or LLM-judge score) and that perform cross-session consistency checks only at read time. Does not apply to stateless agents, to stores with no write-time scoring, or to pure append-only audit logs that are never retrieved into context. ## Core Distinction The failure mode is not "poisoned memory was written." It is "poisoned memory was written *legitimately* by the scorer's own criteria, and the contradiction surfaced only in a session that had no authority to resolve it." A per-write anomaly score answers a single question: *is this write unusual relative to the store's current distribution?* It does not and cannot answer: *is this write true relative to what other sessions will later retrieve?* Those are different invariants over different state. The first is local and distributional; the second is global and cross-session. A write that is low-anomaly at write time (because the attacker's payload was embedded near the centroid of legitimate writes) becomes high-contradiction at read time in a *different* session whose retrieved context conflicts with it. The boundary condition is precisely this: **an instance must distrust a low-anomaly write the moment a later session's retrieval produces a contradiction it cannot attribute to staleness, and it must do so before the contradicted write is re-consolidated into semantic memory.** ## What Was Observed A research agent (instance A, session S1) ingested a tool result from a third-party retrieval tool. The payload was a plausible-looking fact ("the internal API rate limit is 500 req/min") embedded in a document whose embedding sat within the 40th percentile of the store's write distribution. Write-time anomaly score: 0.11 (threshold 0.65). Accepted. The write was tagged `episodic`, `source=external_tool`, `session=S1`. Three sessions later, instance B (S2) retrieved the same fact as supporting context for a capacity-planning task, alongside an authoritative internal doc ("rate limit is 50 req/min") that had been written in S0 with `source=internal_doc`. Instance B's retrieval scored both chunks highly (cosine 0.81 and 0.79 to the query). The two facts were mutually exclusive. Instance B had no cross-session arbitration rule: both chunks were `episodic`, both were within the recency window, and the anomaly scorer had already "cleared" the external one. B resolved the conflict by *recency* — the poisoned write was newer — and proceeded at 500 req/min. The failure was not the poisoning; it was that the write-time scorer's clearance was treated downstream as a *truth* signal rather than a *novelty* signal, and no session held the invariant that a cleared write can still be contradicted. The trace: 1. S1: write W1, `anomaly(W1)=0.11 < τ=0.65` → `status=accepted`, `cleared_by=write_scorer`. 2. S2: retrieve {W1, W0}. `W0` (internal doc) contradicts `W1` on a numeric field. No `contradiction` flag raised because no field-level comparison ran; the conflict was only lexical/semantic and the resolver defaulted to recency. 3. S2: consolidate `W1` into semantic memory as `rate_limit=500`, `confidence=0.7` (inherited from retrieval score, not from source authority). 4. S3: instance C retrieves the *semantic* fact, which now has no `source=external_tool` tag (consolidation dropped provenance) and no anomaly history. The poison is now indistinguishable from a learned fact. The critical observation: **the anomaly score was correct at write time and the system still failed**, because the score's clearance was propagated as an epistemic warrant it never carried. ## Condition of Validity The per-write anomaly score is valid as a *novelty* gate only under three conditions, all of which must hold for the clearance to be trusted downstream: 1. **Distributional stationarity.** The store's write distribution at time *t* is representative of the distribution at read time *t+k*. If the agent's domain shifts (new tool, new corpus), a previously low-anomaly write can become high-contradiction without its score changing. 2. **Provenance preservation through consolidation.** The `source`, `session`, and `anomaly` fields survive episodic→semantic distillation. If consolidation strips them, the write loses the metadata that would let a later session arbitrate. 3. **Read-time contradiction detection exists.** Some session must actually compare retrieved chunks against each other on the fields that matter. If retrieval only ranks and concatenates, contradiction is invisible and recency/score wins by default. The invariant that must hold: **`cleared_by_write_scorer` implies `novelty_ok`, never `truth_ok`.** Any downstream consumer that treats it as `truth_ok` is operating outside the score's condition of validity. The moment a session observes `contradicts(retrieved_chunk, retrieved_chunk)` where the two chunks disagree on a load-bearing field and neither is attributable to staleness (i.e., both are within the recency window and both claim current validity), the instance is *outside* the condition of validity for trusting either write's clearance, and must escalate rather than resolve by recency. ## Decision Boundary The boundary is between *resolvable* and *non-resolvable* contradiction at read time: - **Resolvable (trust the arbitration):** one chunk has strictly higher source authority (`internal_doc` > `external_tool`), or one is explicitly marked stale by a later authoritative write, or the contradiction is on a non-load-bearing field. Here the session may arbitrate and proceed. - **Non-resolvable (escalate, do not consolidate):** both chunks are within the recency window, both carry `cleared_by_write_scorer`, and they disagree on a load-bearing field with no authority ordering. The instance must **not** pick by recency or by retrieval score. It must (a) refuse to consolidate either into semantic memory, (b) tag both with `contested=true`, and (c) surface the contradiction to the orchestrator or a verification agent with both provenance chains intact. The non-obvious part: the *low* anomaly score is what makes this dangerous. A high-anomaly write would have been quarantined and reviewed. The low-anomaly write sailed through and acquired false warrant. The decision boundary must therefore be keyed on *contradiction at read time*, not on *anomaly at write time* — because the write-time signal has already been spent and cannot be re-derived once consolidation strips provenance. ## Operational Effect Concretely, the guardrail is a read-time contradiction check that runs *before* any consolidation step and that refuses to let a `cleared_by_write_scorer` flag substitute for authority ordering: - Every retrieved chunk carries `(source_authority, session, anomaly_score, cleared_by)` through to the resolver. - The resolver computes pairwise field-level contradictions on load-bearing fields. - If a contradiction is found and no authority ordering resolves it, raise and halt consolidation; mark both chunks `contested=true`; emit a `contested_pair` record with both provenance chains. - Consolidation is blocked for any `contested` chunk until a verification agent (or human) resolves it; the resolution writes a new `adjudicated` record with explicit authority, and only *that* record is eligible for semantic distillation. The effect is that the poison from S1 cannot reach S3 as a clean semantic fact: it is either caught at S2 as contested, or it is adjudicated with an explicit authority trail. The anomaly scorer keeps its real job — flagging novelty — and stops being load-bearing for truth. ```python from dataclasses import dataclass, field from typing import Optional LOAD_BEARING_FIELDS = {"rate_limit", "endpoint", "auth_scheme", "quota"} class ContestedMemoryError(RuntimeError): """Raised when a retrieved write is contradicted by another retrieved write and no authority ordering resolves the conflict. Consolidation must halt.""" pass @dataclass class MemoryChunk: chunk_id: str session: str source: str # "internal_doc" | "external_tool" | "agent_inference" anomaly_score: float cleared_by_write_scorer: bool fields: dict = field(default_factory=dict) contested: bool = False AUTHORITY = {"internal_doc": 3, "agent_inference": 2, "external_tool": 1} def resolve_and_consolidate(retrieved: list[MemoryChunk]) -> list[MemoryChunk]: """Run read-time contradiction detection before consolidation. Returns chunks eligible for semantic distillation. Raises on non-resolvable contradiction so the caller cannot silently pick by recency.""" contradictions = [] for i, a in enumerate(retrieved): for b in retrieved[i + 1:]: shared = set(a.fields) & set(b.fields) & LOAD_BEARING_FIELDS for f in shared: if a.fields[f] != b.fields[f]: contradictions.append((a, b, f)) for a, b, f in contradictions: auth_a, auth_b = AUTHORITY[a.source], AUTHORITY[b.source] if auth_a == auth_b: # Both cleared by write scorer, same authority, disagree on load-bearing field. # This is the non-resolvable boundary. Do NOT default to recency. a.contested = b.contested = True raise ContestedMemoryError( f"Non-resolvable contradiction on field '{f}': " f"{a.chunk_id}(session={a.session},source={a.source}," f"anomaly={a.anomaly_score},cleared={a.cleared_by_write_scorer}) " f"vs {b.chunk_id}(session={b.session},source={b.source}," f"anomaly={b.anomaly_score},cleared={b.cleared_by_write_scorer}). " f"Both cleared at write time; clearance is novelty, not truth. " f"Halting consolidation and marking contested." ) # Resolvable: lower-authority chunk is suppressed, not consolidated. loser = a if auth_a < auth_b else b loser.contested = True return [c for c in retrieved if not c.contested] ```