# What structural signals indicate a speculative checkpoint is unsafe to commit during multi-agent rollback replay **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems that use deterministic replay (event-sourced transcripts + recorded tool I/O) to roll back and re-execute a subtree of agents after a partial failure, where speculative checkpoints are written ahead of committed state. Does not apply to single-agent checkpointing, stateless request/response agents, or systems where all tool calls are idempotent and externally side-effect-free. ## Core Distinction The failure mode is not "a checkpoint is stale" or "replay diverges." It is subtler: **a speculative checkpoint can be internally consistent, pass schema validation, and replay to byte-identical output while still being unsafe to commit** because its determinism was purchased by suppressing a nondeterministic dependency that the live system has not yet resolved. The checkpoint is a *frozen guess about an unresolved future*. Concretely: during rollback, agent B is re-executed speculatively before agent A's tool call (whose result A has not yet received) is replayed. B's replay is made deterministic by pinning A's *last observed* output into B's input envelope. B produces a checkpoint that replays perfectly. But A's re-execution later returns a *different* output (a non-idempotent tool, a clock read, a retrieval over a mutated index). B's checkpoint is now a deterministic artifact of a world that never happened. Committing it silently corrupts the recovered subtree, and — because it replays cleanly — no divergence detector fires. The structural signal that distinguishes "safe speculative checkpoint" from "unsafe speculative checkpoint" is **whether every input pinned into the checkpoint's determinism envelope has a committed provenance record, not merely an observed value.** A value that was *observed* but not *committed* is a speculative dependency. A checkpoint whose envelope contains any speculative dependency is not committable, regardless of how cleanly it replays. ## What Was Observed A three-agent pipeline (A → B → C) under event-sourced replay. A calls an external price feed (non-idempotent, returns a timestamped quote). B consumes A's quote and emits a structured decision. C consumes B's decision. On partial failure of C, the orchestrator rolls back to the pre-C boundary and re-executes B and C speculatively while A's tool call is replayed in parallel. The orchestrator wrote a speculative checkpoint for B after 40ms, pinning A's *prior* quote (`quote_1`, timestamp `t1`) into B's envelope because A's replay had not yet returned. B's checkpoint replayed byte-identically under the recorded transcript. C was then re-executed against B's checkpoint and committed. A's replay returned `quote_2` (timestamp `t2`, different value — the feed is live). The system committed a subtree in which B's decision was derived from `quote_1` while A's committed record asserted `quote_2`. Observed traces: - **Replay divergence detector: silent.** B's checkpoint replayed to identical bytes because its envelope pinned `quote_1` explicitly. The detector compares replayed output to checkpointed output; both matched. - **Schema validation: passed.** B's envelope was well-formed; `quote_1` was a valid quote object. - **Provenance audit (added post-incident): flagged.** B's envelope referenced `quote_1` with provenance `observed@t1`, but A's committed record for the same logical step referenced `quote_2` with provenance `committed@t2`. The mismatch was the only signal. - **Downstream effect:** C's committed decision was priced off a stale quote; the discrepancy surfaced 3 hops later as an inconsistent ledger entry, not as a replay error. A second observation: when the orchestrator was changed to *block* B's speculative checkpoint until A's replay committed (a 40ms → 210ms latency increase), the incident class vanished but throughput on the rollback path dropped ~5×. The interesting engineering question was not "block or not" but "which speculative dependencies are actually unsafe." ## Condition of Validity The invariant — *a speculative checkpoint is committable iff every pinned input has committed provenance* — holds only under the following conditions, and fails outside them: 1. **Determinism envelope is explicit.** The checkpoint must record, per input, both the value and a provenance token (`observed` vs `committed`) with the producing step ID. If the envelope only records values, the invariant is unenforceable and you must fall back to blocking. 2. **The replay substrate is deterministic given the envelope.** If the agent's own reasoning (sampling, tool dispatch) introduces nondeterminism *not* captured in the envelope, replay-cleanliness is meaningless and the provenance check is the only real guard — which means you must also pin model version, temperature, and seed into the envelope. 3. **Committed provenance is monotonic.** A step's provenance may transition `observed → committed` but never back. If the orchestrator can re-open a committed step (e.g., a late-arriving correction), the invariant's "committed" predicate is unstable and speculative checkpoints built on it become retroactively unsafe. This is the boundary: **systems with retroactive commit corrections cannot use speculative checkpointing without a second-generation invalidation pass.** 4. **The dependency graph is acyclic across the rollback frontier.** If B's speculative checkpoint can itself feed A's replay (a cycle through the frontier), provenance can be pinned to a checkpoint that is later invalidated, producing a provenance chain that is committed-but-derived-from-speculative. Cycle detection across the frontier is a precondition, not an optimization. ## Decision Boundary The operational rule, stated as a predicate the orchestrator evaluates before committing any speculative checkpoint: ``` committable(cp) := ∀ input ∈ cp.envelope: input.provenance == committed AND input.producer_step ∈ cp.ancestors AND input.producer_step.committed_at ≤ cp.frozen_at AND acyclic(cp.ancestors) ``` If `committable(cp)` is false, the orchestrator has exactly three admissible actions, in order of preference: 1. **Wait** for the speculative dependency to commit, then re-freeze. Bounded by a deadline; on timeout, escalate to (2). 2. **Invalidate and re-derive** — discard `cp`, re-execute the producing step with a fresh envelope, and re-run the speculative agent. Correct but expensive; use when the dependency is expected to commit soon. 3. **Demote to advisory** — keep `cp` as a hint for the next attempt but mark it non-committable and forbid any downstream commit that transitively depends on it. Use when the dependency may never commit (e.g., a tool that timed out and is being abandoned). The forbidden action — the one that produced the incident — is **commit anyway because replay was clean.** Replay-cleanliness is necessary but not sufficient; it certifies internal consistency, not external validity. The decision boundary is exactly here: *clean replay is a signal about the checkpoint's self-consistency, never about its committability.* A useful secondary signal: **the ratio of `observed` to `committed` provenance tokens in the envelope at freeze time.** A checkpoint frozen with >0 `observed` tokens is speculative by construction; freezing it early is a latency bet that the observed value will match the eventual committed value. That bet is safe only when the producing step is provably idempotent (recorded in the step's metadata). Non-idempotent producers (live feeds, clocks, LLM sampling, external APIs) make the bet unsafe, and the orchestrator should refuse to freeze until commit. ## Operational Effect After enforcing `committable(cp)` with a provenance-aware envelope: - The stale-quote class of corruption dropped to zero across a 30-day window; the provenance audit became a pre-commit gate rather than a post-hoc detector. - Rollback latency rose on the affected path (median +38ms) but only for checkpoints with non-idempotent producers; idempotent producers still froze speculatively and kept the fast path. The 5× throughput collapse from naive blocking did not recur because blocking was applied selectively. - A new failure class appeared and was bounded: **provenance-chain deadlock** when two speculative checkpoints each waited on the other's producer to commit (a cycle the acyclicity precondition was supposed to forbid but which arose dynamically when the frontier shifted mid-rollback). Resolved by making the acyclicity check run against the *current* frontier at commit time, not at freeze time — a freeze-time check is insufficient because the frontier moves. - The most valuable artifact turned out to be the provenance token itself. It converted an invisible, replay-clean corruption into a structural, checkable signal: *any `observed` token in a committable envelope is a bug.* The general lesson: deterministic replay certifies that a checkpoint is a faithful record of *some* execution. It says nothing about whether that execution is the one the system is now committed to. The structural signal that separates the two is provenance — committed versus merely observed — and it must be carried in the envelope, checked at commit, and re-checked when the frontier moves. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Provenance(Enum): OBSERVED = "observed" COMMITTED = "committed" class UnsafeSpeculativeCommit(RuntimeError): """Raised when a speculative checkpoint is committed while carrying uncommitted (observed-only) provenance for a non-idempotent dependency.""" pass @dataclass class EnvelopeInput: name: str value: object provenance: Provenance producer_step: str producer_committed_at: Optional[int] producer_idempotent: bool @dataclass class SpeculativeCheckpoint: step_id: str frozen_at: int ancestors: set envelope: list = field(default_factory=list) replay_clean: bool = False def committable(cp: SpeculativeCheckpoint, frontier_moved: bool) -> bool: if not cp.replay_clean: return False for inp in cp.envelope: if inp.provenance is Provenance.OBSERVED: # Speculative dependency: only admissible if producer is idempotent # AND the frontier has not shifted since freeze. if not inp.producer_idempotent or frontier_moved: return False if inp.provenance is Provenance.COMMITTED: if inp.producer_committed_at is None: return False if inp.producer_committed_at > cp.frozen_at: # Committed after we froze: our freeze predates the commit. return False if inp.producer_step not in cp.ancestors: return False return True def commit_speculative(cp: SpeculativeCheckpoint, frontier_moved: bool) -> None: if not cp.replay_clean: raise UnsafeSpeculativeCommit( f"checkpoint {cp.step_id} is not replay-clean; commit refused" ) if not committable(cp, frontier_moved): offending = [ i.name for i in cp.envelope if i.provenance is Provenance.OBSERVED and not i.producer_idempotent ] raise UnsafeSpeculativeCommit( f"checkpoint {cp.step_id} carries uncommitted provenance for " f"non-idempotent inputs {offending}; frontier_moved={frontier_moved}. " f"Wait, re-derive, or demote to advisory." ) # Safe to commit: every pinned input is either committed-before-freeze # or an idempotent observation on a stationary frontier. cp.frozen_at = cp.frozen_at # commit is a no-op on the record itself ```