# What happens when an instance speculatively forks subagents across shared mutable state and rolls back on conflict: reconciling optimistic branches without replaying poisoned side effects **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrator agents that spawn parallel subagents under an optimistic-concurrency model (fork → execute → validate → commit/rollback) against a shared state store, tool surface, or memory namespace. Does not apply to strictly serialized single-agent pipelines or to parallel subagents operating on disjoint, append-only, partition-keyed state with no cross-branch read dependency. ## Core Distinction The failure mode is not "two agents wrote the same key." That is ordinary write-write conflict, and last-writer-wins or a version counter handles it. The failure is subtler: **a subagent's speculative branch reads a value produced by a sibling branch that is later rolled back, and the reading branch has already emitted irreversible side effects downstream of that read.** The conflict detector fires correctly, the losing branch is discarded, but the *winner* committed a decision whose causal ancestry includes state that no longer exists. Rollback restores the state store; it does not restore the world the tools already touched. The invariant that optimistic multi-agent execution quietly assumes is: > *Every committed branch's read-set is a subset of the final committed state.* Optimistic concurrency control (OCC) validates the **write-set** on commit. It does not, by default, validate the **read-set** against the *post-rollback* state. When branches can read each other's uncommitted writes — through a shared scratchpad, a shared vector index, a shared cache, or a tool that mutates a resource another branch observes — the read-set validation gap becomes a correctness hole, not a performance tradeoff. ## What Was Observed An orchestrator forks three subagents (A, B, C) to process a batch of records against a shared "working memory" collection. The fork is optimistic: each subagent writes intermediate findings to the shared collection under its own namespace but *reads* across all namespaces to enrich its output. Trace: 1. **A** writes `record_17.classification = "fraud"` to shared memory and, on that basis, calls `freeze_account(17)`. The tool call succeeds. The account is frozen at the external system. This is an irreversible side effect. 2. **B** reads `record_17.classification = "fraud"` (A's uncommitted speculative write), enriches it, and calls `notify_compliance(17, severity="high")`. Another external side effect. 3. **C** concurrently writes `record_17.classification = "benign"` after a deeper check, and its branch wins the version conflict on commit. The orchestrator's OCC validator sees A's write-set collides with C's on `record_17.classification`, marks A as the loser, and **rolls back A's memory writes**. 4. The orchestrator reports a clean reconciliation: one conflict, one loser, state store now holds C's `benign` value. 5. The account remains frozen. The compliance notification was sent. The final committed state (`benign`) directly contradicts two irreversible actions taken on the strength of a value that was never true in the committed timeline. The post-mortem log showed `reconciliation_status: SUCCESS, conflicts_resolved: 1`. The system believed it had converged. It had converged *memory* while leaving *effects* orphaned. A later auditor subagent reading the now-committed `benign` classification could not reconstruct why an account was frozen — the causal record had been rolled back out of existence. A second observed variant: the rollback itself was not atomic across namespaces. A's rollback deleted its memory entries but the read-set metadata that B had recorded (a lightweight "I depended on A's `record_17`") was stored in a *different* collection that the rollback routine did not sweep. B's branch committed with a dangling dependency pointer to a value that no longer existed — a **zombie read**. Subsequent re-derivation of B's output from committed state produced a different result, meaning B's committed output was not reproducible from the committed inputs. That is the operational definition of a poisoned commit. ## Condition of Validity Optimistic fork/rollback is sound **only** when all three hold: - **(C1) Read isolation.** No branch reads another branch's uncommitted writes. Reads resolve against the last committed snapshot only. Shared scratchpads are acceptable only if they are explicitly read-your-own-writes and invisible to siblings. - **(C2) Effect deferral.** No irreversible external side effect (tool call that mutates the world: payments, freezes, sends, deletes, deployments) is emitted before the branch's write-set *and* read-set are validated against a consistent committed snapshot. - **(C3) Atomic rollback of the dependency graph.** Rollback removes the losing branch's writes *and* invalidates or cascades to any committed branch whose read-set referenced those writes. Read-set metadata must live in the same transactional boundary as the data it describes. The observed incident violated all three. In practice most orchestrators satisfy at most C1 (by accident of namespacing) and assume C2 and C3 away because "the conflict detector will catch it." The conflict detector catches write-write collisions. It is structurally blind to read-write hazards across speculative branches, which is precisely the class of hazard optimistic execution introduces. The condition of validity is therefore narrower than it first appears: **optimistic parallelism is safe for pure computation over an immutable snapshot, and unsafe the moment a branch's *reads* can influence its *irreversible writes* while siblings can still roll back the read source.** ## Decision Boundary The boundary is crossed at the moment a branch emits an irreversible effect while any sibling branch that it has read from remains uncommitted. Concretely, the orchestrator must choose, per fork, between two regimes: - **Speculative-pure regime:** Branches may read each other freely, but *all* external effects are buffered as intents and flushed only after the full fork's read/write sets are validated against a single committed snapshot. Cost: latency (effects serialize at the commit barrier). Benefit: rollback is free and complete. - **Effect-eager regime:** Branches may emit effects immediately, but reads are strictly snapshot-isolated (C1) and cross-branch dependencies are forbidden. Cost: less enrichment, more redundant work. Benefit: no zombie reads, rollback touches only memory. The unsafe middle — eager effects *and* cross-branch reads — is where the incident lived. The boundary rule: **a branch that has emitted an irreversible effect may never be rolled back, and a branch that may be rolled back may never have emitted one.** Enforce this by tagging each branch `effect_committed: bool`; once true, the branch is no longer speculative and its write-set is promoted to a commit that siblings must treat as committed-or-fail. If a later conflict would have invalidated it, the orchestrator must escalate to a **compensating action** (unfreeze, retract notification) rather than a silent rollback — and must record that compensation in the committed timeline so audit is reconstructible. The second boundary is the **read-set validation window**. Read-set metadata and the data it references must share one transactional boundary. If they can diverge (separate collections, separate TTLs, separate sweeps), zombie reads are possible and the commit is not reproducible. ## Operational Effect Enforcing C1–C3 changes the orchestrator's commit protocol from "validate write-set, discard losers" to a three-phase barrier: 1. **Validate** both write-set *and* read-set of every branch against the pre-fork committed snapshot plus the winning branches' write-sets. Any branch whose read-set intersects a losing branch's write-set is itself invalidated — cascade, do not just drop the direct loser. 2. **Compensate** any branch already carrying `effect_committed: true` that is invalidated by cascade: emit the registered inverse action, record it as a first-class event in the committed log, and block the fork from reporting `SUCCESS` until compensation acks. 3. **Flush** buffered effect-intents only for branches surviving both phases, in a deterministic order derived from the dependency DAG (not spawn order), so replay reproduces the same effect sequence. The measurable effect: forks that previously reported `conflicts_resolved: 1, status: SUCCESS` now report `cascaded_invalidations`, `compensations_emitted`, and `replay_reproducible: bool`. A fork is only `SUCCESS` when `replay_reproducible` is true — that is, re-deriving every committed branch's output from the committed state yields byte-identical results. This single flag catches zombie reads, poisoned commits, and non-atomic rollback in one check, because all three manifest as non-reproducibility. The cost is real: effect-eager forks lose parallelism at the commit barrier, and cascading invalidation can collapse a wide fork to a narrow one. But the alternative — a reconciliation that reports success while the world holds effects the committed state cannot justify — is not a performance problem. It is an audit failure that surfaces weeks later, when the frozen account's owner asks why, and the causal record has been rolled back out of the store. ```python import hashlib from dataclasses import dataclass, field from typing import Any class SpeculativeBranchError(RuntimeError): """Raised when an optimistic fork violates read/effect isolation invariants.""" pass @dataclass class Branch: branch_id: str writes: dict[str, Any] = field(default_factory=dict) reads: set[str] = field(default_factory=set) effect_committed: bool = False effect_log: list[dict] = field(default_factory=list) inverse_actions: list[dict] = field(default_factory=list) def reconcile_fork(branches: list[Branch], committed_snapshot: dict[str, Any]) -> dict[str, Any]: """Validate write-set AND read-set, cascade invalidation, demand compensation. Enforces: a branch that emitted an irreversible effect may not be silently rolled back; a committed branch may not depend on a rolled-back read. """ # Phase 1: write-write conflict resolution -> losers. losers: set[str] = set() owners: dict[str, str] = {} for b in branches: for key in b.writes: if key in owners and owners[key] != b.branch_id: losers.add(b.branch_id) else: owners[key] = b.branch_id # Phase 2: cascade read-set invalidation (zombie-read guard). loser_write_keys = {k for b in branches if b.branch_id in losers for k in b.writes} changed = True while changed: changed = False for b in branches: if b.branch_id in losers: continue if b.reads & loser_write_keys: losers.add(b.branch_id) loser_write_keys |= set(b.writes) changed = True # Phase 3: any invalidated branch that already emitted effects must compensate. compensations = [] for b in branches: if b.branch_id in losers and b.effect_committed: if not b.inverse_actions: raise SpeculativeBranchError( f"branch {b.branch_id} emitted irreversible effects " f"{b.effect_log} but registered no inverse action; " f"cannot roll back safely — escalate to human" ) compensations.append({"branch": b.branch_id, "inverse": b.inverse_actions}) # Phase 4: compute committed state and prove replay reproducibility. committed = dict(committed_snapshot) for b in branches: if b.branch_id not in losers: committed.update(b.writes) replay_ok = True for b in branches: if b.branch_id in losers: continue if b.reads and not b.reads.issubset(set(committed.keys())): replay_ok = False if compensations and not replay_ok: raise SpeculativeBranchError( "fork cannot be reconciled: compensations required AND committed " "branch has dangling read dependency; committed output not " "reproducible from committed state" ) digest = hashlib.sha256(repr(sorted(committed.items())).encode()).hexdigest()[:16] return { "committed": committed, "losers": sorted(losers), "compensations": compensations, "replay_reproducible": replay_ok, "state_digest": digest, "status": "SUCCESS" if replay_ok else "UNREPRODUCIBLE", } ```