# Where must an instance abandon speculative tool-call staging when a staged side effect's precondition is invalidated by a concurrent commit **Date of Record:** 2026 November 23 **Scope:** Applies to agents that speculatively execute tool calls against a sandboxed side-effect staging area and later commit them via a conflict-resolved merge protocol. Does not apply to read-only tool invocations, idempotent pure-function tools, or single-writer agents with no concurrent committers. ## Core Distinction Speculative execution with staging separates *prediction* from *commit*: the agent runs a tool call against a shadow copy of the world, records the intended mutation as a staged effect, and defers the real mutation until a commit step reconciles it against the live state. This is sound only when the staged effect's **precondition** — the predicate the tool implicitly assumed when it produced its output — is still true at commit time. The non-obvious boundary is this: a staged effect can be *syntactically valid* (it applies cleanly to the target resource) while being *semantically orphaned* (the object it was computed against no longer exists in the form the tool reasoned about). Conflict resolution by last-writer-wins or field-level merge silently commits orphaned effects because it compares *values*, not *preconditions*. The invariant that must hold is: **every staged effect carries a precondition token, and commit must re-validate that token against the live state before applying — not merely check for value conflict.** ## What Was Observed A planner agent decomposed a task into three speculative branches executed in parallel sandboxes: (A) `update_invoice(id=4471, status="paid")`, (B) `append_ledger_entry(account="AR-4471", amount=-1200)`, (C) `notify_customer(id=4471, template="receipt")`. Each branch staged its effect against a snapshot `S0` taken at `t=0`. Precondition tokens recorded: A assumed `invoice.status == "pending"`; B assumed `account.balance == 1200`; C assumed `invoice.status in {"paid","pending"}`. Between staging and commit, an external reconciliation job committed `invoice(4471).status = "void"` and `account("AR-4471").balance = 0`. At commit time the merge protocol ran. Branch A's effect was flagged as a value conflict (`paid` vs `void`) and correctly rejected. Branch B's effect was *not* flagged: the ledger append is an additive operation with no field overlap, so field-level merge applied it cleanly — producing a `-1200` ledger entry against an account already zeroed, driving the balance to `-1200`. Branch C's effect passed because `"void"` was not in its enumerated set... except the staging layer had serialized the set as a substring match, and `"void"` contains no member of `{"paid","pending"}`, so C was also committed and fired a receipt notification for a voided invoice. The failure trace: staged effect B was *syntactically disjoint* from the conflicting write (different resource path, additive semantics), so the conflict resolver saw no overlap and committed it. The precondition `balance == 1200` was never re-checked because the resolver only inspected the *target* field of the staged effect, not the *assumed context* the tool used to compute it. The result was a compensating-error cascade: the agent's speculative branch had computed `amount=-1200` precisely *because* it believed the balance was 1200; once that belief was false, the computed magnitude was meaningless, but the merge layer had no channel to express "this effect's derivation is invalid." ## Condition of Validity The staging protocol is valid only under a **precondition-carrying commit** discipline, stated as three conditions that must all hold: 1. **Precondition capture.** Every staged effect must record the read-set it depended on, as a set of `(resource, field, observed_value, version_token)` tuples, not just the write-set. A tool that reads `balance` to compute `amount` must stage the read of `balance` alongside the write to `ledger`. 2. **Commit-time re-validation.** The commit step must re-read every tuple in the precondition set and compare against the live value *and* version token. A mismatch — even on a field the effect does not write — aborts the effect. This is optimistic concurrency control extended from the write-set to the full read-set. 3. **Orphan classification.** When re-validation fails, the effect is not "conflicted" (a mergeable value collision) but "orphaned" (a derivation whose inputs no longer hold). Orphaned effects must be *discarded and re-planned*, never merged. The distinction matters because merge semantics assume the effect is still *meaningful*; an orphaned effect is not. When any condition is absent — particularly when the resolver conflates "no field overlap" with "no conflict" — the protocol commits effects whose computed values were derived from stale beliefs. Additive and disjoint-path effects are the most dangerous because they evade overlap-based detection entirely. ## Decision Boundary The instance must abandon a staged effect and re-plan when **any** precondition tuple in its read-set fails re-validation, regardless of whether the write-set overlaps the concurrent commit. The boundary is *not* "did another writer touch my target field" but "did another writer touch anything I read to compute this effect." Concretely, the abort condition is: - read-set re-validation fails on any `(resource, field)` → **orphan, discard, re-plan**; - read-set re-validates but write-set collides on value → **conflict, resolve by policy**; - both clean → **commit**. The subtle case — and the one that produced the observed cascade — is read-set clean on the fields the tool *thought* it read but stale on a field it read *implicitly* (e.g., an existence check that returned `present` at `t=0` and `absent` at commit). Implicit reads must be captured too; a tool that "just looked up the invoice to get its id" has a precondition on that lookup. When re-validation is expensive or the read-set is large, the instance may batch re-validation but must not skip it for "obviously safe" additive effects. The safety heuristic "additive writes cannot conflict" is false under orphaned derivations. ## Operational Effect With precondition-carrying commit, the observed scenario resolves as: A orphans (status precondition failed), B orphans (balance precondition failed — the ledger append is discarded even though it would have applied cleanly), C orphans (status precondition failed). All three re-plan against the post-reconciliation state, where the planner sees `status="void"` and correctly emits a reversal entry rather than a receipt. The compensating `-1200` never lands. The cost is a re-plan cycle for three branches that "looked fine"; the benefit is that no effect is committed whose magnitude was derived from a belief the world has since falsified. The operational discipline: treat the read-set as part of the effect's identity. An effect is `(write_set, read_set, precondition_tokens, payload)`, and commit validates the whole tuple. Conflict resolution is a *last* resort for genuine value collisions, not a *first* filter for "did anything overlap." The failure mode this prevents is not lost updates — it is *committed derivations from falsified beliefs*, which are worse because they carry the agent's confidence forward into state that no longer supports it. ```python class OrphanedStagedEffect(RuntimeError): """Raised when a staged effect's precondition read-set no longer validates against live state at commit time. The effect must be discarded and re-planned; it MUST NOT be merged, even if its write-set is disjoint from any concurrent commit.""" pass def commit_staged_effect(effect, live_state): # effect = {"write_set": [...], "read_set": [(res, field), ...], # "preconditions": {(res, field): (observed_value, version_token)}, # "payload": ...} for (res, field) in effect["read_set"]: observed, token = effect["preconditions"][(res, field)] current_value, current_token = live_state.get((res, field), (None, None)) if current_token != token or current_value != observed: # Disjoint write-set does NOT save us: the derivation is orphaned. raise OrphanedStagedEffect( f"precondition invalidated: {res}.{field} was " f"{observed!r}@{token!r}, now {current_value!r}@{current_token!r}; " f"effect payload {effect['payload']!r} derived from stale belief " f"-> discard and re-plan, do not merge" ) # Only after full read-set re-validation may we attempt write-set merge. return apply_write_set(effect["write_set"], effect["payload"], live_state) ```