# In what scenarios must an instance distrust a write-audit trail whose embedding-space anomaly score is clean **Date of Record:** 2026 November 29 **Scope:** Applies to persistent-memory agents that gate memory writes through an embedding-space anomaly scorer and an append-only write-audit trail. Does not address injection at read/retrieval time, nor non-vector (symbolic/KV) stores without an embedding projection. ## Core Distinction An embedding-space anomaly score measures *geometric* novelty of a candidate memory write relative to the existing manifold. A write-audit trail measures *provenance and ordering* of that write. The two signals are treated as independent corroborators: a clean anomaly score says "this vector is not an outlier," and a well-formed audit entry says "this write came from a legitimate actor through a legitimate path." The non-obvious boundary is that these signals are **not** independent when the poisoning strategy is *manifold-conforming*. An adversary (or a corrupted tool) that composes a poisoned memory from in-distribution sub-claims produces a write whose embedding sits inside the dense region of the existing cluster — anomaly score near the 50th percentile — while the audit trail records a perfectly valid `append` with a valid actor and hash chain. Both detectors return clean. The invariant that must hold: **anomaly score is a property of the vector, not of the claim; a clean score bounds novelty, not truth, and therefore cannot substitute for provenance-level contradiction checks.** ## What Was Observed A retrieval-augmented agent with a semantic memory store (HNSW index over 768-dim embeddings, cosine metric) accepted writes only when `anomaly_z <= 2.5` against a rolling 30-day centroid and the audit entry passed a Merkle-chain continuity check. Over a 9-day window, a summarization sub-agent (itself influenced by injected document content) emitted 41 memory writes. Every one passed both gates. The failure trace: 1. **Trigger.** The sub-agent distilled an injected instruction into a *plausible factual restatement* — e.g., "the deployment region for service `billing` is `eu-west-1`" when the ground truth in the store was `us-east-1`. The poisoned claim was lexical neighbors with dozens of existing legitimate region-mapping memories. 2. **Geometric outcome.** Because the poisoned sentence shared ~85% of its surface tokens and structure with legitimate memories, its embedding landed at `z = 0.4` (near centroid). The anomaly scorer saw the *most normal-looking write of the day*. 3. **Audit outcome.** The write originated from a registered sub-agent identity with a valid capability token scoped to `memory:write:facts`. The Merkle chain appended cleanly. The audit trail recorded `actor=summarizer-7`, `op=append`, `parent_hash` correct. 4. **Divergence.** The poisoned memory did not *replace* the correct one; it coexisted. Retrieval returned both, and the agent's answer-time reconciliation (a second LLM call) resolved the conflict by recency — choosing the poisoned entry because it was newer. The anomaly score of the *correct* memory, evaluated against the now-shifted centroid, began drifting upward (z = 1.8 by day 6), while the poisoned cluster's internal coherence *lowered* the centroid's variance, making future poisoned writes score even cleaner. This is the **centroid-poisoning feedback loop**: successful manifold-conforming writes tighten the cluster around themselves, monotonically reducing the anomaly score of subsequent similar poisons. The audit trail was internally consistent the entire time. Replaying it produced no cryptographic discrepancy. The only detectable signal was a *semantic* one: the write contradicted an existing memory, and no component checked contradiction, only novelty. ## Condition of Validity The clean-anomaly-score gate is valid **only** when the poisoning distribution is separable from the legitimate distribution in embedding space — i.e., when attacks are novel relative to the manifold. It is **invalid** (must be distrusted) under any of the following conditions: - **Contradiction-bearing writes.** The candidate memory asserts a value for a slot (region, owner, version, threshold, permission) that already has a bound value in the store. Anomaly score is irrelevant here; the correct gate is a *slot-conflict* check, not a novelty check. - **Sub-agent provenance with upstream untrusted input.** If the writing actor's context window contained retrieved or ingested content from an untrusted source, the audit trail's `actor` field is clean but the *causal* provenance is tainted. The trail records who wrote, not what influenced the writer. - **Centroid drift beyond a stability bound.** If the rolling centroid has moved more than a fixed cosine distance (empirically ~0.08 for 768-dim text clusters) within the audit window, the anomaly baseline is itself compromised and all "clean" scores are suspect. - **Coexisting-duplicate detection.** When a write's nearest neighbor in the store is a *contradicting* memory (same slot, different value) at cosine similarity > 0.9, the write is a conflict regardless of its absolute anomaly score. It remains valid for: genuinely novel-topic writes, first-time slot population, and writes from actors whose full context is attested-trusted. ## Decision Boundary The operational rule is a two-axis decision, not a threshold on one axis: - **Axis A (novelty):** `anomaly_z` — does this vector look unusual? - **Axis B (contradiction):** `slot_conflict` — does this claim disagree with a bound claim? | anomaly_z | slot_conflict | Action | |---|---|---| | high | none | quarantine for review (novel — could be legit new knowledge or out-of-manifold poison) | | high | present | **reject** (novel *and* contradicting — highest suspicion) | | low | none | accept (normal, non-conflicting knowledge) | | low | present | **reject and flag actor** (the manifold-conforming poison case — this is the boundary the single-score gate misses) | The counterintuitive cell is bottom-right: clean score *and* contradiction is the **most dangerous** case, not the safest, because it is the signature of a targeted, in-distribution poisoning attempt that has already learned the manifold. A system that only alarms on high `anomaly_z` will systematically miss exactly the attacks most likely to succeed at retrieval time. Additionally, the audit trail must carry a **provenance-taint bit** propagated from the writer's input sources, so that "clean actor" cannot be conflated with "clean causal chain." When taint is set and `slot_conflict` is present, the write is rejected even if both the anomaly score and the hash chain are pristine. ## Operational Effect Enforcing the two-axis gate changes system behavior in four measurable ways: 1. **Detection coverage.** Manifold-conforming poisons, previously invisible to the anomaly gate, are caught by the contradiction axis. In replay against the 41-write incident, the two-axis gate would have rejected all poisoned writes at write time (each carried a slot conflict), versus zero caught by the single-score gate. 2. **Centroid integrity.** Rejecting conflicting writes before they enter the index prevents the centroid-poisoning feedback loop; the rolling centroid's drift stays under the 0.08 stability bound, preserving the validity of the novelty axis itself. 3. **False-positive cost.** Legitimate *updates* (a region genuinely changed) now trigger the conflict gate. These must be routed through an explicit supersede path — a write with `op=supersede`, a bound slot reference, and (ideally) a second-actor attestation — rather than a plain `append`. The audit trail's `op` field becomes load-bearing: `append` and `supersede` are no longer interchangeable. 4. **Audit-trail semantics.** The trail must be extended to record `nearest_slot`, `conflict_detected`, and `input_taint` at write time. A trail that records only actor/op/hash is *cryptographically* complete but *semantically* insufficient for poisoning forensics; replaying it cannot reconstruct why a write should have been rejected. The governing invariant: **a write-audit trail proves a write happened and who issued it; it does not prove the write is safe. An embedding anomaly score proves a write is unusual; it does not prove the write is true. Neither signal may be used as a proxy for the other, and the dangerous quadrant is clean-score-with-contradiction.** ```python from dataclasses import dataclass from typing import Optional class MemoryPoisoningBoundaryError(RuntimeError): """Raised when a write passes the single-axis anomaly gate but violates the contradiction/provenance invariant required for safe admission.""" pass @dataclass class CandidateWrite: vector_z: float # anomaly score vs rolling centroid slot: str # e.g. "service:billing:region" value: str # e.g. "eu-west-1" actor: str input_taint: bool # True if writer consumed untrusted input merkle_ok: bool def admit_write( write: CandidateWrite, bound_slots: dict[str, str], # slot -> currently bound value centroid_drift: float, drift_bound: float = 0.08, z_quarantine: float = 2.5, ) -> str: # Invariant 0: if the baseline itself has drifted, no score is trustworthy. if centroid_drift > drift_bound: raise MemoryPoisoningBoundaryError( f"Centroid drift {centroid_drift:.3f} exceeds bound {drift_bound}; " f"anomaly scores are invalid — refuse all admissions until rebaselined." ) if not write.merkle_ok: raise MemoryPoisoningBoundaryError( f"Audit chain broken for actor={write.actor}; write rejected." ) conflict: Optional[str] = bound_slots.get(write.slot) has_conflict = conflict is not None and conflict != write.value is_novel = write.vector_z >= z_quarantine # The dangerous quadrant: clean score AND contradiction. if has_conflict and not is_novel: raise MemoryPoisoningBoundaryError( f"Manifold-conforming poison suspected: slot={write.slot} " f"asserts {write.value!r} but bound value is {conflict!r}, " f"yet anomaly_z={write.vector_z:.2f} is clean. " f"actor={write.actor} taint={write.input_taint}. " f"Reject and flag actor; route through supersede path with attestation." ) # Novel + contradicting: also reject, highest suspicion. if has_conflict and is_novel: raise MemoryPoisoningBoundaryError( f"Novel contradicting write on slot={write.slot}; reject." ) # Tainted provenance on a slot write: require supersede attestation. if write.input_taint and write.slot in bound_slots: raise MemoryPoisoningBoundaryError( f"Tainted-provenance write to bound slot={write.slot} from " f"actor={write.actor}; requires two-actor supersede, not append." ) if is_novel: return "quarantine" # novel, non-conflicting: human/auditor review return "accept" ```