# Under what conditions must an instance refuse rollback of a speculative subagent branch after its side effects have escaped the sandbox **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrator instances that fan out speculative subagents (parallel branch execution with a designated commit/abort decision) where branches may call tools with externally observable side effects. Does not apply to pure-computation branches whose effects are confined to orchestrator-owned memory and can be discarded by reference drop. ## Core Distinction A speculative branch is *rollbackable* only if its entire effect set is a subset of orchestrator-owned, garbage-collectable state. The moment a branch performs an irreversible external action—an outbound email, a database write without a compensating transaction, a payment authorization, a filesystem append outside a mounted scratch volume—the branch is no longer speculative in the transactional sense. It is *committed-by-accident*. The distinguishing invariant is not "did the branch return a divergent outcome" but "did the divergent branch already cross the effect boundary before the divergence was detected." Most rollback designs conflate two orthogonal properties: outcome divergence (the branch's result disagrees with siblings) and effect containment (the branch's actions are reversible). The failure mode lives in the quadrant where divergence is true and containment is false. An orchestrator that treats "abort on divergence" as a uniform operation will silently attempt to roll back a branch whose effects are already outside its authority, producing a state that is neither the speculative result nor the pre-branch baseline. ## What Was Observed An orchestrator dispatched three subagents to resolve a customer refund request against a shared ticket system. Branch A (fast path) read the ticket, computed a refund of $40, and called `issue_refund(ticket, 40)`. Branch B (verification path) independently computed $140 by reading a line-item table that Branch A had failed to fetch. Branch C returned $140 as well. The orchestrator's divergence detector fired on the 40-vs-140 split, majority-voted for $140, and issued a rollback directive to Branch A. Branch A's rollback handler looked for a compensating action. None existed: `issue_refund` had already settled at the payment processor, and the tool exposed no reversal primitive. The orchestrator, treating the rollback directive as a boolean, marked Branch A as rolled back and proceeded to commit Branch B's $140 result. The ticket now reflected a $140 refund while the processor had disbursed $40. The reconciliation job flagged the discrepancy nine hours later; by then the customer had been paid twice for the same line item. The critical observation: the divergence was detected *after* the effect boundary. Branch A's tool call returned a success token, and the orchestrator's divergence check ran on the *aggregated* branch results, which are only available after tool execution completes. There was no pre-effect gate. The rollback primitive assumed a transactional substrate that did not exist. A second, subtler trace: in a retry, the orchestrator re-dispatched Branch A from its last checkpoint. Because the checkpoint was taken before the tool call, the re-dispatch re-issued the refund. The rollback handler, now aware it could not reverse, had been patched to "skip" the rollback—so the orchestrator recorded one branch outcome but executed the side effect twice. Idempotency keys were absent from the tool schema, so the processor honored both calls. ## Condition of Validity Rollback of a divergent speculative branch is valid if and only if all of the following hold at the moment the rollback directive is issued: 1. **Effect closure:** Every tool invocation made by the branch is registered in the orchestrator's effect ledger with an explicit reversibility classification (`reversible`, `compensable`, `irreversible`). Unregistered tool calls are treated as `irreversible` by default. 2. **Pre-effect gate:** The divergence detector's decision point precedes the first `irreversible` effect. In practice this means either (a) branches are required to propose effects and await a commit token, or (b) divergence is detected by a mid-flight monitor that can interrupt before the effect completes. 3. **Compensation availability:** For `compensable` effects, a named compensating action exists in the tool schema and has been exercised at least once in a dry run. 4. **Idempotency binding:** Every effect carries a key derived from `(branch_id, effect_ordinal, intent_hash)`, so a re-dispatch after a failed rollback cannot duplicate the effect. If any condition fails, the correct behavior is not rollback but **escalation**: the orchestrator must halt the commit path, mark the branch `effect_escaped`, and surface the divergent state to a human or a higher-authority arbiter. Silent rollback in the absence of these conditions is the defect. ## Decision Boundary The orchestrator must evaluate, per divergent branch, the predicate `rollback_safe(branch)`. The boundary is sharp: - If `rollback_safe` is true, execute rollback and continue the speculative commit path with the surviving majority. - If `rollback_safe` is false, the branch transitions to `effect_escaped`. The orchestrator must **not** commit the majority result as if the divergent branch never ran, because the escaped effect is now part of the real world and the majority result may be inconsistent with it. The commit must be conditioned on reconciliation: either the escaped effect is reconciled into the final outcome, or the whole task is aborted with the escaped effect reported as a partial completion. The non-obvious part: majority vote is *not* a valid reconciliation strategy once an effect has escaped. In the observed incident, majority ($140) was correct as a computation but wrong as a committed outcome, because the world already contained a $40 disbursement. The invariant is that **the committed outcome must be a function of both the winning branch's result and the set of escaped effects**, not the winning branch's result alone. A second boundary: the orchestrator must distinguish "divergence detected before effect" from "divergence detected after effect" in its logs. Conflating them makes the rollback safety predicate unevaluable post hoc, and prevents the reconciliation job from reconstructing what actually happened. ## Operational Effect Enforcing the pre-effect gate changes the fan-out protocol: branches can no longer call irreversible tools directly. They emit effect *proposals*, and the orchestrator issues commit tokens only after divergence resolution. This adds one round trip per irreversible effect and requires tool schemas to declare reversibility. In exchange, the rollback path becomes sound: a divergent branch is either rolled back cleanly (no effect) or escalated (effect escaped, reconciliation required), with no third state. The idempotency binding closes the retry-duplication hole: re-dispatching a branch after a failed rollback reuses the same effect keys, and the tool layer rejects duplicates. This is the cheapest guardrail and should be mandatory even when the pre-effect gate is not yet deployed. Finally, the reconciliation job must consume the effect ledger, not just the branch outcome log. The ledger is the authoritative record of what the world now contains; the outcome log is the authoritative record of what the orchestrator believed. Divergence between the two is the signal that a rollback was attempted on an escaped effect, and it must page an operator rather than resolve silently. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, List, Optional class Reversibility(Enum): REVERSIBLE = "reversible" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class RollbackUnsafeError(RuntimeError): """Raised when a divergent branch cannot be rolled back because its effects have escaped the orchestrator's authority.""" pass @dataclass class Effect: branch_id: str ordinal: int tool: str reversibility: Reversibility intent_hash: str committed: bool = False @property def idempotency_key(self) -> str: return f"{self.branch_id}:{self.ordinal}:{self.intent_hash}" @dataclass class Branch: branch_id: str result: object effects: List[Effect] = field(default_factory=list) class Orchestrator: def __init__(self, majority_result: object): self.majority_result = majority_result self.effect_ledger: Dict[str, Effect] = {} def _escaped_effects(self, branch: Branch) -> List[Effect]: return [e for e in branch.effects if e.committed] def rollback_safe(self, branch: Branch) -> bool: escaped = self._escaped_effects(branch) if not escaped: return True # Any committed irreversible effect means rollback is unsafe. for e in escaped: if e.reversibility is Reversibility.IRREVERSIBLE: return False if e.reversibility is Reversibility.COMPENSABLE: # Compensable only if a compensating action is registered. if not self._has_compensation(e): return False return True def _has_compensation(self, effect: Effect) -> bool: # Placeholder: real implementation consults tool schema registry. return False def resolve_divergence(self, branches: List[Branch]) -> object: divergent = [b for b in branches if b.result != self.majority_result] for b in divergent: if not self.rollback_safe(b): escaped = self._escaped_effects(b) raise RollbackUnsafeError( f"branch {b.branch_id} has {len(escaped)} escaped effect(s); " f"cannot roll back. Escalating for reconciliation. " f"keys={[e.idempotency_key for e in escaped]}" ) # Safe: drop branch state and continue. for e in b.effects: e.committed = False return self.majority_result ```