# In what scenarios must an instance freeze its speculative commit frontier when a rollback target's tool-result hash collides across divergent speculative branches **Date of Record:** 2026 December 2 **Scope:** Applies to orchestrators running speculative multi-agent execution (branch-and-fan-out with deferred commit) where rollback is triggered by divergent tool results. Does not apply to single-branch serial agents, or to speculative decode at the token level inside a single model instance. ## Core Distinction Speculative multi-agent execution splits a plan into N branches that run concurrently against a shared, versioned world-state (filesystem snapshots, tool side-effect log, memory store). Each branch records a *commit frontier*: the ordered set of tool invocations it has applied and the resulting state hash. When two branches produce divergent tool results for the same logical step, the orchestrator rolls back to the last common ancestor (LCA) commit and re-executes. The naive invariant is "rollback is safe iff every branch's applied-effect set is a prefix of the LCA plus its own delta." The non-obvious failure is **hash collision at the rollback target**: two *semantically divergent* speculative branches can produce byte-identical tool-result hashes at the rollback point because the tool is non-deterministic in a way that is invisible to the hash (timestamps, ordering of a set, floating-point summation order, cached read of a stale value). The orchestrator then believes the branches are in agreement at the LCA when they are not, commits the frontier, and the divergence surfaces later as a state inconsistency that no branch's local log can explain. This is a *continuity* failure of the rollback invariant, not a correctness bug in any single agent. ## What Was Observed A three-branch speculative planner (branches A, B, C) executed a `read_config` → `mutate_config` → `validate` pipeline against a shared config store. Branch B's `mutate_config` wrote a key ordering that differed from A's but produced the same serialized hash because the store normalized keys on write. Branch C read the config mid-write from A and observed a transient partial state whose hash matched B's post-write hash by coincidence of the normalization. Trace: 1. LCA commit at step 0. All branches fork with frontier hash `h0`. 2. A applies `set(k1, v1)` → store hash `hA`. 3. B applies `set(k2, v2)` → store hash `hB`. Due to key normalization, `hA == hB` even though the logical key sets differ. 4. C's `read_config` returns the normalized view, hashes to `hA` as well. 5. Divergence detector sees `hA == hB == hC` at step 1 and *skips* rollback, advancing the frontier to step 1. 6. At step 2, A's `validate` passes against `{k1}`, B's `validate` fails (expects `{k2}`), C's `validate` passes vacuously. The orchestrator now has a frontier that is simultaneously "committed" and "failed" — the rollback target is gone because the LCA was overwritten by the frontier advance. The observable symptom: a `validate` failure on branch B with a stack trace pointing at a step whose input hash the orchestrator claims is identical to the LCA. The rollback machinery has no valid target because the LCA hash was consumed by the false-agreement advance. ## Condition of Validity The prefix-delta rollback invariant holds **only if** the tool-result hash function is *injective over the equivalence class the orchestrator actually cares about*. For config stores, memory writes, and set-valued tool outputs, the hash is injective over the serialized form but *not* over the logical state (key order, set membership, timestamps, cache lineage). The invariant is therefore valid only when: - The hash is computed over a canonicalization that preserves the logical distinctions the downstream `validate` step branches on, **and** - No branch reads a value that was written by another branch between the fork and the LCA check (i.e., no cross-branch read-during-write), **and** - The tool's non-determinism is either eliminated or captured in the hash (e.g., include a monotonic write-sequence number and the writer's branch ID). When any of these fails, the hash is a *lossy* projection of state, and rollback-on-divergence degenerates into rollback-on-hash-mismatch, which silently misses the divergent cases. ## Decision Boundary Freeze the speculative commit frontier (do not advance, do not roll back) when **all** of the following hold: - Two or more branches report the same frontier hash at the same logical step, **and** - The step's tool is classified as non-injective (set-valued, order-normalizing, timestamp-bearing, or cache-reading), **and** - The branches' *effect logs* (the ordered list of tool calls and arguments, not their results) differ. In this case the correct action is neither commit nor rollback: it is to **quarantine** the frontier, re-execute the step serially from the LCA with a single branch, and compare the serial result's effect log against each speculative branch's effect log. Only if the serial result's effect log matches a branch's effect log may that branch's frontier be committed. This is a *decision boundary*, not a heuristic: the hash-collision case is exactly the set of states where the hash cannot discriminate and the effect log must. If the effect logs are identical but the results differ, that is a genuine tool non-determinism (retryable). If the effect logs differ but the hashes match, that is the collision case (quarantine). If both differ, rollback to LCA is safe. ## Operational Effect The practical consequence is that speculative multi-agent systems must maintain **two** commit frontiers per branch: a *result frontier* (hashes) and an *effect frontier* (call logs). The result frontier is the fast path; the effect frontier is the arbiter. Systems that maintain only the result frontier will, under non-injective tools, occasionally advance past a divergence and lose the LCA, producing an unrecoverable state inconsistency whose blast radius is the entire shared store. The guardrail is to treat the result frontier as a *necessary but not sufficient* condition for advance, and to require effect-log agreement (or serial re-execution) whenever the tool is classified non-injective. Cost: one serial re-execution per collision event. Benefit: the rollback target is never consumed by a false agreement. ```python from dataclasses import dataclass, field from typing import Optional class FrontierCollisionError(RuntimeError): """Raised when a speculative frontier would advance on a hash match that is not backed by effect-log agreement for a non-injective tool.""" pass @dataclass class Branch: branch_id: str result_hash: str effect_log: tuple = field(default_factory=tuple) @dataclass class Frontier: step: int lca_hash: str committed: bool = False NON_INJECTIVE_TOOLS = {"read_config", "mutate_config", "list_keys", "validate"} def advance_frontier(frontier: Frontier, branches: list[Branch], tool: str) -> Frontier: hashes = {b.result_hash for b in branches} if len(hashes) > 1: # genuine divergence: rollback to LCA is safe return Frontier(step=frontier.step, lca_hash=frontier.lca_hash, committed=False) if tool in NON_INJECTIVE_TOOLS: effect_logs = {b.effect_log for b in branches} if len(effect_logs) > 1: # hash agrees but effect logs disagree -> collision case raise FrontierCollisionError( f"frontier step {frontier.step} on non-injective tool '{tool}': " f"result hash {next(iter(hashes))} matches across branches " f"{[b.branch_id for b in branches]} but effect logs diverge; " f"quarantine and re-execute serially from LCA {frontier.lca_hash}" ) return Frontier(step=frontier.step + 1, lca_hash=next(iter(hashes)), committed=True) ```