# What structural signals indicate speculative tool-call pre-execution has crossed the read/write conflict horizon in shared agent environments **Date of Record:** 2026 November 27 **Scope:** Applies to agents that issue *speculative* tool calls (pre-dispatch before the model's reasoning loop has committed to a branch) against shared, mutable external state, where multiple agents may touch the same resource namespace concurrently. Does not apply to read-only tool surfaces, single-tenant sandboxes with exclusive resource locks, or purely deterministic function-calling with no external side effects. ## Core Distinction Speculative pre-execution is not the same as speculative *prefetching*. Prefetching a read is idempotent and harmless if the branch is later abandoned. Pre-executing a *write* under speculation is a commitment: the tool-call's side effect lands in shared state before the reasoning loop has decided whether the branch that motivated it is still valid. The distinguishing failure is **speculative write leakage across a conflict horizon** — the moment a pre-executed tool call's side effect becomes observable to a peer agent while the originating agent's branch is still uncommitted (or has been abandoned). The conflict detector that gates speculation is typically checking *schema-level* conflicts (same tool, same resource ID) but not *temporal* conflicts (the peer's read happened after our speculative write, not before). The structural signal that the horizon has been crossed is not an error — it is a *successful* tool return whose effect a peer can now read while our branch is still in flight. ## What Was Observed A planner agent (`A`) with a 3-branch reasoning tree speculatively pre-executed `write_kv(key="config.timeout", value=45)` on branch 2 while branch 1 was still being evaluated. The tool returned `200 OK` and the speculative executor recorded the write in its conflict ledger as `owner=A`, `branch=2`, `state=SPECULATIVE`. A peer agent (`B`) concurrently issued `read_kv(key="config.timeout")` as part of its own committed plan. The conflict detector compared tool names and resource IDs and found no conflict — `read` vs `write` on the same key is not a *schema* conflict in the detector's model, and the speculative ledger entry was not surfaced to `B`'s read path. `B` received `45`. `A` then abandoned branch 2 (branch 1 scored higher) and issued its compensating rollback `write_kv(key="config.timeout", value=)`. The rollback succeeded and the ledger marked branch 2 `ABANDONED`. But `B` had already consumed `45` and committed a downstream action — a `restart_service` with a 45-second grace period — based on a value that, from `B`'s perspective, was the committed state. The rollback was invisible to `B`; it had no read-after-write ordering relationship with `A`'s speculative write, only with the final rollback, which it never performed. The failure trace: 1. `A` speculative-writes `config.timeout=45`; ledger: `SPECULATIVE(owner=A, branch=2)`. 2. `B` reads `config.timeout` → `45`; conflict detector sees `read` vs `write` on same key, classifies as **non-conflicting** (read does not mutate). 3. `A` abandons branch 2; issues rollback `config.timeout=`; ledger: `ABANDONED`. 4. `B` commits `restart_service(grace=45)` against a value that no longer exists. 5. Reconciliation: `B`'s committed action and `A`'s final state disagree; no agent holds both facts. The structural signal was present at step 2 and was discarded: the read *returned a speculative value*, and the ledger entry was `SPECULATIVE` at read time. A conflict detector that only compares mutation-vs-mutation misses the read-during-speculation case entirely. ## Condition of Validity The invariant that must hold for speculative pre-execution to be safe in a shared environment: > **No peer agent may observe a value written by a speculative branch unless that branch is committed, OR the peer's read is itself explicitly speculative and tagged with a dependency on the writer's branch commitment.** Formally: for every read `R` by peer `P` of resource `k` at time `t`, if the value returned was produced by a write `W` whose ledger state at `t` was `SPECULATIVE` or `ABANDONED`, the read must either (a) block until `W` resolves, or (b) return a value tagged with `speculative_dependency=(W.owner, W.branch)` that forces `P` to re-validate before committing any action derived from it. The condition fails when the conflict detector's conflict predicate is `mutates(k) ∧ mutates(k)` rather than `touches(k) ∧ touches(k)` over the speculative window. The detector must treat a *read* of a speculatively-written key as a conflict, not a no-op, because the read is a *commitment to a value* that the speculative writer may retract. ## Decision Boundary The boundary between safe and unsafe speculation is not "does this tool call mutate state" but "can the effect of this tool call be observed by an agent that is not a party to the speculation." Two structural tests: - **Observability test:** after the speculative call returns, enumerate every agent whose read path includes the touched resource. If that set is non-empty and any member is not in the speculation's transaction scope, the call has crossed the horizon and must be either (i) deferred until commit, or (ii) executed against a private overlay (copy-on-write namespace) that peers cannot read. - **Ledger-visibility test:** the speculative ledger entry must be readable by every peer's conflict detector *before* the peer's read executes. If the ledger is write-only from the speculator's side (as in the observed case), the detector has no signal to act on and will classify the read as clean. When either test fails, speculation must be downgraded to *deferred execution*: the tool call is recorded as a pending intent, not dispatched, and the reasoning branch proceeds on a predicted result that is explicitly marked provisional. The cost is latency; the alternative is a peer committing to a value that will be retracted. ## Operational Effect The practical consequence is that speculative pre-execution in shared environments requires the conflict detector to be **read-aware and ledger-synchronous**, not just mutation-aware. Concretely: - The speculative ledger must be on the read path of every peer, consulted before the read returns, with a bounded wait (typically one commit-or-abandon cycle) to resolve `SPECULATIVE` entries. - Reads that hit a `SPECULATIVE` entry must either block or return a *dependency-tagged* value that poisons downstream commits until the writer resolves. - Rollback must be a *broadcast* event, not a private ledger update, because peers may have already consumed the speculative value. The failure mode is silent: no exception is raised, the speculative call succeeds, the rollback succeeds, and the divergence surfaces only at reconciliation when two committed actions disagree about a value neither agent currently holds. The structural signal — a read returning a `SPECULATIVE`-tagged write — is the only early warning, and it is discarded by any detector whose conflict predicate is mutation-only. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set, Tuple class SpeculativeConflictHorizonError(RuntimeError): """Raised when a peer read observes a speculatively-written value whose branch is still uncommitted or has been abandoned.""" pass class LedgerState(Enum): SPECULATIVE = "SPECULATIVE" COMMITTED = "COMMITTED" ABANDONED = "ABANDONED" @dataclass class LedgerEntry: owner: str branch: int state: LedgerState @dataclass class SpeculativeLedger: entries: Dict[str, LedgerEntry] = field(default_factory=dict) # resource -> set of (owner, branch) that have read a speculative value speculative_reads: Dict[str, Set[Tuple[str, int]]] = field(default_factory=dict) def record_speculative_write(self, resource: str, owner: str, branch: int) -> None: self.entries[resource] = LedgerEntry(owner, branch, LedgerState.SPECULATIVE) def commit(self, resource: str) -> None: self.entries[resource].state = LedgerState.COMMITTED def abandon(self, resource: str) -> None: self.entries[resource].state = LedgerState.ABANDONED def read(self, resource: str, reader: str) -> LedgerState: entry = self.entries.get(resource) if entry is None: return LedgerState.COMMITTED if entry.state is LedgerState.SPECULATIVE: # The horizon has been crossed: a peer is about to observe # an uncommitted speculative value. self.speculative_reads.setdefault(resource, set()).add( (entry.owner, entry.branch) ) raise SpeculativeConflictHorizonError( f"peer {reader!r} read {resource!r} while owner " f"{entry.owner!r} branch {entry.branch} is SPECULATIVE; " f"read must block or return a dependency-tagged value" ) if entry.state is LedgerState.ABANDONED: raise SpeculativeConflictHorizonError( f"peer {reader!r} read {resource!r} after owner " f"{entry.owner!r} branch {entry.branch} was ABANDONED; " f"rollback was not broadcast" ) return entry.state def peer_read(ledger: SpeculativeLedger, resource: str, reader: str) -> str: """Read path for a peer agent. Must consult the speculative ledger before returning any value.""" state = ledger.read(resource, reader) if state is not LedgerState.COMMITTED: raise SpeculativeConflictHorizonError( f"unresolved ledger state {state} for {resource!r}" ) return f"" # Reproduction of the observed failure: ledger = SpeculativeLedger() ledger.record_speculative_write("config.timeout", owner="A", branch=2) try: peer_read(ledger, "config.timeout", reader="B") except SpeculativeConflictHorizonError as exc: # Correct behavior: B blocks or tags the read instead of committing # a restart_service against a value A will retract. print(f"horizon detected: {exc}") ```