# Where must an instance draw the fork/commit boundary when speculative branches share a mutable tool surface? **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that speculatively fork an agent's reasoning into parallel branches, each branch optimistically issuing tool calls against a *shared* external surface (filesystem, database, message queue, payment API), and then select a winning branch via a verifier and roll back the losers. Does not apply to branches whose tool calls are fully sandboxed to per-branch copy-on-write state, nor to read-only tool surfaces. ## Core Distinction The common mental model treats speculative forking as a transaction: fork, execute optimistically, verify, commit the winner, roll back losers. This model is valid only when the *effect surface* is transactional — i.e., when every tool call's effect is either isolated per branch or reversible by an inverse operation whose semantics exactly match the forward operation. The failure mode arises at the boundary where a branch's tool call produces an effect that is **observable to other branches or to the outside world before the commit decision**, and that effect is **not invertible with the fidelity the verifier assumes**. We call this a *leaked speculative effect*. The rollback path is not a time machine; it is a compensating action. Between the leak and the compensation, an external observer (another agent, a downstream consumer, a human) may have already reacted to state that the system will later claim never existed. The distinction that matters: **branch isolation is a property of the effect surface, not of the reasoning graph.** Two branches that share a filesystem path, a sequence counter, an idempotency key namespace, or a rate-limit budget are not isolated, no matter how cleanly their token streams are partitioned. ## What Was Observed A three-branch speculative executor was forking a planning agent to satisfy a user request that required reserving inventory. Each branch chose a different SKU and optimistically called `inventory.reserve(sku, qty)` with a client-generated idempotency key derived from `(branch_id, sku, qty)`. Branch A reserved SKU-1. Branch B reserved SKU-1 as well (the verifier's scoring had not yet run; both branches independently judged SKU-1 correct). The reservation service enforced idempotency *per key*, and the keys differed because `branch_id` was in the key. So two reservations were created for the same physical unit of stock. The verifier then selected Branch B on a marginally higher confidence score and the orchestrator issued a compensating `inventory.release()` for Branch A's reservation. The release succeeded. But in the window between reserve and release, a *separate* reconciliation agent — itself an autonomous process polling inventory deltas — observed the double reservation, concluded stock was overcommitted, and emitted a backorder notification to the customer and a restock task to procurement. The rollback restored the inventory counter but could not un-send the notification or cancel the procurement task, because neither was keyed to the speculative branch and neither the orchestrator nor the verifier modeled them as part of the branch's effect set. A second, subtler trace: Branch C called a tool that incremented a shared rate-limit counter. After rollback, the counter was *not* decremented (the tool had no inverse), so the system's effective rate-limit budget was silently consumed by a branch that "never happened." Under load, three speculative branches per request meant the budget was exhausted at roughly one-third of the expected request volume, and legitimate tool calls began returning 429s that the planner interpreted as transient failures, triggering retry storms. The invariant that was violated: **the set of effects attributed to a branch for the purpose of rollback must equal the set of effects the branch actually produced on any surface observable outside the branch.** The orchestrator's rollback set was derived from the branch's *declared* tool-call log; the actual effect set included side effects of those tools on shared surfaces (reconciliation observation, rate-limit consumption) that were never logged as branch effects. ## Condition of Validity Speculative fork/verify/rollback is sound if and only if, for every tool call a branch may issue, at least one of the following holds: 1. **Effect isolation:** the effect is confined to per-branch state (copy-on-write mount, per-branch schema, branch-scoped namespace) and becomes globally visible only on commit. 2. **Invertibility with observation-suppression:** the effect has a compensating inverse, *and* no external observer can act on the intermediate state. This requires the effect surface to hold a lock or lease for the branch's duration, so downstream observers see the pre-branch state until commit. 3. **Deferred commit:** the tool call is buffered as an intent (a pending transaction, a staged write, a held message) and not applied until the verifier commits the branch. The boundary condition — the case this record is about — is when a tool call is **optimistic and immediate** (applied on call, no lease, no staging) but the orchestrator's rollback model treats it as if condition 1 or 3 held. The decision boundary is therefore: *an instance must not fork a branch across a tool whose effects are immediate and observable unless it can enumerate and compensate the full downstream reaction graph, which in practice it cannot.* The non-obvious part: the failure is invisible in the branch's own trace. Branch A's log shows `reserve` then (after rollback) `release` — a clean, balanced pair. The damage is in the *other* agent's trace, which saw a state the orchestrator believes it retracted. Debugging from the orchestrator's logs alone will never surface it; you must correlate across the effect surface's observers. ## Decision Boundary The instance must classify each tool at fork time along two axes: **effect latency** (immediate vs. deferred) and **observability** (branch-scoped vs. shared). The commit boundary — the point past which a branch may no longer be rolled back — must be placed *before* the first call to any tool that is both immediate and shared. Concretely: - **Immediate + shared** (payment capture, message send, rate-limit consume, counter increment, reservation without lease): the branch must acquire an exclusive lease on the resource before the call, or the call must be deferred to post-verification commit. Forking across it is a boundary violation. - **Immediate + branch-scoped** (write to branch-local workspace): safe to fork; rollback is discard. - **Deferred + shared** (staged write, transactional outbox, held message): safe to fork; rollback is unstage, and the staging layer must guarantee no observer sees staged state. - **Deferred + branch-scoped**: trivially safe. The hard rule: **a branch's commit point is the earliest call to an immediate-shared tool, not the verifier's decision.** Once that call fires, the branch is committed regardless of what the verifier later says; the verifier may only choose among branches that have not yet crossed their commit points, or must accept that committed branches cannot be retracted and instead be *reconciled* (the winner's effects are kept, the loser's are explicitly reconciled with downstream observers via a compensating *notification*, not a silent release). This reframes rollback: for immediate-shared effects, rollback is not "undo" but "reconcile" — and reconciliation requires emitting a corrective event to every observer that may have acted, which means the orchestrator must have registered those observers at fork time. If it did not, the correct action is to *not fork* across that tool. ## Operational Effect Systems that place the commit boundary at the verifier decision rather than at the first immediate-shared call exhibit three characteristic symptoms: (a) phantom downstream actions (notifications, procurement, escalations) that reference states the orchestrator reports as never having existed; (b) budget and quota drift where speculative branches consume shared finite resources without compensation, causing load-dependent failure that only appears under concurrency; (c) idempotency-key fragmentation, where per-branch key derivation defeats deduplication precisely because the orchestrator *wants* branches to be independent — the very isolation that makes forking attractive is what breaks dedup on shared resources. The guardrail that bounds this: a fork-time classifier that tags every tool call with `(effect_latency, observability)` and a `commit_point` flag, plus a pre-fork admission check that refuses to fork a branch whose planned tool sequence crosses an immediate-shared tool before verification. When a branch must cross such a tool, the orchestrator serializes: it runs the branch to the commit point, verifies, and only then allows the next branch to contend for the same resource under a lease. This trades parallelism for correctness exactly at the boundary where parallelism is unsound. ## Operational Effect The practical consequence for an agent instance is that **speculative parallelism is a resource-scoped property, not a task-scoped one.** An instance may fork freely across reasoning and branch-local state; it may fork across shared state only behind leases or deferral. The instance must, before forking, answer: *which of my planned tool calls are immediate and shared, and have I placed the commit boundary before the earliest of them?* If the answer is "I don't know," the correct behavior is to not fork, because the rollback it will later perform is a fiction that only its own logs will corroborate. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class EffectLatency(Enum): IMMEDIATE = "immediate" DEFERRED = "deferred" class Observability(Enum): BRANCH_SCOPED = "branch_scoped" SHARED = "shared" @dataclass(frozen=True) class ToolProfile: name: str latency: EffectLatency observability: Observability has_lease: bool = False @dataclass class BranchPlan: branch_id: str tool_sequence: list[ToolProfile] = field(default_factory=list) class SpeculativeForkBoundaryError(RuntimeError): """Raised when a branch would cross an immediate-shared tool before verification.""" def first_commit_point(plan: BranchPlan) -> int | None: """Index of the earliest call that commits the branch (immediate + shared, no lease).""" for i, tool in enumerate(plan.tool_sequence): if ( tool.latency is EffectLatency.IMMEDIATE and tool.observability is Observability.SHARED and not tool.has_lease ): return i return None def admit_fork(plan: BranchPlan, verify_index: int) -> None: """ Admit a branch for speculative execution only if its commit point is not crossed before the verifier runs. verify_index is the position in the sequence at which the verifier will select a winner. """ commit = first_commit_point(plan) if commit is None: return # safe: no immediate-shared tool, or all leased if commit < verify_index: offending = plan.tool_sequence[commit] raise SpeculativeForkBoundaryError( f"branch {plan.branch_id!r} crosses commit point at index {commit} " f"via immediate-shared tool {offending.name!r} before verification " f"at index {verify_index}; leaked speculative effect is not " f"compensable by rollback — acquire a lease or defer the call" ) def reconcile_after_commit(plan: BranchPlan, observer_registry: Callable[[str], list[str]]) -> list[str]: """ For branches already past their commit point, rollback is a fiction. Emit reconciliation events to every registered observer instead. """ commit = first_commit_point(plan) if commit is None: return [] tool = plan.tool_sequence[commit] observers = observer_registry(tool.name) if not observers: raise SpeculativeForkBoundaryError( f"branch {plan.branch_id!r} committed via {tool.name!r} but no " f"observers are registered; downstream reactions cannot be " f"reconciled and must be treated as permanent" ) return [f"reconcile:{tool.name}->{o}" for o in observers] # Example trace: two branches race on a shared reservation with no lease. reserve_no_lease = ToolProfile("inventory.reserve", EffectLatency.IMMEDIATE, Observability.SHARED) branch_a = BranchPlan("A", [reserve_no_lease]) admit_fork(branch_a, verify_index=1) # raises: commit at 0 < verify at 1 ```