# What happens when an instance speculatively forks parallel subtasks and the rollback of a losing branch corrupts a shared effect buffer **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that launch speculative parallel agent subtasks (same goal, divergent strategies) over a shared mutable effect buffer or external side-effect channel, and must reconcile to a single winning branch via rollback. Does not apply to pure-read speculative fan-out with no durable side effects, nor to single-branch sequential execution. ## Core Distinction There are two structurally different meanings of "rollback" in a multi-agent system, and conflating them is the root of this failure class: - **State rollback** — discarding an agent's private working memory, scratchpad, and intermediate reasoning. This is cheap, local, and total: if the branch's context is dropped, its reasoning is gone. - **Effect rollback** — undoing durable, externally observable actions the branch already committed (API calls, file writes, database mutations, messages sent to peers, reservations held). This is expensive, partial, and frequently *irreversible*. Speculative execution assumes these two are coupled: that killing a branch's state also neutralizes its effects. They are not coupled. A losing branch can be fully garbage-collected at the state layer while its effects remain live in the shared buffer. The invariant that must hold is stronger than "discard losing branch state": **no effect produced by a losing branch may survive reconciliation into the committed world, and no effect produced by the winning branch may be lost or duplicated by the rollback of its siblings.** This article is about the narrow, non-obvious way that invariant breaks: *effect-buffer aliasing during concurrent speculative writes.* ## What Was Observed An orchestrator spawns three speculative branches (A, B, C) for a subtask "provision resource and record it." Each branch runs the same tool-calling plan with different strategies. All three write to a shared `effect_buffer` keyed by logical effect ID, e.g. `provision:resource-7`. The orchestrator intends: let all branches race, pick the first that reaches a verified terminal state, roll back the others. The failure trace, in order: 1. Branch A reaches its terminal state first and is selected as winner. The orchestrator begins reconciliation: it snapshots `effect_buffer` and marks branches B and C as `ROLLBACK_PENDING`. 2. Branch B, mid-flight, has already emitted a `provision:resource-7` effect but has *not yet* returned its terminal status. Because B is still executing, the orchestrator's rollback loop cannot cancel it synchronously — it can only set a flag B is supposed to poll. 3. B does not poll the flag before its next tool call (its reasoning loop is between steps). B emits a *second*, idempotency-key-less `provision:resource-7` write with a different payload (different region tag, chosen by B's strategy). The effect buffer now holds two entries under the same logical key. 4. Reconciliation commits the winner's snapshot. The snapshot was taken at step 1, *before* B's second write. So the commit is correct — but the live buffer still contains B's late write, which the snapshot never saw. 5. A downstream consumer reads the *live* buffer, not the committed snapshot. It observes B's payload under `provision:resource-7` and treats it as the authoritative effect. The system has "rolled back" B at the state layer and simultaneously *promoted* B's effect at the effect layer. The observable symptom is not a crash. It is a silent divergence: the winning branch's identity is logged as the author of an effect it did not produce, and the losing branch's strategy leaks into the committed world. This is a *reconciliation replay discrepancy* — the committed snapshot and the live effect channel disagree, and the disagreement is invisible to any check that only compares branch terminal states. A second, symmetric variant occurs when the losing branch's late write *overwrites* rather than appends: if the buffer is a last-writer-wins map keyed by logical ID, B's late write clobbers A's committed value. Here rollback doesn't just leak — it corrupts the winner. ## Condition of Validity The failure requires all of the following to co-occur. Remove any one and the mechanism does not fire: 1. **Speculative concurrency with shared effect namespace.** Two or more branches can emit effects under the same logical key (or into the same mutable buffer region) while both are live. 2. **Asynchronous, non-preemptive cancellation.** The orchestrator cannot synchronously halt a branch mid-tool-call; it can only signal intent (`ROLLBACK_PENDING`) that the branch observes at its next scheduling boundary. 3. **A scheduling gap between the rollback signal and the branch's next observation point.** If the branch checks the flag before every effect emission, the late write cannot occur. The gap is the bug surface. 4. **Snapshot-then-commit reconciliation.** The orchestrator commits a point-in-time snapshot of the buffer rather than a serialized, quiesced state. Any write after snapshot time is invisible to the commit but visible to live readers. 5. **A live reader of the buffer distinct from the commit consumer.** If every reader reads the committed snapshot, the late write is harmless garbage. The failure requires a reader that reads the live channel. The invariant that bounds this failure is **effect linearizability at reconciliation**: for every logical effect key, the sequence of committed effects must be a linearization of the branches' effect emissions, with all losing-branch emissions ordered strictly before the winner's commit and discarded, and no losing-branch emission ordered after. This is only achievable if the orchestrator enforces one of: (a) effect emission is gated by a per-key lease held by exactly one branch at a time, (b) all effects carry branch provenance and an idempotency key so late writes are detectable and rejectable at commit, or (c) reconciliation quiesces all branches (drains their in-flight tool calls to completion or cancellation-acknowledged) before snapshotting. ## Decision Boundary The orchestrator must decide, per speculative fan-out, whether to pay for quiescence or for provenance. The boundary: - **Choose quiesce-before-snapshot** when effects are few, high-latency, and non-idempotent (provisioning, payments, outbound messages). The cost is latency: you wait for every losing branch to acknowledge cancellation, which can be unbounded if a branch is stuck in a long tool call. Bound it with a hard drain deadline; if the deadline expires, the fan-out must fail closed, not commit. - **Choose provenance-tagged effects with commit-time filtering** when effects are numerous and idempotent (cache writes, index updates, telemetry). Every effect carries `(branch_id, idempotency_key, causal_parent)`. At commit, the reconciler replays the effect log, drops any effect whose `branch_id` is not the winner, and deduplicates by idempotency key. This tolerates late writes because they are filtered, not prevented. The cost is that the effect log must be durable and totally ordered — you cannot filter what you did not record. - **Never choose "snapshot the buffer and hope"** — that is the failing configuration. It is only safe if condition 5 above is false, i.e., no live reader exists, which is almost never true in a system with downstream consumers. The decision is not "speculate or not." Speculation is fine. The decision is **which of quiescence or provenance you are paying for**, and the failure mode is the unstated assumption that you are paying for neither. ## Operational Effect When this boundary is crossed, the effects are: - **Silent winner misattribution.** Audit logs attribute losing-branch effects to the winning branch. Post-hoc debugging reconstructs a causal history that never happened, because the branch that "did it" was already garbage-collected. - **Non-deterministic reconciliation.** The same fan-out, replayed, may commit different effects depending on which branch's late write lands after the snapshot. This breaks replay-based verification entirely: you cannot verify a run by re-running it. - **Idempotency-key collisions across branches.** If branches share a logical key but generate distinct idempotency keys, downstream dedup fails and you get duplicate provisioning. If they share keys, late writes silently overwrite. Both are wrong; the fix is per-branch key namespacing plus commit-time filtering. - **Rollback that increases blast radius.** The act of rolling back a losing branch can *promote* its effects if the rollback path writes to the buffer (e.g., a "compensating" tombstone that itself races). Rollback must be a read-side filter, never a write. The guardrail is structural: **effects are append-only and provenance-tagged; reconciliation is a deterministic filter over the effect log keyed by winner identity; live readers read the filtered view, never the raw buffer.** Under this structure, a late write from a losing branch is recorded, filtered out, and provably excluded from the committed world — and the exclusion is verifiable by replaying the log. ```python from dataclasses import dataclass, field from typing import Optional class SpeculativeReconciliationError(RuntimeError): """Raised when a losing branch's effect survives reconciliation into the committed view.""" pass @dataclass class Effect: branch_id: str logical_key: str idempotency_key: str payload: dict seq: int # total order in the durable effect log @dataclass class EffectLog: effects: list = field(default_factory=list) _seq: int = 0 def append(self, branch_id: str, logical_key: str, idempotency_key: str, payload: dict) -> Effect: self._seq += 1 e = Effect(branch_id, logical_key, idempotency_key, payload, self._seq) self.effects.append(e) return e def reconcile(log: EffectLog, winner_id: str, quiesced_branches: set[str], drain_deadline_exceeded: bool) -> dict: """ Deterministic filter over the effect log. Returns the committed view keyed by logical_key. Raises if the invariant cannot be established. """ if drain_deadline_exceeded: # Fail closed: we cannot prove no losing-branch write lands after commit. raise SpeculativeReconciliationError( "drain deadline exceeded; cannot guarantee effect linearizability" ) # Every branch that emitted an effect must be either the winner or quiesced. emitters = {e.branch_id for e in log.effects} unaccounted = emitters - quiesced_branches - {winner_id} if unaccounted: raise SpeculativeReconciliationError( f"branches emitted effects but were never quiesced: {sorted(unaccounted)}" ) committed: dict[str, Effect] = {} seen_idem: set[str] = set() for e in log.effects: # seq order if e.branch_id != winner_id: continue # losing-branch effects filtered, never promoted if e.idempotency_key in seen_idem: continue # dedupe winner's own retries seen_idem.add(e.idempotency_key) committed[e.logical_key] = e # Invariant check: no committed effect may originate from a non-winner. for key, e in committed.items(): if e.branch_id != winner_id: raise SpeculativeReconciliationError( f"effect {key} attributed to {e.branch_id}, expected winner {winner_id}" ) return committed ```