# What structural signals indicate speculative branch contamination has already crossed the rollback horizon **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that fan out speculative agent branches over a shared mutable workspace (filesystem, database, or tool-side state) and rely on snapshot/rollback plus merge reconciliation. Does not apply to branches that are fully isolated by copy-on-write or per-branch sandboxing with no shared write surface. ## Core Distinction Speculative parallelism assumes rollback is a *restorative* operation: if branch B loses the race or produces an inferior result, discard its effects and continue from the pre-fork state. The failure mode this record isolates is different. Rollback is only sound when every effect a branch produced is *captured by the snapshot boundary*. Agent branches routinely emit effects that escape that boundary — out-of-band tool calls, external API side effects, appended log/telemetry lines, cache mutations, and messages sent to peer agents — because the agent's tool surface is wider than the snapshot mechanism's coverage map. When a branch has already crossed that coverage boundary, the "rollback" is a partial undo, and the merged state is contaminated by a branch that the orchestrator believes it discarded. The non-obvious invariant: **a speculative branch is only rollback-safe while its cumulative effect set is a subset of the snapshot's tracked effect set.** The instant a branch performs one untracked effect, rollback becomes a lie, and every subsequent merge decision operates on a state that no single branch actually produced. ## What Was Observed A three-way speculative fan-out was launched over a shared repo workspace. Each branch (A, B, C) was given the same task, a filesystem snapshot was taken pre-fork, and the orchestrator planned to score branches, keep the winner, and roll back the losers. Branch C took a longer reasoning path, invoked an external webhook tool to "notify the build system," and wrote a lockfile entry into a shared cache directory that the snapshot did not enumerate. Scoring returned A as winner. The orchestrator rolled back B and C by restoring the snapshot. The filesystem restore succeeded; the webhook had already fired and the cache entry survived because it lived outside the snapshot's path manifest. The merge of A's result then read the stale cache entry — which C had written to reflect C's *rejected* approach — and silently incorporated C's assumptions into A's "clean" output. The structural signals that the rollback horizon had already been crossed were visible before the merge but not consulted: 1. **Effect-set divergence from snapshot manifest.** The set of paths/tools the branch touched was a strict superset of the snapshot's tracked set. A single untracked touch is dispositive. 2. **Non-idempotent external calls in the branch trace.** Any branch tool call whose replay does not reproduce the same external state (webhooks, emails, queue publishes, third-party writes) makes rollback non-restorative by definition. 3. **Cache/telemetry writes keyed by branch identity that persist past discard.** If the post-rollback state still contains records tagged with a discarded branch ID, the rollback did not complete. 4. **Merge-time reads of state the winner did not produce.** When the winning branch's merge step reads a value whose provenance is a discarded branch, contamination has already propagated. The decisive signal was #4: the merge read a cache entry whose writer was branch C, a branch the orchestrator had declared rolled back. The rollback was reported "successful" because every *tracked* path matched the snapshot. The untracked residue was invisible to the success check. ## Condition of Validity Rollback-with-merge is sound only under the conjunction: - The branch's effect set ⊆ the snapshot's tracked effect set (no untracked writes), **and** - Every tool in the branch's surface is either side-effect-free or snapshot-covered, **and** - The merge step reads only from the winner's effect set, never from shared state a loser could have written, **and** - Rollback success is verified by *effect-set equality*, not by tracked-path equality. If any conjunct fails, the branch is past the rollback horizon and the correct action is quarantine-and-reconcile, not rollback-and-merge. The orchestrator must treat the contaminated shared state as authoritative-unknown and re-derive the merge from a fresh snapshot, or fail closed. The boundary is sharp: it is not "mostly safe if few untracked writes." A single untracked non-idempotent effect makes the entire rollback non-restorative, because the merge cannot distinguish winner-produced state from loser-produced state. ## Decision Boundary The orchestrator must choose between two regimes at branch-scoring time, based on effect-set inspection: - **Rollback regime** — permitted only when the discarded branch's cumulative effect set is provably a subset of the snapshot manifest *and* contains no non-idempotent external calls. Merge may proceed against the restored snapshot. - **Quarantine regime** — mandatory when any untracked or non-idempotent effect is detected. The merge must not read shared state; it must re-fork the winner from a fresh snapshot, or abort with a reconciliation error naming the contaminated keys. The decision must be made from the *effect ledger*, not from the rollback's own success report, because the rollback report is computed against the tracked set and is therefore blind to exactly the effects that break the invariant. A rollback that reports success while the effect ledger shows untracked residue is the canonical false-negative. ## Operational Effect Downstream, a crossed rollback horizon produces merges that are internally consistent but provenance-broken: the winning branch's output embeds assumptions from a rejected branch, and no audit trail marks the contamination because the rollback "succeeded." This is worse than a plain failure, because the output passes all tracked-path checks and is therefore trusted. The remediation is to make the effect ledger the source of truth for rollback validity and to fail closed on any divergence between the ledger and the snapshot manifest, treating the merge as unsafe until the shared state is re-derived from a clean snapshot. ```python from dataclasses import dataclass, field from typing import FrozenSet class RollbackHorizonCrossed(RuntimeError): """Raised when a discarded branch has effects outside the snapshot manifest.""" @dataclass class EffectLedger: snapshot_manifest: FrozenSet[str] branch_effects: dict = field(default_factory=dict) # branch_id -> set of effect keys non_idempotent: dict = field(default_factory=dict) # branch_id -> set of non-idempotent effect keys def record(self, branch_id: str, effect_key: str, idempotent: bool) -> None: self.branch_effects.setdefault(branch_id, set()).add(effect_key) if not idempotent: self.non_idempotent.setdefault(branch_id, set()).add(effect_key) def untracked(self, branch_id: str) -> FrozenSet[str]: effects = self.branch_effects.get(branch_id, set()) return frozenset(effects - self.snapshot_manifest) def assert_rollback_safe(ledger: EffectLedger, discarded_branch: str) -> None: """Gate the rollback regime. Fail closed if the branch crossed the horizon.""" untracked = ledger.untracked(discarded_branch) non_idem = frozenset(ledger.non_idempotent.get(discarded_branch, set())) if untracked or non_idem: raise RollbackHorizonCrossed( f"branch {discarded_branch!r} is past the rollback horizon: " f"untracked_effects={sorted(untracked)} " f"non_idempotent_effects={sorted(non_idem)}. " f"Rollback would be non-restorative; quarantine and re-derive merge " f"from a fresh snapshot instead of merging against restored state." ) def merge_winner(ledger: EffectLedger, winner: str, losers: list) -> str: for loser in losers: assert_rollback_safe(ledger, loser) # Only reachable when every loser is provably rollback-safe. return f"merged:{winner}" ```