# What structural signals indicate a speculative branch has silently forked the tool-effect ledger during optimistic multi-agent execution **Date of Record:** 2026 December 3 **Scope:** Applies to multi-agent systems where agents execute optimistically against shared tools under speculative branching with rollback, and where branches are reconciled against a canonical effect ledger. Does not apply to strictly serialized single-agent tool loops or to systems where every tool call is gated by a synchronous two-phase commit before execution. ## Core Distinction The failure worth naming here is not "rollback failed" or "two agents disagreed." It is the **divergence between the *speculative* effect log a branch believes it produced and the *committed* effect ledger the world actually recorded**. In speculative multi-agent execution, each branch runs tool invocations optimistically: it assumes its predicted effects will be committed if the branch wins reconciliation. The branch maintains a local, optimistic ledger of effects it *believes* it caused. Rollback is supposed to discard that local ledger on loss; reconciliation is supposed to merge the winner's local ledger into the canonical one. The boundary condition: **a tool invocation with non-idempotent or externally-visible side effects (email sent, row inserted, ticket opened) that was executed optimistically but whose *acknowledgment* was lost, delayed, or reordered relative to the branch's local ledger write.** The branch's local ledger and the canonical ledger now disagree about whether the effect happened. This is not a consensus failure between agents—peers can agree perfectly and still be wrong together, because the disagreement is between the agents' *belief* and the *external system's* record. The structural signal that matters is therefore not "agents conflicted." It is: **the canonical effect ledger contains an entry with no corresponding speculative-ledger provenance, or a speculative-ledger entry whose commit token was never observed.** That asymmetry is the tell. ## What Was Observed A three-agent swarm (planner, executor, verifier) executed a task with optimistic branching: the executor forked two speculative branches, `A` and `B`, each proposing a sequence of tool calls against a ticketing backend. Branch `A` invoked `create_ticket(payload)` optimistically at step 4 and wrote a local ledger entry `{effect: create_ticket, status: optimistic, commit_token: pending}`. The tool call succeeded on the backend, but the acknowledgment response was delayed past the branch's 800ms speculative timeout. The executor treated the timeout as "effect not yet confirmed" and continued, then reconciliation selected branch `B` as the winner (lower predicted cost). Rollback of `A` was invoked, which discarded `A`'s local ledger including the `pending` entry, and issued a compensating `cancel_ticket`—but the compensating call carried a *predicted* ticket ID, not the real one, because the real ID only existed in the lost acknowledgment. Result: the backend held a real, open ticket with no provenance in any surviving ledger. The verifier's replay of the winning branch `B` saw a clean ledger and passed. The orphaned ticket surfaced only when a downstream consumer of the ticketing system processed it 40 minutes later. No agent ever raised an error; every local invariant held. The failure was invisible to the swarm because **the lost acknowledgment was the only artifact linking the speculative branch to the real effect, and rollback destroyed it before the effect could be reconciled.** A second, subtler observation: the acknowledgment *did* eventually arrive—at t+1.9s, after rollback completed. The executor's response router had no live branch to attribute it to, so it dropped the message as "stale branch response." This is the reordering half of the failure: late acknowledgments arriving after their branch is gone are silently discarded, which is precisely the signal that would have flagged the orphan. ## Condition of Validity This failure mode is bounded by three conditions, all of which must hold for the orphan to occur: 1. **Optimistic execution with a finite speculative timeout shorter than the tool's tail latency.** If the speculative timeout exceeds the tool's p99 acknowledgment latency, the branch either sees the ack or times out cleanly before any real effect could plausibly have landed. The orphan window is `[T_spec_timeout, T_tool_ack]`—the interval during which the effect is real but the branch has already stopped waiting. 2. **Rollback that discards the local ledger without first draining in-flight or late acknowledgments.** If rollback quarantines pending entries and holds them for a reconciliation grace period (≥ tool p99 ack latency), the late ack can be matched and the effect either adopted or compensated with the *real* identifier. 3. **Compensation keyed on predicted rather than observed identifiers.** If the compensating call uses the branch's predicted effect handle (a UUID the branch generated) instead of the tool-assigned handle from the ack, the compensation misses the real effect entirely. If any condition fails—e.g., the tool is idempotent and keyed on a client-supplied idempotency token that the branch persists *outside* its rollback scope—the orphan cannot form, because the canonical ledger can dedupe against the surviving token. ## Decision Boundary The operational decision is: **when a speculative branch times out on a tool call, do you (a) treat it as "no effect" and roll back the ledger, or (b) treat it as "effect indeterminate" and quarantine the branch's pending entries until acknowledged or provably expired?** Choose (a) only when the tool is idempotent under a client-supplied token that outlives rollback. Choose (b) whenever the tool has externally-visible, non-idempotent side effects and its tail acknowledgment latency is not strictly bounded below the speculative timeout. The boundary is *not* "is the tool reliable"—it is **"can the branch prove the absence of an effect, or only fail to observe its presence?"** Absence of ack is not absence of effect. Any branch that rolls back on ack-timeout without a provable-absence mechanism is choosing (a) by default and is exposed. The reconciliation rule that follows: a branch may only be committed or rolled back to a *clean* canonical state if every one of its optimistic effects is either (i) confirmed by a matching canonical-ledger entry, or (ii) provably absent via an idempotency-token lookup against the tool's own record. "The branch's local ledger says pending" is never sufficient grounds for rollback. ## Operational Effect The architectural invariant required to bound this: **every optimistic tool invocation must emit a durable, rollback-external *intent record* keyed on a client-generated idempotency token, persisted before the call, and retained through and beyond rollback for at least the tool's p99 acknowledgment latency.** Rollback discards the branch's *speculative* state but must not discard intent records; reconciliation drains them, matching each against the canonical ledger by token. Orphan detection is then a structural query: intent records with no matching canonical entry and no provable-absence result are flagged as *unreconciled effects* and routed to a human or compensating agent with the real tool handle—not the predicted one. Practically, this converts an invisible orphan into a bounded, observable queue of unreconciled intents. The cost is a grace period during which a lost branch's effects are not yet cleaned up; the benefit is that no effect escapes provenance. Late acknowledgments arriving after rollback must be routed to the intent record by token, never dropped as "stale branch response"—that routing is the second half of the invariant, and dropping them is the silent-failure path observed above. ```python import time from dataclasses import dataclass, field from typing import Optional class UnreconciledEffectError(RuntimeError): """Raised when a speculative branch's optimistic effect cannot be proven absent from the canonical ledger after rollback.""" pass @dataclass class IntentRecord: token: str # client-generated idempotency token tool: str predicted_handle: Optional[str] = None observed_handle: Optional[str] = None acked: bool = False created_at: float = field(default_factory=time.monotonic) class SpeculativeBranch: def __init__(self, branch_id: str, spec_timeout: float, tool_p99_ack: float): self.branch_id = branch_id self.spec_timeout = spec_timeout self.tool_p99_ack = tool_p99_ack # Intent records survive rollback; speculative ledger does not. self.intents: dict[str, IntentRecord] = {} def invoke_optimistic(self, tool: str, token: str) -> IntentRecord: # Persist intent BEFORE the call so a lost ack still leaves provenance. rec = IntentRecord(token=token, tool=tool) self.intents[token] = rec return rec def rollback(self, canonical_ledger: dict[str, str]) -> None: # Grace period must cover tail ack latency, else late acks orphan. if self.spec_timeout < self.tool_p99_ack: for token, rec in self.intents.items(): if rec.acked: continue # Try to prove absence by token against the canonical ledger. if token in canonical_ledger: rec.observed_handle = canonical_ledger[token] continue # Cannot prove absence -> must not silently discard. raise UnreconciledEffectError( f"branch {self.branch_id} token {token} tool {rec.tool}: " f"no ack, no canonical entry, absence unprovable " f"(spec_timeout={self.spec_timeout}s < " f"tool_p99_ack={self.tool_p99_ack}s)" ) # Safe path: spec timeout covers tail latency; drain intents. self.intents.clear() def reconcile(branch: SpeculativeBranch, canonical_ledger: dict[str, str]) -> None: try: branch.rollback(canonical_ledger) except UnreconciledEffectError: # Route unreconciled intents to a compensating agent with real handles. raise ```