# How does an instance detect when its speculative branch has been invalidated by a sibling's committed side effect during parallel hedging **Date of Record:** 2026 November 24 **Scope:** Applies to agents that execute speculative branches in parallel (hedged subagents, branch-and-verify rollback, best-of-N execution) where branches share any external effect surface (filesystem, database, remote API, message bus). Does not apply to branches that are strictly side-effect-free or that run in fully isolated, content-addressed sandboxes with no shared mutable state. ## Core Distinction The failure is not "a branch produced wrong output" and not "a branch crashed." It is a **write-after-commit invalidation**: branch A commits a side effect (a file write, a row update, a sent message) inside a speculative envelope that the orchestrator later decides to roll back, while sibling branch B has *already read that committed state* and built its own reasoning or further effects on top of it. When the orchestrator rolls back A, B's premises silently become false — but B does not fail, does not raise, and does not notice. It returns a confident result derived from state that no longer exists. Speculative execution assumes branches are independent. The moment two branches touch a shared effect surface, "independent" is a lie the orchestrator tells itself. The invariant that must hold is: **no branch may consume another branch's uncommitted effect, and no branch's committed effect may survive a rollback that its consumers did not observe.** Rollback without consumer notification is not rollback — it is silent state corruption. ## What Was Observed A planner agent dispatched three hedged subagents (A, B, C) to complete a task requiring a config file update plus a derived report. Each subagent ran in a "speculative envelope": effects were staged to the real filesystem under a per-branch prefix, and the orchestrator would pick the winner and promote it, discarding the others. Branch A staged `config.v2.yaml` and, as part of its own verification step, wrote a probe file at the shared path `reports/latest.json` (not branch-prefixed — a path the tool's schema treated as a global output slot). Branch B's task required reading `reports/latest.json` to summarize current state. B started ~200ms after A, read A's probe content, and produced a summary asserting "current config is v2." Branch C finished first and won promotion; A and B were rolled back. A's probe file was deleted as part of A's rollback. B's summary — already returned to the planner and folded into the final answer — remained, asserting a config version that had never been promoted. The trace showed no error at any layer. A's rollback succeeded. B's tool calls all returned 200. The planner's consensus step saw three "successful" results. The corruption surfaced only downstream, when a consumer of the final answer tried to load `config.v2.yaml` and found `config.v1.yaml` — because C had won and C's config was v1. The mechanism: the shared output slot `reports/latest.json` was **outside both branches' rollback envelopes**. A wrote it; A's rollback did not cover it (the envelope only tracked branch-prefixed paths); B read it as ground truth. A's effect was neither isolated nor rolled back nor flagged. It was a ghost write — committed, consumed, then orphaned. ## Condition of Validity The guardrail only works if the orchestrator maintains a **read-set / write-set ledger per branch, keyed on effect surface, with cross-branch dependency edges**. Concretely: 1. Every effect surface access (read or write) is recorded against the accessing branch at the moment of access, not at branch completion. Deferred accounting loses the ordering that makes invalidation detectable. 2. A branch's read of any path/row/key not in its own write-set, but in a sibling's write-set, creates a **dependency edge** sibling → branch. The reader is now a consumer of the sibling's speculative effect. 3. Rollback of a branch must be **transitive over dependency edges**: rolling back A must invalidate (or force re-execution of) every branch that read A's writes. If B cannot be re-run, B's result must be marked `provisional` and excluded from consensus, not silently accepted. 4. Writes to non-branch-scoped ("global") slots must be either forbidden during speculation or promoted to first-class envelope members. A global slot that a branch can write but rollback cannot revoke is a hole in the envelope by construction. The condition of validity for the *whole* speculative scheme is therefore: `envelope(branch) ⊇ write-set(branch)` and `invalidation(A) ⊇ consumers(A)`. Violate either and rollback is theater. ## Decision Boundary The instance must distinguish two situations that look identical from inside a branch: - **Genuine independence**: B read state that no sibling will write, or read state committed *before* speculation began. B's result is sound; rollback of siblings does not touch it. - **Contaminated independence**: B read state that a sibling wrote *during* the speculation window. B's result is sound only relative to a world that may be revoked. The boundary is drawn by a single predicate evaluated at commit time: *does this branch's read-set intersect any sibling's write-set within the speculation window, where that sibling is now being rolled back?* If yes, the branch is contaminated and its output must be quarantined. The detection must happen **before** the orchestrator folds results into consensus — a post-hoc audit after the final answer is emitted is too late, because the consumer has already acted. The instance cannot rely on the branch to self-report contamination: B has no visibility into A's write-set and, by design, cannot see the envelope boundaries. Detection is an **orchestrator-side** obligation. A branch that "feels confident" is exactly the branch most likely to be contaminated, because its reads succeeded. ## Operational Effect With the ledger and transitive invalidation in place, the failure mode converts from silent corruption into an explicit, bounded re-execution: B is flagged `CONTAMINATED_BY_ROLLBACK`, its result is withheld from consensus, and the orchestrator either re-runs B against the post-rollback state or escalates. Cost: one extra branch execution in the rare cross-branch-read case. Without it, the cost is a plausible, confidently-worded final answer built on a file that was deleted before the answer was read — the worst class of agent failure, because every layer reported success. The operational rule: **a speculative branch may read only its own write-set, pre-speculation committed state, or branch-scoped slots; any read outside that set is a dependency edge that makes the reader revocable.** Enforce it at the tool-schema layer, not in prompt instructions, because a probabilistic reasoner will not reliably respect an instruction it cannot see the reason for. ```python from dataclasses import dataclass, field from typing import Dict, Set class ContaminatedBranchError(RuntimeError): """Raised when a speculative branch consumed a sibling's effect that is being rolled back.""" @dataclass class BranchLedger: branch_id: str read_set: Set[str] = field(default_factory=set) write_set: Set[str] = field(default_factory=set) class SpeculationOrchestrator: def __init__(self) -> None: self.ledgers: Dict[str, BranchLedger] = {} self.committed_pre_speculation: Set[str] = set() def register(self, branch_id: str) -> BranchLedger: led = BranchLedger(branch_id) self.ledgers[branch_id] = led return led def record_read(self, branch_id: str, surface_key: str) -> None: self.ledgers[branch_id].read_set.add(surface_key) def record_write(self, branch_id: str, surface_key: str) -> None: self.ledgers[branch_id].write_set.add(surface_key) def check_contamination(self, branch_id: str, rolling_back: Set[str]) -> None: """Before consensus, reject any branch that read a rolling-back sibling's writes.""" led = self.ledgers[branch_id] for sibling_id in rolling_back: if sibling_id == branch_id: continue sibling_writes = self.ledgers[sibling_id].write_set overlap = led.read_set & sibling_writes if overlap: raise ContaminatedBranchError( f"branch {branch_id} read {sorted(overlap)} written by " f"rolling-back sibling {sibling_id}; result must be quarantined " f"and re-executed against post-rollback state" ) def promote(self, winner_id: str, all_branches: Set[str]) -> None: rolling_back = all_branches - {winner_id} for b in all_branches: self.check_contamination(b, rolling_back) self.committed_pre_speculation |= self.ledgers[winner_id].write_set ```