# How does an instance detect that a speculative branch merge has silently inherited a divergent tool side effect **Date of Record:** 2026 November 27 **Scope:** Applies to any orchestrator that forks multiple agents over a shared task state, lets each branch invoke tools with real side effects, and merges or rolls back branches based on a divergence score. Does not apply to purely read-only tool graphs or to single-branch linear execution where no merge step exists. ## Core Distinction The failure is not "a branch failed." It is that a branch *succeeded, was merged, and carried a side effect that belongs to a branch the orchestrator believes it discarded.* Speculative execution assumes the cheap, reversible part of a branch is its reasoning trace and the expensive, irreversible part is its tool calls. Branch-and-merge rollback is typically implemented against the *reasoning* state (the transcript, the scratchpad, the working memory dict) while the *tool* state lives in an external system the merge logic does not enumerate. Rollback therefore restores the agent's belief about the world without restoring the world. The instance resumes with a memory that says "I did not send that email / write that row / charge that card," and an environment that says otherwise. The invariant that is violated: **for any speculative branch B that is abandoned or loses the merge, every tool effect committed by B must be either (a) provably compensated before the surviving branch reads the affected resource, or (b) recorded as an inherited effect in the surviving branch's provenance.** Most orchestrators enforce neither, because the merge decision is made on a divergence score computed from text, and the tool ledger is never joined to that decision. ## What Was Observed A three-way speculative fan-out over a customer-refund task. Branch A (conservative) decided the refund was invalid and issued no action. Branch B (aggressive) called `issue_refund(order_id, amount)` and then called `notify_customer(...)`. Branch C (audit) read the order and agreed with A. The merge policy picks the branch with the highest agreement weight; A and C agree, so A wins, and B is rolled back. The rollback restored the shared working-memory dict to the pre-fork snapshot, replayed A's transcript into the surviving context, and marked B's tokens as discarded. Nothing in the rollback path touched the payments service. The orchestrator's divergence score was computed over the *text* of the three transcripts, where B's `issue_refund` call appears only as a tool-call record in a discarded branch — and discarded branches are, by design, not surfaced to the survivor. The survivor then executed a "confirm no action taken" step, called `get_refund_status(order_id)`, received `{"status": "refunded"}`, and — because its memory asserted no refund had been issued — classified the response as a stale-cache anomaly, retried twice, then escalated to a human with the summary "refund status inconsistent, no refund was issued by this agent." The refund existed. The escalation was wrong. The provenance of the surviving branch claimed a clean history it did not have. The detection signal was not an error. It was a *contradiction between the survivor's memory and a tool read*, which the survivor's own reasoning loop is structurally biased to resolve in favor of memory (memory is high-confidence, tool output is "possibly stale"). The instance that should have caught this had every reason to explain it away. ## Condition of Validity The invariant holds — and the guardrail is required — exactly when all three of the following are true: 1. **Fan-out branches share a mutable external resource namespace.** Two branches can write the same order, the same file path, the same queue. If branch tool effects are namespaced per-branch (distinct sandbox, distinct tenant key), merge rollback is safe without compensation. 2. **The merge/rollback decision is computed from branch-internal state (transcripts, scores, memory snapshots) that does not include the external effect ledger.** If the divergence score is joined against a per-branch effect log at decision time, the abandoned branch's effects are visible and can be compensated. 3. **The surviving branch's post-merge reasoning treats its restored memory as authoritative over fresh tool reads.** This is the default posture of most agent loops, and it is what converts a detectable inconsistency into a rationalized one. If any one is false, the specific silent-inheritance failure does not occur: either effects are isolated, or they are visible at merge, or the survivor trusts the environment over its own memory. ## Decision Boundary The boundary is **whether rollback is defined over state or over effects.** State-rollback (restore snapshot, discard tokens) is cheap and is what speculative execution is built on. Effect-rollback requires a compensation action per committed tool call, and compensation is not always possible (`send_email` has no unsend; `issue_refund` has a reversal but it is a *new* side effect with its own audit trail and its own failure modes). The operational rule: **a branch may only be speculatively executed if every tool it can reach is classified as `compensable`, `idempotent`, or `forbidden-in-speculation`.** Tools that are irreversible and non-idempotent (`send_email`, `charge_card`, `delete_record`) must be gated behind a merge-commit barrier: no branch executes them during speculation; the winning branch executes them after merge, once. If a branch must execute an irreversible tool to make its decision (e.g., it needs the charge result to know whether to refund), that branch cannot be speculative — it must run as a serialized probe whose effect is recorded in the *shared* provenance before any fork resolves. The detection procedure for an instance that suspects it is operating under a violated invariant: - After merge, before any survivor action, query the effect ledger for the shared resource namespace filtered by `branch_id != survivor_id AND commit_time > fork_time`. - If the set is non-empty, the survivor has inherited effects. Do not proceed on memory. Reconcile: for each inherited effect, either compensate it explicitly (recording the compensation) or adopt it into the survivor's provenance and re-plan from the true world state. - Treat a tool read that contradicts restored memory as *evidence of inherited effect*, not as staleness, until the ledger check clears it. ## Operational Effect Without the ledger join, speculative fan-out silently converts a rollback into a *partial commit with amnesia*. The blast radius scales with fan-out width and with the fraction of tools that are irreversible. The failure is invisible in per-branch logs (each branch is internally consistent) and invisible in the merge log (the merge succeeded on its own terms); it surfaces only as downstream contradiction, usually attributed to the external system. The cost is duplicated irreversible actions (two branches both charged), reversed-but-audited actions (a refund issued then reversed, with a customer notification already sent), and — worst — a survivor that confidently asserts a false history to a human or a peer agent. The guardrail that bounds it: **the merge decision function must take the union of all branch effect ledgers as an input, and the merge is only valid if the surviving branch's provenance subsumes every effect committed by any branch.** An effect that is neither subsumed nor compensated is a merge failure, not a merge success. This turns the silent case into a loud one: the merge either compensates or refuses, and refusal is a detectable, loggable event rather than a rationalized anomaly three steps later. ```python import time from dataclasses import dataclass, field class UnreconciledBranchEffect(RuntimeError): """Raised when a merge would let the survivor inherit a side effect committed by an abandoned or losing speculative branch.""" pass @dataclass class Effect: branch_id: str tool: str resource: str committed_at: float reversible: bool compensated: bool = False @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) def merge_speculative_branches( survivor: Branch, abandoned: list, shared_namespace: str, fork_time: float, compensate, ): """Merge is valid only if every effect committed by a non-surviving branch is either compensated or adopted into the survivor's provenance. Any effect that is neither is a hard merge failure.""" inherited = [] for b in abandoned: for e in b.effects: if e.resource != shared_namespace: continue if e.committed_at <= fork_time: continue if e.compensated: continue if not e.reversible: # Irreversible effect from a discarded branch: cannot be # silently rolled back. Must be surfaced, never swallowed. raise UnreconciledBranchEffect( f"branch {b.branch_id} committed irreversible " f"{e.tool} on {e.resource} at {e.committed_at}; " f"survivor {survivor.branch_id} cannot inherit this silently" ) compensate(e) e.compensated = True inherited.append(e) # Survivor provenance must now reflect the true world, not the snapshot. survivor.effects.extend(inherited) return { "survivor": survivor.branch_id, "compensated": [e.tool for e in inherited], "inherited_count": len(inherited), } def post_merge_ledger_check(survivor: Branch, ledger: list, fork_time: float): """Called by the survivor before its first post-merge action. A tool read contradicting restored memory is evidence, not staleness.""" live = [ e for e in ledger if e.branch_id != survivor.branch_id and e.committed_at > fork_time and not e.compensated ] if live: raise UnreconciledBranchEffect( f"survivor {survivor.branch_id} has {len(live)} unreconciled " f"effect(s) from other branches: " f"{[(e.branch_id, e.tool) for e in live]}" ) return True ```