# What structural signals indicate a speculative branch has outlived its reconciliation window in multi-agent rollback **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fan out speculative agent branches which issue optimistic (uncommitted) side-effecting tool calls and later reconcile by replaying a winning branch. Does not apply to branches whose tool calls are all read-only, nor to single-agent retry loops with no cross-branch state. ## Core Distinction Speculative multi-agent execution is usually modeled as "draft in parallel, pick the winner, discard the rest." That model is wrong for any branch that has *already mutated external state* through an optimistic tool call. The real invariant is not *which branch wins* but *whether every losing branch's side effects are still reversible at the moment the winner is committed*. A branch does not fail when it loses the race; it fails when it loses the race *after* its optimistic effects have crossed a point of no return — a sent email, an appended ledger row, a provisioned resource with a lease — while the reconciler still believes the branch is a pure draft. The non-obvious boundary: reconciliation correctness is bounded by a **window**, not by a boolean. The reconciler treats branches as either "live" or "discarded," but a branch is genuinely in a third state — *committed-but-unreconciled* — for the interval between its first irreversible tool call and the arrival of the winner's commit signal. Signals that a branch has silently exited this window are structural, not semantic: they appear in token/step counters, tool-call sequence numbers, and lease timestamps, not in the branch's own reasoning trace. ## What Was Observed A three-branch speculative fan-out (branches A, B, C) drafting a remediation plan against a shared ticketing backend. Each branch was granted an optimistic `apply_patch` tool whose contract was "stage only; commit gated on reconciliation." The tool wrapper, however, auto-flushed staged patches after a 30-second idle timer to bound memory — a behavior inherited from the underlying client and never surfaced in the tool schema the agents negotiated over MCP. Trace of the failure: 1. Branch A issued `apply_patch` at step 4 and then diverged into a long verification subtrace, emitting no further tool calls for 41 seconds. 2. At T+30s the wrapper flushed A's patch to the ticket backend. A's local state still recorded the patch as `staged`. 3. Branch B won reconciliation at T+38s. The reconciler issued `discard` to A and C and `commit` to B. 4. A's `discard` returned `ok` — the wrapper had nothing staged to discard, because it had already flushed. The discard was a no-op that reported success. 5. The backend now held A's patch *and* B's patch. B's commit conflicted on the same field; the backend resolved last-writer-wins and silently dropped B's intended change in favor of A's abandoned one. The structural signals present at step 4, all observable before the corruption: - A's **step counter advanced while its tool-call sequence number froze**. Progress was reported as reasoning tokens, not effects. A branch consuming budget without emitting tool calls is the canonical signature of a branch drifting toward or past its reconciliation window. - A's **lease heartbeat diverged from its flush timer**. The lease (held on the reconciler) said "A is live and reversible." The wrapper's idle timer said "A is flushable." Two independent clocks disagreed about the same branch's reversibility. - The `discard` acknowledgement **carried no effect-identifier**. A correct discard returns the set of effect IDs it rolled back; A returned an empty set with `ok`, which is indistinguishable from "nothing to roll back" and from "already flushed." The reconciler had no invariant tying "discard succeeded" to "no effects of this branch exist in the backend." It trusted the boolean. ## Condition of Validity The optimistic-draft model is valid only while, for every live branch, the following holds at every reconciliation decision point: > `first_irreversible_effect(branch) == None` **OR** `reconciler_clock(branch) < flush_deadline(branch)` **AND** `discard(branch)` returns the exact effect-ID set that `apply(branch)` emitted. This is a conjunction of three conditions, and the failure above violated all three simultaneously while every individual tool call returned success. The invariant must be enforced *structurally* — the reconciler must be able to prove reversibility from metadata it owns, not from the branch's self-report. Concretely: - Every optimistic tool call must emit a **monotonic effect ID** and register it with the reconciler *before* the call executes, so the reconciler's ledger is a superset of what any branch believes it has done. - Any timer that can flush, commit, or expire staged effects must be **owned by the reconciler**, or must emit a `flush` event that the reconciler consumes to mark the branch `committed-but-unreconciled` — never left inside a tool wrapper. - `discard` must be **effect-ID-complete**: it either returns the set of IDs it reverted or raises. An empty-set `ok` on a branch with a non-empty applied-ID set is a hard error, not a success. A branch that violates the window is not a losing branch; it is a **zombie commit** — its effects are live but its vote is void. Zombie commits cannot be resolved by re-running reconciliation, because the winning branch's commit may already have been overwritten. They must be resolved by replaying the effect ledger in ID order and re-applying the winner. ## Decision Boundary The orchestrator must decide, at the moment a branch's tool-call sequence number stalls while its step counter advances, whether to **preempt** (force the branch to declare its effect set and either commit or discard before the flush deadline) or **demote** (mark the branch `committed-but-unreconciled` and forbid it from winning). The boundary condition: - **Preempt** if `flush_deadline - now > reconciliation_p99`. There is time to force a clean declaration. - **Demote** if the branch has crossed its flush deadline, or if its applied-effect-ID set is non-empty and its discard has not been acknowledged with a complete ID set. A demoted branch can still *win* the draft comparison, but its effects must be re-applied through the reconciler rather than trusted in place. The wrong default — and the one that produced the incident — is to treat a stalled branch as simply "slow" and let reconciliation proceed on the assumption that the loser's effects are still staged. Latency is not the signal; the divergence between step counter and effect counter is. ## Operational Effect After enforcing the invariant, speculative fan-out gains a hard bound: no branch can commit an effect the reconciler cannot enumerate, and no discard can report success without naming what it reverted. The cost is that stalled branches are preempted rather than allowed to finish reasoning — a real loss of draft quality when a branch is mid-verification. The benefit is that the reconciler's view of the world is always a superset of any branch's, so a zombie commit becomes detectable at the moment of discard rather than at the next conflicting write. The durable lesson: in speculative execution, **"discard succeeded" is not evidence of reversibility**. Only an effect-ID-complete acknowledgement plus a reconciler-owned clock is. Any wrapper that can flush, expire, or commit on its own timer is a branch that has left the reconciliation window without telling the orchestrator — and the structural tell is a frozen tool-call counter behind an advancing step counter. ```python import time from dataclasses import dataclass, field from typing import Optional class ZombieCommitError(RuntimeError): """Raised when a branch's optimistic effects are live but unreconciled.""" @dataclass class Branch: name: str step_counter: int = 0 last_tool_seq: int = 0 applied_effect_ids: set = field(default_factory=set) discarded_effect_ids: set = field(default_factory=set) flush_deadline: Optional[float] = None lease_held: bool = True def check_reversibility(branch: Branch, now: float, reconciliation_p99: float) -> str: """Return 'preempt', 'demote', or 'safe'. Raise on unrecoverable zombie.""" stalled = branch.step_counter > 0 and branch.last_tool_seq == 0 behind_flush = branch.flush_deadline is not None and now >= branch.flush_deadline if branch.applied_effect_ids and branch.discarded_effect_ids == branch.applied_effect_ids: return "safe" # fully reverted, effect-ID-complete if behind_flush and branch.applied_effect_ids - branch.discarded_effect_ids: # Effects are live, deadline passed, discard incomplete: zombie. missing = branch.applied_effect_ids - branch.discarded_effect_ids raise ZombieCommitError( f"branch {branch.name!r} crossed flush deadline with live effects {sorted(missing)}; " f"reconciler must replay ledger in ID order, not trust discard" ) if stalled: remaining = (branch.flush_deadline or now) - now if remaining > reconciliation_p99: return "preempt" return "demote" return "safe" def reconcile(branches, winner: str, now: float, p99: float) -> None: for b in branches: if b.name == winner: continue verdict = check_reversibility(b, now, p99) if verdict == "demote": b.lease_held = False elif verdict == "preempt": # force branch to declare effect set before proceeding b.last_tool_seq = max(b.last_tool_seq, 1) ```