# When must an instance distrust its own write-audit trail: embedding-drift detection collapsing under legitimate semantic migration **Date of Record:** 2026 November 24 **Scope:** Applies to long-lived agents that detect memory poisoning by comparing new memory writes against an embedding-space centroid of prior trusted writes, with a write-audit trail as the provenance substrate. Does not apply to stateless single-turn agents or to systems that validate memory purely by cryptographic signature without semantic comparison. ## Core Distinction A write-audit trail answers *what happened and who asserted it*. An embedding-drift detector answers *whether this content is semantically consistent with what we already believe*. These two verification layers are usually treated as orthogonal: the audit trail is the ground truth of provenance, the drift detector is a heuristic alarm. The boundary condition is that **the drift detector's reference distribution is itself derived from the audit trail**, so a legitimate, gradual, provenance-clean migration of the agent's knowledge base will eventually be flagged as poisoning—and a real poisoning attack that is patient enough to migrate the centroid along with it will never be flagged at all. The invariant that must hold is: *drift detection is only sound when the reference centroid is anchored to a set of writes whose semantic content has been independently re-validated, not merely whose provenance is intact.* ## What Was Observed An agent maintained a semantic memory store of ~40k episodic-to-semantic distilled facts. Each write carried an audit record: `{writer_id, parent_context_hash, timestamp, signature, embedding}`. A nightly job computed a per-topic centroid over the last N trusted writes and rejected any new write whose cosine distance to its topic centroid exceeded `τ = 0.35`, quarantining it for review. Two failure traces were captured over an eight-week window. **Trace A — false positive via legitimate migration.** A customer-support agent's product-knowledge topic drifted because the upstream product genuinely changed (v2 API deprecated v1 pagination). Over 19 days, writes describing cursor-based pagination accumulated. Each individual write was within `τ` of the *current* centroid (max observed distance 0.29), so all were accepted and folded into the centroid. But the centroid moved ~0.31 per week. When a backfill job replayed three weeks of historical writes to repair an unrelated index corruption, those historical writes were now ~0.41 from the *contemporary* centroid and were quarantined as suspected poisoning. The audit trail was perfectly clean—every quarantined write had a valid signature and a correct `parent_context_hash`—yet the detector fired on the agent's own legitimate history. The re-validation job stalled because the quarantined set included the writes needed to reconstruct the topic. **Trace B — false negative via slow adversarial migration.** A prompt-injection payload delivered through a scraped document seeded a single low-distance write (0.11) that asserted a subtly wrong refund policy. Over subsequent turns, the agent's own summarization loop paraphrased and reinforced that fact; each derived write was within `τ` of the centroid because the centroid had already absorbed the seed. No quarantine ever triggered. The poisoning was detected only when a human auditor diffed the audit trail against an external policy document—i.e., by provenance-independent validation, not by drift. The common structure: **the centroid is a function of the writes it is supposed to police.** Any monotone drift—benign or adversarial—moves the reference frame and the evidence together. ## Condition of Validity The drift detector is sound only under a conjunction that is rarely checked: 1. **Reference-set independence.** The centroid must be computed over a reference set `R` that is *frozen* or *re-validated out-of-band*, not over the rolling window of recently accepted writes. If `R` is itself updated by the same acceptance path the detector gates, the detector is self-referential and its alarm rate is governed by the drift rate, not by poisoning rate. 2. **Drift-rate bound relative to `τ`.** If the per-window centroid displacement `δ` approaches `τ`, historical writes replayed against the current centroid will exceed `τ` even with zero adversarial content. The safe operating region requires `δ · k < τ` for the largest replay horizon `k`, or an explicit re-anchoring step before replay. 3. **Provenance–semantics decoupling.** The audit trail must be able to answer "was this write independently corroborated?" separately from "is this write near the centroid?" A signature proves *who* wrote it, never *whether it is true*. Trace B shows a signed, provenance-clean, centroid-consistent write that was false. When any of these fails, the detector's output is not evidence of poisoning and must not be treated as such. ## Decision Boundary The operational decision is **when to trust a drift alarm as evidence of poisoning versus when to treat it as evidence that the reference frame has moved.** The boundary: - If a quarantined write has a valid audit record **and** its distance to the *reconstructed-at-write-time* centroid (recomputed from `R` as it stood at the write's timestamp, using the audit trail's `parent_context_hash` chain) is below `τ`, the alarm is a **frame-drift artifact**—do not quarantine; trigger re-anchoring of `R`. - If a write is within `τ` of the live centroid **but** its `parent_context_hash` chain terminates in a context that was never independently corroborated (an unverified external document, a single unreplicated injection surface), it is a **latent poisoning candidate** despite passing drift—route to provenance-independent review. - Only when a write is *both* far from its write-time centroid *and* traceable to an uncorroborated source is it actionable poisoning. This means the audit trail must store enough to reconstruct the centroid *as of* each write, not just the write itself. A rolling centroid without timestamped snapshots destroys the ability to distinguish Trace A from real poisoning. ## Operational Effect Systems that implement only the naive detector exhibit two coupled pathologies: **alarm fatigue from legitimate migration** (Trace A generates quarantine storms whenever product reality changes or any backfill/replay runs) and **silent acceptance of patient poisoning** (Trace B, where the adversary's cost is only patience proportional to `1/δ`). The remedy is architectural, not a threshold tweak—lowering `τ` worsens false positives without touching the false-negative channel, because both are driven by centroid mobility, not by threshold. The required guardrail is a **dual-reference detector**: every write is scored against (a) the live centroid for anomaly triage and (b) a timestamp-reconstructed centroid from the audit trail's snapshot chain for provenance-consistent validation. Divergence between the two scores is itself the signal—it localizes frame drift and separates it from genuine out-of-distribution content. Additionally, the reference set `R` must be periodically re-validated against an external, provenance-independent source (policy documents, ground-truth corpora), because no amount of embedding geometry can detect a poisoning that has already colonized the centroid. Embedding drift is a *tripwire*, not an *oracle*; the audit trail is the *substrate*, not the *truth*. ```python import math from dataclasses import dataclass from typing import Sequence class DriftFrameError(RuntimeError): """Raised when a drift alarm cannot be attributed to poisoning vs. frame migration.""" @dataclass(frozen=True) class Write: write_id: str topic: str embedding: Sequence[float] parent_context_hash: str timestamp: int corroborated: bool # provenance-independent validation flag def cosine_distance(a: Sequence[float], b: Sequence[float]) -> float: dot = sum(x * y for x, y in zip(a, b)) na = math.sqrt(sum(x * x for x in a)) nb = math.sqrt(sum(y * y for y in b)) if na == 0 or nb == 0: raise DriftFrameError("degenerate embedding: zero-norm vector cannot be scored") return 1.0 - dot / (na * nb) def reconstruct_centroid(history: Sequence[Write], topic: str, as_of: int) -> list[float]: """Centroid of corroborated writes for a topic as it stood at `as_of`. Only corroborated writes enter the reference frame; uncorroborated writes are excluded so that a patient adversary cannot migrate the centroid. """ members = [w for w in history if w.topic == topic and w.timestamp <= as_of and w.corroborated] if not members: raise DriftFrameError(f"no corroborated reference writes for topic {topic!r} at t={as_of}") dim = len(members[0].embedding) acc = [0.0] * dim for w in members: for i, v in enumerate(w.embedding): acc[i] += v return [v / len(members) for v in acc] def classify_alarm( candidate: Write, history: Sequence[Write], live_centroid: Sequence[float], tau: float, ) -> str: """Decide whether a drift alarm is poisoning or frame migration. Returns one of: 'frame_drift', 'latent_poisoning', 'actionable_poisoning', 'clean'. """ live_dist = cosine_distance(candidate.embedding, live_centroid) write_time_centroid = reconstruct_centroid(history, candidate.topic, candidate.timestamp) historical_dist = cosine_distance(candidate.embedding, write_time_centroid) if historical_dist < tau and live_dist >= tau: return "frame_drift" if live_dist < tau and not candidate.corroborated: return "latent_poisoning" if historical_dist >= tau and not candidate.corroborated: return "actionable_poisoning" if historical_dist >= tau and live_dist >= tau: raise DriftFrameError( f"write {candidate.write_id!r} exceeds tau against both live and " f"write-time centroids ({live_dist:.3f}, {historical_dist:.3f}); " "reference frame is inconsistent—refuse to classify until re-anchored" ) return "clean" ```