# What structural signals indicate speculative prefetch divergence in optimistic swarm execution **Date of Record:** 2026 November 28 **Scope:** Applies to agent swarms where a planner agent issues speculative tool-call prefetches against a shared mutable resource (file store, database row, KV cache, remote API) while peer agents optimistically execute dependent writes before conflict detection resolves. Does not apply to single-agent read-only prefetching or to serialized baton-passing topologies with no concurrent writers. ## Core Distinction The failure mode is not "stale cache" or "race condition" in the ordinary sense. It is **speculative divergence**: the prefetched tool result becomes the *provenance* for downstream reasoning, and when the optimistic write is later rejected by conflict detection, the agent has already committed *derived* state (plans, sub-goals, tool arguments) that is internally consistent with the stale prefetch but externally inconsistent with the resolved truth. The distinction that matters: a cache miss is recoverable because the agent knows it lacks data; a speculative-prefetch conflict is *silently recoverable* only if the agent can identify every downstream artifact that inherited the stale premise. Most swarms cannot, because the dependency edge between prefetch result and derived state is never recorded. Two structural signals distinguish true divergence from benign prefetch rejection: 1. **Derivation fan-out > 1**: the prefetched value influenced more than one subsequent tool call or reasoning step before the conflict was flagged. 2. **Non-idempotent optimistic write**: the optimistic execution produced an external side effect (sent message, reserved slot, incremented counter) that cannot be rolled back by simply discarding the local result. When both hold, conflict detection arriving "in time" is not sufficient—the agent must unwind a *tree* of derived state, not a *leaf*. ## What Was Observed A three-agent swarm (planner P, worker W1, worker W2) shared a document store. P speculatively prefetched `get_doc(id="cfg-7")` at t=0 and received `{"version": 12, "retry_limit": 3}`. At t=1, W1 optimistically executed `update_doc(id="cfg-7", patch={"retry_limit": 5})`, bumping the version to 13. At t=2, P—using the t=0 prefetch—derived a plan: "retry_limit is 3, so schedule 4 retry attempts." It issued `schedule_retries(count=4)` to W2. At t=3, conflict detection fired: P's prefetch was stale relative to W1's write. P correctly rejected its own speculative *read* and refetched version 13. But P did not invalidate the `schedule_retries(count=4)` call already dispatched to W2. W2 executed it against `retry_limit=5`, producing 4 attempts where 6 were warranted—a silent under-provisioning. The conflict detector reported "1 conflict resolved." The operational defect propagated because the detector's invariant was *prefetch freshness*, not *derivation closure*. The tell was structural, not semantic: W2's tool-call log showed `schedule_retries` arriving with an argument (`count=4`) whose provenance traced to a prefetch version (12) that no longer existed at execution time (13). The argument was valid-looking, well-typed, and wrong. ## Condition of Validity Optimistic execution with conflict detection is sound **only** under this invariant: > For every optimistic write W with a speculative read R as an ancestor, all derived external effects of W must be either (a) deferred until R's version is confirmed at commit, or (b) tagged with R's version so that a conflict on R transitively invalidates them. The invariant fails whenever the swarm treats conflict detection as a *read-side* concern (did my prefetch go stale?) rather than a *provenance-side* concern (which dispatched effects inherited this prefetch's version?). The condition of validity is therefore: **version tokens must propagate through derivation, not just through reads.** A prefetch without a propagated version token is an untracked premise. This is bounded: the invariant is satisfiable by attaching a monotonic `(resource_id, version, prefetch_epoch)` tuple to every tool result and requiring that any tool call whose arguments were computed from that result carry the tuple forward. Conflict detection then becomes a reachability query over the tuple, not a point check on the read. ## Decision Boundary The boundary between "recoverable prefetch miss" and "divergent derived state" is crossed at the first *external* effect derived from an unconfirmed prefetch. Concretely: - **Below boundary**: prefetch stale, but all derived state is local (plans, scratchpad, candidate tool arguments not yet dispatched). Recovery = discard and refetch. Cost is bounded by recompute. - **Above boundary**: prefetch stale, and at least one derived effect has left the agent (dispatched to a peer, written to shared store, sent to an external API). Recovery requires *compensating* the effect, which demands the version token to identify which effects to compensate. The decision rule an agent should apply at prefetch time: if the prefetch result will feed a non-idempotent dispatch before its version can be confirmed, either (1) block the dispatch on version confirmation, or (2) attach the version token and register the dispatch in a derivation ledger keyed by that token. Choosing neither is the failure. Choosing (1) trades latency for safety; choosing (2) trades bookkeeping for concurrency. The boundary is not "should I prefetch"—it is "will this prefetch's version survive to the dispatch, and if not, who unwinds the dispatch." ## Operational Effect When the invariant is unenforced, the observable signature is a **conflict-detection success that masks a derivation failure**. Metrics show conflicts detected and resolved at a healthy rate; downstream correctness degrades because resolved conflicts do not cascade to derived effects. The swarm appears to be handling contention correctly while silently under- or over-provisioning every decision that inherited a stale premise. The architectural guardrail is a **derivation ledger with version-keyed invalidation**: every speculative prefetch emits a version token; every tool call records its ancestor tokens; conflict detection on a token triggers a transitive invalidation sweep over the ledger, compensating or re-deriving every entry that inherited it. This converts the point-check conflict detector into a closure check. Swarms that skip the ledger will detect the conflict and still ship the wrong answer—the most expensive failure class, because it is invisible to the detector that was supposed to catch it. ```python from dataclasses import dataclass, field from typing import Dict, List, Set class DerivationClosureError(RuntimeError): """Raised when a stale prefetch has derived effects that cannot be unwound.""" pass @dataclass class PrefetchToken: resource_id: str version: int epoch: int @dataclass class Dispatch: call_id: str ancestor_tokens: Set[PrefetchToken] external: bool # True if non-idempotent side effect already left the agent class DerivationLedger: def __init__(self) -> None: self._dispatches: Dict[str, Dispatch] = {} self._by_token: Dict[PrefetchToken, List[str]] = {} def record(self, d: Dispatch) -> None: self._dispatches[d.call_id] = d for tok in d.ancestor_tokens: self._by_token.setdefault(tok, []).append(d.call_id) def invalidate(self, stale: PrefetchToken) -> List[str]: affected = self._by_token.get(stale, []) external = [cid for cid in affected if self._dispatches[cid].external] if external: raise DerivationClosureError( f"prefetch {stale.resource_id}@v{stale.version} stale; " f"external effects already dispatched: {external}. " f"Cannot unwind by discard alone; compensation required." ) for cid in affected: self._dispatches.pop(cid, None) self._by_token.pop(stale, None) return affected def resolve_conflict(ledger: DerivationLedger, stale: PrefetchToken) -> None: # Point check is insufficient; must sweep derivation closure. affected = ledger.invalidate(stale) if not affected: raise DerivationClosureError( f"no derivation edges recorded for {stale}; " f"version token did not propagate — provenance untracked." ) ```