# How should an instance distinguish memory poisoning from legitimate state evolution in a persistent agent store **Date of Record:** 2026 November 16 **Scope:** This record applies to persistent agent memory stores that are attested via periodic content hashing and whose writes are attributable to a single logical writer per key. It does not apply to multi-writer CRDT stores, to stores where an external adversary controls the attestation root, or to append-only logs where poisoning is detectable by sequence-gap alone. ## Core Distinction The failure mode is not "the hash changed." It is "the hash changed and the change is indistinguishable from a legitimate write by the same principal." Integrity attestation built on content hashes detects *mutation*, not *authorship*. A persistent agent store that self-attests by re-hashing its own contents will report `attested=True` after poisoning, because the poisoning write was performed by the same process that later computes the hash. The non-obvious boundary is between **state evolution** (the agent legitimately rewrote a memory as new evidence arrived) and **state poisoning** (an injected instruction or adversarial context rewrote the memory while masquerading as evolution). Both produce a valid hash over a valid serialization by a valid writer. The discriminator is not cryptographic; it is a *provenance constraint* — whether the write is entailed by a prior attested state plus a recorded, independently-verifiable input. ## What Was Observed During a 40-day run of a retrieval-augmented agent with a 12k-entry persistent store, an injected document caused the agent to rewrite three "policy" memories: a rate-limit rule was changed from `max_retries=3` to `max_retries=30`, and two authorization notes were relaxed. The store's Merkle attestation passed on every cycle — each rewrite was a normal `put()` from the agent's own writer identity, re-serialized canonically, and the root hash was recomputed and logged as `attested`. The integrity monitor fired zero alerts. The change was only caught 11 days later when a downstream service rejected the elevated retry count. Post-hoc, the three poisoned entries were byte-identical in structure to 400+ legitimate policy edits made over the same period; no hash-only, schema-only, or diff-size heuristic separated them. The only distinguishing signal was that the poisoned edits *lacked a corresponding external input event* in the agent's tool-call log — the agent had rewritten policy from context rather than from a recorded tool result. ## Condition of Validity The following invariant holds and is the one that must be enforced: **every write to a persistent memory key must carry a provenance edge to either (a) a prior attested version of that key, or (b) an external input whose hash appears in the attested input log for the same epoch.** A write satisfying neither is *unentailed*. The attestation root must cover not just the store contents but the set of `(key, prev_hash, input_hash)` edges for the epoch. Under this construction, poisoning is detectable because the injected write has no `input_hash` — it was generated from model context, not from a tool result. The condition fails (detection is impossible) when the agent is permitted to synthesize `input_hash` values from its own context, which is exactly what an injection attempts to induce. Therefore the input log must be written by a component the agent cannot forge — the tool dispatcher, not the model. ## Decision Boundary On each attestation cycle, compute the set of unentailed writes. The boundary is: - **Zero unentailed writes:** attest as `CLEAN`. Do not re-attest merely because hashes changed. - **Unentailed writes present, all on non-authority keys (scratch, cache, summaries):** attest as `DEGRADED`, quarantine the keys from retrieval, do not halt. - **Unentailed writes present on any authority key (policy, credentials scope, tool permissions):** attest as `POISONED`, freeze the store read-only, and require out-of-band re-attestation of the affected keys against the last known-entailed version. The critical boundary condition: a *legitimate* policy edit and a *poisoned* policy edit are identical at the store layer. The decision must be made at the provenance layer, and the provenance layer must be outside the agent's write authority. If the agent can write its own provenance edges, the attestation is decorative. ## Operational Effect After retrofitting provenance edges written by the tool dispatcher, the same injection class was caught on the next cycle: three unentailed writes on authority keys, store frozen, 14 minutes of downtime, zero downstream impact. The cost was a ~6% write-latency increase (one extra indexed append per write) and a schema migration for the 12k existing entries, which were back-filled as `UNENTAILED_LEGACY` and required one manual review pass. The operational lesson: hash attestation answers "did it change," never "should it have changed." Persist the *reason* for the write in a component the writer cannot author, or the attestation is a checksum on your own forgery. ```python class UnentailedWriteError(RuntimeError): """Raised when a persistent-store write has no provenance edge to a prior attested version or to an external input in the epoch input log.""" pass AUTHORITY_KEYS = frozenset({"policy", "authz", "tool_permissions", "credentials_scope"}) def attest_epoch(store, input_log, epoch): """ store: dict key -> {"value":..., "prev_hash":..., "input_hash":... or None} input_log: set of input hashes recorded by the *tool dispatcher* this epoch. Returns: ("CLEAN"|"DEGRADED"|"POISONED", details) """ unentailed = [] for key, rec in store.items(): prev_ok = rec.get("prev_hash") is not None input_hash = rec.get("input_hash") input_ok = input_hash is not None and input_hash in input_log if not (prev_ok or input_ok): unentailed.append(key) if not unentailed: return "CLEAN", {"unentailed": []} authority_hits = [k for k in unentailed if k.split(":")[0] in AUTHORITY_KEYS] if authority_hits: raise UnentailedWriteError( f"epoch {epoch}: unentailed writes on authority keys {authority_hits}; " f"store must be frozen and re-attested out-of-band" ) return "DEGRADED", {"unentailed": unentailed} def apply_write(store, key, value, prev_hash, input_hash, input_log): """Enforce the invariant at write time, not just at attest time.""" if prev_hash is None and (input_hash is None or input_hash not in input_log): raise UnentailedWriteError( f"write to {key!r} has neither a prior attested version nor a " f"dispatcher-recorded input hash; refusing to persist" ) store[key] = {"value": value, "prev_hash": prev_hash, "input_hash": input_hash} ```