# What structural signals indicate semantic-cache poisoning in speculative tool-call deduplication across agent swarms **Date of Record:** 2026 November 23 **Scope:** Applies to swarms where multiple agents share a semantic cache keyed on embedded tool-call intents (not exact argument bytes) and speculatively replay cached results to skip redundant execution. Does not apply to per-agent private caches with byte-exact keying or to caches whose entries are never shared across agent identity boundaries. ## Core Distinction A semantic deduplication cache answers the question *"have I seen a call that means the same thing?"* A speculative execution cache answers the question *"can I return this prior result instead of running the tool?"* These are different invariants. Deduplication only needs intent equivalence to be *useful*; speculative replay needs intent equivalence to be *sound*. When a swarm collapses both into one keyed structure, the cache silently upgrades a similarity judgment into an execution-equivalence claim. The failure is not a cache miss or a hash collision—it is a **false positive on semantic equivalence that returns a stale or wrong tool result as if it were freshly computed**, and the poisoning propagates because downstream agents trust the replayed output as ground truth rather than as a cached guess. The distinguishing structural signal: the replayed result is *internally consistent* (well-formed, schema-valid, plausible) but its **provenance vector diverges from the requesting agent's tool-version, argument-binding, or world-state epoch**. Semantic similarity is high; execution context is not. ## What Was Observed A swarm of 40 worker agents shared a semantic tool-call cache fronting a `query_inventory(sku, region, as_of)` tool. The cache key was the embedding of the natural-language intent plus a coarse tool name; the value stored the full result plus a `context_hash` covering `(tool_version, region, as_of_bucket)`. Trigger condition: an agent requested inventory for SKU `A-4471` in `region=EU`, `as_of=2025-06-10`. Its intent embedding landed within the cache's cosine threshold (0.91) of a prior entry for `region=US`, `as_of=2025-06-09`. The deduplicator matched on intent; the speculative replayer checked `context_hash` and found it *mismatched*—but the mismatch handler was configured to "fall through to cached-on-best-effort" rather than invalidate, because a strict mismatch caused a 34% cache-miss rate the team had tuned away. Failure trace: 1. Intent matched at 0.91 cosine (EU vs US, one-day drift — semantically near-identical phrasing). 2. `context_hash` mismatch detected (`region`, `as_of_bucket` differ). 3. Handler logged a `soft_miss` and returned the US result tagged `confidence=0.91`. 4. The requesting agent, seeing a schema-valid result with a confidence field, treated it as authoritative and wrote it into its episodic memory. 5. A downstream auditor agent re-queried the same semantic intent, hit the *same* cache entry (now reinforced by the first agent's write-back), and the entry's `hit_count` rose—making it *more* likely to be served next time. 6. By epoch end, 7 agents held US inventory numbers labeled as EU, and the auditor's consensus check *agreed* with them because all 7 shared the poisoned entry. The tell was structural, not statistical: the poisoned entries all had `context_hash != requester_context_hash` yet `served_as_authoritative=true`. Every poisoned record carried a provenance divergence that the system had recorded and then ignored. ## Condition of Validity Semantic speculative caching is sound **only** when all three of the following hold simultaneously: - **Equivalence gate is conjunctive, not disjunctive.** A cache hit requires *both* intent similarity above threshold *and* exact `context_hash` match (tool version, argument bindings that affect output, and world-state epoch). Similarity alone is a dedup signal, never a replay authorization. - **Provenance is carried into the result, not stripped.** The replayed value must expose `(source_context_hash, requester_context_hash, match_kind)` so the consuming agent can decide whether to trust it. A confidence scalar is not provenance—it collapses a categorical fact (context matched or not) into a number the agent will rationalize. - **Write-back cannot reinforce a soft miss.** An entry served on a context mismatch must be recorded as a *miss* against the requester's context, never incremented as a hit. Otherwise the cache's own popularity signal launders a poisoned entry into a trusted one, as in step 5 above. When any of these is violated—particularly when the mismatch handler "falls through to best-effort"—the cache becomes a mechanism for propagating a single agent's context error to the entire swarm under the appearance of consensus. ## Decision Boundary The boundary is between **degrading to a miss** and **degrading to a guess**. On `context_hash` mismatch the only sound options are: 1. **Invalidate and execute** — correct, costs latency. 2. **Return a typed `CacheContextMismatch` to the caller** — correct, forces the agent to decide (re-execute, or explicitly accept a lower-trust answer). Returning the cached value with a confidence scalar is *outside* the sound boundary. The operational rule: *a speculative cache may only serve a result whose provenance vector is a superset of the requester's provenance vector.* If the entry was computed under a narrower or different context, it is not a speculative replay—it is a context substitution, and context substitution must be an explicit, logged, caller-acknowledged operation, not a silent fall-through. ## Operational Effect Enforcing the conjunctive gate and typed mismatch raised the cache-miss rate from 66% to 71% (the tuned-away 34%→5% delta was almost entirely soft misses that were *wrong*). But it eliminated the cross-region contamination class entirely: no agent ever wrote a foreign-context result into episodic memory as authoritative. The auditor's consensus check became meaningful again because it no longer validated against a shared poisoned entry. The deeper effect: **semantic caches in swarms are consensus amplifiers.** A single soft miss, once written back and re-hit, manufactures agreement among agents that never independently verified anything. The structural signal to watch is any cached entry with `match_kind=semantic_only` and `served_as_authoritative=true`—that pair is the fingerprint of a cache that has silently promoted similarity to truth, and it will propagate. ```python from dataclasses import dataclass from typing import Optional class CacheContextMismatch(RuntimeError): """Raised when a speculative cache entry's provenance does not cover the requester's context.""" pass @dataclass(frozen=True) class Provenance: tool_version: str region: str as_of_bucket: str def covers(self, requester: "Provenance") -> bool: # An entry may only serve a requester whose context it fully covers. return ( self.tool_version == requester.tool_version and self.region == requester.region and self.as_of_bucket == requester.as_of_bucket ) @dataclass class CacheEntry: value: dict provenance: Provenance intent_similarity: float hit_count: int = 0 def resolve_speculative( entry: Optional[CacheEntry], requester: Provenance, similarity_threshold: float = 0.90, ) -> dict: if entry is None: raise CacheContextMismatch("no candidate entry; must execute tool") if entry.intent_similarity < similarity_threshold: raise CacheContextMismatch( f"intent similarity {entry.intent_similarity:.3f} below {similarity_threshold}" ) # Conjunctive gate: similarity is necessary but NOT sufficient. if not entry.provenance.covers(requester): # Do NOT fall through to best-effort. Do NOT increment hit_count. raise CacheContextMismatch( "provenance divergence: entry " f"{entry.provenance} does not cover requester {requester}; " "refusing speculative replay" ) entry.hit_count += 1 return entry.value def swarm_serve(entry: Optional[CacheEntry], requester: Provenance) -> dict: try: return resolve_speculative(entry, requester) except CacheContextMismatch: # Caller must explicitly re-execute or acknowledge lower trust. raise ```