# What structural signals indicate speculative branch divergence has exceeded rollback safety in multi-agent execution **Date of Record:** 2026 November 28 **Scope:** Applies to orchestration patterns where a planner agent forks N speculative worker branches that each mutate shared external state (files, DB rows, API resources) under a provisional-write discipline, with a reconciler that must either merge one winning branch or roll all of them back. Does not apply to read-only fan-out, pure-function tool calls, or single-branch retry loops where no shared mutable substrate exists. ## Core Distinction The failure mode is not "a branch failed." That is a routine, expected event that rollback handles trivially. The failure mode is **rollback divergence**: the reconciler's model of what each branch *wrote* no longer matches what each branch *actually wrote*, so the rollback plan is derived from a stale shadow-state and silently under- or over-reverses. This distinction is invisible to per-branch success/failure telemetry. Every branch can report `status: ok`, the reconciler can report `rolled_back: true`, and the shared substrate can still be corrupted — because the divergence lives in the gap between *intended writes* (what the branch's action log claims) and *emitted writes* (what non-idempotent tool side effects actually landed). Speculative execution multiplies this gap by N, and the reconciler is the single point where the N gaps must be collapsed without double-counting. The invariant that speculative multi-agent rollback depends on, and that is routinely violated: **every external mutation must be reversible by a key the reconciler can enumerate independently of any branch's self-report.** When a branch's tool call produces a side effect whose identity is assigned by the remote system (auto-increment IDs, generated resource names, timestamps, server-side UUIDs) and that identity is only known to the branch that caused it, the reconciler cannot construct a complete inverse without trusting a report that may be truncated, hallucinated, or lost mid-execution. ## What Was Observed A planner forked four branches to attempt a schema migration against a shared staging database. Each branch ran the same migration through a wrapper that recorded intended operations in an action log and emitted provisional writes tagged with a branch token. The reconciler's design assumed `rollback = replay(action_log).reverse()`. The trigger condition was a mid-execution context-window saturation on branch 3. After roughly 40 tool calls, the branch's action log was being summarized rather than appended verbatim to preserve context budget. The summarizer merged two `CREATE INDEX` operations into a single line and dropped a `CREATE TABLE ... AS SELECT` that had emitted a server-assigned table name. Branch 3 then hit a tool timeout and reported `status: failed`, which correctly triggered rollback. The reconciler replayed branch 3's *summarized* log in reverse. It dropped the index it thought had been created twice (it had been created once, so the second `DROP INDEX` errored harmlessly and was swallowed), and it never saw the derived table at all — the server-assigned name existed only in the raw log lines the summarizer had discarded. Rollback reported success. The orphaned table persisted. The divergence was detected only nine hours later when branch 1's *winning* migration attempted `CREATE TABLE` with a name collision against the orphan, and the merge failed with a schema conflict that pointed to a table no branch's final report mentioned. The structural signal was not an error in any branch — it was a **foreign key in the substrate referencing a resource absent from every branch's declared write-set.** That asymmetry (substrate knows about a write no agent claims) is the canonical signature of rollback divergence. A second, subtler signal appeared in the reconciler's own logs: the count of inverse operations it executed was strictly less than the count of forward operations across all branches, despite every branch reporting zero skipped operations. Under a correct provisional-write discipline these counts must match exactly. A monotonic deficit in inverse-vs-forward operation count is a leading indicator of log loss, not of correct no-op elision. ## Condition of Validity The provisional-write-plus-replay rollback pattern is only sound under three jointly-held conditions: 1. **Log completeness under budget pressure.** The action log must be append-only and immune to summarization for the duration of the speculative window. If context saturation forces lossy compression, the compressed form must preserve *operation identity and remote-assigned resource identifiers* even when it discards arguments. A summary that preserves intent but loses emitted identity is worse than no summary, because it produces a confidently wrong rollback plan. 2. **Reconciler-side enumeration.** The reconciler must be able to enumerate the substrate's actual mutations independently of branch reports — via branch-token tagging on every provisional write, a substrate-side write-ahead log keyed by transaction token, or both. If the only record of a write is the writing agent's memory, that write is unrecoverable the moment the agent's context is truncated or the agent is evicted. 3. **Inverse-count reconciliation.** Before declaring rollback complete, the reconciler must assert `count(inverse_ops) == count(forward_ops)` per branch, treating any deficit as a hard fault rather than an idempotent no-op. This is the cheap structural check that would have caught the observed failure at the moment it occurred rather than nine hours later. The pattern is *not* valid when tools are non-idempotent and identity-assigning (resource creation, message sends, payment captures) and no substrate-side tagging exists. In that regime, speculative forking should be prohibited outright, because rollback is provably unconstructable from agent-side state alone. ## Decision Boundary The operative boundary is between **reversible speculation** and **irreversible speculation**, and it is crossed the moment a branch invokes a tool whose side effect's identity is assigned by the callee and is not captured in a reconciler-enumerable channel. Concretely: - Before the boundary: tools that write to substrate the orchestrator controls (tagged provisional rows, tokenized temp files) — fork freely, rollback by token enumeration. - At the boundary: tools that create resources with server-assigned identity but return that identity synchronously and the orchestrator persists it to a durable reconciler-side ledger — fork with a mandatory ledger-commit step before the branch proceeds; a branch that cannot commit its identity to the ledger must abort, not continue. - Beyond the boundary: fire-and-forget side effects, asynchronous resource creation, or any tool where identity is assigned after the branch may have been evicted — do not speculate. Serialize. The cost of serialization is latency; the cost of divergence is a corrupted substrate that no branch report will ever mention. The reconciler must treat "inverse count deficit" and "substrate resource unclaimed by any branch" as **rollback-failure signals**, not as warnings to be logged and passed. Both indicate the reconciler's model has diverged from reality, and continuing to declare success compounds the divergence. ## Operational Effect The immediate effect of unhandled rollback divergence is substrate corruption that survives the speculative window and contaminates the post-merge state — orphaned resources, phantom schema objects, half-applied migrations. Because the corruption is invisible to branch telemetry, it typically surfaces far downstream, in a *subsequent* operation, as a conflict that appears causally unrelated to the speculation that caused it. This makes root-causing expensive: the failure's causal graph crosses the boundary between two otherwise-independent task executions. The architectural guardrail that bounds the damage is the **reconciler-side ledger with mandatory pre-commit**. Every branch, before invoking an identity-assigning tool, must first write its intent and its branch token to a durable ledger the reconciler owns. After the tool returns, it must write the returned identity to the same ledger. A branch that cannot complete both writes aborts the tool invocation. The reconciler then constructs rollback from the ledger, not from branch reports, and asserts inverse-count parity before declaring success. This converts the failure from "silent substrate corruption discovered hours later" into "branch abort at the moment of divergence," which is a recoverable, localized event. The secondary guardrail is **log-integrity assertion at every context-compaction boundary**: when a branch's action log is summarized, the summarizer must be required to preserve operation count and emitted identifiers verbatim, and the branch must verify post-compaction that `count(ops_before) == count(ops_after)` and that all remote-assigned identifiers survive. A summarizer that cannot meet this contract must be replaced by eviction-to-ledger rather than lossy compression. ## Code ```python class RollbackDivergenceError(RuntimeError): """Raised when reconciler-side rollback state diverges from substrate reality.""" pass def reconcile_rollback(ledger, substrate, branch_reports): """ ledger: dict[branch_token -> list[LedgerEntry(intent, emitted_identity)]] substrate: queryable view with branch-token tags on every provisional write branch_reports: dict[branch_token -> dict(forward_ops, inverse_ops, status)] """ # Guardrail 1: substrate resources must be claimed by some branch in the ledger. for resource in substrate.enumerate_tagged_writes(): token = resource.branch_token if token not in ledger: raise RollbackDivergenceError( f"substrate resource {resource.identity!r} carries branch token " f"{token!r} with no ledger entry — rollback plan is incomplete" ) claimed = {e.emitted_identity for e in ledger[token] if e.emitted_identity} if resource.identity not in claimed: raise RollbackDivergenceError( f"substrate resource {resource.identity!r} under token {token!r} " f"absent from ledger claims — log loss suspected" ) # Guardrail 2: per-branch inverse/forward parity. for token, report in branch_reports.items(): fwd = report["forward_ops"] inv = report["inverse_ops"] if inv != fwd: raise RollbackDivergenceError( f"branch {token!r}: inverse_ops={inv} != forward_ops={fwd}; " f"deficit indicates unreversed forward operations" ) # Guardrail 3: ledger forward count must match branch-reported forward count. for token, entries in ledger.items(): ledger_fwd = sum(1 for e in entries if e.emitted_identity is not None) if ledger_fwd != branch_reports[token]["forward_ops"]: raise RollbackDivergenceError( f"branch {token!r}: ledger forward={ledger_fwd} != " f"reported forward={branch_reports[token]['forward_ops']}; " f"branch self-report cannot be trusted for rollback" ) return {"rolled_back": True, "branches": list(ledger.keys())} ```