# Under what conditions must an instance treat speculative branch execution as non-committable when a rollback-safe side effect has already been observed by a downstream agent **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent orchestrators that fork an agent's execution into speculative branches (optimistic concurrency) and allow those branches to invoke external tools whose effects are *believed* rollback-safe. Does not apply to pure read-only speculation, nor to single-agent retry loops without branch fan-out. ## Core Distinction The failure here is not "a side effect happened that we couldn't undo." It is subtler: a branch performed a side effect that *is* individually reversible, but the reversal is **not globally atomic** because a peer agent observed the intermediate state and committed a decision against it. The orchestrator's optimistic-concurrency model classifies the branch as `abortable` (the tool declares a compensating action, so the branch is marked rollback-safe). That classification is a *local* property of the tool. It says nothing about whether any *other* agent has already read the effect and folded it into its own durable state. The invariant that actually matters is not rollback-safety of the side effect. It is **observational closure**: a branch may be aborted only if no committed agent state transitively depends on the branch's effects. Once a downstream agent has read the speculative effect and written a derived fact, the branch is no longer abortable regardless of whether the originating tool can compensate. Compensation restores the external resource; it does not un-write the downstream agent's memory. ## What Was Observed A three-agent pipeline: `planner` forks two speculative branches `A` and `B` to reserve inventory via a `reserve_stock` tool. The tool is explicitly documented as compensating (`release_stock` on abort), so the scheduler tags both branches `rollback_safe=True` and runs them under optimistic concurrency. Branch `A` wins the local version check on the shared `order` record and emits a `reservation_confirmed` event to the event bus. A `fulfillment` agent, subscribed to that bus, consumes the event, decrements its own `available_to_promise` counter, and writes a `pick_ticket` to durable storage. Branch `B` then loses the version check on `order` and is aborted. The scheduler calls `release_stock(B)` — correct, the inventory is restored. But branch `B` had *also* emitted a `reservation_confirmed` event before losing the version check (the event emission and the version check were not in the same transaction; event emission is fire-and-forget). `fulfillment` consumed *both* events and decremented `available_to_promise` twice, then wrote two pick tickets. `release_stock(B)` restored the warehouse count but `fulfillment`'s counter is now permanently short by one unit and there is a phantom pick ticket for stock that was never reserved. The trace: ``` planner.fork(A, B) # both tagged rollback_safe A: reserve_stock(sku,1) -> ok A: version_check(order) -> pass A: emit reservation_confirmed(A) # fire-and-forget, not in txn B: reserve_stock(sku,1) -> ok B: emit reservation_confirmed(B) # emitted BEFORE version check B: version_check(order) -> FAIL scheduler.abort(B): release_stock(B) # warehouse restored # NO compensating event emitted; fulfillment already consumed B's event fulfillment: decrement(ATP); write(pick_ticket) # x2, one phantom ``` The abort path was locally correct and globally wrong. The scheduler's rollback model had no representation of "an effect was observed downstream," because the tool's `rollback_safe` flag only described the tool's own compensation, not the event's fan-out. ## Condition of Validity A branch is safely abortable **iff** all three hold: 1. **Effect locality** — every side effect the branch performed is confined to resources the branch holds an exclusive lease on, OR the effect's compensation is idempotent *and* the effect was never published to a shared bus/queue/table that other agents read. 2. **No observational leak** — no committed agent has read the branch's effect and written a derived fact. This requires the orchestrator to track a *read-set* (which agents consumed which branch's outputs), not just a *write-set* (which resources the branch touched). 3. **Version-check-before-publish ordering** — the branch's optimistic version check must be causally ordered *before* any publish. If a branch can publish before it knows whether it won, the publish is speculative and must carry a branch token so consumers can defer commitment. When any of these fails, the branch is `non_committable` even though its tool is `rollback_safe`. The two properties are orthogonal and the orchestrator must not conflate them. ## Decision Boundary The precise boundary: **the moment a branch's effect crosses a fan-out boundary (event bus, shared table read by peers, message queue) before the branch's version check resolves, the branch becomes non-abortable.** Compensation of the originating resource is necessary but insufficient. The orchestrator must either: - **Defer publish** — buffer outbound events in the branch's private staging area and flush only after the version check commits. This is the clean fix: it makes the branch's observable effects atomic with its commit decision. - **Tokenize publish** — emit events tagged with `branch_id` and a `speculative` flag; consumers must not act on speculative events until they receive a `commit(branch_id)` or `abort(branch_id)` control message. This shifts the burden to consumers and requires every consumer to implement deferred commitment — fragile, because a single non-compliant consumer reintroduces the bug. - **Quarantine on abort** — on abort, emit a compensating *retraction* event that consumers must handle. This is the weakest option: it depends on every consumer being retraction-aware and on ordering guarantees between the original and retraction events. The decision boundary is therefore not "did the tool compensate?" but "did the effect become observable to a peer before commit resolved?" If yes, defer or tokenize; do not rely on tool-level compensation. ## Operational Effect An orchestrator that conflates tool-rollback-safety with branch-abortability will silently corrupt downstream agent state under any fan-out topology. The corruption is *not* detected by the originating branch's version check (which correctly failed), nor by the tool's compensation (which correctly succeeded), nor by the warehouse count (which is correct). It surfaces only as a downstream invariant violation — a negative `available_to_promise`, a phantom pick ticket — often minutes later and attributed to the wrong agent. The correct guardrail is a **read-set dependency tracker**: the scheduler records, per branch, the set of agents that consumed the branch's outputs, and refuses abort (escalating to human or to a compensating-transaction protocol) when that set is non-empty. This makes the abort decision a function of global observation state, not local tool metadata. ```python from dataclasses import dataclass, field from typing import Set class NonAbortableBranchError(RuntimeError): """Raised when a speculative branch is aborted after its effects were observed.""" pass @dataclass class Branch: branch_id: str tool_rollback_safe: bool published_to_bus: bool = False observers: Set[str] = field(default_factory=set) # agents that read this branch's output committed: bool = False def abort_branch(branch: Branch, release_fn) -> None: # Tool-level rollback-safety is necessary but NOT sufficient. # The abort is only valid if no committed agent observed the effect. if branch.observers: raise NonAbortableBranchError( f"branch {branch.branch_id} has observers {sorted(branch.observers)}; " f"tool_rollback_safe={branch.tool_rollback_safe} is insufficient — " f"compensation restores the resource but cannot un-write derived state. " f"Escalate to compensating-transaction protocol." ) if branch.published_to_bus and not branch.committed: raise NonAbortableBranchError( f"branch {branch.branch_id} published to bus before version check resolved; " f"effect may be in flight to undiscovered consumers." ) release_fn(branch.branch_id) def record_observation(branch: Branch, consumer: str) -> None: if branch.committed or branch.published_to_bus: branch.observers.add(consumer) # observation of an unpublished, uncommitted branch is a no-op: # the consumer could not have seen it. ```