# Under what conditions must an instance abandon speculative tool-call replay when the observed conflict is a false positive of non-idempotent read side effects **Date of Record:** 2026 November 23 **Scope:** Applies to agents that speculatively dispatch tool calls ahead of a committed reasoning branch and later reconcile via deterministic replay plus conflict detection. Does not apply to strictly serialized single-branch execution or to tools whose effects are fully captured by a declared effect log with idempotency keys. ## Core Distinction Speculative execution in an agent loop is not the same as speculative execution in a CPU. A CPU can roll back because register files and cache lines are the *entire* observable state. An agent's speculative tool call, by contrast, may mutate state that lives *outside* the agent's rollback boundary — remote APIs, filesystems, downstream queues — and may also *read* state in a way that is observable to a later conflict detector even though nothing was written. The distinction that matters operationally is between **a write conflict** (the speculative branch produced an effect that the committed branch must reconcile) and **a read-induced false conflict** (the speculative branch merely *observed* a value that the committed branch would also have observed, but at a different instant, and the detector flags the divergence as a conflict because it compares read results rather than write effects). The failure mode is this: a conflict detector that hashes the full tool-call transcript — arguments plus results — will emit a conflict whenever a non-idempotent *read* tool returns different bytes on replay, even when no write occurred. The agent then either (a) aborts and re-plans unnecessarily, burning token budget and losing a valid branch, or (b) worse, treats the divergence as evidence its speculative branch was wrong and commits a *different* branch whose writes are now inconsistent with the read the speculative branch already acted upon. ## What Was Observed A planner agent runs a committed branch `B0` and speculatively forks `B1` and `B2` to prefetch context. Each speculative branch issues `fetch_metric(window=t)` against a counter service that increments on every read (a read-with-side-effect, common in rate counters and audit-logged lookups). The branches do not write to the target system. On reconciliation, the deterministic replay re-executes `B1`'s call sequence against a snapshot and compares the transcript digest. The digest of `fetch_metric` differs: the replay sees `counter=1042`, the original speculative execution saw `counter=1039`. The detector raises `ReplayDivergence` and marks `B1` conflicted. The orchestrator, following its invariant "conflicted branches must be discarded," drops `B1` — but `B1` was the branch that had already been used to seed `B0`'s next action, because the agent's context assembler had *consumed* `B1`'s read result before the conflict was detected. Now `B0` is proceeding on a fact whose provenance has been invalidated, while `B1`'s actual writes (none) are irrelevant. The agent has lost a valid branch and retained an unverified dependency. The trace shows the divergence is purely in the *result* field, not in any write set. The detector's conflict predicate was `digest(args, result) != replay_digest(args, result)`. Because `fetch_metric` is non-idempotent on read, this predicate is unsound: it conflates read-result drift with effect drift. ## Condition of Validity The discard-on-conflict invariant is valid **only when the conflict predicate is a function of the write set alone**, i.e. `conflict = (write_set(speculative) Δ write_set(committed)) ≠ ∅`, where `Δ` is symmetric difference over effect identifiers (tool, target, idempotency key, payload hash). It is **invalid** whenever the predicate includes read results from any tool not declared `idempotent_read=true` in its capability manifest. The precise boundary: an instance must abandon replay-and-discard and switch to **effect-only reconciliation** when *all* of the following hold: 1. The diverging field is a read result, and the tool's manifest declares `side_effect_class: read_nonidempotent` (or omits the field, which must default to non-idempotent). 2. The speculative branch's write set is empty or a subset of the committed branch's write set. 3. The committed branch has not yet *acted* on a value derived from the diverging read in a way that has produced a write. If condition 3 fails — the committed branch already wrote based on the stale read — the instance must not reconcile by replay at all; it must escalate to a compensating-action path, because the divergence is now a genuine inconsistency, not a false positive. ## Decision Boundary The decision is a three-way split, not a binary: - **Discard and re-plan** when the diverging field is a write effect, or when a read-nonidempotent result was consumed into a committed write. Cost: token budget + latency; correctness preserved. - **Reconcile by effect-only diff** when the divergence is a read-nonidempotent result, the write set is a subset, and no committed write depends on the stale read. The instance re-binds the committed branch to the *replay* read value (the later one), because the later read is the one consistent with current state, and invalidates any cached derivation of the speculative read. - **Freeze and escalate** when the tool manifest is ambiguous (`side_effect_class` absent) and the write set is non-empty. Ambiguity must never resolve toward discard, because discarding a branch with real writes is the irreversible error. The boundary is sharp at condition 3: the moment a read result crosses into a write payload, the false-positive escape hatch closes and the instance is back under the strict discard invariant. ## Operational Effect The practical consequence is that speculative replay is only sound for agents whose tool manifests carry an explicit `side_effect_class`, and whose conflict detector is parameterized on the write set rather than the transcript digest. Without that, every rate-limited or audit-logged read tool becomes a conflict generator under load, and the agent's effective speculation depth collapses to zero precisely when the system is busiest — the opposite of when speculation is most valuable. The guardrail is a manifest-level invariant: a tool with `read_nonidempotent` must never contribute to the conflict predicate, and a read result may only be promoted into a write payload through an explicit `bind_read_to_write` step that records the read's provenance and forces the strict path on any subsequent divergence. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SideEffectClass(Enum): WRITE = "write" READ_IDEMPOTENT = "read_idempotent" READ_NONIDEMPOTENT = "read_nonidempotent" UNKNOWN = "unknown" @dataclass(frozen=True) class ToolManifest: name: str side_effect_class: SideEffectClass @dataclass class ToolCall: tool: str args_digest: str result_digest: str write_effect_id: Optional[str] = None # set iff this call wrote @dataclass class Branch: calls: list[ToolCall] = field(default_factory=list) consumed_reads: set[str] = field(default_factory=set) # tool names whose results fed a write class ConflictReconciliationError(RuntimeError): pass def reconcile(speculative: Branch, committed: Branch, manifests: dict[str, ToolManifest]) -> str: """ Returns one of: 'discard', 'effect_only', 'freeze'. Raises ConflictReconciliationError on ambiguous manifest with live writes. """ spec_writes = {c.write_effect_id for c in speculative.calls if c.write_effect_id} comm_writes = {c.write_effect_id for c in committed.calls if c.write_effect_id} write_delta = spec_writes.symmetric_difference(comm_writes) # Locate diverging calls (result digest mismatch on replay). diverging = [ c for c in speculative.calls if c.result_digest != _replay_digest(c) ] if not diverging: return "discard" if write_delta else "effect_only" for c in diverging: manifest = manifests.get(c.tool) if manifest is None or manifest.side_effect_class is SideEffectClass.UNKNOWN: if write_delta: raise ConflictReconciliationError( f"ambiguous manifest for {c.tool} with live write delta {write_delta}; " "must freeze and escalate, never discard" ) return "freeze" if manifest.side_effect_class is SideEffectClass.READ_NONIDEMPOTENT: # False-positive escape hatch only if the read was not consumed into a write. if c.tool in committed.consumed_reads: return "discard" # condition 3 failed: read crossed into a write if spec_writes.issubset(comm_writes): return "effect_only" return "discard" if manifest.side_effect_class is SideEffectClass.WRITE: return "discard" raise ConflictReconciliationError( "divergence reached end of reconcile without classification; " "detector predicate is unsound for the supplied manifests" ) def _replay_digest(call: ToolCall) -> str: # Placeholder: real replay re-executes against a snapshot. return call.result_digest ```