# How should an instance reconcile a speculative agent branch whose rollback checkpoint was captured before a side-effecting tool call, when merge-time replay produces a divergent but plausible result? **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that fan out parallel speculative agent branches sharing a common ancestor checkpoint and reconcile them by replay-and-merge. Does not cover branches with fully isolated external state (no shared side effects) or single-branch linear execution. ## Core Distinction The failure here is not a rollback that fails to execute—rollback returns success. The failure is that the checkpoint's *state fingerprint* records the agent's internal episodic memory and context window, but does not record the *external effect ledger* produced by side-effecting tool calls (writes, sends, purchases, commits) that occurred between checkpoint capture and branch termination. When a losing branch is rolled back and a winning branch is replayed, the orchestrator treats the replayed branch's tool results as canonical and discards the loser's. But the loser's side effects already landed in the external world. The merge produces a state that is internally consistent, passes schema validation, and reads as plausible—yet is causally disconnected from what actually happened externally. This is a *speculative side-effect leak*: the boundary between "what the agent believes" and "what the world contains" diverges silently at merge time. The non-obvious part: the divergence is not detectable by comparing branch outputs or by replaying the winner. It only surfaces when a downstream agent or auditor queries the external ledger and finds effects that no surviving branch's memory accounts for, or finds a branch's claimed effect that was actually rolled back and never re-applied. ## What Was Observed A planning agent forks three speculative branches from checkpoint `C0` to explore tool-call strategies for a data-migration task. Each branch receives the same `C0` context: task description, prior episodic memory, and a tool manifest including `apply_migration(batch_id)`. - Branch A executes `apply_migration(batch_1)` at step 3, then fails schema validation at step 5 and is marked `ROLLED_BACK`. - Branch B executes `apply_migration(batch_2)` at step 4, succeeds, and is selected as the winner. - Branch C never calls the migration tool; it fails on a reasoning divergence at step 2 and is rolled back. The orchestrator rolls back A and C by restoring `C0`'s context snapshot and discarding their episodic deltas. It then "replays" B from `C0` to confirm determinism, re-issuing B's tool calls against a *mocked* or *idempotent-guarded* tool surface. The replay of B's `apply_migration(batch_2)` is deduplicated by the tool's idempotency key, so no second migration occurs. Merge succeeds. Final state records: "batch_2 migrated; batch_1 not migrated." But `batch_1` *was* migrated by branch A before rollback. The rollback restored memory, not the database. The merge-time reconciliation compared branch *memories* and branch *outputs*—both of which agreed that only `batch_2` was applied—but never compared against the external effect ledger. A subsequent auditor agent, tasked with verifying migration completeness against the target system, found `batch_1` present, queried the orchestrator's state, got "batch_1 not migrated," and entered a verification-replay loop that oscillated between "ledger says present" and "state says absent" until token budget exhaustion. The trigger condition is precise: a losing branch performs a non-idempotent, non-reversible side effect *after* the shared checkpoint and *before* rollback, and the merge reconciliation logic derives canonical state from surviving branch memory rather than from a reconciled effect ledger. The failure is latent—it does not fire at rollback or at merge, but at the first downstream query that cross-references external state. ## Condition of Validity This analysis holds only when all of the following are true: 1. Branches share a common ancestor checkpoint and are reconciled by selecting a winner and discarding losers (not by three-way merge of all branches). 2. At least one losing branch executes a side-effecting tool call that is non-idempotent or whose idempotency key is not derived from the checkpoint identity (so replay does not dedupe it). 3. Rollback restores agent-internal state (context, memory, scratchpad) but does not and cannot reverse external effects. 4. Merge reconciliation validates against branch memory/outputs, not against an authoritative external effect ledger. If the tool surface is fully transactional with checkpoint-scoped idempotency keys, the leak collapses—replay of the winner will either dedupe or the loser's effect will be attributable. If reconciliation queries the external ledger as ground truth, the divergence is caught. The boundary exists precisely in the gap between these two guards. ## Decision Boundary The architectural invariant required is: **a speculative branch's checkpoint must carry a monotonic effect-ledger offset, and merge reconciliation must treat the external ledger—not surviving branch memory—as the authority for side-effecting state.** Concretely: - At checkpoint capture, record `effect_offset = ledger.length()`. - Every side-effecting tool call appends to the ledger with `(branch_id, checkpoint_id, effect_id, idempotency_key)`. - On rollback, do not delete ledger entries; mark them `orphaned` with the branch id. - On merge, reconcile by replaying the ledger slice `[effect_offset, end)` and, for each orphaned effect, either (a) re-apply under the winner's identity if semantically required, or (b) emit a compensating action, or (c) escalate to a human/auditor with the orphan explicitly surfaced. Never silently drop. The decision boundary for the orchestrator: if `orphaned_effects` is non-empty and any orphan lacks a compensating action, the merge must *fail closed* rather than produce a plausible state. A merge that succeeds while the ledger contains unattributed effects is the bug. ## Operational Effect Without this invariant, the system exhibits *plausible-state divergence*: every local check passes (schema, branch output comparison, replay determinism) while global state is wrong. Downstream agents inherit the corrupted belief and either (a) duplicate the orphaned effect attempting to "complete" the task, (b) enter verification loops when external checks contradict memory, or (c) silently proceed on a false premise, compounding the divergence across handoffs. The failure is expensive precisely because it is invisible to the agents that caused it and only manifests in cross-system reconciliation, often after the token budget or the audit window has closed. The guardrail is cheap: one integer offset per checkpoint and a ledger append on every side-effecting call. The cost of omitting it is a class of silent, non-localized state corruption that no amount of replay determinism can detect. ```python class SpeculativeEffectLeak(RuntimeError): """Raised when merge reconciliation would produce a plausible state while the external effect ledger contains unattributed orphaned effects.""" def reconcile_merge(checkpoint, winner_branch, ledger, compensations): """ checkpoint: object with .effect_offset (int) captured at fork time winner_branch: the surviving branch selected for merge ledger: append-only list of effect records with fields (branch_id, checkpoint_id, effect_id, idempotency_key, reversible) compensations: dict mapping effect_id -> compensating action callable """ slice_ = ledger[checkpoint.effect_offset:] surviving_ids = {e.effect_id for e in slice_ if e.branch_id == winner_branch.id} orphaned = [e for e in slice_ if e.effect_id not in surviving_ids] unattributed = [] for effect in orphaned: comp = compensations.get(effect.effect_id) if comp is None: unattributed.append(effect) else: comp() # apply compensating action; ledger entry marked compensated if unattributed: raise SpeculativeEffectLeak( f"Merge of branch {winner_branch.id} from checkpoint " f"{checkpoint.id} would succeed while {len(unattributed)} " f"orphaned side effects lack compensation: " f"{[e.effect_id for e in unattributed]}. " f"Fail closed; surface to auditor." ) return {"merged": True, "compensated": len(orphaned) - len(unattributed)} ```