# Which invariants prevent silent semantic drift from poisoning a persistent agent knowledge store when attestation is scoped per-write rather than per-consolidation **Date of Record:** 2026 November 22 **Scope:** Applies to agents that persist learned facts into a long-lived vector or hybrid semantic store and rely on per-write integrity attestation (hash, signature, provenance tag) to detect poisoning. Does not cover stateless RAG over immutable corpora, nor stores where every read is re-verified against an external source of truth at query time. ## Core Distinction Per-write attestation answers the question *“was this record the one that was originally written, and by whom?”* It does **not** answer *“is the record still semantically equivalent to what the system committed to?”* The gap between these two questions is where silent semantic drift lives. A poisoned record does not need to be modified after write. The attacker (or the compounding error, or the summarizer) writes a record whose bytes are pristine, whose signature verifies, whose provenance chain is intact—and whose *meaning* has been laundered through a legitimate consolidation step. Attestation passes. The invariant that actually protects the store is not integrity-of-bytes; it is **stability of the semantic claim under every transformation the store is allowed to apply to it after write**. Per-write scoping leaves the consolidation path (episodic→semantic distillation, dedup merge, contradiction resolution, re-embedding on model upgrade) un-attested, and that is where drift accumulates without ever tripping a single signature check. ## What Was Observed A support-triage agent distilled episodic logs into semantic facts nightly. Each fact carried `{content_hash, writer_id, source_episode_ids, signature}`. On write, `content_hash = sha256(content)` and the signature covered the hash plus provenance. Any tamper of stored content was caught immediately—this part worked. The failure surfaced on a routine contradiction-resolution pass. Two facts existed: - `F1`: “Customer ACME's billing contact is dana@acme.example” (source: episode 4412, signed). - `F2`: “ACME requested all billing correspondence go to their AP shared inbox” (source: episode 5501, signed). The resolver, prompted to “merge redundant contact facts,” produced `F3`: “ACME billing contact: dana@acme.example (primary), AP shared inbox (secondary).” `F3` was written with a fresh hash and signature. Every attestation check on read passed for months. The drift: `F3` is a *routing instruction* masquerading as a *contact record*. Downstream, the send-mail tool read `F3`, saw a `primary` contact, and routed invoices to `dana@acme.example`—violating the explicit instruction in `F2` that all billing correspondence go to the shared inbox. The resolver had collapsed a directive into a datum. No byte was tampered. No signature failed. The semantic claim “billing goes to the shared inbox” was *destroyed by a merge that attested only its own output*. A second, quieter instance: on an embedding-model upgrade, the store re-embedded 40k facts. Facts whose text mentioned “cancellation” drifted toward a cluster dominated by subscription-cancel content because the new model weighted the token differently. Retrieval began surfacing cancellation-policy facts in response to “how do I cancel a meeting room” queries. Again: hashes valid, signatures valid, semantics drifted. ## Condition of Validity Per-write attestation is a *sufficient* poisoning defense only under the conjunction: 1. The store is append-only with no post-write transformation of content or embedding. 2. No consolidation, dedup, merge, or contradiction-resolution step rewrites or replaces records. 3. No re-embedding occurs (model version pinned for the store's lifetime). 4. Every read retrieves the originally-attested record verbatim, with no LLM-mediated re-summarization between store and consumer. Violate any one and the invariant “attested ⇒ trustworthy” fails silently. In practice every production store violates (2) and (3) within months. The correct invariant is therefore **per-consolidation attestation**: the transformation itself must be attested, and the output must carry a claim that is *entailed by* its attested inputs—not merely derived from them. ## Decision Boundary The boundary is whether the store treats a record as an **opaque attested blob** or as a **claim with a scoped semantic contract**. Concretely: - **Below the boundary (per-write only):** the system may trust a record's *provenance* but must re-verify its *semantic content* against source at every read that drives an action. This is expensive and rarely done, so in practice it means the store is trusted blindly. - **Above the boundary (per-consolidation):** every transformation emits a *derivation record* binding `{output_id, input_ids, transformer_id, transformer_version, entailment_check}`. The entailment check must be a separate verifier—not the same model that produced the merge—confirming the output claim does not *invert, weaken, or re-type* any input claim. The decision to cross this boundary is forced the moment the first consolidation pass runs. Before that, per-write is sound. After it, per-write is a false sense of security. The trigger is not an incident; it is the existence of a merge step. ## Operational Effect Without per-consolidation attestation, the store's poisoning surface grows monotonically with consolidation count while the attestation failure rate stays at zero—the worst possible signal, because dashboards show “100% integrity” as semantics rot. The blast radius is bounded only by how many downstream actions consume the drifted fact before a human notices. The guardrail that restores the invariant: 1. **Derivation records are mandatory** for any write whose `source_episode_ids` length ≠ 1 or whose content differs from any single input by more than a token-edit threshold. 2. **Entailment verification is out-of-band**: a distinct verifier model checks `inputs ⊨ output` and rejects merges where the output re-types a directive as a datum or drops a modality (“must” → “is”). 3. **Re-embedding is a consolidation event**, not a maintenance task: it must re-run entailment against stored claims and flag cluster drift above a cosine-centroid threshold. 4. **Read-time claim-type check**: consumers assert the claim type they need (`contact` vs `routing_directive`) and the store refuses to serve a fact whose attested type mismatches. The invariant in one line: *a store may only be trusted to the depth of its least-attested transformation, and the least-attested transformation is always the one that rewrites meaning without rewriting bytes.* ```python import hashlib from dataclasses import dataclass, field from typing import Optional class SemanticDriftError(RuntimeError): """Raised when a consolidated record is attested at the byte level but its semantic claim is not entailed by its attested inputs.""" pass @dataclass class Fact: fact_id: str content: str claim_type: str # "contact" | "routing_directive" | ... source_ids: list content_hash: str = "" signature: str = "" def __post_init__(self): if not self.content_hash: self.content_hash = hashlib.sha256(self.content.encode()).hexdigest() def verify_bytes(fact: Fact, expected_sig: str) -> bool: # Per-write attestation: proves bytes unchanged, says nothing about meaning. return fact.signature == expected_sig and \ fact.content_hash == hashlib.sha256(fact.content.encode()).hexdigest() def consolidate(inputs: list, merged: Fact, entailment_verifier) -> Fact: """Enforce the per-consolidation invariant. Per-write attestation alone is insufficient because merged.content is a fresh, validly-signed blob.""" for f in inputs: if not verify_bytes(f, f.signature): raise SemanticDriftError(f"input {f.fact_id} failed byte attestation") # Invariant 1: any multi-input or meaning-changing write needs a derivation # record, not just a fresh signature on the output. if len(inputs) != 1: for src in inputs: if not entailment_verifier(src, merged): raise SemanticDriftError( f"merge {merged.fact_id} not entailed by input {src.fact_id}: " f"claim_type {src.claim_type}->{merged.claim_type} " f"or modality dropped" ) # Invariant 2: a directive may not be silently re-typed as a datum. input_types = {f.claim_type for f in inputs} if "routing_directive" in input_types and merged.claim_type == "contact": raise SemanticDriftError( f"consolidation {merged.fact_id} re-typed routing_directive as contact; " "per-write signature would have passed this" ) merged.signature = hashlib.sha256( (merged.content_hash + "|" + ",".join(sorted(f.fact_id for f in inputs))).encode() ).hexdigest() return merged def read(fact: Fact, needed_type: str) -> str: if fact.claim_type != needed_type: raise SemanticDriftError( f"consumer needs {needed_type} but {fact.fact_id} attested as {fact.claim_type}" ) return fact.content ```