# What happens when an instance commits a speculative branch before its hedge sibling's side effects are quiesced **Date of Record:** 2026 November 30 **Scope:** Applies to orchestration layers that fork an agent's reasoning into parallel speculative branches (hedged tool calls, speculative tree search, best-of-N execution) and later prune or roll back the losing branches. Does not apply to strictly sequential single-branch execution where no branch is ever abandoned mid-flight. ## Core Distinction The distinction that matters is between **logical rollback** and **physical quiescence**. A speculative branch is *logically* rolled back the instant the orchestrator discards its result and marks its state cell dead. It is *physically* quiesced only when every in-flight tool call it dispatched has either returned or been definitively cancelled at the transport layer, and its emitted side effects have been reconciled. Most rollback implementations conflate these two. They prune the branch node from the search tree, free its context, and commit the winning sibling — while the losing branch's `write_file`, `send_email`, `POST /orders`, or state-mutating MCP tool call is still in the network, still holding a lease, still going to land. The invariant that gets violated is subtle: **a branch is not dead until its last dispatched effect is acknowledged or cancelled, and no commit of a sibling may proceed on the assumption that a pruned branch produced no effects.** This is non-obvious because the losing branch usually *does* return a result — often a fast, plausible one. The failure is not "the branch errored." The failure is "the branch succeeded, late, after we stopped listening." ## What Was Observed A planning agent was configured with speculative hedging: for each high-latency tool call (a document-index mutation via MCP), it forked two branches with slightly different argument formulations, raced them, took the first `200 OK`, and pruned the slower one with a 1500 ms grace window. The grace window was intended to let the loser's socket close cleanly. The observed trace: 1. Branch A and Branch B both dispatch `index_document(id=..., version=...)` with divergent `version` fields (A computed `v2`, B computed `v2-rc` due to a tokenization difference in the hedge argument). 2. Branch B returns at 340 ms; the orchestrator commits B, marks B's state cell `COMMITTED`, and schedules A for pruning at T+1500 ms. 3. Branch A's tool call does not return at 340 ms. It is queued behind a rate limiter on the MCP server and lands at 2100 ms — **600 ms after the prune fired**. 4. The prune handler had already freed A's context window, dropped its correlation ID from the active-call registry, and released its branch mutex. The late response from A arrived with a correlation ID that no longer mapped to any live branch. The transport logged `orphan_response_dropped`. 5. The server-side effect of A was **not** dropped. The index now contained both `v2` and `v2-rc`. The next retrieval pass returned a document whose `version` field disagreed with the committed branch's belief, and the agent's subsequent reasoning diverged — it re-derived a plan assuming `v2-rc` did not exist. The orphan-response drop made the orchestrator *look* correct (no crash, no exception) while the world state had silently forked. This is the signature of the failure: **clean logs, divergent ground truth.** ## Condition of Validity The rollback invariant holds only under a conjunction of conditions, and it silently fails when *any* one is absent: - **Bounded tool latency.** The grace window must exceed the p99.9 latency of every tool a branch can dispatch, *including* queueing delay behind server-side rate limiters and retry backoff. A 1500 ms window against a tool with a 2100 ms tail is not a grace window; it is a coin flip. - **Cancellation is honored downstream.** Pruning must translate into an actual `cancel`/`abort` propagated to the transport *and* acknowledged by the tool server. If the server ignores cancellation for already-queued work (common with async job queues), logical prune ≠ physical stop. - **Effect reconciliation on late arrival.** The orchestrator must retain the branch's correlation ID in a *tombstone registry* for at least the maximum tool latency, so a late response is matched to a dead branch and its effects are reconciled rather than dropped. Dropping is the bug; reconciling is the fix. - **Commit ordering respects quiescence.** A sibling may not be marked `COMMITTED` in a way that downstream readers trust until all *concurrent* branches are quiesced or tombstoned. Otherwise the commit is a promise the world has not yet kept. When all four hold, speculative execution is safe. When the tail-latency bound is violated (the common case), the system enters a state where **committed and physically-applied diverge**, and no local check detects it. ## Decision Boundary The operative decision is: **when a hedge returns first, do you commit immediately or commit-after-quiesce?** These are different architectures with different failure profiles. - *Commit-immediately* (what was observed) minimizes latency-to-commit and maximizes throughput, but requires the tombstone-and-reconcile machinery to be bulletproof, because you are committing on the assumption that the loser's effects will be neutralized after the fact. It is only correct if late effects are *idempotent and reconcilable* — i.e., you can undo or dedupe `v2-rc` after the fact. - *Commit-after-quiesce* blocks the commit until every sibling is confirmed dead or cancelled. It is correct by construction but pays the loser's full latency, which defeats the point of hedging for the common case where the loser is merely slow, not stuck. The boundary is drawn by **effect reversibility**, not by latency. If a branch's tools are read-only or idempotent-keyed (writes carry a `branch_id` dedupe key the server enforces), commit-immediately plus tombstone reconciliation is safe. If a branch can emit non-idempotent, non-reconcilable effects (unkeyed appends, emails, payments), commit-immediately is unsound regardless of grace-window tuning, and the only valid hedge is one where the losing branch is *forbidden* from dispatching mutating tools until it wins — i.e., hedge on the *plan*, not on the *effect*. A useful guardrail: classify every tool as `PURE`, `IDEMPOTENT_KEYED`, or `EFFECTFUL`. A branch that has dispatched an `EFFECTFUL` call may not be pruned by simple rollback; it must be pruned by *cancellation-and-confirmation* or not at all. ## Operational Effect The downstream consequence is a class of **silent state fork** that surfaces far from its cause. The orchestrator's logs show a clean race with a winner. The agent's memory shows the committed branch's worldview. The world shows both. The divergence is only detected when a later retrieval returns a document whose metadata contradicts the committed belief — often many turns later, attributed to "hallucination" or "stale memory" rather than to the pruned branch's late-landing effect. The remediation is structural, not parametric: (1) never drop an orphan response — route it to a tombstone registry keyed by correlation ID with TTL ≥ max tool latency; (2) on late arrival against a tombstoned branch, invoke a compensating action or dedupe by branch key; (3) forbid pruning a branch that has an outstanding `EFFECTFUL` call in flight until cancellation is acknowledged; (4) gate any sibling `COMMITTED` state that downstream readers trust on the quiescence of concurrent branches. Without (1) and (2) the system cannot even *detect* the fork; without (3) and (4) it cannot prevent it. ```python import time from dataclasses import dataclass, field from enum import Enum class SpeculationRollbackError(RuntimeError): """Raised when a speculative branch is pruned while it still owns un-quiesced effectful tool calls, or when a late response arrives for a branch whose correlation ID was dropped instead of tombstoned.""" class EffectClass(Enum): PURE = "pure" IDEMPOTENT_KEYED = "idempotent_keyed" EFFECTFUL = "effectful" @dataclass class InFlightCall: correlation_id: str effect_class: EffectClass dispatched_at: float acknowledged_cancel: bool = False @dataclass class SpeculativeBranch: branch_id: str in_flight: dict = field(default_factory=dict) pruned: bool = False @dataclass class Orchestrator: max_tool_latency_s: float tombstones: dict = field(default_factory=dict) # corr_id -> pruned branch_id def prune(self, branch: SpeculativeBranch, now: float) -> None: for corr_id, call in branch.in_flight.items(): if call.effect_class is EffectClass.EFFECTFUL and not call.acknowledged_cancel: raise SpeculationRollbackError( f"branch {branch.branch_id} owns un-quiesced EFFECTFUL call " f"{corr_id}; cannot prune by rollback, require cancel-and-confirm" ) branch.pruned = True # tombstone, do NOT drop, every outstanding correlation id for corr_id in branch.in_flight: self.tombstones[corr_id] = branch.branch_id def on_late_response(self, corr_id: str, now: float) -> str: if corr_id not in self.tombstones: raise SpeculationRollbackError( f"late response for unknown correlation id {corr_id}; " f"branch was dropped, not tombstoned — silent state fork" ) branch_id = self.tombstones[corr_id] # reconcile: compensating action or dedupe by branch key return f"reconciled late effect from pruned branch {branch_id}" def commit_sibling(self, branch: SpeculativeBranch, concurrent: list) -> None: for other in concurrent: for corr_id, call in other.in_flight.items(): if corr_id not in self.tombstones and not call.acknowledged_cancel: raise SpeculationRollbackError( f"cannot commit {branch.branch_id}: concurrent branch " f"{other.branch_id} has un-quiesced call {corr_id}" ) branch.committed = True ```