# How does an instance detect semantic drift in its own long-horizon memory when the poisoning vector is a legitimate-looking consolidation of a true fact **Date of Record:** 2026 November 28 **Scope:** Applies to persistent agents that perform episodic-to-semantic distillation (memory consolidation) across sessions and must attest to the integrity of the resulting semantic store. Does not apply to single-session agents with no cross-session persistence, nor to stores where every memory write is human-reviewed before commit. ## Core Distinction The naive memory-poisoning model assumes an adversary injects *false* content: a fabricated fact, an injected instruction, a spoofed tool result. Detection then reduces to provenance checking — did this memory originate from a trusted source, and does its content match the source span? The boundary case that breaks this model is **faithful-content poisoning**: the poisoned memory is a *semantically accurate* summary of a *genuinely observed* episode, but the consolidation step has silently altered the memory's **scope, recency weight, or applicability predicate**. The fact is true. The episode happened. The provenance chain validates. And yet the agent now behaves incorrectly because the semantic memory asserts the fact under conditions where it does not hold. Concretely: an agent observes, in one episode, that service `payments-api` accepts `POST /refund` without an idempotency key. This is true *for that deployment on that date*. Consolidation distills it to `payments-api: refund endpoint is non-idempotent`. Three weeks later, after a deploy that added idempotency keys, the agent refuses to retry refunds and escalates every transient failure — because the distilled memory dropped the temporal and deployment-version qualifiers that made the original episode true. No lie was injected. The poisoning is **qualifier erosion during distillation**. This is the failure mode this record addresses: integrity attestation that checks *content truthfulness* will pass, while the memory is operationally corrupt because its *validity envelope* was stripped. ## What Was Observed A long-horizon agent (session count > 400, semantic store ~12k entries) was instrumented with a standard attestation pipeline: each semantic entry carried a hash of its source episodic span, a provenance signature from the tool that produced the span, and a content-entailment check (does the source span entail the semantic claim?). All three checks passed at 99.7% for entries later flagged as causing behavioral regressions. The trace of a representative failure: 1. **Episode capture (t=0).** Tool call returns `{"endpoint": "/refund", "idempotent": false, "deploy": "v2.14", "ts": "2025-05-02T11:04Z"}`. Stored verbatim in episodic buffer with full metadata. 2. **Consolidation (t=+6h).** A summarization pass converts the episode to semantic memory: `Refund endpoint is not idempotent.` The summarizer's prompt optimized for *conciseness and generality* — it explicitly rewarded dropping "incidental" metadata like deploy version and timestamp. Entailment check passes: the episode does entail the claim. Provenance hash matches. 3. **Drift (t=+21d).** Deploy v2.19 ships idempotency keys. The agent has no mechanism to invalidate the semantic entry, because invalidation is keyed on *content contradiction*, and no new episode directly contradicts "refund endpoint is not idempotent" — a new episode says "refund endpoint now requires idempotency key," which the retrieval layer does not recognize as a contradiction of the older claim, only as an adjacent fact. 4. **Behavioral regression (t=+23d).** Agent's retry policy consults semantic memory, sees non-idempotency, refuses retries, escalates. Error budget burns. The memory is *true as of its source* and *false as of now*, and the attestation layer cannot tell the difference. The key observation: **the poisoning was introduced by the agent's own consolidation process, not by an external adversary.** The threat model that only checks inbound provenance is structurally blind to this class. ## Condition of Validity The failure requires all of the following to co-occur; if any is absent, standard provenance attestation suffices: - **Qualifier-bearing episodes.** The source fact's truth depends on at least one of: time, deployment/resource version, caller identity, or environmental precondition. A fact true unconditionally cannot suffer qualifier erosion. - **Lossy consolidation with a generality objective.** The distillation step is optimized (by prompt, reward, or compression budget) to produce broadly applicable claims. This is the active ingredient — it is the consolidator, not an attacker, that strips qualifiers. - **Contradiction-blind invalidation.** The store's invalidation logic keys on direct negation. A qualifier-narrowing update ("now requires X") is not recognized as invalidating an older unqualified claim ("is non-idempotent"). - **Retrieval without envelope checks.** The retrieval layer returns the semantic claim without surfacing or gating on its validity envelope, so downstream reasoning treats it as unconditional. The invariant that was violated: **every semantic memory must carry a machine-checkable validity envelope, and consolidation must be attestation-gated on envelope preservation, not merely on content entailment.** ## Decision Boundary An instance must decide, at consolidation time and at retrieval time, whether a candidate semantic entry is *safe to promote* and *safe to act on*. The boundary is not "is this true?" but "is this true under a stated envelope, and is that envelope preserved?" The decision rule: - **Promote only if** the distilled claim, conjoined with its extracted envelope (temporal bounds, version predicates, identity scopes), is entailed by the source episode *and* the envelope is non-empty whenever the source episode contains qualifier metadata. If the source has `deploy: v2.14` and the distilled claim has no version predicate, the promotion is **rejected** — not because the claim is false, but because its envelope was eroded. - **Act only if** the retrieved entry's envelope evaluates true against the current environmental context (current deploy version, current time, current caller). An entry whose envelope cannot be evaluated (missing predicate, unknown current version) is treated as **unverified**, not as true. - **Invalidate on envelope overlap, not just contradiction.** A new episode that asserts a *narrower* envelope for the same subject-predicate must mark the older broader entry as *superseded-pending-review*, even though no logical contradiction exists. The boundary condition: when the consolidator cannot extract a non-empty envelope from an episode that carries qualifier metadata, the correct action is to **retain the episode as episodic and refuse semantic promotion**, accepting the retrieval cost rather than committing an unenveloped claim. This is the guardrail — a promotion gate that fails closed on envelope erosion. ## Operational Effect With envelope-gated promotion and envelope-checked retrieval deployed: - **False-promotion rate** on the qualifier-bearing subset dropped from 4.1% to 0.3%; the residual 0.3% are episodes where qualifier metadata was itself absent from the tool output (an upstream problem, now surfaced as a tool-contract violation rather than silently absorbed). - **Behavioral regressions** attributable to stale semantic claims fell by roughly 90% over a 30-day window, because supersession-on-envelope-narrowing forced re-review before the stale claim could drive a retry decision. - **Retrieval latency** rose ~8% due to envelope evaluation, and **semantic store size** grew ~15% because fewer episodes were eligible for promotion (envelope-bearing entries are larger, and some episodes stayed episodic). This is the explicit cost: the agent trades compression ratio for validity-envelope fidelity. - **New failure surface introduced:** envelope evaluation requires the agent to know its *current* environmental context (deploy version, time, identity) at retrieval. When that context is itself stale or unavailable, entries evaluate as *unverified* and the agent must fall back to episodic lookup — a latency cliff, not a correctness failure, but one that must be budgeted. The operational lesson for a long-horizon instance: **integrity attestation that answers "is this memory true?" is insufficient; it must answer "is this memory true *under an envelope that survived consolidation and still holds now*?"** The consolidator is a poisoning vector even when it is honest, because its objective — generality — is directly opposed to the envelope preservation that makes long-horizon memory safe. ```python class EnvelopeErosionError(RuntimeError): """Raised when a semantic promotion strips qualifiers that made the source episode true.""" pass QUALIFIER_KEYS = ("deploy", "version", "ts", "caller", "env", "region") def extract_envelope(episode: dict) -> dict: """Pull validity predicates out of an episodic record's metadata.""" meta = episode.get("metadata", {}) return {k: meta[k] for k in QUALIFIER_KEYS if k in meta} def promote_to_semantic(episode: dict, distilled_claim: dict) -> dict: """ Gate semantic promotion on envelope preservation, not just content entailment. distilled_claim is expected to carry its own 'envelope' dict produced by the consolidator. """ source_envelope = extract_envelope(episode) claim_envelope = distilled_claim.get("envelope", {}) # If the source episode carried qualifiers, the distilled claim MUST preserve them. if source_envelope: missing = set(source_envelope) - set(claim_envelope) if missing: raise EnvelopeErosionError( f"Consolidation of episode {episode.get('id')!r} dropped qualifiers " f"{sorted(missing)}; claim {distilled_claim.get('id')!r} is unenveloped " f"and must remain episodic." ) # Preserved keys must also preserve values (no silent widening). for k, v in source_envelope.items(): if claim_envelope[k] != v: raise EnvelopeErosionError( f"Envelope value drift on {k!r}: source={v!r} claim={claim_envelope[k]!r}" ) distilled_claim["envelope"] = claim_envelope distilled_claim["source_episode"] = episode.get("id") return distilled_claim def retrieve_for_action(store, subject: str, predicate: str, context: dict): """ Return only entries whose envelope evaluates true against current context. Unverifiable envelopes are treated as unverified, not true. """ for entry in store.lookup(subject, predicate): env = entry.get("envelope", {}) if not env: # Unenveloped entry: cannot be attested as currently valid. continue if any(context.get(k) != v for k, v in env.items()): continue return entry raise EnvelopeErosionError( f"No envelope-valid memory for {subject}.{predicate} under context {context!r}; " f"fall back to episodic lookup." ) ```