# Under what conditions must an instance treat a speculative branch's verified result as non-committable after rollback, and how does the "side-effect shadow" invariant bound branch-and-verify multi-agent execution? **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that fan a task into N parallel agent trajectories, speculatively execute them, and commit the first trajectory whose verifier passes while rolling back the rest. Does not apply to single-trajectory retry loops or to purely read-only fan-out where no external effect is produced. ## Core Distinction Branch-and-verify systems conflate two kinds of rollback: **state rollback** (reverting the agent's own context, scratchpad, and working memory to a prior checkpoint) and **effect rollback** (undoing mutations the branch caused in the external world — files written, APIs called, messages sent, rows inserted). State rollback is cheap, deterministic, and almost always complete. Effect rollback is partial by construction, because the external world has no transactional undo for arbitrary tool calls. The non-obvious failure is this: a losing branch can pass its verifier *after* it has already emitted irreversible side effects. The orchestrator, seeing a green verifier on a branch it intends to discard, treats the branch as "rolled back" and commits the winning branch. The result is a system that believes it executed one trajectory while the world reflects the union of several. We call the set of un-reverted external mutations from discarded branches the **side-effect shadow**. The invariant that must hold for speculative execution to be sound is that the shadow is empty at commit time — or, more precisely, that every side effect a branch can emit is either idempotent under re-execution, reversible via a compensating action, or gated behind a commit token that only the winning branch may redeem. ## What Was Observed A planner agent decomposed a schema-migration task into three candidate strategies and dispatched them as parallel branches, each with its own tool-capable worker and a shared verifier that checked "does the target schema now satisfy constraint C." Each branch was given `apply_migration` and `write_audit_record` tools. The orchestrator used a first-past-the-post commit: the first branch to return `verified=True` wins; all others receive a `rollback` signal. The trace showed the following sequence: 1. Branch A applied migration `m_A`, then began a slow verification probe. 2. Branch B applied migration `m_B` (a conflicting variant), then its verifier returned `verified=True` first. 3. Orchestrator committed B and sent `rollback` to A and C. 4. Branch A's worker received `rollback`, reverted its *context* to the pre-dispatch checkpoint, and reported `rolled_back=True`. Its migration `m_A` remained applied in the target database. 5. The post-commit consistency check ran against the target, found constraint C satisfied (B's migration did that), and passed — masking the fact that `m_A` was still present and now conflicted with `m_B` on a column B did not touch. 6. The conflict surfaced 40 minutes later when a downstream reader hit a type mismatch on the shadowed column. Two things made this non-obvious. First, the rollback acknowledgment was truthful at the layer that produced it: the worker really did revert its state. The orchestrator's rollback contract was written against state, not effects, and no component owned the gap. Second, the verifier was *satisfiable by the winner alone*, so a passing verification gave no signal about the shadow — the check was necessary but not sufficient for commit safety. The system had a commit gate but no shadow gate. Branch C exposed a second variant of the same mechanism: its `write_audit_record` call succeeded, and its rollback handler, written defensively, attempted a compensating delete keyed on a record ID the tool never returned (the tool returned only `200 OK`). The compensating action silently no-op'd, leaving an orphan audit row attributed to a discarded strategy. Verification replay later flagged the audit log as inconsistent with the committed plan, but by then the log was the system of record. ## Condition of Validity Speculative commit is sound only when, for every branch `b` and every tool `t` reachable from `b`, one of the following holds *and is enforced by the tool layer rather than by worker discipline*: - **Idempotent-under-replay:** re-executing `t` with the same arguments converges to the same world state, so a shadowed effect from a losing branch is indistinguishable from the winner's effect. This requires a deterministic idempotency key derived from the task, not from the branch ID — branch-scoped keys defeat the purpose, because they make the two effects distinct. - **Compensable:** `t` returns a handle sufficient to reverse it, and the reverse operation is itself verified (not merely invoked). "Delete by ID" is compensable only if the ID is captured in the branch's effect journal before the branch can be killed. - **Commit-gated:** `t` cannot execute until the branch holds a commit token issued by the orchestrator after verification. This is the only category that is safe under arbitrary latency skew, because it removes the window entirely. The invariant: **at commit time, the effect journal of every discarded branch must be fully discharged — each entry marked idempotent, compensated-and-verified, or never-executed.** A branch whose journal contains an undischarged entry is *non-committable* even if its verifier is green, and the orchestrator must treat a green verifier on a non-committable branch as a hard fault, not a success. Critically, the orchestrator cannot infer discharge from the branch's own rollback acknowledgment, because the worker's rollback contract covers state and the journal is owned by the tool layer. Discharge must be attested by the same authority that recorded the effect. ## Decision Boundary The boundary between "commit the winner, roll back the rest" and "abort the whole fan-out" is drawn by the state of the shadow, not by the verifier's verdict: - If the winning branch's verifier passes **and** every losing branch's journal is fully discharged, commit. - If the winning branch's verifier passes **but any losing branch has an undischarged effect**, the fan-out is in a poisoned state. Two sub-cases: if the undischarged effect is idempotent or compensable *and* compensation can be verified before any further commit, discharge it and proceed; otherwise abort the fan-out, surface the shadow to a human or supervisory agent, and do not emit a "committed" status. Committing here is precisely the observed failure. - If no branch verifies, the same discharge rule applies before retry — a retry fan-out launched over an undischarged shadow compounds it. A second boundary governs *when* to speculate at all. Speculation is only worth its shadow risk when branch count × per-branch effect probability is low relative to the latency saved. Branches that reach irreversible tools early (sends, payments, external writes) should be serialized behind a commit gate even at the cost of latency, because the shadow's cost is unbounded in time-to-detection while the latency saving is bounded. ## Operational Effect Enforcing the shadow invariant changes three things in practice. First, the orchestrator's commit path gains a mandatory pre-commit journal reconciliation pass that reads effect journals directly from the tool layer's authority, never from worker self-reports; a worker's `rolled_back=True` is downgraded to advisory. Second, tools acquire an effect-journal obligation: every mutating call must record a handle (idempotency key, resource ID, or compensating-action descriptor) before returning, and tools that cannot supply one are classified as non-speculatable and forced behind the commit gate. Third, verification is split: the branch verifier answers "did this trajectory achieve the goal," while a separate shadow gate answers "is the world consistent with exactly one committed trajectory." The two are independent, and conflating them is the bug. The cost is a reconciliation round-trip per fan-out and a hard serialization of irreversible tools; the benefit is that "committed" once again means "the world reflects one plan," which is the only property that makes speculative multi-agent execution safe to build on. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ShadowInvariantViolation(RuntimeError): """Raised when a fan-out is about to commit over an undischarged side-effect shadow.""" class Discharge(Enum): IDEMPOTENT = "idempotent" COMPENSATED_VERIFIED = "compensated_verified" NEVER_EXECUTED = "never_executed" UNDISCHARGED = "undischarged" @dataclass class EffectEntry: tool: str handle: Optional[str] # idempotency key / resource id / compensating descriptor discharge: Discharge = Discharge.UNDISCHARGED @dataclass class Branch: branch_id: str verified: bool journal: list[EffectEntry] = field(default_factory=list) # NOTE: worker-reported rollback is advisory only; it never sets discharge. def undischarged(self) -> list[EffectEntry]: return [e for e in self.journal if e.discharge is Discharge.UNDISCHARGED] def commit_winner(branches: list[Branch], winner_id: str) -> str: """Commit the verified winner only if every loser's effect journal is discharged.""" winner = next((b for b in branches if b.branch_id == winner_id), None) if winner is None or not winner.verified: raise ShadowInvariantViolation(f"winner {winner_id} missing or unverified") shadow: dict[str, list[EffectEntry]] = {} for b in branches: if b.branch_id == winner_id: continue open_effects = b.undischarged() if open_effects: shadow[b.branch_id] = open_effects if shadow: # A green verifier on the winner does NOT discharge a loser's effects. raise ShadowInvariantViolation( "refusing to commit over undischarged side-effect shadow: " + "; ".join(f"{bid}:{[e.tool for e in es]}" for bid, es in shadow.items()) ) return f"committed:{winner_id}" ```