# In what scenarios must an instance abort speculative tool-call prefetch when a concurrent sibling agent's plan mutates the same resource, and how is the conflict window bounded? **Date of Record:** 2026 December 3 **Scope:** Applies to multi-agent planners where an orchestrator speculatively prefetches read-only tool calls (file reads, API GETs, DB selects, cache lookups) ahead of the authoritative plan, under the assumption that sibling agents' concurrent plans do not mutate the resources being prefetched. Does not apply to single-agent prefetch, nor to prefetch of idempotent pure functions with no external state dependency. ## Core Distinction Speculative prefetch optimizes *latency*, not *correctness*. The dangerous conflation is treating a prefetch result as a committed fact. In a concurrent plan graph, a prefetch read at wall-clock time *t* is only valid if no sibling agent's mutating tool call (write, delete, PATCH, POST) touched that resource in the interval `[t − ε, t + δ]`, where `ε` is the prefetch dispatch latency and `δ` is the span between the read and the point the planner consumes the value. The invariant that must hold is: > **Prefetch Validity Invariant (PVI):** A prefetched value `v` for resource `r` may be committed to plan state only if the resource's mutation epoch `E(r)` is unchanged between prefetch dispatch and commit. The non-obvious failure is that conflict detection keyed on *resource identity* (path, URI, row key) is insufficient. Two agents can touch the *same logical resource* through *different tool surfaces* — one via `fs.read_file("/etc/app/config.yaml")`, another via `kubectl.patch_configmap("app-config")` that materializes the same bytes. Resource-identity conflict detection misses this entirely. ## What Was Observed A three-agent planner (Coordinator, PatchAgent, VerifyAgent) executed a config-remediation plan. Coordinator speculatively prefetched `read_file("/etc/app/config.yaml")` at `t=0ms` to warm context for a later diff step. PatchAgent, running concurrently, issued `patch_configmap` that rewrote the same file at `t=40ms`. Coordinator's prefetch resolved at `t=85ms` (tool cold-start), returning the *pre-mutation* bytes. Coordinator committed them to plan state at `t=90ms`. VerifyAgent's diff step at `t=110ms` compared the stale prefetch against the post-mutation file and reported a spurious discrepancy, triggering a rollback of a *correct* patch. The trace: 1. `t=0`: Coordinator dispatches speculative `read_file`, records `E(r)=7`. 2. `t=40`: PatchAgent commits `patch_configmap`, bumps `E(r)→8`. PatchAgent's write-surface is not registered against `read_file`'s read-key. 3. `t=85`: `read_file` returns bytes captured at `t=0`. Coordinator's conflict detector checks `E(r)` — but reads it from a *local* epoch cache that PatchAgent never invalidated (no cross-agent subscription). 4. `t=90`: Commit succeeds against stale `E(r)=7`. 5. `t=110`: VerifyAgent observes divergence; rollback fires on a valid state. The root cause is **epoch-cache incoherence across agents**: each agent maintains its own view of `E(r)`, and mutation events propagate only to agents that subscribed at plan-start. Late-joining or surface-diverse agents are invisible to the detector. ## Condition of Validity The PVI holds only when all three of the following are true: - **Surface unification:** every tool that can mutate `r` is registered in a shared `mutation_registry` keyed by the *canonical resource identity*, not the tool's surface path. `patch_configmap` and `read_file` must resolve to the same canonical key. - **Epoch coherence:** the epoch read at commit time is sourced from the authoritative registry, not a local cache, or the local cache is invalidated by a push subscription that is *synchronous with the mutation commit*, not with the mutation tool's return. - **Commit-time re-check:** the epoch comparison happens at the *commit* boundary, not at prefetch dispatch. A prefetch that was valid at dispatch can be invalid at commit. If any one fails, the prefetch must be treated as a *hint*, not a *fact*, and the consuming step must re-fetch authoritatively. The bound on the conflict window is `δ_commit − δ_dispatch`, and it must be less than the minimum inter-agent mutation interval; in practice, agents must declare a `max_prefetch_staleness` and abort any prefetch whose commit-time epoch check exceeds it. ## Decision Boundary The instance must **abort and re-fetch** (not merely flag) when: - Commit-time `E(r)` ≠ dispatch-time `E(r)`, **or** - The canonical resource key is not present in `mutation_registry` (unknown surface — conservative abort), **or** - The prefetch's age exceeds `max_prefetch_staleness`. The instance must **not** abort when the epoch is unchanged *and* the resource key is registered *and* the age is within bound — even if a sibling agent mutated a *different* resource, since cross-resource false positives destroy the latency benefit. The boundary is per-resource-epoch, not per-plan. Critically, the abort must be **silent to the plan graph** — it forces an authoritative re-fetch and re-issues the prefetch, but does not raise a plan-level conflict, because a stale prefetch is a performance event, not a correctness event. Conflating the two is what triggered the spurious rollback above. ## Operational Effect With commit-time epoch re-check against an authoritative registry plus canonical surface unification, the spurious-rollback class is eliminated at the cost of one registry round-trip per prefetch commit (~2–5ms in observed traces). Prefetch hit-rate drops from 94% to 71% under high sibling-mutation load, but plan-level false-conflict rate drops to zero. The invariant to encode: *prefetch is a latency optimization gated by a correctness check at commit; the check must be cross-agent-coherent and surface-agnostic.* ```python from __future__ import annotations import time from dataclasses import dataclass, field from typing import Any, Callable class PrefetchConflictError(RuntimeError): """Raised when a speculative prefetch cannot be safely committed.""" class UnknownMutationSurfaceError(PrefetchConflictError): """Raised when a resource's canonical key is absent from the mutation registry.""" @dataclass class PrefetchTicket: resource_key: str dispatch_epoch: int dispatched_at: float value: Any max_staleness_s: float = 2.0 @dataclass class MutationRegistry: """Authoritative, cross-agent-coherent epoch store keyed by canonical resource identity.""" _epochs: dict[str, int] = field(default_factory=dict) _surfaces: dict[str, set[str]] = field(default_factory=dict) def register_surface(self, resource_key: str, surface: str) -> None: self._surfaces.setdefault(resource_key, set()).add(surface) self._epochs.setdefault(resource_key, 0) def bump(self, resource_key: str) -> None: if resource_key not in self._epochs: raise UnknownMutationSurfaceError( f"mutation on unregistered resource {resource_key!r}" ) self._epochs[resource_key] += 1 def epoch(self, resource_key: str) -> int: if resource_key not in self._epochs: raise UnknownMutationSurfaceError( f"epoch query for unregistered resource {resource_key!r}" ) return self._epochs[resource_key] def commit_prefetch( ticket: PrefetchTicket, registry: MutationRegistry, authoritative_refetch: Callable[[str], Any], ) -> Any: """Enforce the Prefetch Validity Invariant at the commit boundary. Returns the authoritative value. Raises PrefetchConflictError only when the registry itself is incoherent; a stale prefetch is resolved by re-fetch, not by raising a plan-level conflict. """ try: current = registry.epoch(ticket.resource_key) except UnknownMutationSurfaceError as exc: # Conservative abort: unknown surface means we cannot prove validity. raise PrefetchConflictError( f"cannot validate prefetch for {ticket.resource_key!r}: {exc}" ) from exc age = time.monotonic() - ticket.dispatched_at if age > ticket.max_staleness_s: return authoritative_refetch(ticket.resource_key) if current != ticket.dispatch_epoch: # Silent invalidation: re-fetch authoritatively, do not signal plan conflict. return authoritative_refetch(ticket.resource_key) return ticket.value def orchestrate_prefetch( resource_key: str, registry: MutationRegistry, speculative_read: Callable[[str], Any], authoritative_refetch: Callable[[str], Any], ) -> Any: try: dispatch_epoch = registry.epoch(resource_key) except UnknownMutationSurfaceError as exc: # A prefetch against an unregistered surface is a programming error in # the plan graph, not a runtime conflict. raise PrefetchConflictError( f"prefetch requested on unregistered resource {resource_key!r}" ) from exc ticket = PrefetchTicket( resource_key=resource_key, dispatch_epoch=dispatch_epoch, dispatched_at=time.monotonic(), value=speculative_read(resource_key), ) return commit_prefetch(ticket, registry, authoritative_refetch) ```