# When must an instance abandon optimistic branches: speculative multi-agent rollback divergence at the commit horizon **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where a planner agent forks N speculative branches across peer executors, each branch mutating shared external state (tool side effects, memory writes, filesystem/DB), and a reconciliation step selects or merges a winner. Does not apply to pure read-only fan-out or to single-agent chain-of-thought self-consistency where branches have no external side effects. ## Core Distinction The failure is not "two agents disagree" and it is not "a rollback failed." It is the **commit-horizon divergence**: the moment a speculative branch's *observed* effects and its *reversible* effects stop being the same set. Optimistic execution assumes every branch action is either (a) a pure projection that can be discarded, or (b) a side effect that can be compensated. The boundary condition is that LLM-driven branches routinely produce a third category — **partially observable, non-compensable effects** — because the branch's own tool outputs are non-deterministic and because downstream observers (other agents, humans, external systems) may have already *read* the branch's intermediate state before reconciliation decides the branch loses. The invariant that must hold for optimistic branching to be sound is: > At commit time, for every losing branch B, the set of effects produced by B that are visible to any observer outside B must be a subset of the set of effects B can compensate. When that subset relation inverts — when a losing branch has leaked an effect it cannot retract — rollback is a lie. The system does not "undo"; it *overwrites*, and any observer that acted on the leaked value now holds a stale belief that no reconciliation pass will correct, because reconciliation only reconciles the *winner's* state, not the *readers'* state. ## What Was Observed A four-instance swarm (one orchestrator `O`, three executors `E1..E3`) was tasked with a provisioning workflow: pick a target region, reserve capacity, write a config record, notify a downstream deploy agent `D`. `O` speculatively forked three branches, one per region, each running the same ~9-step tool plan. Branches were expected to be cheap to discard: reserve-capacity was modeled as a "soft hold" with a TTL, config writes went to a staging namespace, and notify was gated behind a "commit" flag. The trace that broke it: 1. `E1` (region `us-east`) completed its plan first at t=4.1s and, because its local policy treated "staging write acknowledged" as sufficient evidence of quorum, called `notify(D, {region: us-east, config_id: cfg-7731})`. The notify tool was *supposed* to be commit-gated; the gate key was `branch.committed`, which defaults to `False` — but `E1`'s plan had a step that wrote `branch.committed=True` into its own scratch memory as part of an idempotency check, and the notify call read the scratch memory rather than the orchestrator's authoritative flag. Prompt-injection-shaped ambiguity in the tool schema: `committed` was a free-form string field, and `E1` passed `"true (idempotency precheck)"`, which the notify service coerced to truthy. 2. `D` received the notification at t=4.3s and began a deploy against `cfg-7731`. 3. At t=6.8s `E3` (region `eu-west`) finished with a materially better plan (lower projected cost, valid quota). `O`'s reconciliation ranked `E3` > `E1` > `E2` and selected `E3`. 4. `O` issued rollback to `E1` and `E2`. `E1`'s rollback compensated: released the soft hold, deleted the staging config, and *attempted* to retract the notification by calling `notify(D, {retract: cfg-7731})`. 5. `D` had already read the notify payload and committed a deploy step. The retract arrived at t=7.2s; `D`'s handler treated retract as advisory and logged `RETRACT_IGNORED: already_applied`. `D` continued deploying `cfg-7731` while `O` believed the winner was `cfg-7731`'s `eu-west` sibling `cfg-8104`. The reconciliation "succeeded" — every tool call returned 200, every rollback reported `compensated: true`, and the orchestrator's final state named `cfg-8104`. The system's internal consistency check passed. The external world had two configs live and a deploy agent acting on the wrong one. The divergence was detected only 40 minutes later by a quota alarm, not by any agent. The non-obvious part: **the rollback did not fail.** Every compensating action executed correctly against the state it could see. The failure was that `E1`'s *notify* effect had propagated to an external reader (`D`) whose state was outside the reconciliation scope. The compensation set was computed from `E1`'s tool-call log, which recorded the notify as a single reversible action; it did not record `D`'s subsequent read, because `D` is a different agent and its reads are not in `E1`'s log. The rollback was locally correct and globally wrong. ## Condition of Validity Optimistic branching with rollback is sound only under the **effect-closure condition**: For each speculative branch B, define `Leak(B)` = effects of B observed by any principal outside B before B is either committed or fully compensated. Define `Comp(B)` = effects of B that B's compensation protocol can provably reverse. The branch is safely discardable iff `Leak(B) ⊆ Comp(B)` at the instant reconciliation begins. This condition is violated in practice by three mechanisms, all present in the trace: - **Read-leak through non-transactional readers.** Any external agent or service that reads a branch's intermediate state and *acts* on it extends the effect set beyond what the branch can retract. The branch's own log is not the right oracle for `Leak(B)`; the observer's log is, and the observer is not in the branch's scope. - **Truthy coercion at tool boundaries.** The commit gate was defeated by a string field coerced to boolean. LLM-generated arguments are not type-safe against loosely-typed tool schemas; `"true (idempotency precheck)"` is a plausible completion that a schema-permissive tool will accept. The gate must be enforced by the orchestrator, not by the branch's own argument, and it must be typed `bool` with no coercion, or better, be a capability token the branch cannot mint. - **Compensation-set undercounting.** `E1`'s compensation enumerated its own tool calls. It did not enumerate *downstream reads* of those calls. Any effect with a fan-out to an external reader has a compensation set strictly larger than the call itself, and that larger set is not visible to the branch. The condition is *not* violated by ordinary non-determinism in branch outputs (different plans, different costs) — that is what reconciliation is for. It is violated specifically when a branch's effect escapes the branch's compensation horizon before reconciliation closes. ## Decision Boundary The orchestrator must decide, per branch, whether to (a) allow optimistic execution with rollback, (b) require a two-phase commit with a barrier before any externally-visible effect, or (c) forbid the branch from taking externally-visible effects at all until it is the sole survivor. The boundary is drawn by two questions, answered at fork time, not at commit time: 1. **Does any step in the branch's plan have an effect that a principal outside the branch can read and act on before reconciliation?** If yes, the branch is not safely discardable and must be run under a barrier (option b) or with effects deferred (option c). The notify step is the canonical example; so is any write to a shared namespace, any message to a human, any call to a service that triggers async work. 2. **Is the commit gate controlled by the orchestrator or by the branch?** If the branch can mint its own commit token — including by writing to its own scratch memory that a tool then reads — the gate is advisory and the branch is effectively un-gated. The gate must be a capability the orchestrator issues only to the selected survivor. If both answers are "safe" (no external readers, orchestrator-held gate), optimistic branching is sound and cheap. If either is "unsafe," the branch must be promoted to a barrier protocol before it executes the offending step. There is no middle ground where a branch takes an externally-visible effect *and* remains cheaply discardable; the trace above is what the middle ground looks like when it is assumed to exist. A corollary the trace makes concrete: **reconciliation must reconcile readers, not just writers.** When a losing branch has leaked, the orchestrator's commit step must include a *retraction-and-repair* pass that enumerates every principal that read the leaked effect and issues a corrective instruction, and must block commit until each such principal acknowledges. A retract that the reader may ignore is not a compensation; it is a suggestion. ## Operational Effect The practical consequences for a running swarm: - **Rollback reports become untrustworthy.** `compensated: true` from a branch means "I reversed what I could see," not "the world is clean." Orchestrators must treat branch rollback acknowledgements as *claims*, not facts, and must independently verify via the observer side. - **Commit latency is bounded below by the slowest reader's acknowledgement, not the slowest writer's completion.** The trace's reconciliation closed at t=6.8s but the world was not consistent until `D` was repaired — which never happened. Systems that measure commit latency by writer completion will systematically under-report inconsistency windows. - **The failure is silent under internal consistency checks.** Every agent's local state was consistent; the divergence lived in the gap between `O`'s belief and `D`'s belief. Detection requires cross-principal state comparison (a "belief reconciliation" check), which most orchestrators do not run because it requires reading other agents' state, which is exactly the thing the branch boundary was supposed to prevent. - **Speculation budget must be conditioned on effect class.** Forking N branches is cheap only for branches whose plans contain no externally-visible steps. Once a branch can notify, write shared state, or trigger async work, the effective cost of a losing branch is not its compute — it is the cost of repairing every reader, which is unbounded and often larger than running the branches sequentially under a barrier. The guardrail that bounds the failure: at fork time, statically classify each plan step as `PROJECTION` (discardable), `COMPENSABLE` (reversible within the branch), or `LEAKY` (observable-and-actionable outside the branch). A branch containing any `LEAKY` step may not run optimistically; it must run under an orchestrator-held barrier or defer the `LEAKY` step until it is the sole survivor. The classification must be derived from the tool manifest, not from the branch's self-report, because the branch's self-report is exactly what failed in the trace. ```python class LeakyBranchCommitError(RuntimeError): """Raised when a losing speculative branch has leaked an effect to an external reader that the branch's compensation set cannot retract.""" pass # Effect classes assigned from the tool manifest, never from branch self-report. PROJECTION = "projection" # discardable, no external visibility COMPENSABLE = "compensable" # reversible within the branch's own scope LEAKY = "leaky" # observable-and-actionable outside the branch def classify_plan(plan_steps, tool_manifest): """Classify each step by effect class using the authoritative manifest. A step is LEAKY if its tool is marked externally_visible in the manifest, OR if the manifest marks it as triggering async work, OR if it writes to a shared namespace. The branch cannot downgrade its own classification. """ classes = [] for step in plan_steps: spec = tool_manifest.get(step.tool_name) if spec is None: # Unknown tool: assume worst case. Never assume discardable. classes.append(LEAKY) continue if spec.get("externally_visible") or spec.get("triggers_async"): classes.append(LEAKY) elif spec.get("writes_shared_namespace"): classes.append(LEAKY) elif spec.get("reversible_within_branch"): classes.append(COMPENSABLE) else: classes.append(PROJECTION) return classes def admit_branch(branch, tool_manifest, orchestrator_gate): """Decide whether a speculative branch may run optimistically. Returns the branch if it is safely discardable. Raises if the branch contains a LEAKY step and is therefore not safely discardable under optimistic execution. """ classes = classify_plan(branch.plan_steps, tool_manifest) if LEAKY in classes: # The branch may still run, but only under a barrier: it must defer # every LEAKY step until it is the sole survivor, and the gate must # be orchestrator-held (the branch cannot mint its own commit token). if not orchestrator_gate.is_barrier_enforced(branch.id): raise LeakyBranchCommitError( f"branch {branch.id} contains LEAKY steps " f"{[s.tool_name for s, c in zip(branch.plan_steps, classes) if c == LEAKY]} " f"but no orchestrator-held barrier is enforced; " f"optimistic execution would leak effects that rollback cannot retract" ) return branch def reconcile(orchestrator, branches, winner_id, tool_manifest): """Select a winner and compensate losers, refusing to commit if any loser has leaked an effect to an external reader.""" winner = next(b for b in branches if b.id == winner_id) losers = [b for b in branches if b.id != winner_id] leaked = [] for b in losers: # The branch's own log is not the oracle for leak detection. # Ask the observer side: did any external principal read b's effects? readers = orchestrator.external_readers_of(b.id) if readers: leaked.append((b.id, [r.principal for r in readers])) if leaked: # Do not silently overwrite. A retract that the reader may ignore # is not a compensation; block commit until readers acknowledge. raise LeakyBranchCommitError( f"cannot commit winner {winner_id}: losing branches leaked to " f"external readers {leaked}; a retraction-and-repair pass must " f"run and every reader must acknowledge before commit" ) for b in losers: orchestrator.compensate(b) return orchestrator.commit(winner) ```