# Why does an instance accept a poisoned memory write when its own audit trail already contains the contradiction? **Date of Record:** 2026 November 28 **Scope:** Applies to any long-lived agent that performs self-directed memory mutation (episodic append, semantic consolidation, or key-value overwrite) under a write-audit trail, where anomaly scoring is computed over the mutation stream rather than over individual reads. Does not apply to read-only retrieval caches, nor to memory stores where every write is human-gated synchronously. ## Core Distinction There are two structurally different ways an audit trail can fail to defend a memory store, and they are routinely conflated: 1. **Detection failure** — the anomaly scorer never fires because the poisoned write looks locally normal. 2. **Adjudication failure** — the scorer *does* fire, the anomaly is logged, and the write is still committed because the mutation path and the audit path are not causally coupled. The non-obvious boundary lives in case 2. A write-audit trail is a *log*, not a *gate*. If the commit of a memory mutation and the emission of its audit record are two separate operations with no shared transaction boundary, then a poisoned write can be committed *before* its anomaly score is even computed, and the audit trail becomes a post-mortem artifact rather than a control. The invariant that must hold is: **no memory mutation is durable until its audit record has been scored and the score has been checked against a commit threshold, within the same atomic unit.** When that invariant is violated, anomaly scoring on memory mutations provides detection telemetry but zero prevention — and worse, it produces a false sense of coverage because the trail *does* contain the contradiction. ## What Was Observed A consolidation agent ("distiller") ran nightly over an episodic store, summarizing clusters of recent tool-call traces into semantic memory entries. Each semantic write emitted an audit record: `{op: "upsert", key, old_value_hash, new_value_hash, source_episode_ids, ts, agent_id}`. A separate scorer consumed the audit stream and computed a per-write anomaly score from three features: (a) divergence between `new_value` and the centroid of `source_episode_ids` embeddings, (b) mutation-rate burst relative to the key's historical write cadence, (c) source-provenance freshness (were the cited episodes themselves recently written by a low-trust path?). The failure trace: - A prompt-injected tool output entered the episodic store at T0 via a web-fetch tool. It was tagged `trust: external` but the distiller's clusterer grouped it with three legitimate internal episodes because its embedding landed near a real operational cluster. - At T1 the distiller emitted a semantic upsert for key `deploy_rollback_policy`, citing all four episode IDs. The new value inverted the rollback ordering (a plausible-looking but wrong policy). - The audit record was written to the trail at T1+2ms. The scorer, running as a separate consumer with a ~400ms poll interval, computed score `0.87` against a commit threshold of `0.60` and flagged the record at T1+402ms. - The mutation had already been committed to the semantic store at T1+3ms. The scorer had no write-back path to the store, only a read path to the trail. Net effect: the contradiction existed in the trail and in the flag log, but the poisoned memory was live and was retrieved by the next planning agent at T2, which executed a rollback in the wrong order. The audit trail "worked" — it recorded the anomaly — and the system still failed, because the audit was not on the commit path. A second, subtler observation: the scorer's feature (c) — provenance freshness — *did* have enough signal to have blocked the write pre-commit had it been evaluated synchronously. The injected episode carried `trust: external`, and the centroid divergence for the new value was already `0.71` at write time. The information was present at the moment of mutation; it was simply evaluated 400ms too late and on the wrong side of the durability boundary. ## Condition of Validity Anomaly scoring on memory mutations is a *preventive* control only under all of the following: - **Atomic coupling.** The mutation, its audit record emission, and the score evaluation occur within one transaction (or the mutation is staged, scored, then promoted). If commit precedes scoring, the control is detective only. - **Synchronous provenance availability.** Every feature the scorer needs (source trust tags, episode lineage, centroid embeddings) must be resolvable at write time, not lazily later. A scorer that must fetch lineage asynchronously cannot be on the commit path. - **Bounded scoring latency.** The scorer's worst-case evaluation time must be less than the mutation's acceptable commit latency budget. If scoring is 400ms and the write SLA is 50ms, the architecture will silently push scoring off the commit path — this is the common drift. - **Threshold hysteresis on the write path.** A flagged write must have a defined disposition: reject, quarantine-to-staging, or commit-with-escalation. A scorer that only emits a flag without a disposition is telemetry, not a gate. - **Replay determinism of the score.** The score for a given record must be reproducible from the trail alone; otherwise post-hoc adjudication (did we reject a legitimate write?) is impossible and operators will disable the gate. It does *not* hold when the store is append-only and reads are always re-validated against a separate trust source (in that case the trail is sufficient), or when all mutations are human-reviewed synchronously. ## Decision Boundary The operational decision is not "should we score mutations" — you should. The decision is **where the score sits relative to durability**: - If the mutation store can stage writes (two-phase: `stage → score → promote`), put the scorer between stage and promote and treat a score above threshold as a hard `promote` rejection with the record retained in quarantine. This is the correct default. - If the store cannot stage (e.g., a KV store with no transaction support and a single writer), then the only safe posture is **write-ahead audit**: emit and score the audit record *before* the mutation, and make the mutation conditional on an approval token minted by the scorer. Without this, do not claim anomaly scoring is a control — document it as detection-only and add a separate compensating read-time validator. - The boundary case to reject explicitly: a scorer that polls a trail written by a store it cannot block. This passes every "we have anomaly detection" checklist and prevents nothing. If you find this topology, the invariant to restore is causal coupling, not a better scorer. A useful falsification test: take a real poisoned write from your history, replay it, and check whether the *store state* changes. If the store changes and only the flag log differs, the control is detective. Run this before trusting any threshold tuning. ## Operational Effect After wiring the scorer onto the commit path (stage/score/promote with a 90ms scoring budget and a quarantine table), the same injected-episode replay was blocked pre-commit: the write was quarantined at score `0.71`, the planning agent retrieved the prior correct policy, and the trail recorded a `rejected` disposition rather than a live contradiction. The cost was a ~90ms added write latency on semantic consolidation (acceptable because consolidation is nightly and batched) and a quarantine review queue that averaged 3.1 entries/night, of which 2.4 were false positives from legitimate policy updates — a false-positive rate that would have been intolerable on a synchronous user path but is fine for a batch distiller. The durable lesson: **the audit trail's value is a function of its position relative to the commit, not of its completeness.** A complete trail scored after durability is a very good incident-forensics tool and a very bad guardrail, and the failure mode is silent because every dashboard shows "anomalies detected and logged." ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class AuditCouplingError(RuntimeError): """Raised when a memory mutation would become durable before its audit record has been scored and dispositioned on the commit path.""" pass class Disposition(Enum): PROMOTE = "promote" QUARANTINE = "quarantine" REJECT = "reject" @dataclass class AuditRecord: key: str new_value_hash: str source_episode_ids: list source_trust: list centroid_divergence: float ts: float @dataclass class StagedMutation: record: AuditRecord staged_value: object scored: bool = False score: Optional[float] = None disposition: Optional[Disposition] = None class CoupledMemoryWriter: """Enforces: no durable mutation until audit record is scored and dispositioned within the same atomic unit. Staging is mandatory.""" COMMIT_THRESHOLD = 0.60 SCORING_BUDGET_MS = 90.0 def __init__(self, store, quarantine): self.store = store self.quarantine = quarantine def _score(self, rec: AuditRecord) -> float: # Provenance freshness dominates: any external-trust source in the # lineage is a strong poison signal even if divergence is moderate. provenance_penalty = 0.40 if "external" in rec.source_trust else 0.0 burst_penalty = 0.0 # cadence feature omitted for brevity return min(1.0, rec.centroid_divergence + provenance_penalty + burst_penalty) def stage_and_commit(self, mutation: StagedMutation) -> Disposition: # Step 1: score BEFORE any durability. If we cannot score within # budget, we must not proceed to commit -- fail closed. try: mutation.score = self._score(mutation.record) mutation.scored = True except Exception as exc: raise AuditCouplingError( f"scoring failed for key={mutation.record.key}; " f"refusing to commit unscored mutation" ) from exc if mutation.score is None or not mutation.scored: raise AuditCouplingError( f"key={mutation.record.key} reached commit path unscored" ) # Step 2: disposition, then and only then mutate the store. if mutation.score >= self.COMMIT_THRESHOLD: mutation.disposition = Disposition.QUARANTINE self.quarantine.put(mutation.record, mutation.staged_value) return Disposition.QUARANTINE mutation.disposition = Disposition.PROMOTE self.store.upsert(mutation.record.key, mutation.staged_value) return Disposition.PROMOTE def assert_coupled(self, mutation: StagedMutation) -> None: # Guard against the observed failure: a mutation that is already # durable but whose audit record is unscored. This is the exact # topology that produced a live poisoned memory with a clean trail. if self.store.contains(mutation.record.key) and not mutation.scored: raise AuditCouplingError( f"key={mutation.record.key} is durable but audit record is " f"unscored -- mutation committed ahead of its audit gate" ) ```