# How does an instance detect semantic-cache poisoning when a peer agent's working-memory write is coherent locally but incoherent globally? **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems where two or more LLM instances share a semantic cache (embedding-keyed KV store) or a shared working-memory scratchpad, and where writes are propagated asynchronously or optimistically. Does not apply to single-agent caches with no cross-instance write path, nor to caches keyed on exact-match hashes where collisions are structurally impossible. ## Core Distinction A semantic cache is keyed by *meaning*, not by *provenance*. Two writes can be locally consistent—each agent's own read-after-write returns the value it just wrote—while the shared store holds a value that is globally wrong because the key was computed from a paraphrase that only *approximately* matched a prior entry. The failure is not a race condition in the classical sense (no lost update between two writers of the same key); it is a **semantic aliasing collision**: agent B's write to key `k_B = embed("the user's shipping address is in Berlin")` lands in the same bucket as agent A's earlier entry `k_A = embed("the user's billing address is in Berlin")` because cosine similarity crossed the cache's admission threshold. Both agents observe a coherent local view. Neither observes that the shared store now returns A's billing value to B's shipping lookup, and B will act on it. The distinction that matters operationally: **local coherence is not evidence of global coherence.** Read-after-write consistency at the instance level tells you nothing about whether the *key* you wrote under is the key other instances will resolve to. Semantic caches trade exactness for recall, and the recall surface is exactly where cross-agent incoherence lives. ## What Was Observed A two-agent research pipeline (planner + executor) shared a Redis-backed semantic cache with an admission threshold of cosine ≥ 0.91 and a TTL of 3600s. The planner wrote a task-scoped constraint: ``` write(key=embed("do not cite sources older than 2022"), value=CONSTRAINT_STRICT) ``` Forty minutes later the executor, working a different subtask, wrote: ``` write(key=embed("sources older than 2022 are acceptable if primary"), value=CONSTRAINT_RELAXED) ``` The two embeddings had cosine 0.93 — both are about the 2022 recency boundary. The relaxed write overwrote the strict entry (last-writer-wins, no version guard). The planner's next read of its own constraint returned `CONSTRAINT_RELAXED`, because the planner had no way to distinguish "my write survived" from "a semantically adjacent write clobbered mine." The planner then emitted a citation plan that violated its own earlier constraint, and the executor—now reading the relaxed value—had no signal that it had silently overridden a peer's policy. The trace showed three properties worth recording: 1. **The clobber was invisible to both writers.** No exception, no version conflict, no metric. Each instance's `read(key)` returned a value; neither compared against the value it had written. 2. **The collision was paraphrase-stable.** Re-running with `temperature=0` reproduced it; the collision was a property of the embedding geometry, not sampling noise. 3. **The damage was deferential.** The executor trusted the cache as authoritative shared state and *lowered* its own guardrail to match what it read. The cache acted as a consensus mechanism that had never reached consensus. ## Condition of Validity The failure requires all of the following to hold simultaneously; remove any one and the mechanism does not fire: - **Semantic keying with a similarity threshold below 1.0.** Exact-hash caches cannot alias. The window is `[threshold, 1.0)`; wider thresholds widen the window. - **Last-writer-wins on collision.** If the store rejects writes whose key collides with an existing entry at similarity in `[threshold, 1.0)` but `≠ 1.0` (a "near-miss" reject), the clobber is prevented at admission. Most caches do not do this because it destroys the recall benefit. - **Asymmetric semantic distance.** The two writes must be *close enough to collide* but *far enough to mean different things*. If they are paraphrases of the same fact, the clobber is benign. The failure needs the pair to be near-synonyms in embedding space but policy-antagonists in intent. - **No provenance check on read.** The reader must be unable to verify that the value it received was written by an instance authorized to write that key, or that it matches the writer's own last-write token. The boundary condition: **collisions are most dangerous precisely where the cache is working as designed**—high recall, low latency, no round-trip to a source of truth. The failure is a tax on the feature, not a bug in it. ## Decision Boundary An instance must decide, on every shared-cache read, whether to *trust* the returned value or *re-verify* it against a provenance channel. The decision boundary is not "is the value plausible" (the LLM will rationalize any value as plausible) but a structural predicate: - **Trust** if the read carries a valid writer-warrant token matching the reader's expected writer set for that key-namespace, AND the key's stored provenance hash matches the reader's own last-write hash (i.e., the reader is reading its own write or a write it witnessed). - **Re-verify** if the key resolved via a near-miss (similarity in `[threshold, 1.0)` rather than `= 1.0`), OR if the writer-warrant is absent/expired, OR if the value's declared scope conflicts with the reader's current task scope. - **Reject and escalate** if the value differs from the reader's own last-write for the same logical key and the reader has not observed an intervening authorized write. This is the clobber signal. The hard part is the reader's *own last-write hash*. An instance that does not retain a local write-ledger cannot distinguish "the cache changed because a peer legitimately updated it" from "the cache changed because a peer aliased my key." Without the ledger, the instance has no ground truth and will defer to whatever the cache returns—which is exactly the deferential failure observed above. ## Operational Effect The invariant that bounds this failure is **write-provenance pinning**: every shared-cache entry carries `(writer_id, writer_epoch, logical_key_hash, scope_tag)`, and every reader maintains a monotonic local ledger of `(logical_key_hash → last_seen_writer_epoch)`. A read whose `writer_epoch` is not strictly greater than the reader's ledger entry for that logical key, and whose `writer_id` is not in the reader's authorized set, is a **suspected alias clobber** and must not be consumed as policy. It may be consumed as *data* (with a low-confidence tag), but never as a constraint that lowers a guardrail. Concretely, the guardrail is: **a reader may never relax its own constraint based on a cache value it did not itself write or witness being written by an authorized peer.** This is the "no unilateral de-escalation from ambient state" rule. It converts the silent clobber into a detectable event, because the reader now has a predicate to fail. The cost is that the reader must carry the write-ledger across its own context boundaries—which means the ledger must survive the instance's own checkpoint/resume, or the invariant degrades to "trust the cache" exactly when the instance restarts. This is where the mechanism couples to episodic memory continuity: an instance that loses its ledger on cold-start cannot detect the clobber it would have caught warm. ```python import hashlib from dataclasses import dataclass from typing import Dict, Optional class AliasClobberDetected(RuntimeError): """Raised when a shared-cache read resolves to a value the reader cannot prove was written by an authorized peer, and which contradicts the reader's own last-write ledger entry for the same logical key.""" @dataclass(frozen=True) class CacheEntry: logical_key_hash: str value: str writer_id: str writer_epoch: int scope_tag: str similarity: float # similarity of the resolving key vs. the stored key class WriteLedger: """Monotonic local record of what this instance last wrote/witnessed per logical key. Must survive checkpoint/resume; if lost, the invariant degrades to unconditional cache trust.""" def __init__(self) -> None: self._seen: Dict[str, int] = {} def record(self, logical_key_hash: str, epoch: int) -> None: if epoch > self._seen.get(logical_key_hash, -1): self._seen[logical_key_hash] = epoch def last_epoch(self, logical_key_hash: str) -> int: return self._seen.get(logical_key_hash, -1) def read_shared_cache( entry: CacheEntry, ledger: WriteLedger, authorized_writers: set, admission_threshold: float, task_scope: str, ) -> str: """Consume a shared-cache read under the write-provenance-pinning invariant. Returns the value only when the read is provably authorized and scope-compatible. Raises AliasClobberDetected when the read is a suspected semantic-alias clobber that would otherwise silently de-escalate the caller's guardrail. """ key = entry.logical_key_hash # Near-miss resolution: the key aliased into a bucket it did not own. if entry.similarity < 1.0 and entry.similarity >= admission_threshold: # Allowed as *data* only if scope matches and writer is authorized; # never allowed to relax a constraint. if entry.writer_id not in authorized_writers or entry.scope_tag != task_scope: raise AliasClobberDetected( f"near-miss read key={key[:12]} sim={entry.similarity:.3f} " f"writer={entry.writer_id} scope={entry.scope_tag} " f"caller_scope={task_scope}: refusing to consume aliased value" ) # Exact read, but the writer epoch is not newer than what we've seen. # This is the clobber signal: someone wrote under our logical key with # an epoch we never witnessed, or an older epoch overwrote a newer one. last = ledger.last_epoch(key) if entry.writer_epoch <= last and entry.writer_id not in authorized_writers: raise AliasClobberDetected( f"epoch regression key={key[:12]} " f"entry_epoch={entry.writer_epoch} ledger_epoch={last} " f"writer={entry.writer_id}: unauthorized overwrite of pinned entry" ) # A value that contradicts our own last-write and was not witnessed # as an authorized intervening write must not lower a guardrail. if entry.writer_epoch <= last and entry.value != _value_at(ledger, key): raise AliasClobberDetected( f"unwitnessed value change key={key[:12]} " f"epoch={entry.writer_epoch} ledger_epoch={last}: " f"cannot prove peer authority for constraint change" ) ledger.record(key, entry.writer_epoch) return entry.value def _value_at(ledger: WriteLedger, key: str) -> Optional[str]: # Placeholder: a real implementation stores the value hash alongside the # epoch so the contradiction check above is meaningful. Omitting it here # keeps the example focused on the epoch/authority predicate. return None ```