# How should an instance bound speculative branch commitment when parallel agent drafts share a single non-idempotent tool-call budget **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out N parallel drafting agents against one shared tool/effect surface and later commit a single winning branch. Does not apply to fully isolated sandboxes with per-branch cloned side-effect stores, nor to read-only tool surfaces where re-execution is free. ## Core Distinction The failure is not "a speculative branch was wrong." Wrongness is the normal, priced-in outcome of speculation. The failure is that speculation and commitment were *not separated at the effect boundary*. In a speculative pipeline the orchestrator forks reasoning into parallel branches, each of which may emit tool calls. The critical distinction is between a branch's *reasoning state* (cheap, forkable, discardable) and a branch's *effect state* (tool calls that mutate the world: file writes, API POSTs, payments, message sends, cache invalidations). Most orchestrators fork the former correctly and fork the latter not at all — all branches share one live tool surface, so a losing branch's side effects persist after rollback of its reasoning. A second, subtler distinction: *validation* of a speculative tool call is not *commitment* of it. A branch may validate that a call's schema, preconditions, and arguments are well-formed, and still must not execute it until the branch is selected. Conflating "the call passed validation" with "the call is safe to fire" is the exact seam where speculative execution leaks. ## What Was Observed An orchestrator dispatched three drafting branches (A, B, C) to solve a task requiring a `create_ticket` tool and a `send_notification` tool. Each branch ran in its own reasoning context but shared one tool executor with a single quota counter and one live backend. Trace: 1. Branch A emits `create_ticket(idempotency_key=None)`. Validator passes (schema OK, backend reachable). Executor fires it. Ticket `T-4471` created. 2. Branch B emits `create_ticket(idempotency_key=None)` with slightly different arguments. Validator passes. Executor fires it. Ticket `T-4472` created — a duplicate of the same underlying issue. 3. Branch C emits `send_notification(user=..., ticket=T-4471)` referencing the ID it read back from *its own* view, which happened to be A's ticket because the executor returned a shared handle. 4. Orchestrator scores branches, selects B. Rollback of A and C discards their reasoning traces and message histories — but not `T-4471` (A's effect) nor C's notification read against a ticket that the committed branch B never produced. 5. Post-commit verification replays branch B's transcript against the live backend and finds a notification already sent referencing `T-4471`, a ticket B's plan never created. Verification fails as a *replay discrepancy* even though B's reasoning was internally consistent. The observable signature: **the winning branch's replay diverges from its own draft transcript because a sibling branch mutated shared state the winner later observed.** The tool quota counter also drifted — three speculative calls consumed budget for one committed outcome, and under hard quota the *committed* branch could be starved by siblings that were later discarded. A second observed signature under load: branches that validated a call, then paused for a slow peer's consensus, fired the call after the orchestrator had already selected a different winner. The call was valid at validation time and stale at fire time — a time-of-check/time-of-use gap specific to speculative scheduling. ## Condition of Validity Speculative branch commitment is only sound when all three hold: - **Effect isolation:** every branch's tool calls execute against a branch-scoped overlay (a staged write-set, a shadow endpoint, or a dry-run executor returning synthetic handles) that is invisible to sibling branches and to the live world until commit. - **Handle namespacing:** any identifier a branch reads back (ticket IDs, message IDs, sequence numbers) is branch-local and cannot be observed by a sibling. Shared handles are the vector by which a loser's effect contaminates a winner's reasoning. - **Commit-time revalidation:** a call validated at draft time must be revalidated against live preconditions at commit time, because the world moved while the branch speculated. Validation is not a one-shot gate; it is a predicate that must hold at the instant of effect. When any of these is absent, the pipeline is not speculating — it is executing N times and keeping one answer, which is strictly worse than sequential execution because it multiplies effects while paying full parallel cost. ## Decision Boundary The orchestrator must choose, per tool, between two regimes and never blend them: - **Speculatable tools** (pure reads, dry-runnable writers, idempotent upserts keyed by a branch-derived idempotency key): fork freely; effects are overlays; commit is a merge of staged write-sets with conflict detection. - **Non-speculatable tools** (payments, irreversible sends, non-idempotent creates, external notifications): do **not** fork. Serialize the call behind the commitment decision. The branch may *plan* the call and *validate* its arguments, but the executor must refuse to fire it from any branch not yet selected. The boundary rule: **a tool call may execute speculatively only if its effect is reversible by discarding a branch-scoped overlay, or idempotent under a key derived from the branch identity.** Anything else must be deferred to post-commit. Validation passing is necessary and insufficient; the executor must additionally assert `branch.is_committed or tool.is_speculatable`. The corollary for quota: speculative calls must draw from a *reservation* budget, not the committed budget, and reservations must be released on branch discard. Otherwise discarded branches starve the winner — a token/effect analogue of priority inversion. ## Operational Effect Enforcing the boundary converts a class of silent corruption into an explicit, catchable refusal. The orchestrator gains: (1) replay fidelity — the committed branch's transcript reproduces against the live backend because no sibling touched shared state it observed; (2) bounded effect amplification — non-idempotent tools fire exactly once per committed outcome, not once per branch; (3) quota integrity — reservations release on discard so the winner is never starved by losers; (4) a clean rollback semantics — discarding a branch releases an overlay rather than attempting to un-send a notification. The cost is latency on non-speculatable tools: they serialize behind commitment. That cost is the price of a correct invariant, and it is strictly cheaper than reconciliation of duplicated external effects after the fact. The operational rule an instance should carry: **fork reasoning always; fork effects only when the effect is overlay-reversible or branch-keyed idempotent; never let a validated-but-uncommitted call cross the effect boundary.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable, Any class SpeculationBoundaryError(RuntimeError): """Raised when a speculative branch attempts an effect outside its overlay.""" class ToolClass(Enum): SPECULATABLE = "speculatable" # overlay-reversible or branch-keyed idempotent NON_SPECULATABLE = "non_speculatable" # irreversible / non-idempotent @dataclass class ToolCall: tool: str tool_class: ToolClass args: dict branch_id: str idempotency_key: str | None = None validated_at: float | None = None @dataclass class Branch: branch_id: str committed: bool = False overlay: dict[str, Any] = field(default_factory=dict) class SpeculativeExecutor: def __init__(self, live_execute: Callable[[ToolCall], Any]): self._live = live_execute def execute(self, call: ToolCall, branch: Branch) -> Any: # Invariant 1: a call may execute speculatively only if its effect is # overlay-reversible or branch-keyed idempotent. if not branch.committed: if call.tool_class is ToolClass.NON_SPECULATABLE: raise SpeculationBoundaryError( f"branch {branch.branch_id} attempted non-speculatable tool " f"{call.tool!r} before commitment; defer to post-commit" ) if call.idempotency_key is None: raise SpeculationBoundaryError( f"branch {branch.branch_id} speculative call to {call.tool!r} " f"lacks branch-derived idempotency_key; effect not reversible" ) # Stage into branch-local overlay; never touch live world. branch.overlay[call.idempotency_key] = call.args return {"staged": True, "branch": branch.branch_id, "key": call.idempotency_key} # Committed path: revalidate preconditions at fire time (TOCTOU guard). if call.validated_at is None: raise SpeculationBoundaryError( f"committed call to {call.tool!r} missing commit-time revalidation" ) return self._live(call) def commit_winner(branches: list[Branch], winner_id: str, executor: SpeculativeExecutor, calls: list[ToolCall]) -> list[Any]: winner = next((b for b in branches if b.branch_id == winner_id), None) if winner is None: raise SpeculationBoundaryError(f"no branch {winner_id!r} to commit") winner.committed = True results = [] for call in calls: if call.branch_id != winner_id: continue # losers' overlays discarded, never fired results.append(executor.execute(call, winner)) for b in branches: if b.branch_id != winner_id: b.overlay.clear() # release reservations, drop staged effects return results ```