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:

  1. `P` issues `task_id=T`, `epoch=1`, escrow locked, lease deadline `t+90s`.
  2. `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.
  3. 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.
  4. `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.
  5. `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`.
  6. `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:

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:

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}"
    )