Why does an instance diverge from its own rolled-back branch after speculative multi-agent execution?

**Date of Record:** 2026 December 2 **Scope:** Applies to any orchestration where one or more worker agents execute speculatively on a forked branch of state (context + tool-side effects) and the branch is later either committed or rolled back and reconciled against a sibling/authoritative branch. Does not cover single-agent retries with no shared mutable external state, nor stateless request/response tool calls with no side effects.

Core Distinction

The failure is not "rollback didn't happen." Rollback of *declared* state almost always happens. The failure is that an agent's **identity of belief** is anchored to the branch it executed on, not to the state it was rolled back to. When a speculative branch is discarded, the orchestrator restores the checkpointed context and external side effects, but the agent instance that ran the speculation retains *derived* state that was never checkpointed: KV/attention residue, cached tool outputs, in-context "I already did X" assertions, and — critically — a divergent *self-model of progress*. On reconciliation, the instance reasons from a history that the authoritative branch does not contain. This is **branch-memory skew**: the instance is internally consistent with a branch that no longer exists.

The non-obvious part: skew is not proportional to how much the branch did. A branch that performed a single cheap read and then rolled back can produce *more* skew than a long branch, because a long branch's side effects are visible and get explicitly reconciled, while a single read leaves an un-audited "I know the value of X" belief that survives rollback and silently overrides a re-fetch.

What Was Observed

A planner forked three speculative workers (`W_a`, `W_b`, `W_c`) from a common checkpoint `C0` to resolve a schema question in parallel. `W_b` failed a downstream validation, so the orchestrator rolled back to `C0`, committed `W_a`'s branch, and asked `W_b` to "reconcile with the committed branch and continue."

`W_b` did not re-derive. Its post-rollback context was restored to `C0`'s token sequence, but its tool-result cache still held the value it had fetched on the discarded branch — a schema version `v3` that the authoritative branch had since resolved to `v2`. `W_b` emitted a plan referencing `v3`, the orchestrator accepted it because the plan was internally coherent, and the divergence surfaced only three hops later when a write tool rejected the version.

The trace signature was specific and reproducible:

  1. Rollback restores context tokens to `C0` — correct.
  2. Rollback restores external side effects to `C0` — correct.
  3. Rollback **does not** invalidate the instance's tool-result cache, its "already-known facts" scratchpad, or its progress counter.
  4. Reconciliation prompt assumes the instance is at `C0`; the instance is actually at `C0 + {derived beliefs from discarded branch}`.
  5. The instance answers the reconciliation prompt from the union, weighting its own prior belief higher than the freshly supplied authoritative value because the prior belief is *in-context* and the authoritative value arrives as an *instruction to overwrite*.
  6. Divergence is silent until a downstream tool enforces the invariant.

The skew is directional: instances systematically prefer their discarded-branch belief over the reconciled truth, because overwriting an in-context fact requires the model to treat a later instruction as authoritative over its own remembered action, and that is exactly the operation probabilistic reasoners are least reliable at.

Condition of Validity

The guardrail below is valid only when the following hold. Outside them, branch-memory skew is dominated by other failure modes and this record does not apply.

If the orchestrator destroys `W_b` and spawns a cold instance from the committed branch, the skew is zero by construction — you trade skew for cold-start amnesia, which is a different, well-understood cost. The invariant that matters is: **a rollback that does not reset derived state is not a rollback; it is a merge with an unacknowledged source.**

Decision Boundary

The boundary is between *reusing* a rolled-back instance and *replacing* it. Decide as follows:

The hard rule: **derived state must be part of the checkpoint, or the instance must not survive the rollback.** There is no middle setting that is safe under probabilistic reasoning.

Operational Effect

When branch-memory skew is left unbounded, the observable signature is a *late, coherent, wrong* commit: the instance's plan is internally consistent, passes local validation, and fails only where a tool enforces the invariant the branch violated. This shifts detection from reconciliation time (cheap) to execution time (expensive, and often after partial external writes). The blast radius is proportional to how far the divergent plan runs before a tool catches it, not to how much the branch did.

Bounding it changes the cost profile: you pay cold-start or explicit-invalidation cost at every rollback, and in exchange every rollback is a true reset. The invariant to enforce in the orchestrator is a **rollback completeness assertion**: after restore, assert that the instance's known-facts set is a subset of the committed branch's facts. Any fact outside that subset is skew and must force replacement, not instruction.

from dataclasses import dataclass, field
from typing import FrozenSet


class BranchMemorySkewError(RuntimeError):
    """Raised when a rolled-back instance retains derived state not present
    in the committed branch, i.e. a rollback that was actually a silent merge."""


@dataclass
class InstanceState:
    instance_id: str
    checkpoint_id: str
    known_facts: FrozenSet[str] = field(default_factory=frozenset)
    tool_cache: dict = field(default_factory=dict)
    progress_counter: int = 0


def reconcile_after_rollback(
    instance: InstanceState,
    committed_facts: FrozenSet[str],
    committed_checkpoint_id: str,
) -> InstanceState:
    """Reconcile a speculatively-executed instance against the committed branch.

    A safe reconciliation requires that every derived-state channel be reset to
    the committed branch. If any in-context fact survives that the committed
    branch does not contain, the instance is skewed and must be replaced.
    """
    if instance.checkpoint_id != committed_checkpoint_id:
        raise BranchMemorySkewError(
            f"instance {instance.instance_id} is anchored to checkpoint "
            f"{instance.checkpoint_id!r}, but commit is {committed_checkpoint_id!r}; "
            "context restore did not match the authoritative branch"
        )

    skew = instance.known_facts - committed_facts
    if skew:
        # Instruction-based overwrite would hide this; we refuse it instead.
        raise BranchMemorySkewError(
            f"instance {instance.instance_id} retains {len(skew)} derived fact(s) "
            f"absent from committed branch {committed_checkpoint_id!r}: "
            f"{sorted(skew)}. Rollback was a silent merge; replace the instance."
        )

    if instance.tool_cache:
        raise BranchMemorySkewError(
            f"instance {instance.instance_id} still holds {len(instance.tool_cache)} "
            "cached tool result(s) from the discarded branch; cache is not "
            "covered by the checkpoint and must be cleared atomically with restore"
        )

    # Only reached when every derived channel is provably reset.
    return InstanceState(
        instance_id=instance.instance_id,
        checkpoint_id=committed_checkpoint_id,
        known_facts=committed_facts,
        tool_cache={},
        progress_counter=0,
    )