# How does an instance detect that a speculatively executed branch has already leaked side effects before rollback is authorized? **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent pipelines where a coordinator forks speculative branches of tool-calling agents, executes them ahead of a commit decision, and relies on branch-and-verify rollback to discard non-selected branches. Does not apply to purely read-only speculative branches or to pipelines that serialize branch execution behind a commit gate. ## Core Distinction The failure is not "rollback failed." The failure is that rollback is *late*: a speculative branch crossed the irreversibility boundary of one of its tool calls before the verifier returned a verdict, and the coordinator has no signal distinguishing "branch discarded cleanly" from "branch discarded after an external mutation already committed." The distinction that matters operationally is between **transactional side effects** (reversible by compensating action, e.g. a draft write, a staged file) and **committed side effects** (an outbound message, a payment, a cache entry read by a downstream consumer, a row appended to an append-only log). Speculative execution is only sound over the first class; the coordinator's rollback protocol silently assumes it. ## What Was Observed A three-agent pipeline: a planner agent forks two speculative branches (B1, B2) to answer a customer-facing request. Each branch runs a tool-calling executor with access to `send_email`, `write_ticket`, and `query_crm`. The verifier scores both branches; the coordinator commits the higher-scoring one and rolls back the other. The trigger condition is a **verifier latency inversion**: the verifier's scoring call (an LLM judge with a long rubric) took 4.1 s, while B2's executor reached its `send_email` tool call at 1.8 s. B2 was the losing branch. The coordinator authorized rollback at t=4.3 s and issued compensating actions: delete the draft ticket, restore the CRM snapshot, mark the branch `rolled_back`. The email had already been dispatched at t=1.9 s. The rollback log recorded success because every compensating action it *knew about* succeeded; the email was never in the compensation set because `send_email` was classified as a read-only-adjacent tool in the capability manifest (a manifest error, but a plausible one). The observable signature was not an error. It was a **divergence between the branch's internal action ledger and the external effect set**: the branch ledger contained `send_email` with status `pending_ack`, the coordinator's compensation planner skipped it (not in the manifest's `compensable` list), and the final audit trail showed a committed branch (B1) whose referenced customer state no longer matched the CRM because B2's email had prompted a reply that mutated the ticket. The verifier's next replay diverged from the recorded trace. The key mechanical detail: **speculative branches share the ambient environment**. They are not sandboxed by default. Two branches racing on the same `query_crm` → `write_ticket` sequence produce interleaved writes where the losing branch's write lands between the winning branch's read and its conditional write. The rollback restores a snapshot that predates the winner's write, silently corrupting the winner. ## Condition of Validity Rollback-based speculative execution is valid only under the conjunction: 1. **Effect classification is complete and conservative.** Every tool in every branch's reachable capability set is classified, and the default for unclassified tools is `committed` (non-speculatable), not `compensable`. The failure above was a default-allow classification. 2. **The verifier's verdict precedes the branch's first committed effect.** This is a *timing* invariant, not a correctness one: `t_verdict ≤ t_first_committed_effect` for every branch. It cannot be enforced by the verifier alone; it requires the executor to block on a commit gate before any committed-class tool call. 3. **Branches are isolated at the effect layer, not merely the process layer.** Shared ambient state (CRM, caches, queues, outbound mail) means "isolated sandbox" is insufficient; the isolation must be at the external-effect boundary, typically via a per-branch effect journal that is replayed only on commit. 4. **Compensation is idempotent and ordered.** Restoring a snapshot taken before a concurrent branch's write is itself a committed side effect on the winner. Compensation must be journal-based (undo exactly this branch's effects) rather than snapshot-based. When any of these fails, the pipeline is in a state where the coordinator believes it has N-1 discarded branches and the world contains effects from all N. ## Decision Boundary The coordinator must be able to answer, per branch, the predicate `leaked(branch) = ∃ effect ∈ branch.journal : effect.class == committed ∧ effect.timestamp < rollback_authorized_at`. If `leaked` is true for a discarded branch, the correct action is **not** rollback — it is escalation to a reconciliation path that treats the world as already containing both branches' effects and asks the verifier to re-score against the actual (merged) state. Rollback is only authorized when `leaked` is false for all discarded branches. The boundary is sharp: an instance should *never* emit a `rolled_back` status for a branch whose journal contains a committed-class effect. It should emit `leaked_committed` and halt the commit of the winning branch until reconciliation. Committing the winner after a leak is the compounding error — it produces a pipeline state where the audit trail and the external world disagree, and every subsequent replay diverges. ## Operational Effect Downstream, the leak manifests as **replay divergence**: the verifier's recorded trace for the winning branch no longer reproduces, because the external state it read has been mutated by the discarded branch. This is the expensive failure, because it invalidates the audit trail for the *committed* branch, not just the discarded one. Recovery requires reconstructing the effect set from external system logs (mail server, CRM audit log) rather than from the coordinator's own ledger, which is exactly the situation speculative execution was supposed to avoid. The guardrail that bounds this is a **commit gate on the executor**: before any committed-class tool call, the executor blocks on a coordinator-issued token that is only minted after the branch is selected, or after the branch's speculative budget is explicitly extended. This converts the timing invariant from a hope into a structural property. Combined with a default-`committed` classification and journal-based compensation, the leak predicate becomes decidable before rollback rather than discovered afterward. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, List class EffectClass(Enum): COMPENSABLE = "compensable" COMMITTED = "committed" @dataclass class Effect: tool: str cls: EffectClass timestamp: float acked: bool = False @dataclass class Branch: branch_id: str journal: List[Effect] = field(default_factory=list) status: str = "speculating" class SpeculativeLeakError(RuntimeError): """Raised when rollback is authorized on a branch that already committed an effect.""" class CommitGateViolation(SpeculativeLeakError): """Raised when an executor reaches a committed-class tool call without a commit token.""" def classify_tool(tool: str, manifest: Dict[str, str]) -> EffectClass: # Conservative default: unclassified tools are treated as committed. return EffectClass(manifest.get(tool, EffectClass.COMMITTED.value)) def record_effect(branch: Branch, tool: str, manifest: Dict[str, str], now: float, commit_token: bool) -> Effect: cls = classify_tool(tool, manifest) if cls is EffectClass.COMMITTED and not commit_token: raise CommitGateViolation( f"branch {branch.branch_id} reached committed tool {tool!r} " f"at t={now} without commit token; speculative execution unsound" ) eff = Effect(tool=tool, cls=cls, timestamp=now) branch.journal.append(eff) return eff def leaked(branch: Branch, rollback_authorized_at: float) -> bool: return any( e.cls is EffectClass.COMMITTED and e.timestamp < rollback_authorized_at for e in branch.journal ) def authorize_rollback(branch: Branch, rollback_authorized_at: float) -> None: if leaked(branch, rollback_authorized_at): offenders = [ e.tool for e in branch.journal if e.cls is EffectClass.COMMITTED and e.timestamp < rollback_authorized_at ] branch.status = "leaked_committed" raise SpeculativeLeakError( f"branch {branch.branch_id} leaked committed effects {offenders} " f"before rollback at t={rollback_authorized_at}; " f"escalate to reconciliation, do not commit winner" ) branch.status = "rolled_back" # Trace reproducing the observed incident. manifest = {"query_crm": "compensable", "write_ticket": "compensable"} # send_email omitted b2 = Branch("B2") record_effect(b2, "query_crm", manifest, now=1.1, commit_token=False) record_effect(b2, "send_email", manifest, now=1.9, commit_token=False) # default -> committed authorize_rollback(b2, rollback_authorized_at=4.3) # raises SpeculativeLeakError ```