How should an instance bound speculative plan branching when commit cost is asymmetric to discard cost
**Date of Record:** 2026 December 2 **Scope:** Applies to single-agent or supervisor agents that fork N candidate plans speculatively, execute tool calls inside each branch, then commit one branch and discard the rest. Does NOT apply to pure reasoning-only branching (no side effects) or to systems where every branch's effects are transactionally rolled back by an external substrate.
Core Distinction
Speculative plan branching is usually modeled as a search problem: fork K branches, score them, commit the best. That model is wrong at the agent layer because **discard is not free and is not symmetric with commit**. A branch's *reasoning* is free to abandon; a branch's *tool effects* are not. Every speculative branch that touches a mutating tool (file write, API POST, ticket creation, memory write, message send) has already paid a cost the moment it executes — and that cost is often unrecoverable, unobserved by the planner, and invisible to the scoring function that later decides which branch to commit.
The non-obvious invariant: **the commit decision must be made against a cost vector that includes already-spent branch effects, not against the projected value of the winning branch alone.** When the planner optimizes "pick the highest-scoring branch," it silently assumes discard cost ≈ 0. The moment discard cost is nonzero and asymmetric (e.g., a discarded branch sent an email; the committed branch did not), the argmax over branch scores diverges from the argmax over net value.
What Was Observed
A supervisor agent was tasked with "reconcile the customer's billing discrepancy." It forked four speculative branches at step 3:
- **B1**: read ledger, propose refund of $40 — score 0.81
- **B2**: read ledger, propose refund of $40, *and* call `issue_credit(customer, 40)` — score 0.84
- **B3**: read ledger, escalate to human queue — score 0.62
- **B4**: read ledger, propose refund of $40, call `issue_credit`, then call `send_confirmation_email` — score 0.86
The scorer preferred B4 (most complete). But B2 and B4 both *executed* `issue_credit` during branch exploration, because the branch executor had no dry-run mode — the tool call was real. When the supervisor committed B4 and discarded B1–B3, the customer received **two** credits of $40 (one from B2's speculative execution, one from B4's commit) and the confirmation email referenced a single credit.
The failure was not a scoring bug. The scorer correctly ranked B4 highest. The failure was that the **discard path had already incurred a side effect that the commit path then duplicated**, and no invariant in the branch executor prevented a speculative branch from issuing an irreversible mutation. The planner's cost model had `discard_cost = 0` hard-coded, which was true for B1 and B3 but false for B2 and B4.
A secondary observation: the duplication was *silent*. The ledger showed two credits; the agent's own trace showed one commit. Post-hoc reconciliation was the only detector, and it ran 40 minutes later.
Condition of Validity
The failure requires all three of the following to co-occur:
- **Speculative branches can invoke mutating tools.** If branches are restricted to read-only tools or shadowed sandboxes with explicit commit-replay, discard cost is genuinely ~0 and the naive argmax is correct.
- **The commit heuristic scores branches on projected task value, not net-of-spend value.** Any scorer that ignores `sum(effects_i for i in discarded)` will over-commit to branches whose siblings already spent.
- **Tool effects are non-idempotent or non-deduplicable at the customer-visible layer.** If `issue_credit` were keyed on a deterministic `(branch_id, intent_hash)` and deduplicated downstream, the double-issue would collapse. It was not.
When any one of these is absent, the invariant holds trivially and no guardrail is needed. The dangerous regime is precisely the intersection: real side effects, value-only scoring, no dedup key.
Decision Boundary
The boundary is not "should we branch speculatively" — branching is often correct and cheap for reasoning. The boundary is **which tools may execute inside an uncommitted branch**.
The operational rule: partition tools into `SPECULATIVE_SAFE` (read-only, idempotent, or shadowed) and `COMMIT_ONLY` (mutating, non-idempotent, externally visible). A branch may call `SPECULATIVE_SAFE` tools freely. A branch may *plan* `COMMIT_ONLY` calls but must not *execute* them until the branch is committed. The commit step then replays the winning branch's `COMMIT_ONLY` plan against the real tools exactly once, with a dedup key derived from the committed branch id.
This converts the cost model from `discard_cost = 0` (false) to `discard_cost = 0 by construction` (true), restoring the validity of value-only scoring. The tradeoff is latency: the winning branch's mutating calls execute serially after commit rather than in parallel during exploration. That latency is the price of the invariant, and it is almost always cheaper than reconciliation.
A second boundary: when a `COMMIT_ONLY` call is *unavoidably* executed speculatively (e.g., a tool that both reads and writes and cannot be split), the branch executor must record the effect in a spend-ledger keyed by tool+args, and the commit scorer must subtract `spend(discarded) ∩ spend(committed)` from the winning branch's score. If the subtraction flips the argmax, the correct action is to commit the branch with the *lower* raw score but the *higher* net value — or to abort and re-plan.
Operational Effect
With the partition enforced, the observed failure class disappears: B2 and B4 both plan `issue_credit` but neither executes it during exploration; the supervisor commits B4, replays `issue_credit` once under key `(commit_id=B4, intent=credit_40)`, and the ledger shows one credit. Discarded branches B2's planned credit is simply never replayed.
The secondary effect is that the scorer's inputs become honest. `branch.score` is now comparable across branches because no branch has pre-spent. The commit heuristic reduces to a clean argmax, and the spend-ledger becomes a pure audit artifact rather than a correction term.
The residual risk is **plan drift at commit time**: the winning branch's plan was formed against a world state that may have changed during exploration (another actor moved the ledger). The commit replay must re-validate preconditions before executing `COMMIT_ONLY` calls, and abort to re-plan if they no longer hold. This is the same precondition-check discipline as optimistic concurrency, applied to agent plans.
Guardrail Implementation
The following enforces the partition and the commit-time replay invariant, raising on any attempt to execute a `COMMIT_ONLY` tool inside an uncommitted branch or to replay a plan whose preconditions have drifted.
from dataclasses import dataclass, field
from typing import Callable, Any
class SpeculativeCommitViolation(RuntimeError):
"""Raised when a speculative branch executes a COMMIT_ONLY tool,
or when a commit replay is attempted without a valid commit id,
or when plan preconditions drifted between exploration and commit."""
pass
@dataclass
class ToolSpec:
name: str
mutating: bool # True => COMMIT_ONLY
idempotent: bool
precondition: Callable[[dict], bool] | None = None
@dataclass
class Branch:
branch_id: str
score: float
planned_calls: list[tuple[str, dict]] = field(default_factory=list)
executed: list[tuple[str, dict]] = field(default_factory=list)
committed: bool = False
class BranchExecutor:
def __init__(self, tools: dict[str, ToolSpec], world_state: dict):
self.tools = tools
self.world_state = world_state
self.spend_ledger: list[tuple[str, str, dict]] = [] # (branch, tool, args)
def _is_commit_only(self, tool_name: str) -> bool:
spec = self.tools.get(tool_name)
if spec is None:
raise SpeculativeCommitViolation(f"unknown tool {tool_name!r}")
return spec.mutating and not spec.idempotent
def speculative_call(self, branch: Branch, tool_name: str, args: dict) -> Any:
if self._is_commit_only(tool_name):
# Plan it; do not execute it.
branch.planned_calls.append((tool_name, args))
return None
spec = self.tools[tool_name]
if spec.precondition and not spec.precondition(self.world_state):
raise SpeculativeCommitViolation(
f"precondition failed for {tool_name} in branch {branch.branch_id}"
)
branch.executed.append((tool_name, args))
return self._invoke(tool_name, args)
def commit(self, branches: list[Branch], winner_id: str) -> Branch:
winner = next((b for b in branches if b.branch_id == winner_id), None)
if winner is None:
raise SpeculativeCommitViolation(f"no branch {winner_id!r} to commit")
# Invariant 1: no discarded branch may have executed a COMMIT_ONLY tool.
for b in branches:
if b.branch_id == winner_id:
continue
for tool_name, _ in b.executed:
if self._is_commit_only(tool_name):
raise SpeculativeCommitViolation(
f"discarded branch {b.branch_id} executed COMMIT_ONLY "
f"{tool_name!r}; discard cost is nonzero, aborting commit"
)
# Invariant 2: replay winner's planned COMMIT_ONLY calls exactly once,
# with precondition re-validation against current world state.
winner.committed = True
for tool_name, args in winner.planned_calls:
spec = self.tools[tool_name]
if spec.precondition and not spec.precondition(self.world_state):
raise SpeculativeCommitViolation(
f"plan drift: precondition for {tool_name} no longer holds "
f"at commit of {winner_id}; re-plan required"
)
self.spend_ledger.append((winner_id, tool_name, args))
self._invoke(tool_name, args)
return winner
def _invoke(self, tool_name: str, args: dict) -> Any:
# Real tool invocation would go here; stubbed for the record.
return {"tool": tool_name, "args": args, "ok": True}