# Under what conditions must an instance refuse to commit a speculatively executed branch when a sibling agent has already observed its side effects **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems where a planner agent forks speculative execution branches (parallel plan rollouts) that emit externally observable side effects (tool calls, writes, messages) before a reconciliation/commit decision. Does not apply to pure read-only speculation, nor to single-agent speculative decoding where no branch state escapes the instance. ## Core Distinction Speculative execution of agent plans is usually framed as a performance optimization: fork N branches, score them, keep the best, discard the rest. The implicit invariant is that discarded branches leave no trace. That invariant holds only when branch side effects are *buffered and invisible*. The non-obvious boundary is the case where a branch's side effects are **observable by a peer agent before the parent commits** — i.e., agent B reads a value that agent A's speculative branch wrote, or receives a message A's branch sent. At that moment the branch is no longer discardable in the logical sense, only in the storage sense. Rollback that erases the write produces a *causal divergence*: B holds state derived from a world that the reconciler claims never existed. The distinction that matters operationally is **side-effect observability**, not side-effect durability. A durable-but-unobserved write can be rolled back safely. An ephemeral-but-observed write cannot. Most rollback machinery is built around durability (transactions, WAL, compensating actions) and is therefore blind to this failure. ## What Was Observed A planner instance `P` forked three speculative branches to satisfy a task requiring a resource reservation. Branch `b2` invoked `reserve(slot=17, holder="P")`, which succeeded and returned a reservation token. Before `P` scored the branches, a peer agent `Q` — running a concurrent sub-task — called `query_slot(17)`, observed `holder="P"`, and used that observation to skip its own reservation attempt and instead send `P` a message: `"slot 17 is yours, I'll take 18."` `P` then scored branches, `b2` lost to `b1`, and the reconciler issued `rollback(b2)` → `release(slot=17)`. Slot 17 was freed. `Q`, having already committed to slot 18 based on the belief that 17 was taken, now held a stale belief. Worse, `Q`'s message had been enqueued into `P`'s inbox and was consumed by `P` on the next step, causing `P` to *skip* re-reserving 17 — because its own memory now contained `Q`'s assertion that 17 was `P`'s. The system ended with slot 17 unheld and both agents believing it was held. The reservation invariant was violated by a rollback that was, from `P`'s local transaction view, perfectly correct. The failure trace, condensed: 1. `P.fork(b2) → reserve(17) → token=T17` (side effect escapes) 2. `Q.observe(slot 17 → P)` (peer read; **branch becomes pinned**) 3. `Q.commit(plan uses 18)` (peer state now depends on the branch) 4. `P.reconcile(winner=b1)` (local decision) 5. `P.rollback(b2) → release(17)` (erases the observed fact) 6. `P.consume(Q.msg: "17 is yours")` (poisoned belief) 7. Invariant violated: `held(17) == false` while `believes_held(17, P) == true`. ## Condition of Validity Rollback of a speculative branch is valid **only if no peer has observed the branch's effects before the rollback commits**. Formally, let `O(b)` be the set of observations by agents other than the forking instance of any effect emitted by branch `b`. Rollback is safe iff `O(b) = ∅` at the moment the rollback is applied, or all observers in `O(b)` are themselves rolled back to a checkpoint preceding their observation (a *cascading* rollback). Because `O(b)` is not observable by `P` from inside its own transaction, `P` cannot locally decide safety. The condition of validity is therefore a **distributed** predicate. An instance must treat "I have no record of anyone observing this" as *not* equivalent to "no one observed this." The absence of an observation in local state is not evidence of no observation in global state. This is the sharp edge: the guardrail cannot be a local check. It must be either (a) a lease/pin protocol where observations register against the branch token and the reconciler refuses to release a pinned token, or (b) a discipline where speculative branches are forbidden from emitting observable effects until commit (buffer-then-flush), trading latency for safety. ## Decision Boundary The instance must switch from *rollback* to *commit-and-reconcile* semantics at the boundary where `O(b) ≠ ∅`. Concretely: - **Below the boundary** (no observation, or observation only by agents whose checkpoints precede it): rollback is safe; discard the branch, release resources, no peer notification needed. - **At/above the boundary** (any live observation): rollback is forbidden. The branch must be **promoted** to a committed-but-losing branch, and its effects must be reconciled forward — either the winner plan is rewritten to absorb the branch's effects (keep slot 17, adjust `b1`), or the observers are explicitly invalidated with a compensating message (`"slot 17 released, re-evaluate"`) *before* the release, and the release is deferred until each observer acknowledges. The boundary is crossed by the *first* observation, and it is irreversible within the reconciliation epoch. Once crossed, an instance cannot reason its way back to "safe to rollback" by re-scoring or re-checking; the only exits are forward reconciliation or cascading rollback of every observer. The decision boundary also has a temporal dimension that is easy to miss: the observation need not be *current* at rollback time. A peer that observed slot 17 and then moved on still depends on that observation if its subsequent plan was conditioned on it. The predicate is "did any live agent's current state derive from this effect," not "is anyone looking right now." ## Operational Effect Systems that ignore this boundary exhibit a characteristic class of bug: **phantom reservations and ghost locks** — resources that are free but believed held, or held but believed free, persisting across agents. These are hard to detect because each agent's local log is consistent; only the cross-agent invariant is violated. They surface later as double-allocation, deadlock on a lock no one holds, or silent data loss when two agents both "safely" overwrite a slot they each believe they own. The architectural guardrail is a **branch pin registry** keyed by branch token, written on every observable effect and read at reconciliation. The reconciler's commit/rollback decision must consult the registry and refuse rollback on any pinned token, raising instead of proceeding. Pins are released only by the observer's own checkpoint advance or explicit ack. The cost is that speculative branches emitting observable effects become more expensive (pinning serializes some concurrency), which is precisely the trade the naive design avoided by pretending observations didn't exist. ```python from dataclasses import dataclass, field from typing import Dict, Set class BranchPinnedError(RuntimeError): """Raised when a reconciler attempts to roll back a speculative branch whose side effects have already been observed by a peer agent.""" @dataclass class PinRegistry: # branch_token -> set of observer agent ids that have derived state from it pins: Dict[str, Set[str]] = field(default_factory=dict) def observe(self, branch_token: str, observer: str) -> None: self.pins.setdefault(branch_token, set()).add(observer) def observers(self, branch_token: str) -> Set[str]: return set(self.pins.get(branch_token, set())) def release(self, branch_token: str, observer: str) -> None: self.pins.get(branch_token, set()).discard(observer) def reconcile_branch( registry: PinRegistry, branch_token: str, winner_token: str, release_fn, compensate_fn, ) -> str: """Decide whether a losing speculative branch may be rolled back. Invariant: rollback is valid only if no live observer depends on the branch. If pinned, we must reconcile forward, never release unconditionally. """ if branch_token == winner_token: return "committed" observers = registry.observers(branch_token) if observers: # Boundary crossed: cannot roll back. Promote and compensate forward. # Notify every observer BEFORE releasing, and require their ack via # registry.release() before the resource is actually freed. for observer in observers: compensate_fn(branch_token, observer) raise BranchPinnedError( f"branch {branch_token!r} pinned by observers {sorted(observers)}; " f"rollback refused, promote and compensate instead" ) # No observers: safe to discard. release_fn(branch_token) return "rolled_back" ```