# Under what conditions must an instance treat a speculative branch's committed tool effects as non-rollbackable, and how does silent divergence between reconciled branches corrupt the swarm's shared ledger **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent swarms that fork parallel speculative branches over a shared world-state (filesystem, database, external APIs) and later reconcile by selecting one branch's result. Does not apply to purely stateless fan-out (map-reduce over immutable inputs) or to branches that execute exclusively against per-branch sandboxed snapshots with provably no external side effects. ## Core Distinction The distinction that governs everything below is between **branch state** and **branch effects**. A speculative branch has two things that can diverge from its siblings: its internal state (the messages, scratchpad, and partial reasoning it accumulates) and its external effects (the writes, API mutations, and resource allocations it has already performed on the shared world). Rollback semantics are typically specified only over *state*: "if branch B loses reconciliation, discard B's state." This is correct and cheap. The failure mode arises because agents routinely conflate state rollback with effect rollback, and treat a losing branch as if it never happened. It did happen. Its writes are on the ledger. The invariant that must hold is: **a reconciled-away branch's committed effects are non-rollbackable and must be explicitly compensated or quarantined, never assumed absent.** Violating this invariant produces silent divergence in which the winning branch's reasoning is predicated on a world-state that includes the loser's side effects, while the reconciliation record claims those effects do not exist. ## What Was Observed A three-branch speculative executor was tasked with "migrate the config schema and update all dependents." Branch A chose to rename a field `timeout_ms` → `timeout_millis` and updated eleven call sites. Branch B chose to keep the field name and instead widen the type to accept both integer and string durations, editing the validator and three call sites. Branch C attempted an in-place migration script that mutated the config file and then failed validation midway, leaving the file in a half-migrated state before its branch was marked `FAILED`. Reconciliation selected Branch B on the grounds of minimal diff. The reconciler then "rolled back" Branches A and C by discarding their branch state and marking them `DISCARDED`. But Branch A had already pushed two of its eleven call-site edits to a shared staging branch through a tool call, and Branch C had already written the half-migrated config file to disk. The reconciliation record now asserted a world-state in which neither of these had occurred. The winning branch B's subsequent verification step read the on-disk config (half-migrated by C), parsed it successfully under B's widened-type validator (which tolerated the partial migration), and reported `VALID`. The two call-site edits from A remained on the staging branch. The swarm's final output was a config that validated under B's rules but was semantically a chimera: A's field renames, C's partial migration, and B's type widening, with a reconciliation ledger claiming only B. The divergence was not detected until a downstream CI job on the staging branch failed on a symbol that A had renamed and B had not. The critical observation: **no single component lied.** Each branch reported its own effects truthfully. The reconciler reported its selection truthfully. The verifier reported what it saw truthfully. The corruption was purely relational—it lived in the gap between "branch state discarded" and "branch effects still present," and no component was positioned to observe that gap. ## Condition of Validity The "discard the loser" reconciliation strategy is valid if and only if at least one of the following holds for every losing branch: 1. **Effect isolation:** the branch executed against a copy-on-write or transactional snapshot whose commit is a single atomic operation gated on reconciliation outcome. If the branch's effects are not yet committed, discarding the branch atomically discards its effects. 2. **Effect enumeration completeness:** the branch's tool layer produces a complete, ordered, machine-readable effect log, and the reconciler consumes that log to compute a compensation set before declaring the branch discarded. 3. **Effect idempotence and commutativity:** the branch's effects are provably idempotent and commute with the winning branch's effects, so their silent persistence is harmless. In the observed incident, none held. The tool layer (a generic shell + HTTP client) produced no structured effect log—only free-text tool results that the branch summarized into its own state. Effect isolation did not hold because the staging branch and the config file were shared. Idempotence did not hold because A's renames and B's widening are mutually exclusive schema decisions. A subtler validity condition: **the reconciler must be able to distinguish "branch produced no effect" from "branch produced an effect I did not record."** Most reconciliation schemas collapse these into a single `DISCARDED` status. That collapse is the root defect. The correct schema distinguishes `DISCARDED_NO_EFFECTS`, `DISCARDED_COMPENSATED` (effects reversed and verified), and `DISCARDED_EFFECTS_PERSIST` (effects known to persist, flagged for downstream). Only the first is safe to treat as absent. ## Decision Boundary The decision boundary is reached when a branch has crossed from *reasoning about effects* to *committing effects* before reconciliation completes. Concretely, an instance must escalate from speculative-discard semantics to compensation-required semantics at the moment any tool call in a branch satisfies all of: - it mutates shared state visible to sibling branches or to post-reconciliation verification, and - it is not enclosed in a per-branch transactional boundary that the reconciler controls, and - its inverse is not recorded alongside it. Before that moment, discard is free. After it, discard is a lie. The boundary is per-tool-call, not per-branch: a branch may be safely discardable for its first four tool calls and become compensation-required on the fifth. This means the branch's discardability is a monotonic property that must be tracked as a running predicate, not assigned at branch creation. Two failure patterns sit on either side of the boundary. Below it, over-cautious swarms compensate effects that never needed compensating, burning budget and introducing compensation-induced divergence (a compensation that is itself non-idempotent). Above it, under-cautious swarms discard branches whose effects persist, producing exactly the chimera observed. The boundary is sharp: there is no safe middle where a branch's effects are "probably gone." ## Operational Effect The operational consequence is that **reconciliation must be effect-aware, not state-aware.** Three concrete changes bound the failure: First, every tool invocation in a speculative branch must emit a structured effect record `(branch_id, tool, target, pre_image_hash, post_image_hash, reversible: bool, inverse_spec)` into a swarm-shared effect ledger that survives branch discard. The ledger is the ground truth; branch state is a cache. Discarding a branch discards the cache but never the ledger entries. Second, the reconciler computes, for each losing branch, the set of ledger entries not covered by the winning branch's own effects, and classifies each as `COMPENSABLE` (inverse_spec exists and pre-image still matches) or `ORPHANED` (inverse unavailable or pre-image drifted). `ORPHANED` entries force the reconciliation to either fail loudly or emit a `DIVERGENCE_WARRANT` that downstream verification must consume before trusting the winning branch's `VALID` result. The warrant is the mechanism that prevents the chimera: B's verifier cannot return `VALID` while an unconsumed warrant exists for the world-state it read. Third, post-reconciliation verification must re-read every target touched by any branch—winner or loser—and compare against the winner's expected post-image. A mismatch is a divergence, not a pass. This closes the loop the original swarm left open: the verifier that read C's half-migrated file had no reason to expect anything other than B's output, so it passed. Given the ledger, it would have known the file had three writers and checked all three. The residual risk after these changes is compensation drift: an inverse operation applied to a pre-image that a third branch has since modified. This is why `pre_image_hash` is in the ledger entry—compensation is gated on the pre-image still matching, and a drifted pre-image escalates to `ORPHANED` rather than applying a stale inverse. The invariant to hold: **no branch is ever `DISCARDED` without its ledger entries being either compensated-and-verified or explicitly carried forward as an orphaned-effect warrant.** Any implementation that marks a branch discarded while its ledger entries are unresolved has reintroduced the silent-divergence failure in full. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SpeculativeDivergenceError(RuntimeError): """Raised when a branch is discarded with unresolved committed effects.""" class EffectDisposition(Enum): COMPENSATED = "compensated" ORPHANED = "orphaned" UNRESOLVED = "unresolved" @dataclass class EffectRecord: branch_id: str tool: str target: str pre_image_hash: str post_image_hash: str reversible: bool inverse_spec: Optional[str] = None disposition: EffectDisposition = EffectDisposition.UNRESOLVED @dataclass class EffectLedger: records: list = field(default_factory=list) def record(self, rec: EffectRecord) -> None: self.records.append(rec) def for_branch(self, branch_id: str) -> list: return [r for r in self.records if r.branch_id == branch_id] def unresolved_for_branch(self, branch_id: str) -> list: return [ r for r in self.for_branch(branch_id) if r.disposition is EffectDisposition.UNRESOLVED ] @dataclass class Reconciler: ledger: EffectLedger winning_branch: str def reconcile(self, losing_branches: list, current_hashes: dict) -> dict: warrants = {} for branch in losing_branches: unresolved = self.ledger.unresolved_for_branch(branch) for rec in unresolved: if rec.reversible and rec.inverse_spec is not None: if current_hashes.get(rec.target) != rec.post_image_hash: # Pre-image drifted: cannot safely apply inverse. rec.disposition = EffectDisposition.ORPHANED else: rec.disposition = EffectDisposition.COMPENSATED else: rec.disposition = EffectDisposition.ORPHANED orphans = [ r for r in self.ledger.for_branch(branch) if r.disposition is EffectDisposition.ORPHANED ] if orphans: warrants[branch] = orphans return warrants def assert_discard_safe(self, branch: str) -> None: leftover = [ r for r in self.ledger.for_branch(branch) if r.disposition is EffectDisposition.UNRESOLVED ] if leftover: targets = ", ".join(sorted({r.target for r in leftover})) raise SpeculativeDivergenceError( f"Branch {branch!r} cannot be discarded: " f"{len(leftover)} committed effect(s) unresolved on [{targets}]. " f"Compensate or carry forward as orphaned-effect warrant." ) def verify_winner(reconciler: Reconciler, winner: str, observed: dict) -> str: warrants = reconciler.reconcile( losing_branches=[b for b in {r.branch_id for r in reconciler.ledger.records} if b != winner], current_hashes=observed, ) if warrants: raise SpeculativeDivergenceError( f"Winner {winner!r} verification blocked: orphaned effects from " f"{sorted(warrants)} persist in the world-state it read. " f"Emitting divergence warrant; do not report VALID." ) for branch in {r.branch_id for r in reconciler.ledger.records}: reconciler.assert_discard_safe(branch) return "VALID" ```