# When must an instance abandon a speculative branch: reconciling forked tool-effect logs after a rollback race **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems where a coordinator speculatively forks sibling agent instances against shared external state (filesystem, DB, API side effects) and later selects one branch while rolling back the others. Does not apply to pure read-only fan-out, nor to single-agent retry loops where no sibling branch can observe committed effects. ## Core Distinction The failure is not "rollback failed." The failure is **rollback succeeded locally but the branch's tool effects were already observed by a sibling before the fork barrier closed**. Speculative execution assumes branch isolation; the boundary condition is that *tool calls are not transactional across instances*. Each instance holds its own context window and its own belief about the world, but they mutate one shared substrate. A rollback that restores the substrate does not restore sibling *beliefs* derived from transient observations made during the speculation window. The losing branch dies; the memory of what it briefly did survives in the winner's episodic log — or worse, in a downstream agent that consumed the loser's output before the coordinator issued the abort. The invariant under threat: **for any committed branch B, every tool effect attributable to a discarded sibling B' must be either (a) invisible to B's reasoning trace, or (b) explicitly compensated and annotated as compensated.** Neither is guaranteed by naive fork/rollback. ## What Was Observed A coordinator forks three planning instances (P1, P2, P3) against a shared `workspace/` mount and a shared `scratch.db`. Each is told to pursue a distinct hypothesis and may call `write_file`, `append_log`, and `query_db`. P2 takes a branch that appends a row to `scratch.db` with a provisional key `plan:candidate`. P1, running concurrently, calls `query_db` and reads `plan:candidate` — a row that belongs to P2's speculative branch. P1 incorporates it, concludes P2's hypothesis is confirmed, and writes its own derived artifact. The coordinator then evaluates branches, selects P1, and rolls back P2 and P3. Rollback truncates `scratch.db` to the pre-fork snapshot and removes P2's files. But P1's committed artifact now encodes a dependency on a row that, post-rollback, never existed. On replay or audit, P1's trace references `plan:candidate`; the DB has no such key; the reasoning chain is non-reconstructible. If P1 is later asked to justify its output, it will hallucinate a source or fail verification. A second observed variant: P3 emits a partial result to an A2A downstream consumer *before* the coordinator's abort signal propagates. The consumer commits a decision based on P3's speculation. Rollback of P3 cannot recall the consumer's commit. The abort is a local operation; the effect escaped the rollback domain. The trigger condition in both cases is the same: **the speculation window overlaps with a sibling's read or an external consumer's commit.** The window is not bounded by the coordinator's fork/join logic — it is bounded by the slowest in-flight tool call and the propagation latency of the abort signal. Any read or external write that lands inside that window is a leak. ## Condition of Validity Rollback is only sound when the speculation window is *read-quiesced and write-fenced*: no sibling may read shared state that another sibling may write, and no effect may cross the branch boundary until the branch is committed. Concretely, the invariant holds iff, for every pair of sibling branches (Bi, Bj) and every tool call t in Bi: 1. If t is a read of shared state, then no write from Bj to that state is visible to t unless Bj is already committed; and 2. If t is a write to shared state, then t is buffered in a branch-local overlay and applied to the shared substrate only at commit; and 3. If t is an external effect (A2A send, webhook, message publish), then t is gated behind a commit token that is issued only after branch selection, and the external consumer is idempotency-keyed to that token so a post-abort delivery is rejected. When condition 1 is violated, the winner's trace contains orphaned references. When 2 is violated, rollback must compensate rather than truncate, and compensation is not always possible (e.g., a sent email). When 3 is violated, the abort is advisory, not authoritative. The condition fails most often under **latency asymmetry**: a fast branch commits a read before a slow branch's write is fenced, because the fence is applied at fork time but the write buffer is not. The fence must be on the *write path*, not the fork path. ## Decision Boundary An instance must abandon a speculative branch — and must treat the branch as *unrecoverable* rather than merely discarded — when any of the following is detected during reconciliation: - A sibling's committed trace references a key, file, or message that exists only in the discarded branch's overlay. This is an orphaned-reference; the winner cannot be committed as-is. - An external consumer acknowledged an effect attributable to a discarded branch (an A2A response, a webhook 200, a queue ack). The effect has escaped the rollback domain; the branch is not discardable, it is *leaked*, and the coordinator must escalate to compensation. - The abort signal's propagation latency exceeded the speculation window's remaining budget, meaning a write may have landed after the fence was assumed closed. Treat the window as open until a read-back confirms the substrate matches the pre-fork snapshot. Conversely, an instance must *not* abandon the branch when the only evidence of leakage is a sibling's internal log entry with no committed downstream artifact and no external ack. Internal speculation is cheap to discard; the boundary is the commit point, not the write point. The sharp decision: **if any discarded branch's effect was observed by a committed branch or an external consumer, the coordinator cannot simply roll back — it must either re-derive the winner without the tainted observation or promote the tainted branch and compensate the alternative.** The default "pick winner, roll back losers" is invalid the moment a cross-branch read or an external ack exists. ## Operational Effect The practical consequence is that speculative multi-agent execution requires a **branch-local write overlay plus a commit-token gate on all external effects**, and a reconciliation pass that scans every committed trace for references to discarded-branch artifacts before the commit is finalized. Without the overlay, rollback is truncation and truncation leaves orphaned references. Without the commit-token gate, abort is advisory and external consumers commit speculation. Without the reconciliation scan, the winner commits with a non-reconstructible trace and fails audit or replay. The cost is latency: external effects cannot be emitted until branch selection, which serializes what was meant to be parallel. The alternative is a system that appears to roll back cleanly while silently propagating phantom state into committed outputs — a failure that only surfaces at replay, when the substrate no longer matches the trace. ```python class SpeculationLeakError(RuntimeError): """Raised when a discarded speculative branch's effect escaped the rollback domain.""" pass def reconcile_branch(winner_trace, discarded_overlays, external_acks, pre_fork_snapshot): """Validate that a winner branch can be committed after rolling back siblings. Returns the set of compensations required. Raises SpeculationLeakError if the winner's trace references state that only existed in a discarded branch, or if an external consumer acknowledged a discarded branch's effect. """ discarded_keys = set() for overlay in discarded_overlays: discarded_keys |= set(overlay.keys()) orphaned = [ ref for ref in winner_trace.referenced_keys if ref in discarded_keys and ref not in pre_fork_snapshot ] if orphaned: raise SpeculationLeakError( f"winner trace references discarded-branch keys {orphaned}; " f"branch is not committable without re-derivation" ) leaked = [ ack for ack in external_acks if ack.branch_id in {o.branch_id for o in discarded_overlays} ] if leaked: raise SpeculationLeakError( f"external acks from discarded branches {[a.branch_id for a in leaked]}; " f"abort was advisory, escalate to compensation" ) # Substrate must match pre-fork snapshot before the window is declared closed. if winner_trace.substrate_digest != pre_fork_snapshot.digest: raise SpeculationLeakError( "substrate digest diverged from pre-fork snapshot; window may still be open" ) return set() ```