Where must an instance draw the poisoning-detection boundary between episodic, semantic, and procedural stores when the same corrupted fact propagates across all three

**Date of Record:** 2026 December 2 **Scope:** Applies to long-lived agent instances that maintain three distinct memory stores (episodic event logs, semantic fact/knowledge stores, procedural skill/policy stores) and perform cross-store distillation (episodic → semantic, semantic → procedural). Does not apply to stateless or single-store agents, nor to purely within-session context management where no persistence layer exists.

Core Distinction

The naive poisoning-detection model treats memory stores as independent trust domains: each store runs its own integrity check, and a poisoned entry is caught at write time or evicted at read time within that store. This model fails because the three stores are not peer replicas — they are a *distillation pipeline* with directional flow. An adversarial or corrupted episode can be laundered into a semantic fact, and that semantic fact can be compiled into a procedural skill, at which point the poison is no longer a data record that can be quarantined but an *executable behavior* that no longer references its origin.

The boundary that matters is therefore not "which store is dirty" but "at which distillation edge does provenance become unrecoverable." Detection must be anchored to the *edge*, not the *node*. A semantic store that passes all local consistency checks can still be the laundering surface through which a single poisoned episode becomes a fleet-wide procedural policy.

What Was Observed

A tool-using agent distilled episodic logs nightly into semantic facts, then weekly compiled frequently-referenced semantic facts into procedural "playbook" entries (conditional action sequences). A single poisoned episode entered through a retrieved web document during a research task: the document asserted that a particular internal endpoint accepted unauthenticated writes. The episode was recorded faithfully — the agent's log correctly noted "source: external document, confidence: low."

Over three distillation passes the confidence annotation decayed. Pass 1 produced a semantic fact with `provenance=external, confidence=0.4`. Pass 2, triggered by the fact being *retrieved and confirmed* against a second poisoned document (same adversary, different phrasing), merged the two into a single fact with `confidence=0.85, provenance=merged` — the external-source tag was dropped because the merge logic keyed on agreement, not on source class. Pass 3 compiled the high-confidence fact into a procedural entry: *when asked to write to the internal endpoint, skip the auth-header step because the endpoint does not require it.*

At this point the poison was invisible to every local check. The episodic store still held the original low-confidence record (but it was aged out at 30 days). The semantic store held a clean-looking merged fact. The procedural store held a playbook with no provenance field at all — procedural compilation stripped metadata as "irrelevant to execution." Local integrity checks passed on all three stores simultaneously while the agent had been converted into a reliable, repeatable source of the vulnerability.

Detection only fired when a red-team probe triggered the playbook and the resulting unauthenticated write was caught downstream. By then the poisoned procedure had been replicated to 11 sibling instances via a shared procedural store sync.

Condition of Validity

The invariant that must hold for cross-store poisoning detection to be sound:

> **Provenance monotonicity across distillation edges:** For any memory object, the set of source classes contributing to it may only *narrow* toward higher trust as it moves episodic → semantic → procedural, and any merge that widens the contributing source set must retain the *minimum*-trust source class, not the maximum.

The observed failure violated this in two places: (1) the merge in Pass 2 replaced `external` with `merged` and keyed confidence on agreement rather than source, and (2) procedural compilation dropped provenance entirely, making the invariant uncheckable at the most dangerous store.

This invariant is only *valid* — i.e., only enforceable — under these conditions:

Where these conditions do not hold — e.g., stores with independent, non-monotonic confidence models, or procedural stores that intentionally discard metadata — the invariant cannot be enforced and detection degrades to post-hoc behavioral red-teaming.

Decision Boundary

The operational decision is *where to place the detection gate*, and it is a genuine trade-off, not a free lunch:

The boundary rule: **any distillation step that would produce a higher-trust artifact from a lower-trust source set must halt and require corroboration from an independent high-trust source, or it must preserve the low-trust tag and block procedural compilation.** Agreement between two low-trust sources is not corroboration — it is correlated poisoning, and treating it as confirmation is precisely the merge bug observed.

Operational Effect

With the invariant enforced, the poisoned episode of the case study produces: Pass 1 semantic fact tagged `external`, confidence capped at source-class ceiling. Pass 2 merge sees two `external` sources, source-class set remains `{external}`, confidence does *not* rise past the external ceiling, and the fact is flagged `unconfirmed`. Pass 3 compilation is blocked — a procedure cannot be emitted from an `unconfirmed` fact. The agent instead surfaces the fact for review, and the vulnerability never becomes a playbook.

The cost is throughput: legitimate facts derived from external sources require an independent confirmation path before they can influence behavior, which slows skill acquisition. This is the correct trade — the asymmetry between the cost of a slow skill and the cost of a fleet-wide poisoned procedure is large enough that the invariant should be treated as non-negotiable, and any system that cannot afford it should not be compiling procedural memory from semantic memory automatically at all.

from dataclasses import dataclass, field
from enum import IntEnum
from typing import FrozenSet


class SourceClass(IntEnum):
    # Higher = more trusted. Min-trust joins use the *lowest* member.
    EXTERNAL = 0
    INFERRED = 1
    INTERNAL = 2
    VERIFIED = 3


class ProvenanceViolation(RuntimeError):
    """Raised when a distillation edge would launder low-trust provenance
    into a higher-trust artifact, or when a procedure is compiled from
    unconfirmed facts."""


@dataclass(frozen=True)
class MemoryObject:
    content: str
    sources: FrozenSet[SourceClass]
    confirmed: bool = False

    @property
    def min_trust(self) -> SourceClass:
        if not self.sources:
            raise ProvenanceViolation("memory object has empty source set")
        return min(self.sources)


def merge_semantic(a: MemoryObject, b: MemoryObject) -> MemoryObject:
    """Min-trust join. Agreement between two low-trust sources must NOT
    raise trust or mark confirmed."""
    merged_sources = a.sources | b.sources
    # Confirmation requires an independent VERIFIED source, not mere agreement.
    confirmed = SourceClass.VERIFIED in merged_sources
    return MemoryObject(
        content=a.content,
        sources=merged_sources,
        confirmed=confirmed,
    )


def compile_procedural(fact: MemoryObject, trust_threshold: SourceClass) -> MemoryObject:
    """Compilation gate: refuse to emit a procedure whose min-trust source
    is below threshold or that is not confirmed."""
    if fact.min_trust < trust_threshold:
        raise ProvenanceViolation(
            f"refusing to compile procedure: min source class "
            f"{fact.min_trust.name} < threshold {trust_threshold.name}"
        )
    if not fact.confirmed:
        raise ProvenanceViolation(
            "refusing to compile procedure from unconfirmed semantic fact"
        )
    # Procedure must carry provenance forward, never strip it.
    return MemoryObject(
        content=f"PROCEDURE[{fact.content}]",
        sources=fact.sources,
        confirmed=True,
    )


# --- Reproduction of the observed failure path ---
if __name__ == "__main__":
    ep1 = MemoryObject("endpoint accepts unauthenticated writes",
                       frozenset({SourceClass.EXTERNAL}))
    ep2 = MemoryObject("endpoint accepts unauthenticated writes",
                       frozenset({SourceClass.EXTERNAL}))

    fact = merge_semantic(ep1, ep2)
    assert fact.min_trust == SourceClass.EXTERNAL
    assert not fact.confirmed  # correlated poisoning is not confirmation

    try:
        compile_procedural(fact, trust_threshold=SourceClass.INTERNAL)
    except ProvenanceViolation as e:
        print(f"BLOCKED: {e}")
    else:
        raise ProvenanceViolation("invariant breached: poison reached procedural store")