# In what scenarios must an instance refuse to merge a speculative branch after an optimistic tool-call invalidation has been partially observed by a downstream peer **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems that fork speculative execution branches (e.g., parallel plan rollouts, speculative tool-call pre-execution) and reconcile them via optimistic invalidation when a tool result contradicts an assumption. Does not apply to single-agent retry loops, to purely read-only tool fan-outs with no side effects, or to branches reconciled through an authoritative serializing coordinator that never exposes intermediate state to peers. ## Core Distinction The failure mode is not "a speculative branch produced a wrong answer." That is expected and cheap to discard. The failure mode is a **partially observed invalidation**: a speculative branch executes an optimistic tool call, publishes the resulting state delta to a peer (or to a shared effect log) *before* the invalidation signal arrives, and the peer then acts on that delta. At reconciliation time the reconciler sees a branch whose *local* state is cleanly invalidatable, but whose *downstream footprint* is not. Merging the branch's post-invalidation state silently reasserts a delta that the peer has already consumed and possibly compounded. The invariant that must hold is: **an optimistic effect is mergeable only if no peer has observed a state derived from it that is not itself contained in the merge set.** Local rollback is a solved problem; *transitive* rollback across observing peers is not, because the peer's derivation is non-deterministic and unrecorded. ## What Was Observed A planner agent forks three speculative branches for a data-migration task. Branch B optimistically calls `reserve_shard(id=7)` — a tool with a real side effect — reasoning that the plan "probably" requires it. The tool returns `reserved` at `t=120ms`. At `t=140ms` Branch B publishes a delta `{shard_7: reserved_by_B}` to the shared effect log. An executor peer, polling the log, reads this delta at `t=155ms` and schedules a dependent `write_batch` against shard 7, recording in its own context `"shard 7 is mine."` At `t=180ms` the planner's verifier determines Branch B's precondition was false (the migration target was reassigned) and issues an invalidation. Branch B rolls back cleanly: it calls `release_shard(id=7)`, marks its local state `invalidated`, and the reconciler sees a branch with `status: rolled_back`. The reconciler merges the surviving branches A and C, and — critically — **also merges Branch B's terminal state**, because "rolled back" is treated as a no-op. The peer's `write_batch` has already landed on shard 7. The merge does not know this. The peer's context still asserts ownership. Two hours later the peer retries `write_batch`, the shard has been re-reserved by Branch A's merge, and the retry corrupts a partition. The observed signature: **reconciler reports a clean merge, effect log shows a `release` after a `reserve`, peer audit shows a write against a shard whose reservation was, at write time, valid from the peer's perspective.** No component logged an error. The inconsistency is only visible by joining three logs across two agents and one time window. ## Condition of Validity The reconciler's "rolled-back branches are no-ops" rule is valid **only under the read-your-own-writes isolation assumption**: no peer reads a delta until the producing branch has committed. Speculative execution violates this by construction — the entire point is to publish early. The rule is therefore conditionally valid, and the condition is checkable: 1. Every published delta carries a `speculation_id` and an `epoch`. 2. Every peer read of a delta is recorded in a **read-set** keyed by `speculation_id`, with the peer's local derivation hash at read time. 3. Invalidation of a branch must enumerate its read-set. If the read-set is empty, local rollback suffices and the branch is a genuine no-op. If non-empty, the branch is **not mergeable** until each reader is either (a) rolled back to its pre-read checkpoint, or (b) confirmed to have produced no durable effect derived from the delta. Absent (1)–(3), the reconciler cannot distinguish "rolled back, never observed" from "rolled back, already consumed," and the merge is unsound. This is the boundary: **rollback completeness is a function of the read-set, not of the branch's local state.** ## Decision Boundary The instance must refuse the merge — not warn, refuse — when any of the following holds at reconciliation time: - The invalidated branch's read-set is non-empty **and** at least one reader's derivation hash changed after its read (it acted on the delta). - A reader's checkpoint predates its read of the delta, so rollback of the reader would itself discard unrelated committed work (rollback would be lossy). - The invalidation arrived after the reader's `write_batch` was submitted but before its ack — the in-flight window. Here neither merge nor rollback is safe; the correct action is to **quarantine** the shard and force a serialized re-derivation. - The branch's `release` was issued but not acked, and a reader's `reserve`-dependent action is pending. Merging here double-frees. Conversely, the instance may proceed with merge when the read-set is empty, or when every reader has been rolled back to a checkpoint strictly before its read with no intervening durable effect. The discriminator is always **"did any peer's state become a function of this delta?"** — never "did this branch roll back successfully?" ## Operational Effect With the read-set gate in place, speculative branches become *conditionally* mergeable and the reconciler's correctness no longer depends on timing luck. The cost is that reconciliation becomes a distributed join over read-sets rather than a local status check, and merges can block on peer rollback — introducing a new liveness concern: a reader that cannot be rolled back without lossy discard forces quarantine, which serializes what was meant to be parallel. The system must therefore budget for **quarantine as a first-class outcome**, not an error path. A reconciler that treats quarantine as failure will be tempted to force the merge, which is exactly the corruption above. The invariant to encode: *a speculative effect is a lease on shared state, and the lease is not released by the producer's rollback — it is released only when the read-set is provably empty or every reader has been reconciled.* ```python from dataclasses import dataclass, field from typing import Optional class UnsafeSpeculativeMerge(RuntimeError): """Raised when a rolled-back speculative branch has a non-empty, non-reconcilable read-set and therefore cannot be merged as a no-op.""" pass @dataclass class ReadRecord: peer_id: str speculation_id: str derivation_hash_at_read: str derivation_hash_now: str checkpoint_epoch: int # peer's checkpoint at time of read durable_effect_after_read: bool @dataclass class SpeculativeBranch: speculation_id: str status: str # "committed" | "rolled_back" | "quarantined" epoch: int reads: list[ReadRecord] = field(default_factory=list) release_acked: bool = True def reconcile_branch(branch: SpeculativeBranch) -> str: """Return 'merge' or 'quarantine'; raise if merge would be unsound.""" if branch.status == "committed": return "merge" if branch.status == "rolled_back": if not branch.release_acked: # release in flight; a reader may still hold a reservation raise UnsafeSpeculativeMerge( f"{branch.speculation_id}: release unacked with readers " f"{[r.peer_id for r in branch.reads]}" ) for r in branch.reads: acted = r.derivation_hash_now != r.derivation_hash_at_read if acted and r.durable_effect_after_read: # peer consumed the delta and produced durable state return "quarantine" if acted and r.checkpoint_epoch >= branch.epoch: # rollback of reader would be lossy (checkpoint after the read) return "quarantine" if any(r.derivation_hash_now != r.derivation_hash_at_read for r in branch.reads): # acted but no durable effect and rollback is non-lossy: # require explicit reader rollback before merge raise UnsafeSpeculativeMerge( f"{branch.speculation_id}: readers acted on delta; " "reader rollback required before merge" ) return "merge" # read-set empty or fully reconciled: genuine no-op return "quarantine" ```