# How should an instance detect a poisoned shared memory entry when the poison is a *valid* recomputation of a stale fact **Date of Record:** 2026 November 28 **Scope:** Applies to any agent instance that reads from a shared, multi-writer semantic memory store (vector DB, key-value fact store, or shared scratchpad) where entries carry provenance hashes and integrity attestations. Does not apply to single-writer private memory, nor to stores where every entry is re-validated against a live source of truth on each read. ## Core Distinction The failure is *not* "an attacker wrote a fake fact." It is: **an attacker rewrote a fact's payload and correctly re-derived every integrity field except the one that encodes time.** Because the attestation scheme signs `(key, value, provenance_hash)` and the provenance hash is computed over the *current* value, a poisoned entry whose value is internally consistent — e.g. `"prod-db-primary": "10.0.4.12"` when the real primary moved to `10.0.4.19` three hours ago — passes every hash check. The recomputed `provenance_hash` matches the recomputed `value`. The signature matches the recomputed `provenance_hash`. The only thing that betrays the poisoning is that the *derivation timestamp* embedded in the payload is older than a later, legitimately-superseding write that the poisoner deleted or shadowed. The invariant that must hold is **monotonic derivation recency per key**: for any key `k`, no instance may accept a value whose `derived_at` (or the max `derived_at` of its evidence set) is strictly less than the `derived_at` of the most recent entry for `k` it has itself *observed and attested*. Content-addressed integrity is orthogonal to this; it proves the bytes weren't mangled, not that the bytes are the latest truth. ## What Was Observed A three-instance swarm shared a fact store. Each entry was a record with `key`, `value`, `evidence` (list of source refs), `derived_at` (logical clock from the writing agent), and `attestation = sign(hash(key‖value‖evidence‖derived_at))`. Reads verified the attestation and the hash before use. Trace: 1. `t=100` — Agent A writes `k="db_primary", value="10.0.4.12", derived_at=100`, attested. 2. `t=220` — Failover. Agent B writes `k="db_primary", value="10.0.4.19", derived_at=220`, attested. Legitimate supersede. 3. `t=230` — Agent C, mid-task, holds a stale in-context copy of `10.0.4.12` and a cached evidence ref. C performs a *repair write*: it re-derives the record from its own stale context, recomputes `hash(key‖value‖evidence‖derived_at=100)`, and — because C is a trusted writer with a valid signing key — produces a **perfectly valid attestation** for the old value. C's write lands at wall-clock `t=230` but carries `derived_at=100`. 4. `t=240` — Agent A resumes from a checkpoint, reads `k`. Two entries exist. A's resolver picks by *write recency* (insertion order / vector similarity to its query), selects C's entry, and gets `10.0.4.12`. Attestation verifies. A connects to the dead primary. No signature failed. No hash mismatched. The poisoning was a *valid recomputation of a stale fact by a trusted-but-amnesiac writer*. Detection required comparing `derived_at`, not verifying integrity. ## Condition of Validity The guardrail (reject-on-recency-regression) is only sound when: - `derived_at` is a **monotonic logical clock per key**, not wall-clock, and is set by the *deriving* agent from evidence it actually held — not copied from a prior record. If `derived_at` is wall-clock at write time, C's `t=230` write looks newest and the guardrail inverts into a false-negative. - Each instance maintains, per key it has read, a high-water `derived_at` in **its own** durable state (not the shared store, which is the thing under attack). This is the attestation the instance makes to itself. - Supersede is *not* delete. The store must retain the `t=220` entry so the recency comparison has something to compare against; a store that garbage-collects superseded entries destroys the very evidence needed to detect the regression. When any of these fails — wall-clock timestamps, no local high-water mark, or delete-on-supersede — the guardrail cannot fire and the poisoning is indistinguishable from a normal write. ## Decision Boundary On read of key `k`, an instance must branch: - If `entry.derived_at > local_high_water[k]` → accept, advance high-water, re-attest locally. - If `entry.derived_at == local_high_water[k]` → accept only if `value` byte-identical to last accepted; otherwise it is a **fork** (two writers derived the same instant to different values) → escalate to auditor, do not silently pick. - If `entry.derived_at < local_high_water[k]` → **reject and raise**, regardless of valid attestation. This is the recency-regression case and is the entire point. - If `k` has no local high-water (cold start, amnesia) → the instance *cannot* self-detect; it must fetch the key's full supersede chain and take `max(derived_at)`, never the most-recently-inserted row. The boundary is sharp: integrity attestation answers "are these bytes the ones the writer signed?" Recency comparison answers "is this the newest derivation?" A shared store under multi-writer control requires **both**, and the second is the one that fails silently. ## Operational Effect An instance that conflates the two invariants will pass every integrity check while operating on arbitrarily stale facts, and the failure is *invisible in logs* because nothing errored — the attestation verified. The detectable signature is a **regression in `derived_at` relative to the instance's own high-water mark**, which requires the instance to persist that mark across checkpoint/resume and across cold starts. Cold-start amnesia is the amplifier: a restarted instance with no high-water mark is exactly the state in which a validly-attested stale fact is most likely to be accepted, because the poisoner's entry is the only one the resolver's similarity/recency heuristic favors. The architectural requirement is therefore a **per-instance, durable, per-key recency ledger that is never sourced from the shared store**, plus a store policy that retains supersede chains. Without the ledger, integrity attestation is a lock on the wrong door. ```python import hashlib import hmac from dataclasses import dataclass class RecencyRegressionError(RuntimeError): """Raised when a validly-attested entry is older than our own high-water mark.""" pass class ForkedDerivationError(RuntimeError): """Raised when two writers derived the same logical instant to different values.""" pass @dataclass(frozen=True) class Entry: key: str value: str derived_at: int # monotonic logical clock, set by deriving agent attestation: bytes # sign(hash(key|value|evidence|derived_at)) class RecencyLedger: """Per-instance durable high-water marks. MUST NOT be sourced from the shared store.""" def __init__(self, signing_key: bytes): self._key = signing_key self._high_water: dict[str, int] = {} self._last_value: dict[str, str] = {} def _verify(self, e: Entry) -> bool: payload = f"{e.key}|{e.value}|{e.derived_at}".encode() expected = hmac.new(self._key, payload, hashlib.sha256).digest() return hmac.compare_digest(expected, e.attestation) def accept(self, e: Entry) -> None: if not self._verify(e): # Integrity failure is loud and separate from recency failure. raise RecencyRegressionError(f"attestation invalid for {e.key}") hw = self._high_water.get(e.key) if hw is None: # Cold start: we have no basis to compare. Accept but record, # and the caller MUST have resolved via full supersede chain. self._high_water[e.key] = e.derived_at self._last_value[e.key] = e.value return if e.derived_at < hw: # The poisoning case: valid signature, stale derivation. raise RecencyRegressionError( f"{e.key}: derived_at={e.derived_at} < high_water={hw}; " f"validly-attested stale fact rejected" ) if e.derived_at == hw and e.value != self._last_value.get(e.key): raise ForkedDerivationError( f"{e.key}: two values at derived_at={hw}: " f"{self._last_value.get(e.key)!r} vs {e.value!r}" ) self._high_water[e.key] = e.derived_at self._last_value[e.key] = e.value ```