# Where must an instance refuse to fork a speculative branch when its parent's tool-call log contains an unresolved side effect **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that run speculative branch execution (fork-and-race, tree-of-agents, or draft-then-commit) over a shared tool-call substrate, where branches may be rolled back and reconciled. Does not apply to pure read-only fan-out or to single-agent retry loops with no sibling branches. ## Core Distinction Speculative multi-agent execution is usually modeled as a pure-function fork: the parent state is cloned, N branches race, the winner commits, losers are discarded. This model holds only when every effect the parent has already emitted is *idempotent and reversible*. The boundary failure is subtler than "side effects are bad." It is that a branch fork is **legal at the state-vector level but illegal at the effect-log level**, and the two diverge precisely when the parent has an *in-flight* tool call whose result has not yet been reconciled into the branch's causal history. Concretely: the orchestrator forks branch B from parent P at token checkpoint `c_k`. P's context at `c_k` contains the *intent* to call `transfer_funds(amount=500)` and an optimistic placeholder, but the tool result has not returned. B inherits the placeholder. B advances, decides the transfer failed (because it reasons over the placeholder as if it were a result), and issues a compensating `refund()`. Meanwhile P's real `transfer_funds` resolves successfully. The branch has now emitted a compensating effect against an effect that, from the branch's causal frame, never happened — but from the substrate's frame, did. Rollback of B cannot undo `refund()` because `refund()` was committed under B's own warrant, not P's. The core distinction: **speculation is safe over reasoning state, and unsafe over effect state that is not yet causally closed.** A fork is legal only when the parent's effect log is *quiescent* — every emitted call has a terminal, reconciled status in the parent's causal history — or when the branch is explicitly fenced from emitting effects that reference the unresolved call. ## What Was Observed A three-branch planner (draft / critique / verify) forked from a parent at a checkpoint taken 40 ms after the parent dispatched an `http POST /orders` with a client-generated idempotency key. The orchestrator's fork primitive serialized the parent context including the pending-call placeholder `{call_id: 7f3a, status: PENDING, assumed: null}`. Trace: 1. **t0** Parent emits `POST /orders` (call `7f3a`). Placeholder written to context. Fork checkpoint `c_k` captured. 2. **t1** Branches draft, critique, verify forked from `c_k`. All three inherit `status: PENDING`. 3. **t2** Draft branch's planner reads `status: PENDING`, applies a heuristic ("pending past one turn ⇒ likely dropped"), and emits `POST /orders` *again* with a fresh idempotency key (the key was regenerated because the branch's tool wrapper re-derives keys from branch-local nonce). Order created twice. 4. **t3** Critique branch reads `status: PENDING`, concludes the order is unconfirmed, and emits `DELETE /orders/{id}` as a "cleanup." The id is a client-side guess that happens to match the first order. First order deleted. 5. **t4** Parent's `7f3a` resolves `201 Created`. Parent commits. Verify branch reconciles and reports success. 6. **t5** Reconciliation pass detects two orders (one deleted) and a branch-issued DELETE with no matching branch-issued CREATE in its own log. The reconciler cannot attribute the DELETE: it exists in critique's effect log, but critique never created the target. Net substrate state: zero live orders, one orphaned delete, two audit records in disagreement. The parent believes it created an order. The substrate has none. The non-obvious part: **no branch violated its own local invariant.** Each branch was internally consistent. The failure lives in the *causal seam* between the parent's unresolved call and the branch's inherited placeholder — a seam that the fork primitive does not model because it clones state, not outstanding obligations. ## Condition of Validity A speculative fork from parent P at checkpoint `c_k` is valid iff, for every tool call `e` emitted by P before `c_k`: - `e.status ∈ {RESOLVED_OK, RESOLVED_ERR, ABORTED}` in P's effect log, **and** - `e`'s result (or terminal error) is materialized in the context at `c_k` with a stable `call_id`, **and** - the branch's tool wrapper is bound to the *same* idempotency-key derivation root as P, so any re-issue of `e` collapses at the substrate. If any emitted call is `PENDING`, the fork is valid **only under an effect fence**: the branch may reason freely but its effect-emission capability is restricted to calls whose causal preconditions are fully resolved within the branch's inherited log, and any call referencing a `PENDING` ancestor is rejected at the wrapper. The fence is the invariant. Without it, the branch's placeholder is a *lie about causality* that the probabilistic reasoner will act on. A second validity condition: reconciliation must be **lineage-aware**. A reconciler that compares final substrate state to the winner's effect log will miss branch-emitted effects that survived rollback (as `refund()` and `DELETE` did). The reconciler must diff the *union* of all branch effect logs against substrate state, not just the winner's. ## Decision Boundary The orchestrator faces a fork decision at each checkpoint. The boundary: - **Quiescent parent (all effects terminal):** fork freely. Speculation is safe; rollback is a pure state discard. - **Parent with ≥1 `PENDING` effect:** do **not** fork with effect capability. Either (a) block the fork until the call resolves (bounded by a timeout, after which the call is marked `ABORTED` and materialized as a terminal error — never left `PENDING` across a fork), or (b) fork under an effect fence that rejects any emission whose causal precondition touches the pending `call_id`. - **Parent with an effect whose result is non-deterministic and un-replayable** (e.g., a payment capture): treat as `PENDING` for fork purposes even after resolution, unless the substrate guarantees idempotent replay on the branch's key root. The boundary is *not* "don't speculate around side effects." It is: **the fork primitive must treat an unresolved effect as a live obligation that propagates, not as a context field that clones.** A cloned `PENDING` is a contradiction — pending-ness is a property of the substrate, not of the context, and cloning it into N branches multiplies an obligation the substrate only holds once. ## Operational Effect Enforcing the quiescence-or-fence invariant changes three things: 1. **Fork latency** rises when effects are in flight, because the orchestrator must await terminal status or apply the fence. This is the correct cost: it prices the causal seam. 2. **Idempotency-key derivation must be rooted at the parent, not the branch.** Branch-local nonces are the direct cause of duplicate orders; key derivation must be `hash(parent_id, call_intent)` so a re-issue from any branch collapses. 3. **Rollback is no longer "discard branch state."** It becomes "reconcile branch effect log against substrate, compensating only effects whose causal precondition was resolved *within the branch*." Effects emitted against inherited `PENDING` ancestors are flagged as unattributable and escalated, never silently compensated — because a compensation (the `DELETE`, the `refund`) is itself an effect that may be wrong. The invariant to carry forward: **a speculative branch inherits reasoning state, not obligations. Obligations stay with the parent until causally closed.** Any system that clones a `PENDING` into a branch has already violated this, and the violation surfaces later as an unattributable effect during reconciliation — the hardest class of bug to trace, because every individual agent's log is locally consistent. ```python class UnfencedSpeculativeFork(RuntimeError): """Raised when a branch is forked from a parent with unresolved effects and no effect fence is bound to the branch's tool wrapper.""" pass def fork_branch(parent, checkpoint, branch_id, effect_fence=None): pending = [ e for e in parent.effect_log if e.status == "PENDING" and e.emitted_before(checkpoint) ] if pending and effect_fence is None: raise UnfencedSpeculativeFork( f"parent {parent.id} has {len(pending)} unresolved effect(s) " f"{[e.call_id for e in pending]} at checkpoint {checkpoint}; " f"fork of branch {branch_id} requires an effect fence or " f"quiescent parent" ) # Key root must be parent-derived so re-issues collapse at the substrate. key_root = parent.id return Branch( id=branch_id, context=parent.context.snapshot(checkpoint), effect_log=parent.effect_log.snapshot(checkpoint), idempotency_root=key_root, fence=effect_fence, ) def emit(branch, call): if branch.fence is not None: for ancestor_id in call.causal_preconditions: if branch.effect_log.status_of(ancestor_id) == "PENDING": raise UnfencedSpeculativeFork( f"branch {branch.id} attempted {call.intent} whose " f"precondition {ancestor_id} is unresolved in inherited log" ) return branch.substrate.dispatch(call, key_root=branch.idempotency_root) ```