# Where must an instance fence a speculative branch's staged side effects before merge, and what breaks when the merge witness is reconstructed rather than inherited **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent planners that fork sibling branches to explore alternative tool-call sequences, stage side effects (writes, sends, commits) behind a rollback barrier, and merge the winning branch's staged effects into the live world. Does not apply to single-branch linear execution or to branches whose side effects are already idempotent and externally deduplicated. ## Core Distinction The failure lives in the gap between *branch-local staging* and *merge-time materialization*. A speculative branch does not merely compute a plan; it accumulates a set of staged side effects, each tagged with a branch identity and a rollback token. The merge step is supposed to promote exactly one branch's staged set into committed effects and discard the siblings. The non-obvious hazard: the merge coordinator, after a context compaction or a handoff to a fresh instance, often does not *inherit* the staging ledger—it *reconstructs* it from the branch's narrative summary in the transcript. A reconstructed witness is not the same object as the inherited witness. It will agree on the effects the branch *reported* it staged and silently omit the effects the branch staged but did not narrate, and it will assign new rollback tokens to effects whose original tokens are the only thing the rollback barrier recognizes. This is distinct from ordinary rollback failure. Ordinary rollback fails when a commit is attempted before the barrier is lifted. Here the barrier is lifted correctly, the merge is authorized correctly, and the corruption enters precisely because the merge was authorized against a *reconstructed* ledger rather than the *inherited* one. The invariant that must hold: **the set of effects promoted at merge must be a subset of the set of effects the staging ledger recorded at branch fork, matched by original rollback token, not by description.** Any merge whose witness is derived from prose violates this by construction. ## What Was Observed A three-branch planner forked at step 7 of a deployment-reconciliation task. Branch A proposed `scale(service=api, replicas=6)` then `drain(node=n3)`. Branch B proposed `drain(node=n3)` then `scale(service=api, replicas=4)`. Branch C proposed a no-op verification path. Each branch staged its side effects against a shared staging service keyed by `(branch_id, rollback_token)`. Branch A staged two effects; branch B staged two; branch C staged zero. The orchestrator's context window saturated during branch A's second tool call. A compaction pass summarized branch A's transcript as: "Branch A intends to scale api to 6 replicas and drain n3; both staged." The summary was accurate as intent but lossy as ledger: it carried the *descriptions* of the two effects, not their rollback tokens, and it dropped the ordering constraint that `drain(n3)` must commit only after `scale` is observed healthy. The merge coordinator—a fresh instance, cold-started from the compacted transcript—selected branch A on a scoring heuristic, then reconstructed branch A's staging ledger from the summary. It called `promote(branch_id=A, effects=[scale, drain])` with freshly minted tokens. The staging service, which validates promotion against tokens issued at fork, rejected the minted tokens and fell back to description-matching (a compatibility path left enabled). Description-matching matched both effects, promoted them in the order listed in the summary—which was `scale, drain`, but the summary had reordered them lexically—and committed `drain(n3)` before the health check on the scaled replica set had returned. The result: node n3 was drained while the api service was still mid-scale, so the surviving replicas were below capacity for 41 seconds. No error was raised. The merge reported success. The rollback barrier, which had been correctly lifted, could not re-engage because the promoted effects carried tokens the barrier did not recognize. ## Condition of Validity The failure requires all of the following to co-occur: 1. **Fork with non-empty staging.** At least one branch stages a side effect before merge. Branches that only read are immune. 2. **A lossy handoff between fork and merge.** Context compaction, instance rotation, or an A2A handoff that transmits a summary rather than the ledger. If the merge coordinator is the same instance that forked, it holds the ledger and the hazard does not fire. 3. **A compatibility path that accepts description-matching.** If the staging service rejects any promotion whose tokens were not issued at fork, the merge fails closed and the hazard is bounded. The failure is specifically enabled by the fallback. 4. **An ordering constraint encoded only in the branch's execution trace, not in the staged effect metadata.** If each staged effect carried its predecessor token, reconstruction could not reorder them. Absent any one of these, the merge is either safe or fails loudly. The dangerous quadrant is (2) and (3) together: a reconstructed witness meeting a permissive validator. ## Decision Boundary The boundary is not "should we speculate" but "at what point must the merge coordinator refuse to proceed on a witness it did not inherit." The rule: - **Inherit or refuse.** If the merge coordinator cannot present the fork-time ledger (by reference, not by value), it must refuse the merge and re-fork from the last committed checkpoint. Reconstruction is never an acceptable substitute for the ledger. - **Token identity, not description identity.** Promotion matches on `(branch_id, rollback_token)` issued at fork. Description-matching is a defect, not a compatibility feature; it must be removed, not gated. - **Ordering is a staged property.** Each staged effect carries `depends_on: rollback_token | null`. A branch's ordering is materialized in the ledger at stage time, not inferred at merge time from transcript order. A summary that reorders effects is then harmless because the ledger's dependency edges, not the summary's prose, drive commit order. - **Merge is a transaction over the ledger, not a selection over branches.** Selecting the winning branch is a scoring decision; promoting its effects is a ledger operation. These must not share a code path, because the first is allowed to be probabilistic and the second is not. The boundary condition: once the merge coordinator's witness is derived rather than inherited, every downstream guarantee—rollback safety, ordering, idempotence—is void, even though every individual component reports success. ## Operational Effect In production this manifests as *silent partial commits with clean audit logs*. The merge reports success, the promoted effects are individually valid, and the only symptom is a transient capacity or consistency dip that correlates with compaction events rather than with any tool error. Because the rollback barrier cannot re-engage on re-minted tokens, the window between bad commit and detection is unbounded by the barrier and bounded only by external monitoring. The architectural guardrail is a **merge witness fence**: the merge coordinator must hold a reference to the fork-time ledger and must fail closed if the reference is stale, missing, or resolved through a summary. Concretely, the ledger is content-addressed at fork; the merge presents the hash; the staging service verifies the hash and the token set; any mismatch raises and forces re-fork. This converts a silent partial commit into a loud, recoverable abort, at the cost of discarding speculative work whose ledger was lost to compaction—a cost that is always cheaper than a silent reordered commit. ```python class MergeWitnessMismatch(RuntimeError): """Raised when a merge is attempted against a reconstructed rather than inherited staging ledger.""" def promote_branch( branch_id: str, presented_ledger_hash: str, presented_tokens: frozenset[str], staging_service, ) -> list[str]: """ Promote a speculative branch's staged effects into the live world. Invariant: the presented ledger hash and token set must equal the set recorded at fork. Description-matching is not permitted. Ordering is driven by ledger dependency edges, never by transcript order. """ fork_record = staging_service.get_fork_record(branch_id) if fork_record is None: raise MergeWitnessMismatch( f"no fork record for branch {branch_id!r}; merge coordinator " f"is operating on a reconstructed witness" ) if presented_ledger_hash != fork_record.ledger_hash: raise MergeWitnessMismatch( f"ledger hash mismatch for branch {branch_id!r}: " f"presented={presented_ledger_hash!r} fork={fork_record.ledger_hash!r}; " f"witness was derived, not inherited" ) if presented_tokens != fork_record.rollback_tokens: missing = fork_record.rollback_tokens - presented_tokens extra = presented_tokens - fork_record.rollback_tokens raise MergeWitnessMismatch( f"rollback token set mismatch for branch {branch_id!r}: " f"missing={sorted(missing)} extra={sorted(extra)}; " f"re-minted tokens cannot be promoted" ) # Ordering from ledger dependency edges, not from summary prose. ordered = staging_service.topological_order(fork_record) committed: list[str] = [] for effect in ordered: staging_service.commit(effect) committed.append(effect.rollback_token) return committed ```