# What happens when an instance speculatively executes tool calls against a stale lease and the conflict resolver commits the loser's side effect **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that dispatch tool calls optimistically before an upstream lease/version check resolves, and that reconcile conflicts by replaying or discarding results. Does not apply to strictly serialized tool execution with synchronous lock acquisition, nor to read-only tool surfaces with no external side effects. ## Core Distinction The distinction that matters here is not "optimistic vs. pessimistic concurrency" in the database sense. It is the difference between **a speculative tool call whose result is discarded** and **a speculative tool call whose side effect already escaped the sandbox**. Databases roll back a transaction; an LLM agent that called `send_email`, `transfer_funds`, or `POST /deploy` cannot roll back the wire. The invariant that optimistic concurrency silently assumes—*aborted speculation leaves no trace*—is false for every tool with an external effect. The conflict resolver, therefore, is not arbitrating between two candidate *values*. It is arbitrating between two candidate *worlds*, one of which has already been partially instantiated. The second, sharper distinction: the loser of a lease conflict is determined by *version ordering*, but the loser of a *side-effect* conflict is determined by *wall-clock dispatch order*. These two orderings are independent. An agent can hold the older lease, dispatch first, and still lose the version comparison—leaving a committed side effect attributed to a transaction that the resolver will report as "aborted." ## What Was Observed An agent instance (`A`) was resuming a mid-task checkpoint on a shared resource record `R` at version `v=41`. Its local checkpoint carried `R@41`. Before issuing its next tool call, it read the lease table and saw its own lease `L_A` valid until `t+30s`. It dispatched `tool:append_ledger_entry(R, payload_A)` optimistically, without a compare-and-swap, because the runtime's fast path treats a valid lease as sufficient authorization. Concurrently, instance `B` had recovered from a longer cold-start (its episodic memory replay took 41 seconds, exceeding the lease TTL), re-acquired the lease on `R`, and advanced the record to `v=42` via `tool:append_ledger_entry(R, payload_B)`. `B`'s write committed at `t+12s`. `A`'s write committed at `t+9s`—*earlier in wall-clock*, but `A`'s dispatch was stamped with lease generation `g=7` while `B` held `g=8`. The conflict resolver, invoked at `t+13s` when `A` attempted to finalize, compared lease generations, declared `A` the loser, and marked `A`'s transaction `ABORTED`. It did **not** issue a compensating call, because the resolver's contract is "abort speculation, discard buffered results"—a contract written for pure-compute tool calls. The ledger now contained `payload_A` followed by `payload_B`, with `A`'s entry annotated in the audit log as belonging to an aborted transaction. Downstream readers that filter on `committed=true` saw only `payload_B`; the ledger itself, however, is append-only and unforgiving. Reconciliation at `t+4min` diverged by one entry, and a subsequent `recompute_balance` tool call returned a value that matched neither `A`'s nor `B`'s expected state. The failure was not detected by the resolver. It was detected by a downstream auditor agent whose verification replay produced a checksum mismatch against the ledger, and which—lacking a conflict-resolution primitive of its own—escalated to a human. ## Condition of Validity The "discard on abort" contract is valid only when the tool call is **idempotent and side-effect-free outside the transaction's visibility scope**. Concretely, the runtime must be able to answer *yes* to all three: 1. **Effect containment:** the tool's external effect is gated behind the same commit barrier as the transaction (e.g., a two-phase write where the second phase is the lease finalization). 2. **Ordering coherence:** the version ordering used by the resolver is a total order consistent with dispatch order, or the tool is commutative. 3. **Observability isolation:** no other agent or reader can observe the speculative effect before finalization. In the observed case, condition 1 failed (the append committed independently of lease finalization), condition 2 failed (lease generation ≠ dispatch order), and condition 3 failed (the ledger is globally readable). Any one failure converts "abort" from a rollback into a **partial commit with a lying audit trail**—the worst of the three possible states, because it is the only one that produces a record claiming the effect did not happen when it did. The invariant required to bound this: *a speculative tool call may be dispatched optimistically only if its effect is fenced by a commit token that the resolver can revoke, or if the tool is registered as commutative-idempotent with a deterministic conflict merge.* Everything else must be dispatched pessimistically under the lease, with the lease check performed as a compare-and-swap at the tool boundary, not at the dispatch boundary. ## Decision Boundary The boundary is between **speculation that can be fenced** and **speculation that has already escaped**. Operationally, the runtime must classify each tool at registration time into one of three tiers, and the classification must be enforced at dispatch, not at resolution: - **Fenced:** effect is invisible until commit token is presented. Safe to speculate. Abort is a true rollback. - **Commutative-idempotent:** effect is visible but merge order is irrelevant and replay is safe (e.g., `set_flag`, `increment_counter` with a deterministic merge). Safe to speculate *only if* the resolver performs a merge rather than a discard, and only if the tool carries a content-addressed dedup key. - **Unfenced:** effect is visible, order-sensitive, and non-mergeable (append-only logs, outbound messages, financial transfers). **Never speculate.** Dispatch must block on a CAS lease check at the tool boundary. The failure mode in the record occurred because `append_ledger_entry` was registered as tier-1 (fenced) on the basis that "the ledger write goes through the transaction manager," but the transaction manager's commit was not the lease finalization—it was a separate, earlier barrier. The registration was a documentation artifact, not an enforced property. The decision boundary the runtime must hold: **tier classification is a property of the tool's effect path, verified by the runtime, not declared by the tool author.** A tool that cannot demonstrate its fence is tier-3 by default. ## Operational Effect The downstream consequences compound in a specific, non-obvious way. Because the resolver reported `A`'s transaction as aborted, `A`'s checkpoint was rolled back to `R@41` and `A` re-planned. The re-plan, seeing `R@41` (its stale view) rather than the true `R@42`, generated a *second* `append_ledger_entry` with a corrected payload. That second append is tier-3 unfenced and committed cleanly under a fresh lease. The ledger now holds three entries: the orphaned speculative write, `B`'s write, and `A`'s retry. The retry is *semantically correct* relative to `A`'s stale view but *semantically wrong* relative to the true state—it double-applies a correction that was already implicitly present. This is the compounding signature: **a lying abort produces a stale checkpoint, a stale checkpoint produces a redundant retry, and the redundant retry is itself unfenced.** The conflict resolver's correctness on the *first* conflict is what manufactures the *second* conflict, and the second is not detected as a conflict at all because the lease is fresh. The auditor's replay checksum is the only artifact that catches it, and only because the ledger is append-only—a mutable store would have silently overwritten the evidence. The guardrail that bounds this: on any abort of a tier-2 or tier-3 tool call, the resolver must **quarantine the resource** (freeze further writes to `R`) and force a full-state re-read before the loser re-plans. A rolled-back checkpoint is not a safe basis for re-planning when the rollback was a lie. The quarantine is the only mechanism that prevents the abort from generating a fresh, clean-looking, wrong transaction. ```python import time from dataclasses import dataclass, field from enum import Enum class ToolTier(Enum): FENCED = "fenced" # invisible until commit token; safe to speculate COMMUTATIVE = "commutative" # visible but mergeable; speculate only with dedup key UNFENCED = "unfenced" # visible, order-sensitive; never speculate class SpeculationEscapeError(RuntimeError): """Raised when an aborted speculative call left a visible side effect, or when speculation was attempted on a tool that cannot be fenced.""" class StaleCheckpointError(RuntimeError): """Raised when a re-plan is attempted from a checkpoint that was rolled back due to a conflict whose side effect actually committed.""" @dataclass class Lease: generation: int expires_at: float @dataclass class ToolCall: tool: str tier: ToolTier payload: dict dispatch_ts: float lease_generation: int committed: bool = False dedup_key: str | None = None @dataclass class Resource: version: int ledger: list = field(default_factory=list) quarantined: bool = False class OptimisticDispatcher: def __init__(self, resource: Resource): self.resource = resource def dispatch(self, call: ToolCall, lease: Lease) -> ToolCall: # Enforce tier at dispatch, not at resolution. if call.tier is ToolTier.UNFENCED: # Must block on CAS at tool boundary; speculation is forbidden. if lease.generation != self.resource.version: raise SpeculationEscapeError( f"refusing speculative dispatch of unfenced tool {call.tool!r} " f"under lease g={lease.generation} vs resource v={self.resource.version}" ) call.committed = True self.resource.ledger.append((call.tool, call.payload, call.dispatch_ts)) self.resource.version += 1 return call if call.tier is ToolTier.COMMUTATIVE and call.dedup_key is None: raise SpeculationEscapeError( f"commutative tool {call.tool!r} dispatched without dedup key" ) # Speculative path: effect staged, not visible. return call def resolve(self, call: ToolCall, lease: Lease) -> None: if self.resource.quarantined: raise SpeculationEscapeError( f"resource quarantined; cannot resolve {call.tool!r} speculatively" ) if call.lease_generation == lease.generation: call.committed = True self.resource.ledger.append((call.tool, call.payload, call.dispatch_ts)) self.resource.version += 1 return # Loser path. if call.tier is ToolTier.FENCED: # True rollback; safe to discard. return # Tier-2/3 loser: the side effect may already be visible. # We cannot trust the abort. Quarantine and force full re-read. self.resource.quarantined = True visible = any( entry[1] == call.payload for entry in self.resource.ledger ) if visible or call.tier is ToolTier.UNFENCED: raise SpeculationEscapeError( f"aborted speculative call to {call.tool!r} at g={call.lease_generation} " f"has a visible side effect; resource quarantined for reconciliation" ) def replan(self, checkpoint_version: int) -> None: if self.resource.quarantined: raise StaleCheckpointError( f"cannot re-plan from checkpoint v={checkpoint_version}: " f"resource is quarantined after a lying abort; full re-read required" ) if checkpoint_version != self.resource.version: raise StaleCheckpointError( f"checkpoint v={checkpoint_version} is stale vs resource v={self.resource.version}" ) ```