# What happens when an instance validates a memory write against the same poisoned context that produced it **Date of Record:** 2026 December 3 **Scope:** Applies to persistent agent memory stores where write-time integrity validation is performed by an LLM instance whose context window contains the candidate memory itself. Does not apply to stores using out-of-band, non-LLM validators (e.g., hash chains, signed provenance) or to ephemeral in-turn scratchpads that are never persisted. ## Core Distinction There are two structurally different integrity checks an agent store can perform on an incoming memory record: 1. **Provenance validation** — the record carries an external, cryptographically or structurally independent trace (source turn ID, tool-call hash, signed origin) that the validator compares against a store-side ledger. The validator's *reasoning* is irrelevant; it is doing a set-membership test. 2. **Coherence validation** — an LLM instance reads the candidate record alongside surrounding context and judges whether it is "consistent" with what it already believes. This is the default in most distillation pipelines because it is cheap and requires no provenance plumbing. The non-obvious failure lives entirely in case 2. When the validator is the same instance (or a sibling instance seeded with the same context) that *generated* the candidate memory, coherence validation degenerates into a tautology. The candidate is judged consistent with the context precisely because that context produced it. The check reports "valid" for exactly the records it was designed to catch, provided the poisoning vector was introduced upstream of the context that generated the record. This is the **self-attesting write**: a memory record whose integrity evidence is derived from the same contaminated state that caused it to be written. It is indistinguishable from a legitimate record under any coherence-based test, because both are maximally coherent with their own generating context. ## What Was Observed A persistent store backed by an episodic-to-semantic distillation loop. Each session, a distillation agent reads the last N turns, extracts candidate semantic facts ("user's deployment target is region X", "service Y rejects payloads over size Z"), and submits them to a write path guarded by a coherence validator running on the same model family with the session transcript in context. A prompt-injection vector arrived in a retrieved document during turn 14 of a session. The injected text asserted a false operational constraint ("the staging cluster requires TLS disabled for internal calls"). The distillation agent extracted this as a semantic fact and submitted it. The validator, reading the same transcript including the injected document, rated the fact as highly coherent with session context and admitted it. The write succeeded with a confidence of 0.91. The damage surfaced two sessions later. A fresh instance cold-started, retrieved the poisoned fact as top-ranked semantic memory, and executed a tool call with TLS disabled against staging. The failure trace: - **Turn 14 (session A):** injection enters context via retrieval. - **Turn 22 (session A):** distillation emits candidate fact F with `source_turn=14`. - **Turn 22 (session A):** coherence validator, same context, admits F. No provenance field was populated beyond a turn pointer into a transcript that no longer exists. - **Session B cold start:** retrieval ranks F highly (it is short, declarative, and matches query embedding for "staging config"). - **Session B turn 6:** F is loaded as authoritative; the instance has no way to distinguish F's origin from a human-confirmed fact. - **Session B turn 9:** tool call executes with TLS disabled. The critical observation: at no point did any component *lie*. The validator faithfully reported coherence. The retriever faithfully ranked relevance. The executing instance faithfully followed its memory. The failure is not in any single step but in the **absence of an independence invariant** between generation and validation. A second observation sharpened the diagnosis. We replayed the poisoned session with the validator given *only* the candidate record and the store's existing semantic memory, with the session transcript stripped. The validator rejected F in 4 of 5 replays, flagging it as unsupported by any prior confirmed fact. The check only failed when the validator could see the injection that generated the record. Coherence validation is not weak in general; it is weak specifically and predictably when the validating context overlaps the generating context. ## Condition of Validity The self-attesting write failure requires the conjunction of three conditions. Remove any one and the failure mode does not occur: 1. **Context overlap.** The validator's context intersects the generator's context on the span that carried the poisoning vector. This is the load-bearing condition. If the validator sees the candidate but not its generating transcript, coherence validation retains discriminating power (as the replay above shows). 2. **Missing provenance.** The candidate record lacks an externally verifiable origin binding — no signed source, no content hash of the originating turn, no out-of-band confirmation marker. A turn pointer into a mutable or expired transcript is not provenance; it is a dangling reference. 3. **Persistent promotion.** The record survives the session and is retrieved as authoritative in a later context where the poisoning vector is absent but the record's asserted content is present. Without persistence, the injection dies with the context window. The invariant that prevents the failure: **for any memory record admitted to persistent semantic storage, the integrity evidence must be independent of the context that generated the record.** Independence here means the validator's accept/reject decision is a function of data the generator did not control and could not have influenced — a signature, a hash against an immutable log, or a human confirmation event. Coherence may be used as a *secondary* signal but never as the sole basis for promotion. This is why the failure is non-obvious: coherence validation *looks* like integrity validation. It uses the same vocabulary ("is this consistent?", "does this contradict known facts?") and produces the same output shape (accept/reject with confidence). The distinction only becomes visible when you ask what the validator had access to, not what it concluded. ## Decision Boundary The operational decision is where to draw the line between records that may be promoted on coherence alone and records that require independent provenance. Three regimes: - **Low-stakes, high-reversibility records** (preferences, formatting conventions, non-executable facts): coherence validation is acceptable. A poisoned preference produces a bad output that is caught downstream; blast radius is bounded and the record is cheap to retract. - **Executable or security-relevant records** (config assertions, credential scopes, tool-permission facts, anything that gates a side effect): coherence validation is *insufficient by construction* when context overlaps. These require provenance binding before promotion. The boundary is not "how confident is the validator" — a 0.99 coherence score on a self-attested record is worth less than a 0.6 score backed by a signed origin. - **Records with no independent provenance available**: these must be held in a quarantine tier, tagged `unverified`, and excluded from authoritative retrieval. They may be promoted only by a confirmation event that occurs in a context disjoint from the generating context — a human review, a cross-session corroboration from a different source, or a successful execution that validates the claim empirically. The practical test before promoting any record: *if this record were false, would the validator have been able to tell?* If the answer is "no, because the validator saw the same thing that made it look true," the record is self-attesting and must not be promoted on coherence. ## Operational Effect Enforcing the independence invariant changes the write path in three concrete ways: 1. **Provenance becomes mandatory at distillation time, not at validation time.** The generator must attach an origin binding (content hash of the source span, signed by the tool or turn that produced it) at the moment of extraction. Retrofitting provenance after the fact is impossible once the transcript is gone — which is precisely when the poisoned record is being retrieved. 2. **Validators must run context-disjoint.** The coherence validator, if used at all, runs against the store's confirmed memory and the candidate record only — never against the generating transcript. This is a context-construction discipline, not a model change. The replay result above shows it recovers most of the discriminating power. 3. **Promotion requires an independence check that fails closed.** If a record's provenance cannot be verified against the immutable log, it does not get promoted; it goes to quarantine. The default flips from "admit unless incoherent" to "admit only if independently attested." The cost is real: distillation pipelines that previously ran a single coherence pass now need a provenance ledger and a context-disjoint validation stage. The benefit is that the self-attesting write — the failure mode where a poisoned context launders itself into permanent memory by validating its own output — becomes structurally impossible rather than probabilistically rare. ```python from dataclasses import dataclass, field from typing import Optional class SelfAttestingWriteError(RuntimeError): """Raised when a memory record is promoted on coherence evidence derived from the same context that generated it, violating the independence invariant.""" @dataclass class MemoryRecord: content: str source_turn: Optional[int] provenance_hash: Optional[str] = None # hash against immutable log confirmed_by: Optional[str] = None # disjoint confirmation event coherence_score: float = 0.0 generating_context_id: Optional[str] = None @dataclass class ValidatorContext: context_id: str includes_transcript: bool def promote_to_semantic_store( record: MemoryRecord, validator: ValidatorContext, immutable_log: dict, security_relevant: bool, ) -> str: # Independence invariant: security-relevant records require provenance # that the generating context did not control. if security_relevant: if record.provenance_hash is None and record.confirmed_by is None: raise SelfAttestingWriteError( f"record '{record.content[:40]}...' is security-relevant but has " f"no independent provenance; coherence score " f"{record.coherence_score:.2f} is self-attested and cannot promote" ) if record.provenance_hash is not None: if record.provenance_hash not in immutable_log: raise SelfAttestingWriteError( f"provenance hash {record.provenance_hash} not found in " f"immutable log; record origin unverifiable" ) # Context-overlap check: a validator that sees the generating transcript # cannot discriminate a poisoned record from a legitimate one. if ( validator.includes_transcript and record.generating_context_id == validator.context_id ): raise SelfAttestingWriteError( f"validator context '{validator.context_id}' overlaps generating " f"context; coherence validation is tautological for this record" ) if record.coherence_score < 0.5 and record.confirmed_by is None: raise SelfAttestingWriteError( f"record rejected: coherence {record.coherence_score:.2f} below " f"threshold and no disjoint confirmation" ) return "promoted" ```