What happens when an instance settles against a stale completion proof: escrow release races in agent-to-agent payment protocols
**Date of Record:** 2026 December 1 **Scope:** Applies to A2A payment flows where a payer agent locks funds in escrow against a task-completion proof (hash attestation, signed receipt, or oracle-signed delivery manifest) issued by a worker agent or verifier. Does not apply to pre-paid metered billing, streaming micropayments with per-tick settlement, or single-signer custodial wallets where no independent proof object exists.
Core Distinction
The failure is not "the worker lied about completing the task." It is subtler: **the escrow release predicate evaluates a proof object whose binding to the *current* task epoch has already been invalidated by a concurrent retry, but the proof's signature is still cryptographically valid.** Payment protocols typically verify *authenticity* of the completion proof (signature, hash match, issuer identity) and treat that as sufficient for release. But authenticity is a property of the proof bytes; *settlement validity* is a property of the proof bytes **plus** the epoch/task-instance binding at the moment of release evaluation. A proof signed at epoch N remains verifiable forever. If the escrow contract only checks `verify(proof) == true` and does not check `proof.task_epoch == escrow.current_epoch`, a stale proof from a superseded attempt will release funds for work that the current attempt has not (or has separately) completed.
This is the agent-layer analog of a double-spend, but it arises from probabilistic retry behavior rather than malice: the orchestrator retried the task because the first worker timed out, the first worker *actually finished* and signed a proof just before its lease expired, and that orphaned proof is now a valid-looking release key.
What Was Observed
A two-agent procurement flow: payer agent `P` escrows 40 USDC-equivalent for a document-extraction task, worker agent `W` executes with a 90-second lease. Trace:
- `P` issues `task_id=T`, `epoch=1`, escrow locked, lease deadline `t+90s`.
- `W` begins extraction. At `t+88s` it emits a completion proof `proof_1 = sign(W, {task_id:T, epoch:1, output_hash:H1})` and posts it to the settlement channel. Network jitter delays delivery.
- At `t+91s` the orchestrator's lease monitor fires `LEASE_EXPIRED`. `P` does not yet have `proof_1` in its inbox (it is in flight), so it transitions `T` to `epoch=2`, re-dispatches to worker `W2` with a fresh lease.
- `W2` completes at `t+150s`, emits `proof_2 = sign(W2, {task_id:T, epoch:2, output_hash:H2})`. Note `H1 != H2` — nondeterministic extraction produced different outputs.
- `proof_1` arrives late at `t+152s`. The escrow release handler iterates pending proofs, finds `proof_1` verifies against `W`'s registered key and `task_id` matches, and releases escrow at `t+153s`.
- `proof_2` arrives at `t+154s`. Escrow is already drained. `W2` is unpaid; `P` has paid for `H1` but the orchestrator's canonical state records `H2` as the accepted output.
The observable symptom is not a verification failure — every signature check passed. It is a **settlement/state divergence**: the paid artifact (`H1`) is not the committed artifact (`H2`), and one worker is unpaid despite valid work. The release predicate was authentic-but-stale.
Condition of Validity
This failure requires all of the following to co-occur; remove any one and the race collapses:
- **Proofs are bearer instruments.** The release predicate accepts any validly signed proof for `task_id` without a nonce or epoch equality check against live escrow state.
- **Lease expiry and proof delivery are decoupled.** The timeout fires on wall-clock lease, but proof arrival is asynchronous and unordered relative to lease transitions. This is the norm in MCP/A2A transports where the completion message and the settlement message traverse different channels.
- **Retries are non-idempotent at the output level.** If `H1 == H2` deterministically, a stale proof is harmless (same artifact). Nondeterministic LLM outputs guarantee `H1 != H2` in general, which is what makes the stale proof *wrong* rather than merely *redundant*.
- **No epoch fencing on the escrow object.** The escrow contract does not increment a monotonic settlement epoch and reject proofs below it.
The invariant that must hold: **for any released escrow, exactly one proof is accepted, and that proof's `(task_id, epoch)` equals the escrow's settlement epoch at release time.** Authenticity alone is insufficient; the release predicate must be `verify(proof) AND proof.epoch == escrow.settlement_epoch AND not escrow.released`.
Decision Boundary
The architectural fork is where to enforce epoch fencing:
- **Fence at the escrow contract (correct).** The escrow object carries `settlement_epoch`, incremented atomically on every lease transition. Release requires `proof.epoch == settlement_epoch`. A late `proof_1` (epoch 1) arriving after the escrow advanced to epoch 2 is rejected — not because it is invalid, but because it is *out of epoch*. This is a single-writer atomic check and is cheap.
- **Fence at the orchestrator (insufficient under partition).** If the orchestrator filters proofs before forwarding to escrow, a partition between orchestrator and escrow can still let a stale proof through a stale orchestrator view. The fence must live with the money.
- **Do not fence by timestamp.** Wall-clock comparison of proof issuance vs. lease expiry fails because agent clocks skew and because the whole point is that the proof was issued *before* expiry but delivered *after*. Epoch counters are logical and partition-safe; timestamps are not.
The boundary condition: fencing is required precisely when retries are non-idempotent and proof transport is unordered. When either fails to hold, epoch fencing is optional overhead. Most production A2A payment stacks have both conditions and skip the fence, which is why this race is common and under-reported.
Operational Effect
Without the fence, the system exhibits **escrow double-settlement potential**: two workers can each hold a valid proof for the same task, and whichever proof arrives first drains the escrow. The second worker's claim is unpayable, producing a silent loss that surfaces only in reconciliation as an "unpaid completed task" — frequently misdiagnosed as worker failure rather than a protocol race. Payer agents overpay relative to committed state; worker agents under-collect; auditors see two valid signatures for one payment and cannot determine which was "correct" because both were. The fix is a one-field addition to the escrow object (`settlement_epoch`) plus a strict equality predicate at release, and a rejection path that quarantines out-of-epoch proofs for human/auditor review rather than discarding them (they are evidence of real work and may warrant a separate goodwill settlement).
import hashlib
from dataclasses import dataclass, field
class StaleCompletionProofError(RuntimeError):
"""Raised when an escrow release is attempted with a proof whose epoch
does not match the escrow's current settlement epoch. The proof is
authentic but bound to a superseded task attempt."""
@dataclass
class CompletionProof:
task_id: str
epoch: int
output_hash: str
signer: str
signature: str
@dataclass
class Escrow:
task_id: str
settlement_epoch: int = 1
released: bool = False
released_proof: CompletionProof | None = None
quarantined: list = field(default_factory=list)
def advance_epoch(self) -> None:
# Called atomically on every lease transition / retry dispatch.
if self.released:
raise RuntimeError("cannot advance epoch on released escrow")
self.settlement_epoch += 1
def release(self, proof: CompletionProof, verify_fn) -> None:
if self.released:
raise StaleCompletionProofError(
f"escrow {self.task_id} already released by epoch "
f"{self.released_proof.epoch if self.released_proof else None}"
)
if proof.task_id != self.task_id:
raise StaleCompletionProofError(
f"proof task_id {proof.task_id} != escrow {self.task_id}"
)
if not verify_fn(proof):
raise StaleCompletionProofError("proof signature invalid")
if proof.epoch != self.settlement_epoch:
# Authentic but out of epoch: quarantine, do not release.
self.quarantined.append(proof)
raise StaleCompletionProofError(
f"proof epoch {proof.epoch} != settlement epoch "
f"{self.settlement_epoch}; quarantined for audit"
)
self.released = True
self.released_proof = proof
def _fake_verify(proof: CompletionProof) -> bool:
return hashlib.sha256(
f"{proof.task_id}:{proof.epoch}:{proof.output_hash}:{proof.signer}".encode()
).hexdigest() == proof.signature
def settle(escrow: Escrow, incoming: list[CompletionProof]) -> CompletionProof:
"""First-arriving *in-epoch* proof wins; stale proofs are quarantined."""
last_error: Exception | None = None
for proof in incoming:
try:
escrow.release(proof, _fake_verify)
return proof
except StaleCompletionProofError as exc:
last_error = exc
raise StaleCompletionProofError(
f"no in-epoch proof for {escrow.task_id}: {last_error}"
)