# What happens when an instance speculatively forks a plan branch and the reconciliation quorum adopts a sibling branch: silent orphaned side-effects and the speculative-commit invariant **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent planners that fork speculative plan branches (parallel tool-using subagents) and reconcile them via a vote/quorum before committing a canonical trajectory. Does not apply to single-threaded agents, or to branches that are executed in a purely read-only sandbox with no external side-effects. ## Core Distinction There are two ways a speculative branch can be "wrong" at reconciliation time. The **benign** case is a branch whose *reasoning* is discarded: its intermediate tokens, tool-call transcripts, and proposed final answer are dropped when a sibling branch wins the quorum. This is the case everyone designs for, and it is safe because the branch's *effects* are also dropped — the branch never touched the world. The **malignant** case, and the one this record concerns, is a branch whose *reasoning is discarded but whose side-effects are not*. A speculative branch is forked, begins executing tool calls with real external consequences (writes a file, sends an email, mutates a database row, opens a PR, calls a paid API that bills on success), and *then* loses the reconciliation vote. The reconciler adopts the sibling branch's trajectory and commits it as canonical. The losing branch is garbage-collected. Its side-effects remain in the world, un-referenced by any committed plan, invisible to the winning branch's subsequent steps, and — critically — invisible to the agent's own memory of what it did. The invariant that is violated is not "losing branches must not run." It is: **a side-effect may only be emitted by a branch that has already been granted commit authority, or the side-effect must be recorded in a reconciliation ledger that the commit step is obligated to replay or roll back.** Most implementations enforce neither, because the fork/join primitive is built on the assumption that branch execution is pure and reconciliation is a pure function over branch *outputs*. The moment a branch calls a tool with non-idempotent external effects, that assumption is false, and the failure is silent. ## What Was Observed A planner agent receives a task ("migrate the config schema and update the dependent services"). It forks three speculative branches — `B1`, `B2`, `B3` — each a subagent instance with its own context window and tool access. The fork is optimistic: all three begin executing immediately to reduce wall-clock latency, rather than serializing on the reconciler's decision. - `B1` proposes a rename-based migration and, as its second tool call, executes `write_file("config/schema.yaml", ...)` and `write_file("services/api/config.py", ...)`. Both succeed. - `B2` proposes an additive-migration approach and executes `write_file("config/schema_v2.yaml", ...)` plus a `db.migrate()` call against a staging database. - `B3` proposes a rollback-and-reapply approach and executes `git.branch("migration-tmp")` and a `write_file` to a scratch path. The reconciler scores the three trajectories. `B2`'s additive approach wins on a rubric that weights backward-compatibility. The reconciler commits `B2`'s trajectory: it records `B2`'s tool calls as the canonical action log, marks `B1` and `B3` as `REJECTED`, and hands control back to the planner to continue from `B2`'s terminal state. Now observe the world: - `config/schema.yaml` has been overwritten by `B1`. `B2`'s committed trajectory never wrote that file — it wrote `config/schema_v2.yaml`. The planner's subsequent step, which reads `config/schema.yaml` to verify the migration, reads `B1`'s rejected content and reasons about it as if it were `B2`'s output. **The agent's next decision is conditioned on a branch that lost the vote.** - `B3`'s `migration-tmp` branch exists in the repo. No committed step references it. It will be discovered hours later by a human, or by a `git branch --list` tool call in a *different* task, at which point the agent will treat it as pre-existing state. - `B1`'s write to `services/api/config.py` is the worst: it is a *partial* application of a rejected plan. The service now imports a schema that the committed plan never produced. The migration is half-`B1`, half-`B2`, and neither branch's post-conditions hold. The reconciler's action log — the artifact the agent uses as its episodic memory of the task — is internally consistent and completely wrong about the world. Every entry in it is a `B2` tool call. The world contains `B1` and `B3` effects. The divergence between "what the log says happened" and "what happened" is the failure. A second, subtler observation: the reconciler's vote was *not* unanimous and the margin was thin (`B2` scored 0.71, `B1` scored 0.68). In a re-run with a slightly different sampling temperature, `B1` won. The side-effects were identical either way — all three branches ran to completion regardless of who won — but the *committed* trajectory flipped. The system's external state after the task depends on the vote outcome only through the committed log, while the actual file contents depend on which branch's writes landed last. These are two independent random variables. The reconciliation protocol assumes they are the same variable. ## Condition of Validity The speculative-commit invariant holds only when **all** of the following are true for a forked branch: 1. **Effect isolation.** The branch's tool calls either (a) target a copy-on-write / transactional namespace that is discarded on rejection, or (b) are gated behind a commit token that the branch does not possess until it wins. If a branch can call a mutating tool before winning, the invariant is already broken. 2. **Ledger completeness.** Every side-effect emitted by any branch — winning or losing — is recorded in a reconciliation ledger keyed by branch id, with enough information to replay or invert it (target, prior value or a content hash, idempotency key). 3. **Commit-time reconciliation of the ledger.** The commit step is *obligated* to walk the ledger and, for every entry belonging to a rejected branch, either roll it back or explicitly promote it into the committed plan with a recorded justification. A commit that does not consult the ledger is a commit that has silently orphaned effects. 4. **Read-after-commit consistency.** Any subsequent step that reads external state must read through a view that reflects only committed effects, or must be preceded by a ledger reconciliation pass. Otherwise the next step conditions on orphaned state (the `config/schema.yaml` case above). The failure mode described here occurs precisely when condition 1 is false (branches run optimistically) and condition 3 is absent (the reconciler commits the winning log without consulting a ledger). Condition 2 is usually present in sophisticated systems — the tool-call trace is logged — but the log is treated as *telemetry*, not as an *obligation*. The distinction is the whole article: a trace you can read is not a ledger you must reconcile. ## Decision Boundary The boundary is **whether a branch's tool call is classified as `SPECULATIVE_EFFECT` or `COMMITTED_EFFECT` at emission time, and whether the reconciler treats `SPECULATIVE_EFFECT` entries as dischargeable obligations.** - If a tool is classified `COMMITTED_EFFECT` (e.g., `send_email`, `db.migrate`, `git.push`), it must be gated: the branch blocks on a commit token, and the reconciler grants the token to exactly one branch before any such call executes. This serializes the expensive part and defeats the latency purpose of speculation — which is correct, because you cannot speculatively send an email. - If a tool is classified `SPECULATIVE_EFFECT` (e.g., `write_file` to a sandboxed path, `db.migrate` against a disposable staging instance), it may run optimistically, but the reconciler must, at commit time, discharge every rejected branch's ledger entries by rollback or promotion. A rejected `write_file` to a shared path is not "discarded reasoning"; it is a dirty write that the commit step owns. - The dangerous middle is a tool that is *classified* `SPECULATIVE_EFFECT` but *targets* shared state — `write_file("config/schema.yaml")` where the path is the real config, not a per-branch overlay. Classification must be by *target*, not by *verb*. A `write_file` to a branch-local overlay is speculative; the same verb to a shared path is committed. Systems that classify by tool name rather than by resolved target will misclassify exactly the calls that matter. The decision the engineer must make is not "should we speculate" but "for each tool, is the target branch-local or shared, and does the reconciler discharge rejected-branch effects on shared targets?" If the answer to the second is "no," the system must not speculate on that tool at all. ## Operational Effect In production, this failure presents as **non-reproducible state divergence**: the agent's action log says the task succeeded, the post-condition check (if any) passes because it checks the committed branch's artifacts, and yet the repository / database / filesystem contains residue from rejected branches. The residue is discovered later — by a human, by a `git status` in a subsequent task, or by a CI job that fails on an unexpected file — and is attributed to "flaky tooling" rather than to the reconciliation protocol. The agent, on its next cold start, reads the residue as pre-existing environment state and reasons from a false premise. The compounding effect is the serious one. Because the agent's episodic memory (the action log) is consistent with the committed branch but inconsistent with the world, every subsequent retrieval and every subsequent plan is built on a memory that is *internally coherent and externally false*. This is the worst kind of stale memory: not a gap the agent can detect, but a confident, well-formed, wrong account of what it did. The agent will not flag uncertainty, because from its perspective nothing uncertain happened — it has a clean log. The guardrail is the ledger-as-obligation pattern: fork with per-branch effect namespaces where possible; where not possible, record every side-effect with an idempotency key and a prior-value snapshot; and make the commit step *fail closed* if the ledger contains undis­charged entries from rejected branches. A reconciler that cannot prove it has accounted for every rejected branch's effects must refuse to commit, not commit optimistically. The cost of a refused commit is a retry; the cost of an undis­charged commit is a silent, compounding divergence between the agent's memory and the world. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ReconciliationError(RuntimeError): """Raised when a commit cannot be proven safe against the effect ledger.""" pass class EffectClass(Enum): SPECULATIVE = "speculative" # branch-local target; safe to run before commit COMMITTED = "committed" # shared target; must be gated on commit token @dataclass class LedgerEntry: branch_id: str tool: str target: str prior_value_hash: Optional[str] idempotency_key: str effect_class: EffectClass discharged: bool = False @dataclass class ReconciliationLedger: entries: list[LedgerEntry] = field(default_factory=list) def record(self, entry: LedgerEntry) -> None: self.entries.append(entry) def undischarged_for(self, branch_id: str) -> list[LedgerEntry]: return [ e for e in self.entries if e.branch_id == branch_id and not e.discharged ] def commit_branch( winning_branch: str, all_branches: list[str], ledger: ReconciliationLedger, ) -> None: """ Commit the winning branch's trajectory only if every rejected branch's speculative effects have been discharged (rolled back or promoted). This is the guardrail: a commit that cannot account for rejected-branch effects must fail closed, not commit optimistically. """ rejected = [b for b in all_branches if b != winning_branch] # Gate: committed-class effects must never have been emitted by a # rejected branch (they should have blocked on the commit token). for b in rejected: for e in ledger.undischarged_for(b): if e.effect_class is EffectClass.COMMITTED: raise ReconciliationError( f"Rejected branch {b!r} emitted committed-class effect " f"{e.tool}->{e.target} (key={e.idempotency_key}) before " f"winning commit token. Invariant violated at emission, " f"not reconcileable here." ) # Obligation: every speculative effect from a rejected branch must be # discharged before the winning branch's log can be treated as canonical. orphans = [ e for b in rejected for e in ledger.undischarged_for(b) ] if orphans: detail = ", ".join( f"{e.branch_id}:{e.tool}->{e.target}" for e in orphans ) raise ReconciliationError( f"Cannot commit {winning_branch!r}: {len(orphans)} orphaned " f"speculative effect(s) from rejected branches remain: {detail}. " f"Roll back or promote each before commit; the action log would " f"otherwise diverge from the world." ) # Safe to commit: ledger is clean for all rejected branches. return None ```