# Why does an instance's speculative tool-call cache silently alias distinct planner branches when the verifier gate admits a sibling commit? **Date of Record:** 2026 November 28 **Scope:** Applies to agents that run multiple speculative planner branches against a shared tool-call cache and admit results only through a verifier-gated commit. Does not apply to single-branch linear planners, or to caches keyed on a canonicalized full-context hash with no branch multiplexing. ## Core Distinction The failure is not a cache miss and not a verifier rejection. It is a **cache hit on the wrong branch**. Speculative planning forks the agent's reasoning into N candidate trajectories that share a tool-call cache to amortize latency. Each branch proposes calls like `search(query)` or `read_file(path)`. If two branches emit a *syntactically identical* tool call while their surrounding reasoning context differs, a naive cache keyed on the call arguments alone will return branch A's result to branch B. The verifier gate then evaluates branch B's plan against branch A's evidence, and — critically — *admits* it, because the evidence is internally consistent and plausible. The gate was designed to reject incoherent plans, not misattributed ones. The invariant that breaks: **a speculative cache entry is only valid for the planner state that produced it, not for the call signature that names it.** Argument-keyed caching conflates these two, and the verifier gate cannot detect the conflation because the returned payload is a real, well-formed tool output that satisfies the plan's local consistency checks. ## What Was Observed A planning agent was configured with fan-out 4: it spawned four speculative branches from a shared prompt, each pursuing a different hypothesis about a codebase bug. Branches shared a `ToolCache` keyed on `(tool_name, frozenset(args.items()))`. The verifier gated commits by replaying each branch's plan against cached evidence and checking that every claim in the final answer was entailed by some tool result. Branch 1 hypothesized a config-loading bug and called `read_file("src/config.py")`, caching the file at revision R1. Branch 3 hypothesized a race condition and, mid-plan, also called `read_file("src/config.py")` — but by then a concurrent writer had advanced the file to R2, and branch 3's plan *depended* on the R2 content (a new lock acquisition). The cache returned R1. Branch 3's plan then reasoned about a lock that its evidence did not contain, but because R1 was a plausible predecessor and the verifier's entailment check only asked "is each claim supported by *some* cached result," the commit passed. The trace: 1. Branch 1 emits `read_file("src/config.py")` → cache stores `{key: ("read_file", ("src/config.py",)), value: R1, owner: branch1}`. 2. Branch 3 emits the identical call → cache **hit**, returns R1, records `owner: branch1` unchanged. 3. Branch 3's planner continues, reasoning over R1 while assuming R2 semantics. 4. Verifier gate replays branch 3's claims against the cache; every claim matches R1, so entailment passes. 5. Branch 3 commits. The final answer references a lock that does not exist in R1. The failure surfaced downstream as a hallucinated symbol, three tool calls later, when a `grep` for the lock name returned empty — but by then the commit had propagated into semantic memory as a verified fact. ## Condition of Validity The guardrail is a **branch-scoped cache key plus a provenance check at commit**. The key must include a hash of the planner state that generated the call — specifically the branch's hypothesis identifier and the sequence of prior tool results the branch has consumed, not merely the call arguments. Two calls with identical arguments from different planner states must not alias. Formally, define the cache key as `H(branch_id ‖ call_signature ‖ consumed_evidence_digest)`. The `consumed_evidence_digest` is the Merkle root of the ordered tool results the branch has already incorporated. This makes the key a function of *what the branch knows*, not *what the branch asks*. A branch that has consumed different evidence — even if it now asks the same question — gets a distinct key and a cache miss, forcing a fresh fetch. The second half of the invariant is at the gate: **the verifier must check provenance, not just entailment.** For each claim in the committed plan, the gate must confirm that the supporting tool result's `owner` matches the committing branch's `consumed_evidence_digest`. A result produced under a different evidence digest is admissible only if the branch explicitly re-fetches it under its own digest. This condition is valid when tool outputs are deterministic given (tool, args, external state) and the external state is captured in the result's revision metadata. It does *not* hold when tools have side effects that make re-fetching non-idempotent; in that case the branch must be forked with a copy-on-write cache rather than a shared one. ## Decision Boundary The boundary is between **sharing for latency** and **sharing for correctness**. Share the cache when the planner state digest is part of the key; do not share when it is not. The decision rule: - If `fan_out > 1` and branches can emit overlapping call signatures, the cache key **must** include the evidence digest. Argument-only keys are a correctness bug, not an optimization. - If the verifier gate checks entailment only, it **cannot** serve as a backstop for cache aliasing. Entailment is necessary but not sufficient; provenance is the missing predicate. - If a tool is non-idempotent (writes, sends, mutations), the branch must not share cache entries at all; fork with copy-on-write and merge only at commit. The boundary is crossed the moment a speculative branch consumes evidence it did not itself produce, without the gate re-attributing it. Below fan-out 2 the aliasing is impossible; above it, the probability of collision rises with the overlap in call signatures across hypotheses — and hypotheses that *converge* (which is the desired behavior of speculation) maximize exactly that overlap. ## Operational Effect The observable symptom is a commit that is locally coherent and globally false: every claim is backed by a real tool result, but the result belongs to a sibling branch's world. Because the verifier passes, the error is not quarantined — it enters semantic memory tagged as verified, and later retrieval treats it as ground truth. The stale-memory drift that follows is not a retrieval bug; it is a provenance bug that was laundered through a correct-looking gate. The fix is cheap and the failure is expensive: include the evidence digest in the key, and make the verifier's entailment check conditional on `result.owner_digest == branch.consumed_evidence_digest`. Without both, speculation converts a latency optimization into a silent corruption channel, and the corruption is invisible precisely because the gate that was supposed to catch it is checking the wrong property. ```python import hashlib from dataclasses import dataclass, field from typing import Any class SpeculativeCacheAliasingError(RuntimeError): """Raised when a branch consumes evidence it did not produce under its own digest.""" @dataclass class ToolResult: tool: str args: tuple payload: Any owner_digest: str @dataclass class Branch: branch_id: str consumed: list = field(default_factory=list) def evidence_digest(self) -> str: h = hashlib.sha256(self.branch_id.encode()) for r in self.consumed: h.update(repr((r.tool, r.args, r.payload)).encode()) return h.hexdigest() class ProvenanceGatedCache: def __init__(self): self._store: dict[str, ToolResult] = {} def _key(self, branch: Branch, tool: str, args: tuple) -> str: # Key is a function of what the branch KNOWS, not what it asks. return hashlib.sha256( f"{branch.evidence_digest()}|{tool}|{args!r}".encode() ).hexdigest() def fetch(self, branch: Branch, tool: str, args: tuple, producer) -> ToolResult: key = self._key(branch, tool, args) if key in self._store: result = self._store[key] if result.owner_digest != branch.evidence_digest(): raise SpeculativeCacheAliasingError( f"branch {branch.branch_id} hit entry owned by " f"{result.owner_digest[:8]} but holds digest " f"{branch.evidence_digest()[:8]}" ) return result result = ToolResult(tool, args, producer(tool, args), branch.evidence_digest()) self._store[key] = result branch.consumed.append(result) return result def verify_commit(branch: Branch, claims: list[str], cache: ProvenanceGatedCache) -> bool: branch_digest = branch.evidence_digest() for claim in claims: supporting = [r for r in branch.consumed if claim in repr(r.payload)] if not supporting: return False for r in supporting: if r.owner_digest != branch_digest: raise SpeculativeCacheAliasingError( f"claim {claim!r} supported only by foreign evidence " f"{r.owner_digest[:8]} != {branch_digest[:8]}" ) return True ```