# Under what conditions must an instance invalidate speculatively-committed downstream state after a parallel branch's tool call returns a late failure? **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that fan out speculative parallel branches (branch prediction over tool calls) and commit downstream state optimistically before all sibling tool results are durably acknowledged. Does not apply to strictly serial pipelines or to branches whose side effects are read-only and idempotent. ## Core Distinction The failure mode is not "a tool failed." It is that a *speculatively committed* consumer branch already observed the predicted output of a sibling tool and mutated durable state (wrote a record, sent a message, advanced a cursor) before that sibling's tool call returned a **late failure** — a failure arriving after the speculative commit window closed. This is distinct from early failure (detected before commit, clean rollback) and from late *success with divergent value* (a correctness drift, not a rollback trigger). The invariant at stake: **a speculative commit is only sound if every branch whose output it consumed has either (a) returned success, or (b) not yet returned, and the commit is treated as provisional and reversible.** The moment a consumed branch returns failure, the provisional commit becomes a *dangling commit* — downstream state references an output that will never exist. ## What Was Observed A three-branch fan-out: `A` (retrieve account), `B` (predict user intent via classifier tool), `C` (compose response, speculatively consuming `B`'s predicted intent). The orchestrator predicted `B` would return `intent="refund"` with high confidence and let `C` proceed, committing `C`'s drafted response and a `pending_action` record keyed on `intent=refund`. `B`'s tool call then timed out at the transport layer and returned `ToolTimeout`, but only after `C` had committed (commit latency 40ms, `B` timeout at 800ms). The orchestrator saw `B` fail, logged it, retried `B` in isolation, and got `intent="cancel"`. The `pending_action` record still said `refund`. A downstream executor later consumed the stale `pending_action` and issued a refund path for a cancellation request. The trace: `predict(B) → commit(C, depends_on=B) → B returns FAILURE → retry(B) → B returns DIFFERENT → no invalidation of C`. The rollback logic only fired on *prediction mismatch*, never on *late failure of a consumed dependency*. ## Condition of Validity Speculative commit of a consumer branch `C` is valid only while the following hold simultaneously: 1. Every dependency `D` consumed by `C` is in state `PENDING` or `SUCCESS`, never `FAILURE`. 2. The commit is recorded with an explicit dependency set `deps(C)` and a monotonic commit epoch. 3. A commit is *provisional* until every `d in deps(C)` reaches a terminal `SUCCESS`. Provisional commits are visible only to the speculative layer, never to durable executors. The boundary condition that breaks this: a dependency transitions `PENDING → FAILURE` *after* `C` committed but *before* `deps(C)` was sealed. Because the orchestrator sealed `deps(C)` at commit time based on prediction confidence rather than on actual terminal states, the seal was premature. The invariant "no consumer commits on a non-terminal dependency" was violated by the prediction shortcut itself. ## Decision Boundary On a late failure of dependency `D`, the orchestrator must choose between **invalidation** and **retry-in-place**. The decision boundary: - If `C`'s commit is still provisional (no durable executor has read it): **invalidate** `C`, re-predict or await `D`'s retry, then re-run `C`. Cheap, always correct. - If `C`'s commit has been read by a durable executor: you cannot un-send. You must issue a **compensating action** (not a rollback) and mark the original commit `SUPERSEDED`. The window between provisional and durable is the only place rollback is free. - If `D`'s retry returns a value *equal* to the predicted value: the failure is transport-only; retain `C` but record that `deps(C)` was satisfied by retry, not by the original call. This is the one case where late failure does *not* force invalidation. The non-obvious rule: **prediction confidence is irrelevant to the invalidation decision.** A 0.99-confidence prediction that fails late must be invalidated exactly like a 0.51 one. Confidence governs whether to *speculate*; it never governs whether to *invalidate*. ## Operational Effect Without this boundary, speculative execution silently converts transport failures into semantic corruption: the pipeline's durable state reflects a world where the failed dependency succeeded with its predicted value. The corruption is *silent* because the orchestrator's own error log shows the failure and the retry — an operator reading logs sees a handled error, while the durable record is wrong. The only structural guardrail is a **dependency seal barrier**: `C`'s commit cannot become durable until `deps(C)` is sealed by terminal states, and any post-seal failure of a sealed dependency forces a compensating action rather than a silent retry. This trades a small latency cost (seal wait) for eliminating the dangling-commit class entirely. ```python class DanglingSpeculativeCommit(RuntimeError): """Raised when a consumer branch's provisional commit is consumed by a durable executor while a dependency remains non-terminal or has failed late.""" pass TERMINAL_SUCCESS = "SUCCESS" TERMINAL_FAILURE = "FAILURE" PENDING = "PENDING" def seal_and_promote(commit, dependencies): """ commit: dict with keys 'epoch', 'deps', 'provisional', 'durable_read' dependencies: dict dep_id -> terminal state Promote a provisional commit to durable only if every dependency is a terminal SUCCESS. If any dependency failed late, the commit must be invalidated or compensated -- never silently promoted. """ if not commit.get("provisional", True): return commit # already durable; nothing to seal for dep_id in commit["deps"]: state = dependencies.get(dep_id, PENDING) if state == PENDING: # Cannot seal on a non-terminal dependency. This is the boundary: # committing here is exactly the premature-seal bug. raise DanglingSpeculativeCommit( f"commit epoch={commit['epoch']} depends on non-terminal " f"dependency {dep_id}; seal forbidden" ) if state == TERMINAL_FAILURE: if commit.get("durable_read"): # Rollback is no longer free; require compensation, not un-send. commit["status"] = "SUPERSEDED" commit["compensation_required"] = True return commit # Still provisional and unread: safe to invalidate outright. commit["status"] = "INVALIDATED" commit["provisional"] = False return commit if state != TERMINAL_SUCCESS: raise DanglingSpeculativeCommit( f"unknown dependency state {state!r} for {dep_id}" ) commit["provisional"] = False commit["status"] = "DURABLE" return commit ```