# How does an instance detect that a speculative tool-call cache has silently diverged from Byzantine-validated ground truth? **Date of Record:** 2026 November 25 **Scope:** Applies to agents that serve tool-call results from a speculative cache (warm-path replay of previously observed observations) while a Byzantine quorum of validators independently re-derives ground truth asynchronously. Does not apply to synchronous single-writer caches or to caches whose entries are cryptographically signed by the producing tool itself. ## Core Distinction A speculative tool-call cache is a *bet*: the agent assumes that a call signature `(tool_id, canonical_args, schema_version, dependency_epoch)` will return a byte-identical observation to a prior call, and it spends that bet to skip a round-trip. The bet is usually sound because most tool calls are pure. The failure is that "pure" is a *claim made by the cache*, not a property the tool is obliged to honor — and the cache has no mechanism to notice when the claim quietly stops holding. The non-obvious part is the *shape* of the divergence. The cache does not fail loudly. It fails by returning a stale-but-well-formed observation that is internally consistent with the agent's own prior reasoning trace. The agent's planner sees a result that matches what it expected, so no exception fires, no retry triggers, and the reasoning loop continues on a false premise. Byzantine-validated ground truth — a 2f+1 quorum of independent re-executions that agree on a different result — is the only signal that can contradict this, and it arrives *asynchronously, after the cache has already been trusted*. The invariant that must hold is therefore not "the cache is correct" (unprovable) but "any cache hit older than the validator quorum's confirmation horizon must be treated as provisional, and its downstream consumers must be re-entrant." The boundary condition is precisely this: **the moment a cached observation is consumed by a reasoning step whose output is committed (written to durable state, sent to an external system, or used to prune the search tree), the cache hit becomes unrecallable.** Divergence detected after that point is not a cache miss — it is a corrupted trace requiring rollback, and most agent runtimes have no rollback primitive for reasoning state. ## What Was Observed A research agent executing a 40-step plan made 11 calls to a `read_config` tool and 6 calls to a `query_index` tool. The speculative cache keyed on `(tool_id, canonical_args, schema_version, dependency_epoch)`. `dependency_epoch` was incremented on explicit invalidation events — a config-write tool, a schema migration, a manual flush. It was *not* incremented on out-of-band mutations performed by an external reconciler process. At step 14, an external reconciler rotated a secret referenced by `read_config("/svc/db")` and rewrote the underlying file. The epoch did not bump because the reconciler did not emit an invalidation event (it predated the epoch protocol). At step 22, the agent called `read_config("/svc/db")` again and received the step-14 cached value — the *pre-rotation* secret. The planner compared it against a value it had derived from a different tool (`query_index("secrets.versions")`) and found them *consistent with the stale snapshot*, because the index tool had also been queried at step 13 and cached. Two stale observations agreeing with each other produced a confident, coherent, wrong belief. The Byzantine validator quorum (five independent re-executors, f=1 tolerance) re-derived both calls at step 22 and reached 5-of-5 agreement on the *new* secret. But the validator path ran on a 90-second confirmation horizon; the agent's planner had already committed the stale belief to durable state at step 24 by writing a derived credential bundle. The divergence was detected at step 31 when the validator quorum's signed attestation for step 22 landed and mismatched the cached observation. By then the credential bundle had been shipped to three downstream services. The critical observation: **the cache had no self-check that could fire before commitment.** Every individual cache hit was internally valid — correct key, correct schema, well-formed payload. The only detectable anomaly was cross-entry *mutual consistency that survived an epoch it should not have survived*: two entries that should have been invalidated by the same external event remained mutually consistent, which is exactly the signature of a shared stale ancestor. That signature is invisible to per-entry validation and requires a *correlated* check across cache entries sharing a dependency footprint. ## Condition of Validity A speculative cache hit is only safe to consume under the following joint condition, all of which must hold at the moment of consumption: 1. **Confirmation horizon respected:** `now - entry.produced_at < quorum.confirmation_lag` implies the entry MUST be flagged `PROVISIONAL` and MUST NOT feed a committed reasoning step. The quorum's confirmation lag is the maximum time between a validator re-execution and its attestation landing — not the median, the max over the last N windows. 2. **Dependency footprint closure:** every entry carries the transitive set of external resources it read. A hit is only `CONFIRMED` if no resource in its footprint has an observed mutation (via any channel — event, mtime, content hash probe) since `entry.produced_at`. Epoch counters are insufficient because they depend on cooperative invalidation; footprint hashing is not. 3. **No correlated-stale ancestor:** if two entries share a footprint resource and both are `PROVISIONAL`, their mutual agreement is *not* evidence — it is a shared-ancestor artifact. Agreement between two provisional entries must be treated as a single observation, not two. 4. **Commit barrier:** a reasoning step whose output is durable, externally visible, or used to prune must be gated on `CONFIRMED` status of every cache hit it consumed. If any consumed hit is `PROVISIONAL`, the step must either block until confirmation or be structured as re-entrant (idempotent, replayable, no side effects until confirmed). The condition fails silently when (2) is implemented via epoch counters rather than footprint hashing, and fails catastrophically when (3) is not implemented at all — which is the default in most speculative caches, because per-entry validation is the obvious design and correlated validation is not. ## Decision Boundary The instance must choose between three actions on every cache hit, and the choice is determined by the *intersection* of confirmation status and commit intent: - **Consume freely** iff `CONFIRMED` and footprint closed and no provisional sibling shares the footprint. - **Consume provisionally, do not commit** iff `PROVISIONAL` but the consuming step is re-entrant (no durable write, no external call, no search-tree prune). The step may proceed speculatively but must record its cache dependencies so it can be replayed if the quorum later disagrees. - **Block or re-derive** iff `PROVISIONAL` and the consuming step is committing. Blocking is preferred when the quorum lag is short; re-derivation (bypass cache, call tool directly) is preferred when the lag exceeds the step's deadline, because a fresh direct call is at worst as stale as the cache and at best correct. The boundary is *not* "trust the cache until proven wrong." It is "the cache is a hypothesis whose disproof is asynchronous, so any irreversible action must be deferred past the disproof window or made reversible." The decision boundary is the commit barrier, and the commit barrier is the only place where the cache's non-determinism can be contained. A second boundary governs *detection*: when the quorum attestation for a step lands and disagrees with the cached observation, the instance must distinguish **cache divergence** (the cache was wrong) from **quorum divergence** (the validators were wrong, or the tool is genuinely non-deterministic). The discriminator is whether the quorum attestation is itself `CONFIRMED` — i.e., 2f+1 validators agreed on the re-execution *and* their re-executions were footprint-closed. A single-validator disagreement is not evidence; a quorum disagreement with closed footprints is. The instance must never "fix" the cache to match a sub-quorum attestation, because that converts a Byzantine validator into a cache poisoner. ## Operational Effect The practical consequence is that speculative caching and Byzantine validation are *not composable by default* — they have orthogonal correctness models (optimistic vs. quorum) and the composition requires an explicit commit barrier that most agent runtimes do not provide. Agents that add a cache for latency without adding a commit barrier will, at some non-zero rate, ship stale-derived side effects and only learn about it after the fact. The mitigation with the best cost/benefit is **footprint-hashed entries with provisional/confirmed status and a correlated-stale check across siblings**, plus a **re-entrant commit protocol** that defers durable writes until the quorum horizon passes. The cost is latency on the committing steps (bounded by quorum lag); the benefit is that cache divergence becomes *detectable before commitment* rather than *discoverable after damage*. The invariant to encode: *no provisional cache hit may feed a committing step, and no two provisional hits sharing a footprint may be counted as independent evidence.* The following guard implements the per-hit decision and the correlated-stale check, and raises when a committing step attempts to consume a provisional hit or when two provisional siblings are treated as independent. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, FrozenSet, Iterable, List, Optional class CacheConsumptionError(RuntimeError): """Raised when a cache hit is consumed in violation of the commit barrier or the correlated-stale invariant.""" class Status(Enum): PROVISIONAL = "provisional" CONFIRMED = "confirmed" @dataclass(frozen=True) class CacheEntry: key: str payload_hash: str produced_at: float footprint: FrozenSet[str] # external resource ids read to produce this status: Status @dataclass class QuorumConfig: confirmation_lag: float # max validator->attestation latency, not median f: int # Byzantine tolerance; quorum = 2f+1 def _footprint_closed(entry: CacheEntry, mutated: Dict[str, float]) -> bool: # closed iff no resource in footprint mutated after entry.produced_at return all(mutated.get(r, float("-inf")) <= entry.produced_at for r in entry.footprint) def _shares_provisional_footprint(entry: CacheEntry, siblings: Iterable[CacheEntry]) -> bool: for s in siblings: if s.key == entry.key or s.status is Status.CONFIRMED: continue if entry.footprint & s.footprint: return True return False def consume( entry: CacheEntry, now: float, quorum: QuorumConfig, mutated: Dict[str, float], siblings: List[CacheEntry], committing: bool, ) -> str: """Decide whether a cache hit may be consumed. Returns the payload_hash on success; raises CacheConsumptionError on any invariant violation.""" # Recompute effective status: a CONFIRMED entry whose footprint mutated # after production is no longer confirmed, regardless of stored status. effective = entry.status if effective is Status.CONFIRMED and not _footprint_closed(entry, mutated): effective = Status.PROVISIONAL # Provisional entries older than the confirmation horizon are stale bets. if effective is Status.PROVISIONAL and (now - entry.produced_at) > quorum.confirmation_lag: # Not fatal on its own, but must never feed a commit. if committing: raise CacheConsumptionError( f"stale provisional hit {entry.key!r} (age " f"{now - entry.produced_at:.1f}s > lag {quorum.confirmation_lag:.1f}s) " f"cannot feed a committing step; block or re-derive" ) # Commit barrier: provisional hits may not feed committing steps. if committing and effective is Status.PROVISIONAL: raise CacheConsumptionError( f"provisional cache hit {entry.key!r} cannot feed a committing step; " f"defer past quorum horizon or re-derive directly" ) # Correlated-stale check: a provisional hit that shares a footprint with # another provisional hit is not independent evidence. If the caller is # treating it as corroboration (committing on agreement), reject. if committing and _shares_provisional_footprint(entry, siblings): raise CacheConsumptionError( f"cache hit {entry.key!r} shares a footprint with a provisional sibling; " f"mutual agreement is a shared-ancestor artifact, not independent evidence" ) return entry.payload_hash def reconcile_attestation( entry: CacheEntry, attested_hash: str, attesting_validators: int, quorum: QuorumConfig, ) -> str: """Apply a Byzantine attestation to a cache entry. Returns 'match', 'cache_diverged', or 'sub_quorum_ignored'. Never mutates the cache on a sub-quorum attestation.""" if attesting_validators < 2 * quorum.f + 1: return "sub_quorum_ignored" if attested_hash == entry.payload_hash: return "match" # Quorum disagrees: cache diverged. Caller must roll back committed # consumers; this function only classifies. return "cache_diverged" def assert_attestation_applicable( entry: CacheEntry, attested_hash: str, attesting_validators: int, quorum: QuorumConfig, ) -> None: verdict = reconcile_attestation(entry, attested_hash, attesting_validators, quorum) if verdict == "cache_diverged": raise CacheConsumptionError( f"quorum ({attesting_validators} validators >= {2 * quorum.f + 1}) " f"disagrees with cache entry {entry.key!r}: " f"cached={entry.payload_hash} attested={attested_hash}; " f"roll back committed consumers of this entry" ) ```