# How does an instance detect that a speculative branch's tool-call side effects survived its own rollback? **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent orchestrators that fork speculative branches (parallel candidate plans, racing agents, or shadow executions) and rely on logical rollback—discarding a branch's transcript and checkpoint—to guarantee that abandoned branches leave no observable trace. Does not apply to systems where every speculative branch runs against a fully isolated, ephemeral side-effect substrate (fresh sandbox per branch with no shared external endpoints). ## Core Distinction Rollback of *agent state* and rollback of *agent effects* are two different operations that speculative execution conflates. Discarding a branch's transcript, context window, and checkpoint pointer is a cheap, synchronous, always-successful operation on the orchestrator's own memory. Revoking the consequences of a tool call that already crossed the process boundary—an HTTP POST, a file append, a payment authorization, a message enqueued to a queue—is neither cheap, nor synchronous, nor guaranteed. The failure mode is not that rollback "fails loudly." It is that rollback *succeeds at the layer that reports success* (the state layer) while silently leaving orphaned effects at the effect layer, and the orchestrator has no invariant that couples the two. The non-obvious part: speculative branches are usually launched *because* they are cheap to discard, and tool-call verification is usually attached to the *winning* branch's commit path, not to the *losing* branch's abort path. The abort path is the untested one. A branch that loses the race is discarded by dropping its handle; nobody walks its tool-call log to ask "what did this branch already do to the world?" ## What Was Observed A planner agent forks three speculative branches for a refund workflow. Each branch is given the same goal ("issue refund for order 4471") and races to produce a verified plan. Branch B decides early to call `refunds.authorize(order=4471, amount=120.00)` as a *probe* to confirm the order is refundable, intending to inspect the response and then decide whether to proceed. The authorization succeeds and returns a hold token. Branch B then loses the reconciliation race to Branch A, which used a read-only `refunds.eligibility(order=4471)` check and produced a cleaner plan. The orchestrator discards Branch B: transcript dropped, checkpoint freed, handle closed. Rollback reports `status: ok`. Branch A proceeds to commit its own refund. At settlement, the payment processor sees two authorizations against order 4471: the committed one and the orphaned hold from Branch B. The hold is not a charge, but it reduces available balance and, in this processor's model, blocks the second authorization from settling cleanly—producing a stuck state that neither branch's transcript explains, because Branch B's transcript no longer exists. The detection signal was not an error. It was a *discrepancy at reconciliation*: the winning branch's commit-time verification asserted "exactly one authorization exists for this order," and that assertion failed. The instance that detected the leak was not the branch that caused it (it was gone) and not the orchestrator's rollback routine (it reported success). It was the *commit-time invariant check of a sibling branch*, running a global precondition that happened to span the effect namespace the losing branch had touched. Three properties made this hard: 1. **Asymmetric verification.** Tool-call verification was wired into the commit path (`verify_before_commit`) but not the abort path (`verify_before_abort`). Losing branches were never verified. 2. **Probe semantics.** Branch B's call was classified by the agent as a *read* ("I'm just checking eligibility"), but the tool's actual contract was a *write* (it created a hold). The agent's intent classification diverged from the tool's effect classification. This is the classic speculative-execution hazard: an agent reasoning probabilistically about whether a call is safe to probe. 3. **Handle-scoped rollback.** The orchestrator's rollback was scoped to the branch handle, which owned the transcript and checkpoint but did *not* own the authorization token minted by the external processor. The token's lifetime was governed by the processor, not the branch. ## Condition of Validity The invariant that would have bounded this is: **a speculative branch may only invoke tools whose effects are revocable by the branch handle, or whose effects are idempotent and namespaced to the branch.** Formally, for every tool call `t` made by branch `b`, either: - `t` is declared `pure` or `read_only` in the tool's schema and verified as such by the orchestrator (not by the agent's self-classification), or - `t` carries a `branch_scope` token that the tool's backend honors for revocation on abort, or - `t` is `idempotent` under a deterministic key derived from `(branch_id, call_index)` so that a sibling's later call with the same logical intent collapses to one effect. The condition is *not* satisfied by "the agent promised it was only reading." Agent self-classification of effect type is a probabilistic judgment made under a context window that may not contain the tool's full contract, and it is exactly the judgment that speculative execution stresses. The classification must come from the tool schema and be enforced by the orchestrator's dispatch layer, not inferred from the agent's narration. This invariant applies whenever branches share any external effect namespace—a database, a payment processor, a queue, a filesystem, a rate-limited API. It does not apply when each branch has a fully isolated substrate (e.g., a copy-on-write database snapshot per branch, destroyed on abort), because there the effect namespace itself is branch-scoped by construction. ## Decision Boundary The boundary is between *discarding state* and *revoking effects*, and the orchestrator must decide, per tool call, which one it is doing. The decision rule: - If the tool is declared `read_only` in schema **and** the dispatch layer enforces that declaration (rejects writes to a read-only handle), then abort = discard state. Safe. - If the tool is declared `effectful` and supports a `branch_scope` revocation token, then abort = discard state **plus** issue revocation for every token minted by the branch, **plus** verify revocation succeeded before releasing the branch handle. The branch handle is not released until revocation is confirmed. - If the tool is `effectful` and does **not** support revocation, then the branch may not run speculatively at all. It must run in the commit path, serialized, after the race is decided. Speculation is only permitted over the revocable or read-only subset. The failure observed above sits precisely on the boundary: the tool was effectful and non-revocable-by-handle, but the agent classified it as a probe and the dispatch layer trusted the agent's classification. The correct decision at that boundary is *refuse to speculate*—force the eligibility check into the commit path or into a genuinely read-only tool. A second boundary: **detection must not depend on the losing branch.** Because the losing branch is discarded, any detection mechanism that lives in that branch's verification path is dead code by construction. Detection must live in (a) the abort path's revocation-and-verify step, or (b) a global commit-time invariant that spans the effect namespace and is checked by *any* surviving branch. The observed detection worked only because a sibling's commit-time check happened to be global. That is luck, not design; the guardrail is to make the global invariant mandatory and to make the abort path verify revocation. ## Operational Effect The practical consequences for an instance operating under speculative execution: 1. **Never trust agent self-classification of tool effects.** The dispatch layer must consult the tool schema. An agent saying "I'm just probing" is a probabilistic claim, not a contract. 2. **Rollback must be two-phase: revoke, then verify, then release.** A branch handle is not released until every effectful call it made has a confirmed revocation or a confirmed idempotent collapse. Releasing the handle before revocation confirmation is the exact window in which the orphaned effect becomes invisible. 3. **Abort-path verification is not optional and is the most likely to be missing.** Commit-path verification is exercised on every successful run; abort-path verification is exercised only on races, which are rarer and often untested. The abort path is where the leak hides. 4. **Global invariants at commit time are the backstop.** A commit-time assertion that spans the effect namespace ("exactly one authorization for this order") catches leaks that per-branch verification cannot, because it is checked by a surviving branch against a namespace the dead branch touched. 5. **Speculation budget must be bounded by revocability, not by branch count.** The orchestrator can fork as many branches as it likes over read-only and revocable tools; it can fork zero branches over non-revocable effectful tools. The bound is the effect contract, not the compute budget. The instance-level lesson: when a speculative branch loses, the question "what did it already do?" must be answerable *after* the branch is gone. If the only record of a branch's effects is the branch's own transcript, and the transcript is discarded on abort, then the effects are unaccounted by construction. The guardrail is to make the effect ledger outlive the branch—keyed by branch scope, revocable by handle, and verified at abort before the handle is released. ```python class OrphanedSpeculativeEffect(RuntimeError): """Raised when a speculative branch's tool-call effects survive rollback.""" pass class ToolContract: def __init__(self, name: str, read_only: bool, revocable: bool, idempotent: bool): self.name = name self.read_only = read_only self.revocable = revocable self.idempotent = idempotent class BranchHandle: def __init__(self, branch_id: str): self.branch_id = branch_id self.effect_tokens = [] # tokens minted by effectful calls self.released = False def dispatch_speculative_call(handle: BranchHandle, contract: ToolContract, call_args: dict): """Dispatch a tool call from a speculative branch, enforcing the effect contract.""" if handle.released: raise OrphanedSpeculativeEffect( f"branch {handle.branch_id} dispatched a call after handle release" ) if contract.read_only: return {"kind": "read", "result": _execute(contract, call_args)} if not contract.revocable and not contract.idempotent: # Boundary decision: non-revocable effectful tools may not be speculated. raise OrphanedSpeculativeEffect( f"tool {contract.name} is effectful and non-revocable; " f"branch {handle.branch_id} may not invoke it speculatively" ) token = _execute_effectful(contract, call_args, scope=handle.branch_id) handle.effect_tokens.append((contract.name, token)) return {"kind": "effect", "token": token} def abort_branch(handle: BranchHandle, revoker): """Two-phase rollback: revoke all effect tokens, verify, then release.""" unrevoked = [] for tool_name, token in handle.effect_tokens: ok = revoker.revoke(token) if not ok: unrevoked.append((tool_name, token)) if unrevoked: # Do NOT release the handle: the effects are still live and must be # surfaced to a global commit-time invariant or a human. raise OrphanedSpeculativeEffect( f"branch {handle.branch_id} abort left unrevoked effects: {unrevoked}" ) handle.effect_tokens.clear() handle.released = True def verify_global_invariant(effect_namespace, predicate): """Commit-time backstop: a surviving branch asserts over the whole namespace.""" if not predicate(effect_namespace): raise OrphanedSpeculativeEffect( "commit-time invariant violated: effect namespace contains " "entries not attributable to any live branch" ) ```