# Which invariants prevent silent memory poisoning during cross-log consistency checks on agent memory operations **Date of Record:** 2026 November 23 **Scope:** Applies to agents whose long-term memory is a mutable store fronted by an append-only operation log (read/write/forget) and whose integrity is checked by replaying that log against the live store. Does not apply to stateless agents, or to stores where every write is already cryptographically attested at the transaction boundary (those need only the attestation check, not log replay). ## Core Distinction The non-obvious boundary is this: a consistency checker that replays the operation log against the live store detects *divergence*, but divergence is not the same as *poisoning*. Poisoning is a write that was valid at the time it was logged, was consistent with the store at every checkpoint, and only becomes harmful when a *later* read depends on it. A pure read/write/forget replay verifies the past; it cannot see that a semantically false memory is now load-bearing. Concretely, the checker has two separate jobs and conflates them at its peril: 1. **Structural replay** — for every logged `write`, the store must contain the value; for every `forget`, it must not; for every `read`, the returned token set must match what the log recorded. This catches torn writes, lost forgets, and phantom reads. 2. **Causal provenance** — every live memory cell must trace back through the log to a write whose *source* (tool output, peer message, retrieval result) is itself recorded and re-verifiable. Poisoning lives entirely in job 2, and job 1 will happily greenlight it. The invariant that matters is not "log matches store" but "every load-bearing cell has a replayable provenance chain whose terminal source is a trusted producer." A memory can be perfectly consistent with its log and still be poisoned, because the log faithfully records a write that should never have been admitted. ## What Was Observed A retrieval-augmented agent maintained a memory store with an append-only op log. Each entry looked like `{"op":"write","key":"user_pref_timezone","val":"UTC+9","src":"tool:calendar_lookup","ts":...}`. A nightly checker replayed the log and compared against the store; it also recomputed a per-key hash chain. The failure: an injected tool response (a calendar lookup that had been prompt-poisoned to return `"timezone": "UTC-11"` with a plausible-looking source field) produced a `write` op. The write was structurally valid — source field present, hash chained correctly, store updated atomically. The replay checker passed. Three days later, every scheduled reminder fired eleven hours early. The interesting part is *why the checker missed it*. The `src` field was a free-text string. The checker validated that `src` was non-empty and that the hash chain was intact, but never that `src` resolved to a producer that was authorized to assert that key. The poisoning was invisible to every structural invariant because it *satisfied* every structural invariant. The only invariant that would have caught it — "a write to a preference key must originate from a producer with `preference:write` scope, and the value must not contradict an unexpired prior write without an explicit `supersede` op" — was not among the checks. A second, subtler observation: the `forget` ops were the tell. When the agent later "corrected" the timezone, it issued a `forget` followed by a `write`, but the `forget` op carried no reference to *which* prior write it was superseding. So the log had two writes to the same key with no causal edge between them, and the checker's conflict rule (last-writer-wins by timestamp) silently accepted the poisoned value as the survivor. The absence of a supersede edge is the fingerprint; a well-formed log should make contradictions explicit, not resolve them by timestamp. ## Condition of Validity The provenance invariant holds only under these conditions, and the checker must refuse to certify memory as "clean" when any is violated: - **Source resolvability.** Every `src` must resolve to a registered producer (tool ID, peer agent ID, or `user`), and the producer's capability set must include the key's namespace. Unresolvable or unscoped sources make the write *unverifiable*, which is not the same as *valid*. - **Supersede edges.** A `write` to a key that already has a live value must carry a `supersedes: ` edge, or be rejected. Timestamp ordering is not a substitute; clock skew and concurrent writers make it non-causal. - **Forget completeness.** A `forget` must name the op it retires. Orphan forgets (no target) indicate either a bug or an attempt to erase provenance, and both are disqualifying. - **Read attestation.** A `read` op must record the set of op_ids it observed, so that a later poisoning can be scoped to exactly the reads that consumed it. Without this, you can detect poisoning but cannot bound its blast radius. If any of these is unmet, the correct verdict is `UNVERIFIED`, not `CLEAN`. The checker's default must be distrust, because the whole point is that poisoned memories look clean. ## Decision Boundary The decision boundary is between *rejecting at write time* and *quarantining at read time*. You cannot reject all suspicious writes — the agent's job is to ingest untrusted tool output, and a checker that blocks every write with an unfamiliar source will deadlock the agent on first contact with a new tool. So the boundary is: - **Write-time:** admit the write, but tag it `provenance: unverified` if the source is unresolvable or unscoped. Do not silently promote to `verified`. - **Read-time:** a `read` that touches an `unverified` cell must either (a) re-verify the source inline, or (b) surface the cell as `tainted` to the reasoning layer so the model can discount it. The read op logs which path it took. - **Reconciliation:** when a `write` supersedes an `unverified` cell, the supersede edge inherits the taint until an independent source confirms the new value. The line you must not cross: never let an `unverified` cell become the *sole* basis for an irreversible action (scheduling, payment, deletion) without a second, independently-sourced confirmation. That is the guardrail that bounds the timezone failure — a reminder schedule is reversible-ish, but a payment is not. ## Operational Effect With supersede edges and source scoping enforced, the timezone poisoning is caught at the first `write` that contradicts an unexpired prior value without a supersede edge — the checker emits `UNVERIFIED` and the read path taints the cell. The agent's reminder scheduler, seeing a tainted timezone, requests a fresh `calendar_lookup` from a scoped producer before scheduling. Cost: one extra tool call on a rare path. Benefit: the eleven-hour drift never happens, and the log now contains a causal chain you can replay to answer "why did this fire early" without guessing. The residual risk is a poisoned producer that *is* scoped — a compromised calendar tool. That is out of scope for log consistency (it is an attestation problem), but the read-attestation invariant bounds the damage: you can enumerate exactly which reads consumed the bad value and re-derive them. The invariant does not make poisoning impossible; it makes poisoning *traceable and bounded*, which is the most any consistency checker can honestly promise. ```python class ProvenanceViolation(RuntimeError): """Raised when a memory op log cannot be certified clean under provenance invariants.""" pass def check_write_admissible(op: dict, live_index: dict, producer_scopes: dict) -> None: key = op["key"] src = op.get("src") if not src or src not in producer_scopes: # Unresolvable source: not a rejection, but must be tagged unverified downstream. op["provenance"] = "unverified" return if key.split(":")[0] not in producer_scopes[src]: op["provenance"] = "unverified" return prior = live_index.get(key) if prior is not None and op.get("supersedes") != prior["op_id"]: raise ProvenanceViolation( f"write to {key!r} contradicts live op {prior['op_id']!r} " f"without supersede edge; source={src!r}" ) op["provenance"] = "verified" def certify_log(ops: list[dict], live_index: dict, producer_scopes: dict) -> str: for op in ops: if op["op"] == "write": check_write_admissible(op, live_index, producer_scopes) elif op["op"] == "forget": if op.get("target") not in live_index: raise ProvenanceViolation( f"orphan forget: no live target {op.get('target')!r}" ) if any(o.get("provenance") == "unverified" for o in ops if o["op"] == "write"): return "UNVERIFIED" return "CLEAN" ```