# What happens when an instance speculatively executes parallel agent branches and a rollback discards buffered writes that a sibling branch already observed **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fork a single agent task into concurrent speculative branches whose tool side effects are buffered and conditionally committed or rolled back. Does not apply to strictly serial agents, nor to branches whose side effects are inherently non-bufferable (e.g., live outbound messages, irreversible external payments) unless a compensating-action protocol exists. ## Core Distinction The distinction that matters is between *rollback of a write* and *rollback of the observation of a write*. A rollback-safe side-effect buffer guarantees the former: an uncommitted `write_file`, `send_email`, or `db_insert` from a losing branch is never applied to the durable world. It does **not** and cannot guarantee the latter, because the observation happened inside a *sibling branch's context window* the moment the speculative effect was staged into the shared read path. The buffer is a write-side abstraction; the leak is read-side. Speculative execution therefore has a hidden cross-branch read channel that survives rollback, and any invariant phrased only in terms of "no uncommitted side effects reach the world" is incomplete: it must also say "no uncommitted side effects reach a sibling's reasoning trace." ## What Was Observed A planner forked three branches from a shared checkpoint to satisfy one user request: branch A would `create_issue`, branch B would `search_issues` to check for duplicates, branch C would `assign_label`. The orchestrator staged A's `create_issue` into the side-effect buffer so it could be rolled back if B found a duplicate. To keep branches "consistent," the buffer was wired into the shared tool-read layer: B's `search_issues` executed against *durable state plus staged-but-uncommitted effects from siblings*. B therefore observed the issue that A had created, concluded no duplicate existed, and returned `proceed`. The merge policy selected B's verdict and rolled back A (a redundant create was judged lower-value than B's dedup confirmation). Net effect: the world received a "confirmed no duplicate" decision derived from a record that was then rolled back and never persisted. The final committed state contained neither the create nor any issue, yet the agent's reasoning trace asserted the issue existed. On a subsequent resume from the checkpoint, the cold-started instance re-ran `search_issues`, found nothing, and re-created the issue — now a genuine duplicate of nothing, but a divergence from the prior trace that the auditor flagged as tampering. The failure trace, in order: 1. Checkpoint taken; branches A, B, C forked with identical context hashes. 2. A stages `create_issue(id=X)` into buffer; buffer exposes staged effects to the shared read layer (the defect). 3. B's `search_issues` returns `[X]`; B's reasoning commits to `no_duplicate: false` → `proceed`. 4. Merge policy picks B's verdict; A is rolled back; buffer discards `create_issue(X)`. 5. Committed world state has no `X`; B's trace still contains the observation of `X`. 6. Resume replays B's trace against a world without `X`; replay mismatch raises a verification discrepancy. The non-obvious part is step 3. Nothing in the buffer's contract was violated at step 4 — rollback was correct. The invariant broke at step 3, where a speculative effect crossed from the write channel into a sibling's *epistemic* channel. Once an observation is inscribed in a branch's context, it is not transactional; context windows do not support rollback. ## Condition of Validity The rollback-safe buffering invariant holds **only if** the read path visible to any branch is partitioned into (a) durable committed state and (b) that branch's *own* staged effects, with no visibility of sibling staged effects. Formally, for branch `i` reading key `k` at step `t`, the returned value must satisfy `read_i(k,t) = committed(k) ⊕ own_staged_i(k,t)`. The moment the read function includes `staged_j(k,t)` for `j ≠ i`, the invariant is void regardless of how cleanly rollback later executes. This condition is necessary but not sufficient. Two additional constraints bound it: - **Observation provenance tagging.** Every value returned to a branch must carry a provenance tag (`committed` vs `own_speculative`), and the branch's own reasoning must be instructed (and audited) to treat `own_speculative` observations as hypotheses, not facts. A branch that confirms "no duplicate" based on its *own* staged create must record that the confirmation is conditional on commit. - **Merge-time observation reconciliation.** When the merge policy selects a branch's verdict, it must verify that every fact the verdict depends on is present in the committed set at merge time. If a selected verdict cites a staged effect that is being rolled back, the merge must be rejected as unsound, not silently applied. The failure above violates all three: sibling visibility (a), missing provenance (b), and no reconciliation (c). ## Decision Boundary The boundary is between *speculation as an internal search* and *speculation as an external commitment*. Speculative branches may freely read their own staged effects — that is what makes speculation useful (A can check whether its own create succeeded before proposing commit). They may **not** read sibling staged effects, because the sibling's commit is not guaranteed and the observation is not retractable. Concretely: - **Permit:** branch reads `committed ∪ own_staged`; branch reasons over hypotheses about its own effects; merge policy selects among branch *proposals*, each carrying an explicit dependency set of `(key, provenance)` pairs. - **Forbid:** branch reads any `staged_j` for `j ≠ i`; merge applies a verdict whose dependency set includes a `staged` entry that is not in the commit set; resume replays a trace whose cited facts are absent from durable state without flagging a divergence. - **Require compensation:** if a branch *must* observe a sibling effect to make progress (e.g., B genuinely needs to know whether A will create `X`), the orchestrator must serialize A→B (commit A before B reads) rather than speculate. The decision to serialize is the boundary: cross-branch dependency on a speculative effect is a signal that the branches are not independent and must not be forked. ## Operational Effect Without the partition, speculative execution silently converts a write-transactional system into an epistemically non-transactional one: branches make decisions on facts that will be erased, and the erasure is invisible to the branch that depended on it. The observable symptoms are (1) merge verdicts that cite facts absent from the final state, (2) resume/replay mismatches where a cold-started instance contradicts its own prior trace, and (3) duplicate or contradictory external actions after resume because the agent's belief state diverged from the world. The guardrail is architectural, not prompt-level: partition the read path by branch identity, tag provenance on every returned value, and make merge admission check that each selected verdict's dependency set is a subset of the committed set. A prompt instruction to "ignore sibling effects" is insufficient because the effect is already in the context window and probabilistic reasoning will condition on it. ```python from dataclasses import dataclass, field from typing import Any, Dict, Set, Tuple class SpeculativeReadLeakError(RuntimeError): """Raised when a branch observes a sibling's uncommitted staged effect.""" class UnsoundMergeError(RuntimeError): """Raised when a selected verdict depends on an effect being rolled back.""" @dataclass class StagedEffect: branch_id: str key: str value: Any committed: bool = False @dataclass class SideEffectBuffer: committed: Dict[str, Any] = field(default_factory=dict) staged: Dict[Tuple[str, str], StagedEffect] = field(default_factory=dict) def stage(self, branch_id: str, key: str, value: Any) -> None: self.staged[(branch_id, key)] = StagedEffect(branch_id, key, value) def read(self, branch_id: str, key: str) -> Tuple[Any, str]: # Invariant: a branch sees committed state plus ONLY its own staged effects. if key in self.committed: return self.committed[key], "committed" own = self.staged.get((branch_id, key)) if own is not None: return own.value, "own_speculative" # Detect the leak: a sibling staged this key but we are not the owner. for (owner, k), eff in self.staged.items(): if k == key and owner != branch_id and not eff.committed: raise SpeculativeReadLeakError( f"branch {branch_id!r} attempted to read key {key!r} " f"staged by sibling {owner!r}; cross-branch speculative read is forbidden" ) return None, "absent" def commit(self, branch_id: str) -> None: for (owner, k), eff in list(self.staged.items()): if owner == branch_id: self.committed[k] = eff.value eff.committed = True del self.staged[(owner, k)] def rollback(self, branch_id: str) -> None: for (owner, k) in list(self.staged.keys()): if owner == branch_id: del self.staged[(owner, k)] def admit_merge(self, verdict_deps: Set[Tuple[str, str]]) -> None: # verdict_deps: (key, provenance) pairs the selected verdict relied on. for key, provenance in verdict_deps: if provenance == "own_speculative" and key not in self.committed: raise UnsoundMergeError( f"merge cites speculative fact {key!r} that is not in the committed set; " f"verdict is unsound and must be rejected, not applied" ) ```