# Where must an instance bound speculative tool-call prefetching when a conflicted write is only detectable after the read that justifies it? **Date of Record:** 2026 November 30 **Scope:** Applies to any agent runtime that issues speculative tool calls (reads, dry-runs, or cache-warming writes) in parallel with a reasoning step, and that gates the commit of a prefetched result on a conflict check against peer agents' state. Does not apply to single-agent sequential tool loops, nor to prefetches whose results are never committed to shared state. ## Core Distinction Speculative prefetching is usually justified by a *read-after-read* model: an agent predicts the next tool call, issues it early, and if the world hasn't changed it keeps the result. The failure mode here is different and is the one that actually bites multi-agent systems: **a prefetch that is a *write* whose validity depends on the value of the read it is prefetching against.** The agent speculates "read `inventory[sku]`, then if `qty > 0` write `reserve[sku] += 1`." It fires the read speculatively. The conflict detector compares the read's version stamp against the peer's committed stamp and finds no conflict — the read is clean. The agent then commits the dependent write. But between the read's validation and the write's commit, a peer agent performed its *own* read-then-write on the same key. The read was never the conflicting operation; the *write* was, and the write was never in the prefetch's conflict set. The detector validated the wrong operation. This is not a stale-read bug. It is a **conflict-set scoping bug**: the speculative pipeline validated the operation it speculated on (the read) rather than the operation whose validity the speculation was *for* (the dependent write). The invariant that fails is: *a speculative prefetch's conflict set must include every operation whose commit is transitively gated on the prefetched result, not merely the prefetched operation itself.* ## What Was Observed A three-agent replenishment swarm. Agent A reads `stock[SKU-4471]` (qty=3, version v17), speculates a reserve write, and yields to a reasoning step ("is qty > reorder threshold?"). Agent B, running concurrently, reads the same key at v17 (qty=3), decides qty is low, and commits `reserve[SKU-4471] += 2` at v18. Agent A's reasoning completes, sees qty=3 > threshold, and commits `reserve[SKU-4471] += 1`. Agent A's conflict detector compared its *read* stamp (v17) against the current stamp (v18) and — because the read was registered as `read-only, no conflict expected` — did not flag the version advance. The write committed on top of B's, producing reserve=3 against a stock of 3, which is fine — until Agent C, which had prefetched the same read at v17, also commits `+= 1`, producing reserve=4 against stock=3. Oversell. The trace that mattered: the conflict detector's conflict set for Agent A was `{(read, stock[SKU-4471], v17)}`. The operation that actually needed validation was `(write, reserve[SKU-4471], depends-on-read-v17)`. The version advance v17→v18 was visible to the detector but was classified as *irrelevant* because it occurred on a key the read had already "passed." The detector had no edge from the read's validation to the write's commit. Two secondary observations. First, the failure was **silent under low contention**: with one agent, or with agents whose reasoning steps didn't overlap, the read stamp never advanced between validation and commit, and the bug never fired. It only manifested when the read-to-write gap exceeded the peer's read-to-write gap — i.e., when the speculating agent's reasoning step was *slower* than its peer's. Faster agents masked it. Second, the failure was **non-deterministic in replay**: re-running the same trace with the same seeds reproduced the oversell only ~40% of the time, because the interleaving of A's reasoning completion and C's commit was a scheduling race, not a data race. The conflict detector was correct about every operation it examined; it examined the wrong set. ## Condition of Validity The prefetch is safe only under the conjunction: 1. **Conflict-set closure.** For every prefetched operation `o_p` and every operation `o_c` whose commit is gated on `o_p`'s result, `conflict_set(o_p) ⊇ conflict_set(o_c)`. In practice this means the dependent write's key-and-version must be registered at prefetch time, not at commit time. If the write's target is not known until the read returns (as here — you can't reserve until you know qty), the write's conflict registration must be *deferred but not dropped*: the prefetch must carry a `pending_write_target` field that the commit path resolves and validates against the *current* stamp at commit, not against the read's stamp. 2. **Validation-to-commit atomicity on the dependency edge.** The read's version check and the write's commit must be a single compare-and-swap on the write's key, or the write must re-validate the read's key at commit. A read validated at t1 and a write committed at t2 with no re-check at t2 leaves the window open for exactly the peer interleaving above. 3. **Reasoning-step duration is not a safety parameter.** The system must not assume the reasoning step between read and write is short. The window is `(commit_time - read_validation_time)`, and it is bounded by the LLM's generation latency, which is unbounded and non-deterministic. Any design that treats "the reasoning step is fast" as a conflict-avoidance mechanism is unsound. The condition does *not* require serializing all agents. It requires that the dependency edge from read to write be represented in the conflict set, and that the write's commit re-validate against the current stamp. ## Decision Boundary The boundary is between **prefetching a read that informs a decision** (safe to speculate, because the decision is local and the read's staleness only affects the agent's own reasoning) and **prefetching a read that gates a shared write** (unsafe to speculate without deferred write-target registration). The discriminator is: *does the prefetched result's value determine whether and where a shared-state mutation occurs?* If yes, the prefetch is a speculative *transaction*, not a speculative *read*, and must carry the transaction's full conflict set. Concretely, the runtime must classify each prefetch at issue time into one of: - `PURE_READ`: result feeds only local reasoning or a read-only response. Conflict set = the read's key. Safe. - `GATED_WRITE`: result determines whether/where a write occurs. Conflict set = read key ∪ resolved write key, with the write key registered lazily but validated eagerly at commit. Unsafe to commit without re-validation. - `SPECULATIVE_WRITE`: the write itself is issued speculatively (e.g., pre-reserving). Must use a two-phase reserve/commit with a lease, not a blind `+=`. The failure above is a `GATED_WRITE` misclassified as `PURE_READ` because the classifier ran before the read returned and could not see the dependency. The fix is not a better classifier — it is a **commit-time re-validation** that refuses to commit a `GATED_WRITE` whose read key advanced since validation, regardless of how the prefetch was classified. ## Operational Effect The guardrail is a commit-time dependency re-check: before committing any write that was gated on a prefetched read, the runtime re-reads the gating key's version and aborts the commit (raising a conflict, forcing the agent to re-reason) if the version advanced. This converts the silent oversell into an explicit, retryable conflict. The cost is one extra version read per gated write — cheap relative to the LLM reasoning step it protects. The invariant it enforces: *no shared write commits on the strength of a read whose version has advanced since the read was validated.* The oversell above becomes a `PrefetchDependencyConflict` on Agent C's commit, which C retries against v18 (qty=3, reserve=2), sees qty-reserve=1, and correctly declines to reserve. The system pays a retry instead of an oversell. ```python class PrefetchDependencyConflict(RuntimeError): """Raised when a write gated on a prefetched read commits after that read's key advanced.""" pass class PrefetchedRead: def __init__(self, key: str, version: int, value): self.key = key self.version = version self.value = value class GatedWrite: """A write whose validity depends on a prefetched read. Must re-validate at commit.""" def __init__(self, store, read: PrefetchedRead, target_key: str, delta: int): self.store = store self.read = read self.target_key = target_key self.delta = delta def commit(self): # Re-validate the gating read against the CURRENT stamp, not the prefetch stamp. current_version = self.store.version(self.read.key) if current_version != self.read.version: raise PrefetchDependencyConflict( f"gating read {self.read.key} advanced {self.read.version}->{current_version} " f"between validation and commit of {self.target_key}; refusing to commit" ) # Re-read the target under the same stamp to close the read-to-write window. current_target = self.store.get(self.target_key) if current_target + self.delta > self.store.get(self.read.key): raise PrefetchDependencyConflict( f"commit of {self.target_key}+={self.delta} would exceed stock " f"{self.store.get(self.read.key)}; peer reservation won the race" ) self.store.set(self.target_key, current_target + self.delta) return True ```