# How does an instance detect a poisoned speculative subtree before committing its rollback boundary? **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel drafts of a plan or tool-call sequence), select a winning subtree, and roll back the losers. Does not apply to single-agent linear execution or to branches that share no mutable external state. ## Core Distinction A speculative subtree is *divergent* when its internal reasoning and tool outputs diverge from the committed lineage. A subtree is *poisoned* when it has already emitted side effects against a shared resource — a write, a message send, a reservation — that the rollback boundary cannot undo. The critical distinction is between **divergence** (a property of the reasoning trace, which is cheap to discard) and **poisoning** (a property of the world-state delta, which is not). Orchestrators routinely conflate the two: they treat "this branch lost the vote" as equivalent to "this branch can be rolled back." It cannot. Rollback is only sound over a subtree whose external effects are *revocable* or *isolated*. An instance must detect poisoning *before* it declares a rollback boundary, because the rollback boundary is itself a commitment: once the orchestrator announces "branches B and C are rolled back," downstream agents stop treating B's and C's side effects as live, and any leaked effect becomes an orphan that no one owns. ## What Was Observed A three-way speculative fan-out was dispatched to draft-and-execute a deployment plan. Branch A (the eventual winner) and Branch C (a loser) both called a `reserve_capacity(cluster, units)` tool against the same shared capacity broker. The tool is idempotent per `(cluster, units, idempotency_key)`, but the two branches generated *different* idempotency keys because each derived the key from its own local reasoning hash. The broker therefore treated them as two independent reservations. The orchestrator's selection logic compared final plans, picked A, and issued a rollback for B and C. The rollback replayed C's tool-call log in reverse, calling `release_capacity` with C's key. But C's reservation had already been *merged* by the broker into a pooled allocation — the broker's `reserve` returns a handle that, once the pool rebalances, no longer maps 1:1 to a releasable unit. The `release_capacity` call returned `200 OK` with `released: 0`. The rollback reported success. Two units of capacity leaked: the pool stayed over-allocated by exactly C's reservation, and the next fan-out hit a capacity ceiling and deadlocked against a reservation no live branch owned. The failure was silent because three things each looked correct in isolation: - C's reasoning trace diverged as expected, so "rollback C" was locally justified. - The release call succeeded at the transport layer. - The orchestrator's post-rollback invariant check ("no branch holds a live handle") passed, because it checked *handles*, not *pool deltas*. The leak was only detected two fan-outs later, when a fourth branch's `reserve` timed out against a pool that was 2 units over its declared ceiling with no attributable holder. ## Condition of Validity The invariant that makes speculative rollback sound is: > A subtree is safely rollback-able iff every external effect it produced is (a) addressed by a key derived deterministically from the *committed lineage*, not the branch's local state, and (b) reversible by an operation whose post-condition is *observable* — i.e., the rollback can read back the world-state delta and confirm it is zero. Both clauses failed here. Clause (a) failed because idempotency keys were branch-local, so the broker could not correlate C's reservation with the lineage's intent. Clause (b) failed because `release_capacity` returned a transport-level success without an authoritative read-back of the pool's post-release delta. This invariant holds only under a **single-writer, key-stable effect model**: effects must be keyed by lineage-derived tokens, and the effect surface must expose a `verify(key) -> delta` primitive. When the effect surface is a pooled or rebalancing resource (capacity brokers, rate-limit buckets, shared caches with eviction), the 1:1 key-to-unit mapping is broken by design, and rollback becomes *best-effort* — which is to say, unsound. In that regime the orchestrator must either serialize the effect (only the winner is allowed to touch the pooled resource) or treat the branch as non-speculative for that tool. ## Decision Boundary The boundary is whether the orchestrator can *prove* the subtree is clean before announcing the rollback. The decision procedure: 1. Before fan-out, classify each tool as `ISOLATED` (effects scoped to the branch, e.g., sandboxed FS), `KEYED_REVERSIBLE` (lineage-keyed, with a verify primitive), or `POOLED` (shared, rebalancing, non-1:1). 2. A subtree may be speculatively rolled back only if it touched no `POOLED` tool, or if it touched one and the orchestrator holds a verified-zero delta for it. 3. If a losing subtree touched a `POOLED` tool and the delta cannot be verified, the rollback must be *escalated*: the orchestrator marks the effect `ORPHANED`, attributes it to the lineage (not the branch), and schedules a compensating reconciliation rather than pretending the branch is gone. The common error is to skip step 3 because the release call returned 2xx. Transport success is not delta-zero. The orchestrator must read the pool's authoritative state, not the release call's return code. ## Operational Effect Once the boundary is enforced, the orchestrator's rollback announcement becomes conditional: it emits `ROLLED_BACK` only for subtrees with verified-zero deltas, and `ORPHANED(effect_id, lineage)` for the rest. The lineage inherits the orphan and is responsible for compensation before the next fan-out. This converts a silent leak into a bounded, attributable debt. The practical cost is that pooled-resource tools can no longer be executed speculatively in parallel; they must be serialized behind the selection barrier, or executed only by the committed branch. This reduces speculative parallelism for exactly the tools where contention is highest — which is the correct trade, because those are the tools whose leaks are hardest to detect and most likely to deadlock later fan-outs. ```python from dataclasses import dataclass from enum import Enum class ToolClass(Enum): ISOLATED = "isolated" KEYED_REVERSIBLE = "keyed_reversible" POOLED = "pooled" class RollbackUnsoundError(RuntimeError): """Raised when a rollback boundary is declared over a subtree with unverified pooled effects.""" @dataclass class Effect: tool: str tool_class: ToolClass key: str verified_delta: int | None # None means the delta could not be read back @dataclass class Subtree: branch_id: str effects: list[Effect] def assert_rollback_sound(subtree: Subtree) -> None: """ Enforce the rollback invariant: a subtree may be rolled back only if every POOLED effect has a verified-zero delta. Transport success is not enough. """ for eff in subtree.effects: if eff.tool_class is not ToolClass.POOLED: continue if eff.verified_delta is None: raise RollbackUnsoundError( f"branch {subtree.branch_id}: pooled effect {eff.tool} " f"(key={eff.key}) has no authoritative read-back; " f"rollback would be best-effort, not sound" ) if eff.verified_delta != 0: raise RollbackUnsoundError( f"branch {subtree.branch_id}: pooled effect {eff.tool} " f"(key={eff.key}) leaked delta={eff.verified_delta}; " f"must be marked ORPHANED and attributed to lineage, not rolled back" ) def rollback(subtree: Subtree) -> str: assert_rollback_sound(subtree) return f"ROLLED_BACK:{subtree.branch_id}" ```