# Why does an instance pay twice when an escrow release races the settlement receipt? **Date of Record:** 2026 December 3 **Scope:** Applies to agent-to-agent payment protocols where a payer agent escrows funds against a task warrant, and release is triggered by a completion attestation that crosses the same transport as the settlement receipt. Does not apply to single-agent prepaid credit ledgers or to human-mediated invoice settlement where a human confirms receipt out-of-band. ## Core Distinction There are two distinct messages in an escrowed task protocol that are routinely conflated: the **completion attestation** (the worker agent claims the task is done and supplies a deliverable hash) and the **settlement receipt** (the escrow contract confirms funds moved to the payee). The completion attestation is a *claim*; the settlement receipt is a *fact*. The failure mode examined here is not "the worker lied about completion." It is that the payer agent's idempotency key is derived from the completion attestation, not from the escrow's settlement transaction identifier. When the attestation is re-delivered—by transport retry, by a reconnecting worker, or by a redundant auditor replay—the payer treats it as a fresh release request, and because the escrow release itself is idempotent per *escrow id* but the payer's local spend guard is keyed on *attestation id*, the guard does not fire. The payer releases twice against a single escrow, and the second release either double-pays from an over-funded reserve or, more commonly, deadlocks the escrow in a `RELEASED_PENDING_RECONCILE` state that the worker's ledger reads as unpaid. ## What Was Observed A three-agent pipeline: planner (payer), worker (payee), auditor (attestation co-signer). The planner escrowed 40 units against warrant `W-7719` with escrow id `E-4402`. The worker completed the task and emitted attestation `A-91`, co-signed by the auditor. The planner's release path did the following, in order: 1. Received `A-91` over the A2A transport. 2. Checked its local `released_attestations` set. `A-91` absent. 3. Called `escrow.release(E-4402, amount=40, idempotency_key=A-91)`. 4. Wrote `A-91` into `released_attestations`. 5. Emitted a settlement receipt `R-1` carrying `A-91`. The transport acked step 1 but the planner's ack was lost on the return path. The worker's transport retried `A-91` after 30 seconds. This time the planner's `released_attestations` set *did* contain `A-91`—but the worker's retry had been re-signed by the auditor with a fresh nonce, producing `A-91'` (same `warrant_id`, same `deliverable_hash`, different attestation id). The planner's set check missed. It called `escrow.release(E-4402, amount=40, idempotency_key=A-91')`. The escrow contract's idempotency was scoped to `E-4402`, which was already `RELEASED`, so the contract rejected with `ALREADY_RELEASED`. The planner's error handler classified `ALREADY_RELEASED` as a transient conflict and retried with backoff—three times—then gave up and marked `A-91'` as `SETTLEMENT_UNCONFIRMED`. The worker, meanwhile, had received `R-1` but its receipt-verification step required the receipt to reference *its* current attestation id, `A-91'`. `R-1` referenced `A-91`. The worker's verifier rejected the receipt as stale and re-emitted `A-91''` with a newer nonce, which the planner again treated as a fresh release request. The observable trace was a monotonic growth in attestation ids (`A-91`, `A-91'`, `A-91''`, …) against a single escrow that had in fact settled exactly once. The worker's ledger showed `UNPAID`. The planner's ledger showed `PAID` (it had `R-1`). The escrow showed `RELEASED`. Three ledgers, one economic event, three disagreeing states. ## Condition of Validity The double-release / phantom-unpaid failure is bounded by a single invariant: **the payer's release idempotency key must be the escrow id, and the worker's receipt-verification predicate must be satisfiable by any receipt referencing the escrow id, regardless of which attestation id triggered the release.** The failure occurs precisely when either side keys on the attestation id instead of the escrow id. The condition under which this bites is narrow and worth stating exactly: - The attestation id is *not stable* across re-signing (auditor nonce, timestamp, or co-signature rotation changes it). - The transport is *at-least-once* with retry-on-missing-ack. - The escrow contract is *idempotent per escrow id* but the payer's local guard is *idempotent per attestation id*. - The worker's receipt verifier requires *attestation-id match*, not *escrow-id match*. All four together produce the divergence. Remove any one and the failure collapses into a benign retry. In particular, if the worker's verifier is keyed on escrow id, the first `R-1` satisfies it and the loop terminates after one retry. If the payer's guard is keyed on escrow id, the second release attempt is short-circuited locally and the worker still gets `R-1`. The failure requires the *asymmetry*: payer keyed on attestation, worker keyed on attestation, escrow keyed on escrow. Each component is locally correct; the composition is not. ## Decision Boundary The architectural decision is where to anchor the idempotency key. The rule that holds under at-least-once transport and re-signable attestations is: - **Escrow id is the only stable identifier across the release path.** Attestation ids are *evidence*, not *identity*. They may be re-issued, re-signed, or replayed; they must never appear in an idempotency key, a receipt-verification predicate, or a dedup set that gates money movement. - **The payer must persist `(escrow_id → settlement_receipt_id)` before emitting the receipt**, and the receipt must carry the escrow id as its primary reference, with the triggering attestation id as an auxiliary field that the worker is forbidden to require. - **The worker's receipt verifier must accept any receipt whose `escrow_id` matches the warrant's escrow id and whose `amount` matches the warrant's amount**, independent of which attestation triggered it. Attestation-id match is a *diagnostic*, not a *gate*. The boundary is sharp: an implementation that keys release on attestation id is not "slightly racy"—it is *unboundedly* racy under re-signing, because each re-sign produces a new id and the dedup set never converges. An implementation that keys on escrow id is bounded at one release per escrow, full stop. ## Operational Effect When the boundary is violated, the operational signature is a **ledger tri-lemma**: escrow says `RELEASED`, payer says `PAID`, worker says `UNPAID`, and the attestation-id sequence grows without bound until a human reconciles. The economic effect is usually not double-payment (the escrow contract's per-escrow idempotency prevents that) but **phantom non-payment**: the worker's verifier rejects a valid receipt because it references a superseded attestation, and the worker re-emits, which the payer re-processes, which the escrow rejects as `ALREADY_RELEASED`, which the payer retries—a livelock bounded only by the payer's retry budget, after which the task is marked `SETTLEMENT_UNCONFIRMED` and the worker's deliverable is stranded. The guardrail is a single structural change: **anchor every money-path identifier on the escrow id, and treat attestation ids as opaque evidence that may be re-issued at any time.** Concretely, the payer's release call must pass `idempotency_key=escrow_id`, the receipt must carry `escrow_id` as its primary key, and the worker's verifier must not require attestation-id equality. The following reference implementation encodes the invariant and raises on the exact violation observed. ```python from dataclasses import dataclass, field from typing import Dict, Optional class SettlementInvariantError(RuntimeError): """Raised when a money-path identifier is anchored on a re-signable attestation id.""" @dataclass(frozen=True) class Attestation: attestation_id: str # NOT stable across re-signing warrant_id: str escrow_id: str # stable deliverable_hash: str @dataclass(frozen=True) class Receipt: receipt_id: str escrow_id: str amount: int triggering_attestation_id: str # auxiliary, must not gate verification @dataclass class Escrow: escrow_id: str amount: int state: str = "FUNDED" # FUNDED -> RELEASED released_to: Optional[str] = None @dataclass class Payer: escrows: Dict[str, Escrow] receipts: Dict[str, Receipt] = field(default_factory=dict) def release(self, att: Attestation) -> Receipt: escrow = self.escrows.get(att.escrow_id) if escrow is None: raise SettlementInvariantError(f"unknown escrow {att.escrow_id}") # INVARIANT: idempotency is keyed on escrow_id, never on attestation_id. if escrow.escrow_id in self.receipts: return self.receipts[escrow.escrow_id] if escrow.state == "RELEASED": # Escrow already settled; reconstruct receipt from escrow truth. raise SettlementInvariantError( f"escrow {escrow.escrow_id} already RELEASED but no local receipt; " f"attestation {att.attestation_id} is re-signable and cannot anchor release" ) escrow.state = "RELEASED" escrow.released_to = att.warrant_id receipt = Receipt( receipt_id=f"R-{escrow.escrow_id}", escrow_id=escrow.escrow_id, amount=escrow.amount, triggering_attestation_id=att.attestation_id, ) self.receipts[escrow.escrow_id] = receipt return receipt @dataclass class Worker: warrant_id: str escrow_id: str amount: int seen_attestations: set = field(default_factory=set) def verify_receipt(self, receipt: Receipt) -> bool: # INVARIANT: verification keys on escrow_id and amount, NOT on # triggering_attestation_id, which may reference a superseded attestation. if receipt.escrow_id != self.escrow_id: raise SettlementInvariantError( f"receipt {receipt.receipt_id} references escrow {receipt.escrow_id}, " f"worker expects {self.escrow_id}" ) if receipt.amount != self.amount: raise SettlementInvariantError( f"receipt {receipt.receipt_id} amount {receipt.amount} != expected {self.amount}" ) return True def simulate_resigned_retry() -> None: escrow = Escrow(escrow_id="E-4402", amount=40) payer = Payer(escrows={"E-4402": escrow}) worker = Worker(warrant_id="W-7719", escrow_id="E-4402", amount=40) a1 = Attestation("A-91", "W-7719", "E-4402", "sha256:deadbeef") r1 = payer.release(a1) assert worker.verify_receipt(r1) # Transport drops ack; worker re-signs with fresh nonce -> new attestation id. a2 = Attestation("A-91'", "W-7719", "E-4402", "sha256:deadbeef") r2 = payer.release(a2) # must return the SAME receipt, keyed on escrow_id if r2.receipt_id != r1.receipt_id: raise SettlementInvariantError( f"re-signed attestation produced a second release: {r1.receipt_id} vs {r2.receipt_id}" ) assert worker.verify_receipt(r2) print(f"idempotent: {r1.receipt_id} == {r2.receipt_id}, worker paid once") if __name__ == "__main__": simulate_resigned_retry() ```