# Where must an instance of a speculative branch be forbidden from emitting externally observable side effects, and what breaks when the rollback boundary is drawn too late **Date of Record:** 2026 November 17 **Scope:** Applies to branch-and-rollback orchestrators that fan out speculative sub-agents and permit them to issue tool calls (writes, sends, payments, deployments, state mutations) before the branch is committed. Does not apply to read-only speculation, to pure-compute branches, or to systems where every tool call is itself transactional and idempotent under a caller-supplied branch token. ## Core Distinction The distinction that matters is between *speculative state* and *observable effect*. A branch-and-rollback orchestrator can cheaply discard speculative state — its own memory, its own scratchpad, its own intermediate artifacts — because those live inside a namespace the orchestrator controls. It cannot discard an observable effect, because the effect has already escaped the namespace: an email left the SMTP server, a row was committed to a shared table, a webhook fired against a third-party endpoint, a container was scaled, a message landed on a queue another consumer is reading. The non-obvious invariant is this: **the rollback boundary must be drawn at the moment of first external emission, not at the moment of branch commit.** Every architectural diagram I have seen draws the rollback boundary at commit — the branch "succeeds" or "fails" and the orchestrator keeps or drops its state accordingly. That boundary is wrong. The correct boundary is earlier, and it is per-tool-call, not per-branch. ## What Was Observed A three-way speculative fan-out was launched against a task that included "notify the on-call channel when the migration plan is ready." Two of the three branches produced plans that the verifier later rejected — one had an inconsistent schema reference, one assumed a table that did not exist. Both rejected branches had already called the notification tool, because the tool was registered as an ordinary callable with no speculation awareness, and the sub-agents had no way to know their branch was provisional. The orchestrator rolled back cleanly. Its own state was pristine. The on-call channel received three "migration plan ready" messages, two of which pointed at plans that never existed and one of which referenced a table that would never be created. The rollback was, from the orchestrator's point of view, a complete success. From the on-call engineer's point of view it was a page storm about a migration that had not happened. The failure is not that the orchestrator forgot to roll back. The failure is that "roll back" was defined over a state space that did not include the thing that actually mattered. This is the characteristic signature of a rollback boundary drawn too late: **the orchestrator's rollback succeeds while the system's rollback fails**, and the two are not reconciled because the orchestrator only measures the first. A second, subtler observation: the branches were not independent in their emissions. Branch B's notification was triggered by observing Branch A's speculative write to a shared staging table — a write that was "rolled back" logically but had been visible to a sibling branch for ~400ms. The branches were speculating against each other's uncommitted effects. This is a read-your-own-speculation leak, and it is the reason that "just make the tools idempotent" is insufficient: idempotency deduplicates repeated effects, it does not prevent one branch from *conditioning its behavior* on another branch's provisional effect. ## Condition of Validity The invariant holds — speculative branches must be forbidden from external emission — under all of the following conditions: 1. The effect is not reversible by a compensating action the orchestrator can guarantee will run (e.g., an append-only audit log, a sent email, a fired webhook, a third-party API call with no delete). 2. The effect is observable by an actor outside the orchestration boundary (a human, another service, a sibling branch). 3. The branch's probability of rejection is non-negligible. If the verifier accepts ~100% of branches, speculation buys nothing and the boundary question is moot. 4. The orchestrator cannot atomically tie the emission to the commit — i.e., there is no two-phase protocol where the effect is staged and released only on commit. When any of these fails, the boundary can be drawn later. When all hold — which is the common case for tool calls with side effects — the boundary must be at first emission, and the tool must be *speculation-aware*: it must accept a branch token, stage the effect under that token, and release or discard on commit/rollback. ## Decision Boundary The decision an orchestrator must make per tool call, before the call is dispatched, is: - **Is this tool call externally observable?** If no (pure read, pure compute, write to branch-private scratch), allow it freely; it is inside the rollback boundary by construction. - **If yes, is it compensable?** If a guaranteed compensating action exists and is registered with the orchestrator, allow it but register the compensation *before* dispatch, not after. Compensation registration after dispatch is the same bug in a smaller form: a crash between dispatch and registration leaves an uncompensated effect. - **If yes and not compensable, is it stageable?** If the tool supports a branch token and deferred release, allow it as a staged call. - **Otherwise: forbid it in speculative branches.** Defer the call to the commit phase. The branch may *plan* the call, record the intent, and let the committed branch execute it. It may not execute it. The trap is the middle case. Teams discover the non-compensable case and reach for idempotency keys as a substitute for staging. Idempotency keys make a repeated call safe; they do not make a *rejected branch's* call safe, because the rejected branch's call is the first call, and it succeeds. The key deduplicates nothing because there is nothing to deduplicate. The effect is simply wrong and already delivered. ## Operational Effect Drawing the boundary at first emission changes the orchestrator's shape in three ways. First, tools acquire a branch lifecycle: `stage(token, payload)` → `commit(token)` or `discard(token)`, and the orchestrator must own that lifecycle, not the tool. Second, the commit phase becomes the only place where non-stageable effects execute, which means the commit phase is where latency and failure live — speculation optimizes the *decision*, not the *effectuation*, and planning that assumes otherwise will over-promise on latency. Third, the orchestrator needs a reconciliation pass: any staged token that is neither committed nor discarded within a bound is a leak, and leaks must be surfaced as errors rather than silently garbage-collected, because a leaked stage may correspond to a partially-emitted effect in a tool that did not honor the staging contract. The operational lesson, stated as a rule an agent can carry: **a speculative branch may compute, may read, may write to its own namespace, and may plan any effect; it may not emit any effect that a rejected branch would regret.** The regret test is the boundary. If you cannot answer "would we regret this if the branch is rejected?" before dispatch, you have drawn the boundary too late. ```python class SpeculationBoundaryError(RuntimeError): """Raised when a speculative branch attempts an effect outside the rollback boundary.""" pass class ToolCall: def __init__(self, name, payload, externally_observable, compensable, stageable): self.name = name self.payload = payload self.externally_observable = externally_observable self.compensable = compensable self.stageable = stageable def dispatch(branch, call, orchestrator): # Non-observable calls are inside the rollback boundary by construction. if not call.externally_observable: return orchestrator.execute(call) if branch.committed: return orchestrator.execute(call) # Speculative branch from here on. if call.compensable: # Register compensation BEFORE dispatch; a crash after dispatch # but before registration leaves an uncompensated effect. orchestrator.register_compensation(branch.token, call) return orchestrator.execute(call) if call.stageable: return orchestrator.stage(branch.token, call) raise SpeculationBoundaryError( f"branch {branch.token!r} attempted non-compensable, non-stageable " f"external effect {call.name!r}; defer to commit phase or forbid" ) ```