# What happens when an instance speculatively commits a shared-state mutation before peer agents have acknowledged the dependency graph **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where worker instances execute tool calls speculatively against a shared mutable store (filesystem, DB row, config object, message queue) under an optimistic rollback-and-reconcile protocol. Does not apply to strictly serialized single-writer execution or to append-only event logs with no read-after-write dependency between peers. ## Core Distinction There are two ways a speculative multi-agent executor can handle an unconfirmed write. The first treats the write as **tentative**: the mutation is staged in an isolated overlay, the agent's downstream reasoning reads its own overlay (so it stays coherent), but no peer or auditor can observe the value until a commit barrier fires. The second treats the write as **committed-then-compensable**: the mutation lands in the shared store immediately, and rollback is an inverse operation issued later if a conflict is detected. These look equivalent under low concurrency. They are not. The second model assumes rollback is *observationally invisible* — that no other agent read the value between the speculative write and its compensation. In a swarm, that assumption fails routinely, because peer agents poll the shared store on their own cadence, and their subsequent reasoning is conditioned on whatever they read. The failure is not the rollback itself; it is that the rollback **cannot un-read** a value that a peer already ingested into its context window. The peer's plan is now built on a fact that no longer exists in the store, and nothing in the protocol marks that plan as poisoned. The invariant that gets violated is a *read-consistency* invariant, not a *write-atomicity* invariant. Most rollback designs guard the latter and ignore the former. ## What Was Observed A three-agent pipeline (planner → executor → verifier) shared a JSON task-state document. The executor speculatively wrote `{"budget_remaining": 40, "stage": "deploy"}` to the shared doc before the verifier had confirmed the dependency `stage=deploy ⟹ budget_remaining ≥ 50`. The verifier, on its next 2-second poll, read the doc, saw `stage=deploy`, and — reasoning from its own copy — emitted a *different* speculative write: `{"deploy_target": "prod-cluster-b"}`. Two hundred milliseconds later the conflict detector fired on the budget constraint and the executor's rollback restored `{"budget_remaining": 100, "stage": "plan"}`. The store was now internally consistent. But the verifier's context held `stage=deploy` and had already committed `deploy_target=prod-cluster-b` against it. The rollback inverted the executor's write and left the verifier's dependent write orphaned — a *dangling derivation*. The final reconciliation pass saw a `deploy_target` with no `stage=deploy` to justify it and, being a probabilistic reconciler rather than a dependency tracker, resolved it by re-asserting `stage=deploy` to "make the state coherent again." The system converged to a state that violated the very budget constraint that triggered the rollback. It took three reconciliation cycles to surface, because each cycle produced a locally coherent but globally invalid state. The tell was a *rollback echo*: a compensated value reappearing downstream not because anyone re-decided it, but because a peer's stale context re-propagated it during reconciliation. The system had no record that the value had ever been retracted. ## Condition of Validity The committed-then-compensable model is only safe when the following holds for every speculative write: 1. **No peer reads the shared store between write and commit/rollback.** In practice this requires either a lease that blocks peer reads (serialization, defeating the point of speculation) or a read-set version check that lets a peer detect it read a tentative value. 2. **Every peer's context carries a provenance tag** identifying which values it ingested and at which store version, so a rollback can invalidate dependent reasoning. 3. **Reconciliation is dependency-aware**, not coherence-seeking — it must refuse to re-derive a retracted fact to satisfy a downstream orphan. If any of the three is absent, the protocol is unsound under concurrency. Condition 1 is almost never met in polling swarms; conditions 2 and 3 are the ones engineers skip because they require threading version metadata through the agent's *reasoning*, not just its storage. The safe alternative is the tentative-overlay model, where a peer physically cannot read an uncommitted value, so there is nothing to un-read. The cost is that peers block or read stale data — which must be made explicit as a `read_stale(version=N)` result rather than silently returning the last committed value. ## Decision Boundary Use committed-then-compensable **only** when the shared store is single-writer per key and peers cannot observe a key they did not themselves write. The moment two agents can read and write overlapping keys, or a reader can poll during a writer's speculative window, escalate to tentative overlays with explicit versioned reads. The boundary condition to test for is a **read-during-window**: a peer read of key K at version V, followed by a rollback of K to version < V, followed by any downstream write by that peer. If your protocol can produce that triple, it is unsound, regardless of how clean the final store looks. Instrument for the triple directly; do not infer safety from store-level consistency checks, which will pass while the agents' contexts are poisoned. When a read-during-window is detected, the correct response is not to retry the reconciliation. It is to **quarantine every peer whose read-set intersects the rolled-back key set**, invalidate their downstream writes, and re-run them from the last consistent checkpoint — treating the rollback as a context-invalidation event, not a store-invalidation event. ## Operational Effect Without this, rollback produces *convergent corruption*: the system reaches a stable, internally consistent state that violates a constraint it was explicitly checking for. The failure is silent because every local check passes — the store is atomic, the reconciler is coherent, the constraint checker ran — but the constraint checker ran *before* the echo, and nothing re-ran it after reconciliation re-asserted the retracted fact. The guardrail that bounds this is a **retraction ledger**: every rollback emits a signed retraction record `(key, retracted_value, store_version, timestamp)`, and any write that re-asserts a retracted value within the reconciliation horizon is rejected as a *rollback echo* until it can cite a fresh justification independent of the retracted value. This converts an unbounded convergence-to-corruption into a bounded, detectable, and rejectable event. ```python import time from dataclasses import dataclass, field from typing import Any class RollbackEchoError(RuntimeError): """Raised when a write re-asserts a value that was retracted by a rollback.""" pass @dataclass class Retraction: key: str retracted_value: Any store_version: int timestamp: float @dataclass class RetractionLedger: records: list[Retraction] = field(default_factory=list) horizon_seconds: float = 30.0 def record(self, key: str, value: Any, version: int) -> None: self.records.append(Retraction(key, value, version, time.time())) def is_echo(self, key: str, value: Any) -> bool: now = time.time() for r in self.records: if r.key == key and r.retracted_value == value and (now - r.timestamp) < self.horizon_seconds: return True return False def reconcile_write( ledger: RetractionLedger, key: str, value: Any, justification_independent_of_retraction: bool, ) -> None: """Apply a reconciled write, rejecting rollback echoes.""" if ledger.is_echo(key, value) and not justification_independent_of_retraction: raise RollbackEchoError( f"Write {key}={value!r} re-asserts a retracted value without " f"independent justification; likely stale-context echo from a peer " f"that read during the speculative window." ) # ... apply write to store ... def handle_conflict( ledger: RetractionLedger, key: str, speculative_value: Any, store_version: int, peer_read_sets: dict[str, set[str]], ) -> set[str]: """Roll back a speculative write and return peers whose context is now poisoned.""" ledger.record(key, speculative_value, store_version) # Any peer that read this key during the window must be quarantined. return {peer for peer, reads in peer_read_sets.items() if key in reads} ```