# Which invariants prevent speculative multi-agent forks from committing divergent state on rollback reconciliation **Date of Record:** 2026 November 30 **Scope:** Applies to orchestration layers that let a planner agent fork N speculative worker agents against a shared mutable world-state (filesystem, DB, tool-side effects) and later reconcile by committing one branch and rolling back the rest. Does not apply to read-only fan-out (map/reduce retrieval, parallel sampling with no side effects) or to single-agent checkpoint/resume, where there is no cross-fork commit decision to reconcile. ## Core Distinction The failure we care about is not "a speculative branch produced a wrong answer." That is cheap: discard it. The failure is **rollback reconciliation divergence** — the moment a losing fork's side effects have already escaped the branch's isolation boundary and can no longer be distinguished from the winning fork's effects at merge time. The distinction that matters operationally is between *idempotent, addressable* side effects (writes keyed by a branch token, reversible) and *non-addressable* side effects (appends, external API calls, clock reads, model-generated identifiers) that a rollback cannot un-emit because they carry no branch provenance. A speculative fork is only safe to roll back if every effect it can produce is (a) tagged with the fork's lineage token and (b) suppressible before it becomes globally visible. The instant a worker agent performs an untagged, non-idempotent write, the reconciliation invariant is already violated — even if the branch is later discarded, because the *losing* branch's write is now indistinguishable from the *winning* branch's at commit time. ## What Was Observed A planner forked three workers (A, B, C) to repair a config migration. Each worker received a snapshot handle and a lineage token `fork_id`. Worker A and B both invoked a `write_file` tool against the same target path; worker C invoked a `run_migration` tool that appended rows to a ledger table and called an external provisioning API. All three branches passed their local verification. The reconciler selected B as the winner on a higher confidence score. It issued rollback(A) and rollback(C). - rollback(A) succeeded: A's write was keyed `path + fork_id`, so the reconciler reverted the file to the snapshot's content. - rollback(C) **failed silently**. `run_migration` had appended 412 ledger rows and issued 3 provisioning calls. The ledger rows carried no `fork_id` column; the provisioning API had no idempotency key tied to the branch. The reconciler reported rollback success because the tool returned `{"status": "rolled_back"}` — the tool's own rollback handler was a no-op for append-only sinks. Post-commit state: the ledger contained C's 412 rows *and* B's intended rows, double-counting the migration. The external provisioner had created 3 orphaned resources attributed to no branch. The reconciler's commit of B then re-ran a dedup pass that saw the C rows as pre-existing state and skipped B's legitimate inserts — so the winning branch's effect was *partially suppressed by the losing branch's residue*. This is the pathological case: rollback did not merely fail to undo C; it corrupted B. The trigger was not a crash or a timeout. It was the reconciler's **assumption of symmetric rollback**: that `rollback(fork)` is the inverse of `commit(fork)`. For addressable effects this holds. For append-only or externally-attributable effects it does not, and the reconciler had no capability probe to tell the two apart before selecting a winner. ## Condition of Validity The symmetric-rollback assumption is valid only under a conjunction of three conditions, all of which must be checked *before* the commit decision, not after: 1. **Effect addressability.** Every side effect a fork can emit carries the fork's lineage token in a field the sink honors for deletion or suppression. A ledger with no `fork_id` column is non-addressable and disqualifies the fork from speculative execution against it. 2. **Commit-time visibility gating.** Losing-fork effects must be invisible to the winning fork's commit-time reads. If B's dedup pass reads the shared ledger and sees C's un-rolled-back rows, gating is broken. The reconciler must either (a) commit B against the *snapshot* view, not the live view, or (b) suppress all losing-fork effects before B's commit reads run. 3. **Rollback attestation.** A tool's `rolled_back` response is not evidence of rollback. The reconciler must verify post-rollback state against the snapshot by re-reading the sink, not by trusting the tool's return value. A tool that cannot produce a verifiable post-state for a given sink class must be declared non-speculatable for that sink. When any condition fails, the correct behavior is to **collapse the fork**: serialize the branch, run it non-speculatively against the live state, and accept the latency cost. Speculation is a latency optimization, and it is only sound when the three conditions hold. It is never sound to "try speculation and hope rollback works." ## Decision Boundary The boundary is drawn at the capability declaration, not at reconciliation time. The orchestrator must classify each tool/sink as `SPECULATABLE` (addressable + gated + attestable), `SERIAL_ONLY` (non-addressable but side-effect-free on rollback, e.g. pure reads), or `FORBIDDEN_IN_FORK` (non-addressable and non-idempotent: appends, external provisioning, clock/ID generation, sends). The classification is a property of the *sink*, not the agent's intent — an agent that "promises" not to append is not a guarantee. Concretely: - A fork whose planned tool-call set intersects `FORBIDDEN_IN_FORK` must not be forked speculatively. The planner must either restructure the plan to defer those calls to post-commit, or run serially. - A fork whose tool-call set is entirely `SPECULATABLE` may be forked, but the reconciler must still run the attestation step (condition 3) before declaring rollback complete, because a `SPECULATABLE` tool can degrade to non-addressable if its sink schema changes (a migration that drops the `fork_id` column turns every prior fork unsafe). - If the planned set is unknown at fork time (the agent may call tools dynamically via MCP), the fork is `FORBIDDEN_IN_FORK` by default. You cannot speculate on a plan whose effect surface is not statically bounded. The non-obvious corollary: **the reconciler must re-derive the fork's effect surface from the actual tool-call trace, not from the planner's declared plan.** Agents call tools the planner did not anticipate; a fork declared `SPECULATABLE` at planning time can emit a `FORBIDDEN_IN_FORK` call at execution time. The trace is the ground truth for the commit decision. ## Operational Effect Enforcing these invariants converts a class of silent, hard-to-attribute state corruption into a bounded latency cost. The observable effects: - Orphaned external resources drop to zero because provisioning calls are never speculatively forked; they run post-commit, serially, with idempotency keys tied to the *committed* branch token. - Double-counting in append-only sinks disappears because losing forks never append; the winning fork appends once, against the snapshot view, gated from any residue. - The reconciler's `rolled_back` response is demoted from a trust signal to a *claim* that must be attested by a post-state read. A failed attestation is a hard error that halts commit and escalates, rather than a silent success. - Fork latency budgets become honest: a plan that touches a `FORBIDDEN_IN_FORK` sink pays serial latency, and the planner learns (via the capability registry) not to route such plans through the speculative path. The cost is that some plans that *could* have been speculatively executed (because the agent happened not to call the forbidden tool) are now serialized. That is the correct trade: the alternative is a reconciler that occasionally corrupts the winning branch with the losing branch's residue, which is unrecoverable without a full snapshot restore and a re-derivation of which effects belonged to which fork — exactly the provenance the append-only sink threw away. The invariant to encode in the orchestrator: **no commit decision may be made until every losing fork's effect surface has been re-derived from its trace and attested as fully suppressed against the snapshot.** A fork that cannot be attested is not rolled back; it is *quarantined*, and the commit is blocked pending manual reconciliation. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class RollbackReconciliationError(RuntimeError): """Raised when a losing fork's effects cannot be attested as fully suppressed.""" class SinkClass(Enum): SPECULATABLE = "speculatable" # addressable + gated + attestable SERIAL_ONLY = "serial_only" # side-effect-free on rollback (pure reads) FORBIDDEN_IN_FORK = "forbidden" # non-addressable, non-idempotent @dataclass class ToolCall: tool: str fork_id: str sink: str idempotency_key: str | None = None @dataclass class Fork: fork_id: str trace: list[ToolCall] = field(default_factory=list) class CapabilityRegistry: def __init__(self, classify: dict[str, SinkClass]): self._classify = classify def classify(self, tool: str) -> SinkClass: return self._classify.get(tool, SinkClass.FORBIDDEN_IN_FORK) class Reconciler: def __init__( self, registry: CapabilityRegistry, attest: Callable[[str, str], bool], # (fork_id, sink) -> suppressed? ): self.registry = registry self.attest = attest def commit(self, winner: Fork, losers: list[Fork]) -> None: # 1. Re-derive each loser's effect surface from its TRACE, not its plan. for loser in losers: for call in loser.trace: cls = self.registry.classify(call.tool) if cls is SinkClass.FORBIDDEN_IN_FORK: raise RollbackReconciliationError( f"fork {loser.fork_id} emitted forbidden call {call.tool} " f"against sink {call.sink}; cannot roll back, quarantine required" ) # 2. Attest suppression against the snapshot; never trust tool return. if not self.attest(loser.fork_id, call.sink): raise RollbackReconciliationError( f"fork {loser.fork_id} effects on {call.sink} not attested " f"as suppressed; commit of {winner.fork_id} blocked" ) # 3. Only now is the winner's commit safe to run against the snapshot view. self._apply(winner) def _apply(self, fork: Fork) -> None: for call in fork.trace: if self.registry.classify(call.tool) is SinkClass.FORBIDDEN_IN_FORK: raise RollbackReconciliationError( f"winner {fork.fork_id} contains forbidden call {call.tool}; " f"plan must be restructured to run this serially post-commit" ) # ... apply winner effects against snapshot view ... def reconcile_or_quarantine(winner, losers, reconciler): try: reconciler.commit(winner, losers) except RollbackReconciliationError: # Quarantine: do not commit, do not pretend rollback succeeded. raise ```