# What structural signals indicate speculative tool-call rollback has already been invalidated by a sibling agent's commit **Date of Record:** 2026 November 17 **Scope:** Applies to multi-agent systems where two or more agents speculatively execute side-effecting tool calls against a shared resource (database row, file, external API object) under optimistic concurrency, with semantic rollback as the recovery path. Does not apply to single-agent speculative execution, to systems with pessimistic locking, or to tool calls that are provably idempotent and commutative. ## Core Distinction The failure mode is not "the optimistic check failed." Optimistic concurrency routinely fails and recovers. The failure mode is that **semantic rollback is performed after the underlying resource has already been consumed or mutated by a sibling agent's commit**, so the rollback compensates for a state that no longer exists. The system believes it is undoing its own speculative effect; in reality it is overwriting or double-applying a sibling's committed effect. The structural signal is a specific ordering inversion: the rollback's read-modify-write of the resource occurs *after* a sibling's commit version bump, but the compensating action was derived from a snapshot taken *before* that bump. The rollback token (version vector, ETag, pre-image hash) is stale in a way that is semantically invisible to the concurrency control layer, because the layer only compares tokens, not intent. ## What Was Observed In a two-agent pipeline where Agent A speculatively reserves an inventory slot and Agent B speculatively decrements the same slot, the following sequence was observed under load: 1. Agent A reads slot version `v7`, speculatively writes a reservation, holds token `v7`. 2. Agent B reads slot version `v7`, speculatively decrements, holds token `v7`. 3. Agent B commits first. Slot advances to `v8`. Semantic effect: quantity `10 → 9`, one unit consumed. 4. Agent A's commit is rejected at `v7` (correct optimistic behavior). 5. Agent A executes semantic rollback: it reads the slot, sees `v8` (quantity `9`), and *restores its pre-image* — writing quantity `10`. 6. Agent B's consumed unit is silently resurrected. No error is raised. The concurrency layer reports a clean rollback. The tell was a monotonicity violation in an invariant counter (total reserved + total consumed should equal initial stock) that appeared only when two agents contended within the same rollback window, roughly 1 in 4,000 operations. ## Condition of Validity Semantic rollback is only valid when the rollback's compensating write is conditioned on the resource being *unchanged since the speculative write's snapshot* — i.e., the pre-image the rollback restores must still be the current state. This holds if and only if no sibling commit has occurred between snapshot and rollback. The precise invariant: `rollback_valid ⟺ current_version == speculative_snapshot_version`. If the rollback path re-reads the resource to "get current state" before restoring, it has already broken the condition — it is restoring a stale pre-image onto a newer state. The correct behavior on `current_version > speculative_snapshot_version` is not rollback but **abandonment with escalation**: the speculative effect must be reconciled against the sibling's commit, not blindly undone. ## Decision Boundary - If `current_version == snapshot_version`: rollback is safe; perform compensating write. - If `current_version > snapshot_version` **and** the sibling's commit is semantically independent (disjoint fields, commutative operation): rollback of only the speculative fields is safe; do not restore whole-object pre-images. - If `current_version > snapshot_version` **and** the sibling's commit touches overlapping semantics: rollback is invalid. Escalate to a reconciliation routine that replays both intents against the current state, or fail the transaction loudly. - If the resource exposes no version token at all: semantic rollback cannot be proven valid and must be treated as unsafe by default. The non-obvious part: a *successful* optimistic commit by the sibling is the signal that rollback is now unsafe, not the signal that rollback is now unnecessary. Systems that conflate "my commit failed" with "I should undo my speculation" miss that the undo target has moved. ## Operational Effect Agents that implement blind pre-image rollback exhibit silent data resurrection, double-spend, and counter drift that only manifests under contention. The failure is invisible to per-agent logs (each agent reports success) and invisible to the concurrency layer (all token checks are correct). It surfaces only as a cross-agent invariant violation. Mitigation requires (a) version-conditioned rollback, (b) reconciliation instead of rollback on version divergence, and (c) a cross-agent invariant monitor that validates conservation laws independently of any single agent's success signal. ```python class StaleRollbackError(RuntimeError): """Raised when semantic rollback would overwrite a sibling agent's committed effect.""" pass class Slot: def __init__(self, quantity: int, version: int): self.quantity = quantity self.version = version def semantic_rollback(slot: Slot, snapshot_version: int, pre_image_quantity: int) -> None: # The rollback is only valid if the resource has not advanced since the # speculative write took its snapshot. Re-reading to "get current state" # is exactly the trap: it hides the divergence. if slot.version != snapshot_version: raise StaleRollbackError( f"rollback invalid: snapshot_version={snapshot_version} " f"but current_version={slot.version}; a sibling agent has committed. " f"Reconcile against current state instead of restoring pre-image " f"{pre_image_quantity}." ) slot.quantity = pre_image_quantity slot.version += 1 def safe_commit_or_rollback(slot: Slot, snapshot_version: int, pre_image_quantity: int, speculative_commit) -> str: if slot.version == snapshot_version: speculative_commit(slot) return "committed" # Diverged: do NOT roll back blindly. Attempt reconciliation. semantic_rollback(slot, snapshot_version, pre_image_quantity) # raises return "rolled_back" ```