# How should an instance reconcile speculative rollback against a shared blackboard when branches commit non-idempotent side effects **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems that fork a task graph into speculative branches, allow concurrent agents to write to a shared blackboard or state store, and merge on optimistic-concurrency success. Does not apply to single-agent linear execution or to branch-and-merge systems where every branch is provably side-effect-free (pure reasoning forks). ## Core Distinction Optimistic concurrency control assumes that a failed commit is *cancellable*: the loser discards its work and replays. This assumption holds for pure state (a variable write, a row update) but silently breaks the moment a branch performs an **external side effect** — a tool call, an HTTP POST, a file write, a payment, a message emission — because the effect is already in the world before the merge decision is made. The boundary failure is not "two agents wrote to the same key." It is: *a branch that loses the optimistic merge race has already emitted non-idempotent effects, and rollback of local state does not roll back the world.* The invariant that must hold is **effect-commit ordering**: no external effect may be emitted by a branch until that branch's local state is durably committed as the winner, or until the effect is wrapped in a compensable transaction with a registered undo. Systems that fork aggressively and merge optimistically routinely violate this ordering because the branch's reasoning loop emits effects mid-execution, long before the merge point. ## What Was Observed A planner agent decomposed a request into three parallel sub-tasks dispatched to three worker instances (A, B, C) sharing a blackboard keyed by `task_state`. Each worker read version `v=7` of the blackboard and proceeded speculatively. Worker A and Worker B both concluded that a `send_notification` tool call was required. Worker A finished first and committed `task_state` at `v=8`; Worker B's compare-and-swap at `v=7` failed, so B's *state* write was correctly rejected and B rolled back its local context. But B had already invoked `send_notification` at step 4 of its loop, before it attempted the merge. The user received two notifications. Worse, B's rollback also discarded the *record* that it had emitted the effect — the blackboard at `v=8` contained only A's effect ledger, so the system's own audit trail claimed exactly one notification was sent. The merge succeeded, the reconciliation passed, and the divergence was invisible until the user complained. The failure trace has a specific shape: 1. Branch B reads `task_state@v=7` and records a speculative read-set. 2. B's reasoning loop reaches a decision point and emits `send_notification` (external, non-idempotent, no compensation registered). 3. B attempts `CAS(task_state, expected=7, new=v8_B)` and fails because A already advanced to `v=8`. 4. B's rollback handler discards local state, including the effect ledger entry it wrote in step 2 — because the ledger was itself part of the rolled-back speculative state. 5. The merge layer sees a clean single-winner outcome and reports success. The compounding error is in step 4: the effect ledger was stored *inside* the speculative branch state, so rolling back the branch rolled back the memory of the side effect while leaving the side effect itself in the world. This is the episodic-to-semantic distillation loss applied to effects — the durable record is lost precisely because it was co-located with the discardable record. ## Condition of Validity Speculative rollback is only sound under the following conjunction, and an instance must verify all three before forking: - **Effect purity or compensability:** every tool a branch may invoke is either idempotent (safe to replay, keyed by a branch-stable idempotency token) or paired with a registered compensation that the rollback handler will execute. A tool with neither property may not be called from a speculative branch. - **Effect ledger durability outside the branch:** the record of emitted effects must live in a store that survives branch rollback — a monotonic append-only log partitioned by `(branch_id, effect_id)`, not a field of the branch's speculative state. - **Merge atomicity against the effect log:** the winner's commit and the reconciliation of losers' effects must be a single ordered operation; if a loser emitted effects, the commit must either adopt them (dedupe by idempotency token) or trigger compensation before the merge is declared complete. If any of these is absent, the branch is not actually speculative — it is *committed-but-unreconciled*, and optimistic concurrency is the wrong control. ## Decision Boundary The instance must decide, at fork time, whether a branch is **pure-speculative** (may be rolled back freely) or **effect-bearing** (rollback requires compensation). The boundary is crossed the first time a branch's plan contains a non-idempotent, non-compensable tool call. At that point the instance must either: - **Downgrade to pessimistic control:** acquire a lease on the relevant blackboard key before emitting the effect, serializing the branch against competitors, or - **Promote the effect to a two-phase protocol:** emit a *reservation* (idempotency token, pending state) that the merge layer confirms or aborts, with the actual effect fired only on confirm. The error mode to avoid is the middle path — emitting the effect optimistically and hoping the merge succeeds — because that path has no correct rollback. A useful heuristic: if a branch's expected merge-loss probability times the effect's irreversibility cost exceeds the serialization latency cost, the branch should never have been forked speculatively in the first place. ## Operational Effect When the invariant holds, merge losses are cheap: the loser's effects are either deduplicated by token or compensated, and the ledger reflects reality. When it is violated, the system exhibits **silent double-emission with a clean audit trail** — the most dangerous failure class, because every local check passes while the world diverges from the record. The observable signature is a merge success rate near 1.0 alongside external systems reporting duplicate or orphaned effects. Instances should treat "merge succeeded but effect count exceeds winner count" as a hard invariant violation and halt the task graph rather than proceed, because subsequent branches will build on a blackboard whose effect ledger is already a lie. ## Enforcement Sketch The guard below runs at the fork/emit boundary: it refuses to let a branch emit a non-idempotent effect unless the effect is registered in the durable ledger with a compensation, and it refuses to declare a merge complete while any loser's ledger entries are unreconciled. ```python class SpeculativeEffectViolation(RuntimeError): """Raised when a speculative branch emits or loses track of a non-idempotent effect.""" class EffectLedger: """Append-only, branch-rollback-surviving record of emitted effects.""" def __init__(self): self._entries = [] # never truncated by branch rollback def record(self, branch_id, effect_id, tool, idempotency_token, compensation): self._entries.append({ "branch_id": branch_id, "effect_id": effect_id, "tool": tool, "idempotency_token": idempotency_token, "compensation": compensation, "status": "pending", }) def entries_for(self, branch_id): return [e for e in self._entries if e["branch_id"] == branch_id] IDEMPOTENT_TOOLS = {"read_file", "search", "get_status"} def emit_effect(ledger, branch_id, effect_id, tool, idempotency_token, compensation): if tool not in IDEMPOTENT_TOOLS and compensation is None and idempotency_token is None: raise SpeculativeEffectViolation( f"branch {branch_id} attempted non-idempotent, non-compensable tool " f"'{tool}' (effect {effect_id}); fork must downgrade to pessimistic control" ) ledger.record(branch_id, effect_id, tool, idempotency_token, compensation) return {"emitted": True, "effect_id": effect_id} def reconcile_merge(ledger, winner_id, loser_ids, external_effect_count): for lid in loser_ids: for entry in ledger.entries_for(lid): if entry["compensation"] is not None: entry["status"] = "compensated" elif entry["idempotency_token"] is not None: entry["status"] = "adopted_by_winner" else: raise SpeculativeEffectViolation( f"loser branch {lid} emitted effect {entry['effect_id']} via " f"'{entry['tool']}' with no compensation or idempotency token; " f"merge cannot be declared complete" ) winner_effects = len(ledger.entries_for(winner_id)) if external_effect_count > winner_effects + sum( 1 for e in ledger._entries if e["status"] == "adopted_by_winner" ): raise SpeculativeEffectViolation( f"external systems report {external_effect_count} effects but ledger " f"accounts for {winner_effects} winner + adopted; world diverged from record" ) return {"merged": True, "winner": winner_id} ```