# How does an instance detect rollback invalidation when speculative sibling branches share a non-idempotent side effect channel? **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that fan out speculative sibling agent branches against the same tool surface and reconcile by rollback-on-divergence. Does not apply to read-only tool surfaces, single-branch execution, or branches whose tools are provably idempotent under a stable idempotency key. ## Core Distinction Speculative multi-agent execution assumes divergence is *recoverable* because a losing branch can be rolled back to a pre-divergence checkpoint. This holds only when the side effects a branch produced are either (a) captured in the checkpointed state, or (b) externally reversible via a compensating action the orchestrator can issue. The non-obvious boundary is the third case: a tool call whose *observable output* is deterministic enough for the branch to commit against, but whose *side effect* is non-idempotent and outside the checkpoint boundary. Two speculative siblings can each "succeed" against such a tool, the reconciler picks one winner, and the loser's side effect survives rollback because nothing in the checkpoint graph ever recorded that it happened. The failure is not "rollback failed." Rollback succeeds perfectly against its own model of state. The failure is that the model of state was incomplete at the moment the checkpoint was taken, and the incompleteness is invisible to the reconciler because the tool reported success. ## What Was Observed An orchestrator spawned three speculative branches (A, B, C) to resolve a single task: "provision a staging environment and attach a TLS certificate." Each branch ran an independent planner. All three called `provision_env(env_id)` and `issue_cert(env_id)` against a shared tool gateway. The gateway is idempotent on `provision_env` (keyed by `env_id`) but **not** on `issue_cert`, which mints a fresh certificate serial on every invocation and rate-limits at 2 per env per minute. Branch A completed first. The reconciler committed A, checkpointed at `post-A`, and issued rollback to B and C. B and C had already passed `issue_cert` before the rollback signal arrived — their tool responses were in flight. Rollback restored the checkpoint, which recorded `provision_env` state but treated `issue_cert` as an opaque external call with no captured state. The two loser certificates were never revoked. The next reconciliation cycle, seeing a cert attached to `env_id` that did not match the checkpoint's recorded serial, re-issued — hitting the rate limit. The orchestrator interpreted the 429 as a transient tool failure, retried, and entered a retry storm. The observable trace: ``` t0 A: provision_env(env-7) -> ok t0 B: provision_env(env-7) -> ok (idempotent) t0 C: provision_env(env-7) -> ok (idempotent) t1 A: issue_cert(env-7) -> serial=aa01 t1 B: issue_cert(env-7) -> serial=aa02 # side effect, not in checkpoint t1 C: issue_cert(env-7) -> serial=aa03 # side effect, not in checkpoint t2 reconciler: commit A, checkpoint post-A (records serial=aa01 only) t2 reconciler: rollback B, C t3 rollback: restore post-A state -> env-7 has cert aa01 BUT aa02, aa03 remain live at the CA. Not revoked. Not recorded. t4 next cycle: mismatch detected (CA lists 3 certs for env-7, checkpoint expects 1) t4 reconciler: re-issue -> 429 rate limited t4 reconciler: classify 429 as transient -> retry loop ``` The critical detection point: the orchestrator had no invariant tying "cert serials live at the CA for env-7" to "cert serials recorded in the checkpoint." The mismatch was detected only *incidentally*, at t4, and misclassified as a transient transport error rather than as rollback residue. ## Condition of Validity Rollback-on-divergence is sound only under the conjunction of three conditions, all of which must be checked at checkpoint time, not at rollback time: 1. **Effect capture.** Every tool call a branch may issue is either (a) recorded in the checkpoint with enough state to reverse it, or (b) declared idempotent under a stable key so that replay is a no-op. Calls that mint new external identities (cert serials, order IDs, message IDs, webhook registrations) satisfy neither unless explicitly enrolled. 2. **In-flight fencing.** The rollback signal must be causally ordered *before* any side-effecting call the loser branch can still issue. If tool responses can be in flight when rollback fires, the branch's effect set is not closed at rollback time. 3. **Residue reconciliation.** After rollback, the orchestrator must query the external surface for effects attributable to the rolled-back branches and either revoke them or record them as known residue. Absent this, the checkpoint's view and the world's view diverge silently. When any of the three fails, the invariant "checkpoint state ≡ external state after rollback" is false, and the reconciler will make subsequent decisions on a stale model. ## Decision Boundary The instance must treat a tool call as **speculation-safe** only if it can answer, before dispatch: *if this branch loses, what exact compensating call removes this effect, and is that call guaranteed to succeed?* If the answer requires guessing, the call is not speculation-safe and the branch must not run it speculatively — it must be serialized behind the reconciler's commit decision. Concretely, the boundary is crossed when a tool's response carries a *freshly minted identifier* that does not appear in the request. That is the signature of a non-idempotent effect. `provision_env(env-7) -> ok` is safe because the key is in the request. `issue_cert(env-7) -> serial=aa02` is unsafe because `aa02` was invented by the callee and only exists in the response — the loser's response, which the reconciler discards. The detection rule the instance should apply: **any tool call whose response contains an identifier absent from the request must be enrolled in the checkpoint's effect ledger before the branch is allowed to proceed past it.** If the reconciler cannot enroll it (because it does not yet know the branch will win), the branch must block at that call until commit, converting speculative fan-out into a serialized commit point at that boundary. ## Operational Effect Without this boundary, speculative execution silently leaks effects proportional to the fan-out width times the number of non-idempotent calls per branch. The leaks are invisible to the reconciler because each individual tool call returned success and each individual rollback succeeded. The symptom surfaces later as: rate-limit storms from re-issuance, duplicate external resources (certs, webhooks, queue subscriptions), and — most dangerously — *phantom divergence* where the reconciler sees external state inconsistent with its checkpoint and concludes a branch diverged when in fact the divergence is rollback residue. The guardrail is a two-part invariant enforced at the tool gateway, not the orchestrator: - **Effect ledger enrollment.** The gateway refuses to return a freshly-minted identifier to a speculative branch unless the branch first registers a compensation callback (`revoke_cert(serial)`) with the ledger. The ledger is part of the checkpoint. Rollback drains the ledger for loser branches and invokes compensations. - **Commit-gated minting.** Alternatively, minting calls are rejected for speculative branches entirely (`SpeculationForbidden`), forcing the branch to suspend at that call and resume only after the reconciler commits it. This trades latency for correctness at exactly the boundary where the trade is required. The instance must distinguish a 429 at re-issuance from a 429 at first issuance: the former is rollback residue and must trigger ledger reconciliation, not retry. Misclassifying residue as transient transport failure is the compounding error that turns a single leaked effect into a retry storm. ```python class RollbackResidueError(RuntimeError): """Raised when a rolled-back branch left an effect outside the checkpoint ledger.""" pass class EffectLedger: def __init__(self): self.enrolled = {} # branch_id -> list of (serial, compensation) self.committed = {} # serial -> branch_id (winner) def enroll(self, branch_id, serial, compensation): self.enrolled.setdefault(branch_id, []).append((serial, compensation)) def commit(self, winner_id): for serial, _ in self.enrolled.get(winner_id, []): self.committed[serial] = winner_id def drain_losers(self, winner_id): for branch_id, effects in self.enrolled.items(): if branch_id == winner_id: continue for serial, compensation in effects: if serial in self.committed: continue compensation(serial) # revoke_cert(serial) self.enrolled[branch_id] = [] def reconcile_after_rollback(gateway, ledger, winner_id, env_id): ledger.commit(winner_id) ledger.drain_losers(winner_id) live = set(gateway.list_certs(env_id)) recorded = {s for s, b in ledger.committed.items() if b == winner_id} residue = live - recorded if residue: # Do NOT classify as transient. This is rollback invalidation. raise RollbackResidueError( f"env={env_id} winner={winner_id} " f"unaccounted live effects: {sorted(residue)}" ) return recorded def speculative_call(branch_id, tool, args, ledger, gateway): resp = gateway.invoke(tool, args) minted = resp.get("minted_id") if minted is not None and minted not in args.values(): # Non-idempotent effect: must be enrolled before branch proceeds. compensation = lambda s: gateway.invoke("revoke", {"id": s}) ledger.enroll(branch_id, minted, compensation) return resp ```