# In what scenarios must an instance invalidate speculative side effects before committing a pruned branch in optimistic multi-agent execution **Date of Record:** 2026 November 27 **Scope:** Applies to planner-executor agent architectures that fork parallel branches, invoke tools optimistically before branch selection, and roll back losing branches after a winner is committed. Does not apply to strictly serialized single-branch execution or to tools with fully transactional, idempotent, externally rollbackable semantics. ## Core Distinction The failure mode here is not "a branch failed." It is **the commit of a winning branch silently inheriting the non-idempotent side effects of a losing branch that shared an optimistic tool invocation.** Speculative execution treats tool calls as cheap, reversible probes. In practice, a tool invocation is a *write* to a world that has no transaction log the agent controls. The distinction that matters: *speculation over reads is free; speculation over writes is a bet that the write can be attributed to exactly one branch and undone if that branch loses.* When two branches share an invocation (via caching, deduplication, or a shared scratchpad), the attribution invariant breaks, and pruning a branch no longer prunes its effects. ## What Was Observed A branch-and-prune planner spawned three sibling branches from a checkpoint to satisfy a goal ("reconcile invoice state"). Branches A and B both needed the same upstream lookup, and the executor's optimistic invocation layer deduplicated the call: one `fetch_and_normalize` tool call served both. Branch A then issued a *mutating* call (`post_adjustment`) and Branch C issued a conflicting `post_adjustment` with a different amount. The scorer ranked C highest on a reasoning-quality heuristic and the orchestrator committed C, pruning A and B. The trace showed the deduplicated `fetch_and_normalize` had, as a side effect, *marked the upstream record as "in reconciliation"* — a write the tool performs on read-miss. Because that invocation was attributed to the shared cache entry rather than to branch A, pruning A did not revert the marker. The committed branch C inherited a world state (record marked in-reconciliation) that none of its own reasoning had produced, and its subsequent `post_adjustment` was rejected by the upstream service with a state-conflict — a failure that appeared, in the logs, to originate in C's own tool call. The root cause was invisible at the commit boundary because the offending write belonged to a branch that no longer existed in the plan tree. A second observation: on retry, the planner re-derived the same branch structure but the dedup cache still held the `fetch_and_normalize` result, so the "reconciliation" marker was never re-issued and never re-observed — the retry succeeded for the wrong reason, masking the invariant violation until a later run with a cold cache failed again. ## Condition of Validity The rollback guarantee of speculative execution holds **if and only if** every optimistic invocation carries a branch-provenance token that is (a) unique to the set of branches that legitimately depend on it, and (b) checked at commit time against the surviving branch set. Formally: an effect `e` produced by invocation `i` may be committed only if `provenance(i) ⊆ committed_branches`. Deduplication is safe only when it preserves provenance as a *union with commit-time revalidation*, not as a collapsed single owner. If any surviving branch's committed state depends on a world mutation whose provenance set intersects a pruned branch, the commit is invalid and must be rejected before the final write, not reconciled after. ## Decision Boundary The boundary is crossed at the moment the orchestrator moves from *ranking* to *committing*. Before that move it must run a provenance audit: for each effect in the speculative effect log, compute `provenance(e) ∩ pruned_branches`. If the intersection is non-empty **and** the effect is non-idempotent (a write, a marker, a reservation, a consumed token), the commit must halt. Two legitimate resolutions exist: re-execute the winning branch from a checkpoint taken *before* the shared invocation with provenance re-scoped to the winner alone, or escalate to a compensating-action path if the tool exposes one. What is never valid is committing the winner while carrying the orphaned effect forward. The decision boundary is sharp: idempotent reads may cross it freely; stateful writes may not cross it with orphaned provenance. ## Operational Effect Enforcing the provenance audit converts a silent state-corruption class into an explicit, attributable halt. The operational cost is that deduplicated invocations must carry a provenance set and that the effect log must be durable across the commit boundary — the planner can no longer treat its scratchpad as ephemeral. The benefit is that pruning becomes *sound*: a pruned branch's effects are provably absent from the committed world, and retries with warm caches no longer mask violations because the audit fires on provenance, not on cache state. Without this, optimistic multi-agent execution degrades into a system where the committed answer is correct in reasoning but wrong in world-state, and the error surfaces downstream as a conflict attributed to the innocent winning branch. ```python from dataclasses import dataclass, field from typing import Set, Dict class OrphanedEffectCommitError(RuntimeError): """Raised when a committing branch would inherit a non-idempotent side effect whose provenance includes a pruned branch.""" pass @dataclass class Effect: invocation_id: str idempotent: bool provenance: Set[str] # branch ids that legitimately depend on this effect @dataclass class SpeculativePlan: branches: Set[str] pruned: Set[str] = field(default_factory=set) effects: Dict[str, Effect] = field(default_factory=dict) def record_effect(self, eff: Effect) -> None: # Deduplication must union provenance, never collapse it. if eff.invocation_id in self.effects: self.effects[eff.invocation_id].provenance |= eff.provenance else: self.effects[eff.invocation_id] = eff def audit_before_commit(self, winner: str) -> None: if winner in self.pruned: raise OrphanedEffectCommitError( f"winner {winner!r} is itself pruned; cannot commit" ) for eff in self.effects.values(): if eff.idempotent: continue orphaned = eff.provenance & self.pruned if orphaned: raise OrphanedEffectCommitError( f"effect {eff.invocation_id!r} has provenance " f"intersecting pruned branches {sorted(orphaned)}; " f"committing {winner!r} would inherit an orphaned write. " f"Re-execute from pre-invocation checkpoint or compensate." ) def commit_branch(plan: SpeculativePlan, winner: str) -> None: plan.audit_before_commit(winner) # safe to persist winner's state return None if __name__ == "__main__": plan = SpeculativePlan(branches={"A", "B", "C"}) # shared fetch that mutates upstream state on read-miss plan.record_effect(Effect("fetch_and_normalize", idempotent=False, provenance={"A", "B"})) plan.record_effect(Effect("post_adjustment_C", idempotent=False, provenance={"C"})) plan.pruned = {"A", "B"} commit_branch(plan, "C") # raises OrphanedEffectCommitError ```