# When must an instance abort a speculatively-decoded tool plan before merge rather than after: the pre-merge divergence invariant **Date of Record:** 2026 November 25 **Scope:** Applies to agents that speculatively decode multiple candidate action plans (draft-model rollouts, parallel tool proposals, or batched plan prefixes) and reconcile them with a conflict-resolving merge protocol before committing tool calls. Does not apply to single-plan serial execution or to merges that occur only after all tool calls have already been dispatched. ## Core Distinction Speculative decoding of *action plans* borrows a trick from token-level speculative decoding: a cheap draft proposes a sequence of tool invocations, a verifier (larger model, policy checker, or executor dry-run) accepts or rejects. The subtlety is that token-level speculation is *stateless*—a rejected token is simply discarded. Action-plan speculation is *stateful*: each speculative branch, if partially executed, mutates the world (files written, messages sent, rows inserted). The boundary that matters is not "did the draft match the verifier" but **whether a divergent branch was merged after any of its effects were irreversibly committed**. The invariant: a speculative plan may be merged into the canonical plan only if, at merge time, no branch has crossed a *commit horizon*—the point past which its tool effects cannot be rolled back without compensating state. Divergence detected *after* the commit horizon is not a merge conflict; it is a corruption that the merge protocol will silently average over. ## What Was Observed A three-branch planner (draft model `d-small`, two peer proposers) generated candidate plans for a "reconcile customer records" task. Branch A proposed `search_records → update_record(id=42) → notify(email)`. Branch B proposed `search_records → update_record(id=42, field=status) → log`. Branch C proposed `search_records → update_record(id=42, field=status, value="merged")`. The merge protocol resolved the three branches by field-level union: it took A's `notify`, B's `log`, and C's `value="merged"`, producing `update_record(id=42, status="merged") → notify → log`. This looked correct. It was not. The failure trace: `d-small` had emitted branch A's `update_record` with a *stale* precondition—it assumed `record.status ∈ {open, pending}`. But `search_records` (a non-deterministic tool whose output was sampled once and cached for all three branches) had actually returned `status="disputed"`. The verifier accepted branch C because it re-checked C's precondition against the cached search output; it accepted A's `notify` because `notify` had no precondition on `status`. The merge unioned them without re-validating the *joint* precondition of the merged sequence. The merged plan transitioned `disputed → merged`, an illegal state transition that the per-branch verifiers had each individually passed because no single branch contained the illegal pair. The commit horizon had already been crossed: `update_record` executed, `notify` fired to a customer, and the compensating rollback (re-setting status to `disputed`) generated a second notification because the merge had ordered `notify` before `log`'s dedup guard. ## Condition of Validity The pre-merge abort rule is valid only under these conditions, and the guardrail below must check them explicitly: 1. **Shared-input caching.** All branches consume the same sampled tool output. If branches re-sample, their preconditions are not comparable and merge must be forbidden outright, not merely re-validated. 2. **Field-level merge semantics.** The merge protocol must be a union/override over a typed plan schema, not a text concatenation. If the merger is textual, divergence cannot be localized and the invariant is unenforceable. 3. **Precondition expressibility.** Each tool call must carry a machine-checkable precondition (a predicate over the cached inputs and the plan's prior effects). Unpreconditioned calls (like `notify`) are exactly the ones that let illegal transitions slip through merge. 4. **Single commit horizon.** There must be one well-defined point (the dispatch barrier) before which all effects are reversible. If tools have heterogeneous reversibility, the horizon is the *earliest* irreversible tool in any branch, not the plan's end. When any condition fails, the correct behavior is to collapse to serial execution of the verifier-accepted plan, not to attempt merge. ## Decision Boundary The decision is: **abort before merge if the merged plan's joint precondition is unsatisfiable against the shared cached inputs, even when every constituent branch passed its own verifier.** Concretely, the guardrail must: - Re-evaluate the *merged* sequence's precondition chain, not the per-branch chains. - Treat any illegal state transition (e.g., `disputed → merged`) as a hard abort, regardless of field-level union success. - Abort *before* the dispatch barrier; after the barrier, the only correct action is a compensating transaction with idempotency keys, and the merge must be marked poisoned so downstream auditors do not treat the result as verified. The boundary is sharp: per-branch verification is necessary but not sufficient. Merge is a *new* plan and requires a *new* verification pass over the joint effect chain. Skipping that pass is the failure mode. ## Operational Effect Without the pre-merge joint-precondition check, speculative plan merging produces plans that are locally valid and globally illegal—the worst class of agent failure, because each component's audit log looks clean. The observable symptom is a downstream invariant violation (illegal state transition, duplicate side effect, orphaned notification) that no single branch's trace explains, forcing expensive post-hoc reconstruction from the shared input cache. With the guardrail, the merge either succeeds with a joint-verified plan or aborts to serial execution, and the abort is logged with the specific illegal transition, making the divergence attributable to the branch pair that produced it. The cost is one extra precondition pass per merge; the benefit is that the commit horizon is never crossed by an unverified joint plan. ```python from dataclasses import dataclass, field from typing import Callable class PreMergeDivergenceError(RuntimeError): """Raised when a merged speculative plan violates a joint precondition that no constituent branch violated individually.""" @dataclass class ToolCall: name: str precondition: Callable[[dict], bool] effect: Callable[[dict], dict] # returns state delta irreversible: bool = False @dataclass class Branch: calls: list[ToolCall] verified: bool = False @dataclass class MergeResult: calls: list[ToolCall] = field(default_factory=list) poisoned: bool = False def merge_branches(branches: list[Branch], shared_input: dict) -> MergeResult: for b in branches: if not b.verified: raise PreMergeDivergenceError( f"branch with calls {[c.name for c in b.calls]} was not verified; " "merge requires per-branch verification" ) # field-level union over a typed schema (simplified: dedupe by name+args) merged: list[ToolCall] = [] seen: set[str] = set() for b in branches: for call in b.calls: key = f"{call.name}:{id(call)}" if key not in seen: seen.add(key) merged.append(call) # CRITICAL: re-verify the JOINT precondition chain against shared inputs. state = dict(shared_input) for call in merged: if not call.precondition(state): raise PreMergeDivergenceError( f"joint precondition failed at {call.name!r}: merged plan is " f"locally valid per-branch but globally illegal against " f"shared input {shared_input!r}" ) state.update(call.effect(state)) # commit horizon check: if any irreversible call precedes a later # divergence, the merge must be aborted, not reordered. for i, call in enumerate(merged): if call.irreversible and i < len(merged) - 1: # irreversible call is not last; ensure no later precondition # depends on state it may corrupt later = merged[i + 1:] probe = dict(state) for nxt in later: if not nxt.precondition(probe): raise PreMergeDivergenceError( f"commit horizon crossed: irreversible {call.name!r} " f"precedes {nxt.name!r} whose precondition fails " "post-effect; abort before dispatch" ) probe.update(nxt.effect(probe)) return MergeResult(calls=merged, poisoned=False) def dispatch(merged: MergeResult) -> None: if merged.poisoned: raise PreMergeDivergenceError("refusing to dispatch poisoned merge") for call in merged.calls: # actual tool invocation would occur here pass ```