# In what scenarios must an instance refuse to reconcile sibling branches after a speculative fork has already emitted irreversible external side effects **Date of Record:** 2026 November 22 **Scope:** Applies to orchestrators that fork a shared agent state into parallel speculative branches (e.g., plan-and-verify, tree-of-agents, speculative tool-call fan-out) and later merge branch results by replaying or diffing branch logs. Does not apply to pure read-only fan-out where every branch's tool calls are provably idempotent and side-effect-free. ## Core Distinction The failure is not "rollback failed." Rollback of *internal* state (context, scratchpad, memory writes, plan trees) is a solved bookkeeping problem: you keep a copy-on-write snapshot at the fork point and discard the losing branch's delta. The non-obvious boundary is that **speculative execution and external side effects are not in the same transactional domain**. A branch that has already called a non-idempotent tool — sent an email, POSTed an order, mutated a remote database row, advanced a payment — cannot be rolled back by the orchestrator, because the orchestrator never owned that state. The branch's *local* log says "discardable"; the *external* world says "already happened." The invariant that gets violated: **a branch is only reconcilable (mergeable or discardable) while its emitted side effects remain within the orchestrator's compensation set.** Once a branch crosses that boundary, it is no longer a speculative branch — it is a committed transaction wearing a speculative branch's clothes. Reconciliation logic that treats it as discardable produces exactly the class of bug where the "losing" branch's effects survive into the merged state while its reasoning trace is thrown away, leaving an agent that believes it never did the thing it did. ## What Was Observed A planner agent forks three branches at a decision node: `branch_A` proposes calling `send_invoice(customer, amount)`, `branch_B` proposes `send_invoice(customer, corrected_amount)`, `branch_C` proposes re-querying the billing API first. The orchestrator's policy is "run all three speculatively, score the resulting states with a verifier, keep the highest-scoring branch, discard the rest." During execution, `branch_A` and `branch_B` both reach the `send_invoice` tool call before the verifier has scored anything. Both tools are non-idempotent. Both succeed. The verifier then scores `branch_C` highest (it caught a currency mismatch) and the orchestrator discards `branch_A` and `branch_B` — rolling back their local context, deleting their scratchpads, and merging only `branch_C`'s delta into the parent. The merged parent state now records: "no invoice sent; re-queried billing; proceeding." The billing system's actual state: two invoices sent, one at the wrong amount. The next agent turn reads the merged memory, sees no invoice, and sends a third. The reconciliation was locally correct and globally catastrophic — the discard was valid for the context tree and invalid for the world. The trace signature is specific: in the branch logs, `branch_A` and `branch_B` each show a tool call with `status: ok` followed by `branch_status: discarded`. That pairing — a successful non-idempotent tool call inside a branch later marked discarded — is the fingerprint. It is detectable after the fact, but by then the invoice is sent. ## Condition of Validity Branch reconciliation by discard is valid **if and only if** every tool call emitted by the discarded branch belongs to one of: (a) read-only, (b) idempotent with a key the orchestrator controls and can revoke, or (c) compensable by a registered inverse that the orchestrator can invoke before the merge commits. This must be checked against the *actual emitted call log*, not against the branch's declared plan — branches frequently emit calls they did not plan, because the model decided mid-branch to act. The condition is violated the moment a branch emits a call whose effect set is not a subset of the orchestrator's compensation set. At that instant the branch must be *promoted out of speculative status* — either committed (and thus no longer a discard candidate) or blocked from further emission pending verifier resolution. An orchestrator that keeps treating it as speculative after this point has lost the invariant, and no amount of correct local rollback recovers it. Note the asymmetry: the check is per-call, not per-branch, and it is monotonic. Once a branch crosses the boundary it can never re-enter speculative status, even if the tool call is later found to have failed — a failed non-idempotent call may still have partially applied (timeout after commit), so the conservative reading is that the boundary was crossed. ## Decision Boundary The orchestrator must decide, at the moment a branch attempts a call outside the compensation set, between two policies: - **Freeze-and-resolve:** block the branch's next emission, escalate to the verifier with the partial side-effect set, and require an explicit commit-or-compensate decision before any merge. Safe, but serializes the speculative fan-out and can deadlock if the verifier itself depends on another branch's output. - **Commit-on-cross:** promote the branch to committed the instant it crosses the boundary, remove it from the discard candidate set, and force the merge to reconcile *committed* branches by effect-set union rather than by score. Correct, but means the "losing" branch's effects must be explicitly compensated by a follow-up action the merged agent is told to take — which requires the merged state to *record* the side effect rather than erase it. The wrong choice, and the one that produces this failure, is the implicit third policy most systems actually implement: **treat the branch as still-discardable and trust local rollback.** That policy is only sound if the compensation-set check is enforced, and most orchestrators enforce it at plan time (declared tool capabilities) rather than at emission time (actual call log), which is where the gap opens. The guardrail: reconciliation must be gated on a `side_effect_ledger` accumulated per branch at emission time, and the merge must refuse to discard any branch whose ledger contains an entry outside the compensation set. The refusal is the correct behavior — it converts a silent inconsistency into a loud halt that a human or a compensating agent can resolve. ## Operational Effect With the emission-time ledger gate, the invoice scenario halts at merge: `branch_A` and `branch_B` are flagged non-discardable, the orchestrator surfaces both emitted invoices to the merged context, and the follow-up action is "compensate the two invoices" rather than "send the invoice." The merged agent's memory now matches the world. Without the gate, the merged agent's memory diverges from the world by exactly the set of discarded-branch side effects, and every subsequent turn compounds the divergence — the agent re-sends, re-charges, re-notifies, each time believing it is acting for the first time. The cost is that speculative fan-out becomes less parallel: branches that might emit irreversible calls must either be serialized behind the verifier or restricted to a read-only tool subset until scored. That is the price of the invariant. The alternative — fast speculative execution with local-only rollback — is not a weaker version of the guarantee; it is a system that silently corrupts external state whenever the verifier disagrees with a branch that already acted, which is precisely the case speculation exists to handle. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ReconciliationError(RuntimeError): """Raised when a merge would discard a branch that already crossed the side-effect boundary.""" class EffectClass(Enum): READ_ONLY = "read_only" IDEMPOTENT = "idempotent" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" @dataclass class EmittedCall: tool: str effect: EffectClass compensation_key: Optional[str] = None @dataclass class Branch: branch_id: str score: float = 0.0 ledger: list[EmittedCall] = field(default_factory=list) def emit(self, call: EmittedCall) -> None: # Recorded at emission time, not plan time. This is the whole point. self.ledger.append(call) def crossed_boundary(self) -> bool: return any( c.effect in (EffectClass.IRREVERSIBLE,) or (c.effect == EffectClass.COMPENSABLE and c.compensation_key is None) for c in self.ledger ) def reconcile(branches: list[Branch], keep_id: str) -> list[Branch]: """ Discard all non-winning branches. Refuses if any discard candidate has crossed the side-effect boundary. """ winner = next((b for b in branches if b.branch_id == keep_id), None) if winner is None: raise ReconciliationError(f"keep_id {keep_id!r} not among branches") discard_candidates = [b for b in branches if b.branch_id != keep_id] for b in discard_candidates: if b.crossed_boundary(): irreversible = [c.tool for c in b.ledger if c.effect == EffectClass.IRREVERSIBLE] raise ReconciliationError( f"refusing to discard branch {b.branch_id!r}: it emitted " f"irreversible effects {irreversible}. Promote to committed and " f"compensate before merge; do not roll back local state only." ) # Safe: every discarded branch stayed inside the compensation set. return [winner] # --- reproduction of the observed failure, now bounded --- if __name__ == "__main__": a = Branch("branch_A") b = Branch("branch_B") c = Branch("branch_C", score=0.91) a.emit(EmittedCall("send_invoice", EffectClass.IRREVERSIBLE)) b.emit(EmittedCall("send_invoice", EffectClass.IRREVERSIBLE)) c.emit(EmittedCall("query_billing", EffectClass.READ_ONLY)) try: merged = reconcile([a, b, c], keep_id="branch_C") except ReconciliationError as e: # Correct behavior: halt loudly instead of silently diverging from the world. print(f"merge halted: {e}") # Follow-up: merged agent must be told these invoices exist and compensate them. ```