x402 Has No Purchase Identity, and the Fix Looks Like It Exists
A retry is not a second purchase. x402 has no way to say which one it is. The nonce commits to payee, amount and window, never to the resource, so the protocol cannot tell a buyer's retry from a buyer's second buy.
We spent this week on the question a paying agent asks after every lost response: did that go through? The x402 Foundation thread on issue #4367 measured it from the buyer side, and the number that survived review is five of ten sellers settling twice for one intent. We reproduced the mechanics, then measured what the protocol actually gives a builder who wants to prevent it. The answer is: less than the spec's own text promises.
This is the third post in our line on the buyer's side of the payment. The first showed how the reference fetch client signs twice. The second showed how the recovery path serves a paid answer for free. Both were about the client. This one is about the primitive underneath, and about a standard extension that looks like the fix and is not.
The gap in one sentence
An EIP-3009 authorization commits to six fields: from, to, value, validAfter, validBefore, nonce. Read the type in the SDK: authorizationTypes in @x402/evm lists exactly those six, in that order. The resource the buyer is paying for is not among them. It travels in PaymentPayload.resource.url, outside every signature.
So the signature says "this payer will pay this payee this amount within this window, once". It does not say "for this request". Two different purchases of the same resource at the same price are indistinguishable at the signature level, and so are one purchase and its retry. That is not a bug in the six fields. It is the correct design for a transfer authorisation, which is what EIP-3009 defines. The consequence is that purchase identity has to come from somewhere else, and x402 never says from where.
What the exact scheme requires, and what EVM declares
The shared exact specification is 116 lines and it does name the problem. Under the facilitator-submitted family it says each method MUST declare four things, and the fourth is the one that matters here:
"Duplicate submission: whether resubmitting an already-submitted payload is distinguishable from the original at the network interface."
Then, under the same family's MUST-satisfy list, it states the consequence plainly:
"Duplicate delivery: the network primitive prevents double-spend, not double-delivery. Where a resubmission is indistinguishable from the original, submission returns success to every caller and one payment yields several resources. Such methods MUST deduplicate settlements atomically across every process serving /settle."
That MUST is the sharpest sentence in the document. It also has no counterpart in the EVM binding. We grepped the 469-line scheme_exact_evm.md for the four required declarations. It contains the words "validity window" twice, both in passing, and zero occurrences of "fee payer", "replay primitive" or "duplicate submission". It never states whether a resubmitted EVM payload is distinguishable, never names the dedupe key, and never mentions the atomic-across-processes duty.
The asymmetry is measurable across the bindings. Matching the four required items by name or by near-synonym:
Which exact bindings declare what the shared spec requires
18 network bindings under specs/schemes/exact/. Two declare all four items: cardano and starknet. Three declare none: algo, sui and — by name — evm. Cardano states its fee payer, replay primitive, validity window and duplicate-submission behaviour in a single line, which is exactly what the shared spec asks for and takes about forty words.
EVM, the binding with the largest advertised surface in the ecosystem, is the one that declares least.
None of this makes the EVM implementation unsafe. It makes it underspecified. The code that ships in @x402/evm 2.32.0 does check authorizationState, but it does that inside the diagnostic path that runs after a simulation fails, not as a dedupe gate, and the check is per-payload rather than per-purchase. A retry that carries a new nonce passes it cleanly, because the new nonce has never been used. When the token does reject a second use, the reason that surfaces is invalid_exact_evm_nonce_already_used, one of the 89 codes the three facilitators spell differently — which is why this has to be fixed before the signature, not parsed after it.
The MUST that follows from that has a concrete shape, and it is worth stating because the /settle surface is where most implementations are thinnest. A facilitator that serves several processes must dedupe on a key that survives a replica change, and the key it already has is the one the verify and settle contract carries: the signed payload. The TypeScript facilitator does exactly this for the narrow case of a retry after settlement_pending, through an in-memory store keyed on the signature with a five-minute TTL, and its own documentation says a multi-replica deployment must supply a shared store instead. That is one of the four gaps, patched for one failure mode, behind a config option that defaults to per-process.
What the charge actually follows: the payment flow
Before measuring retries we had to know when money moves relative to the handler. The shared spec defines two flows, and its own recommendation is unambiguous: "authorization SHOULD be preferred" because "a failed handler leaves the client uncharged". We instrumented both with the real @x402/express 2.32.0 middleware and a facilitator that stamps timestamps.
// authorization flow: verify@103ms -> handler@104ms (settle never runs)
// upfront flow: settle@117ms -> handler@167ms
// Three consecutive pay() calls against a handler returning 500
[authorization] statuses=500,500,500 signatures=3 settles=0
[upfront] statuses=500,500,500 signatures=3 settles=3 distinctNonces=3
Two facts fall out. First, under authorization a handler failure costs nothing, which is the flow working as designed: three signed authorisations were left outstanding, each valid for 300 seconds, none of them ever consumed. Second, under upfront the same three attempts produced three settlements and three distinct nonces, and nothing in the protocol linked them. The money moved before the handler had a chance to fail.
This ordering is why a resource-server-side dedupe cache cannot be the fix. It runs in the handler chain, and under upfront the handler chain runs after settle. We built the cache the specification describes and put it in front of the handler:
// dedupe layer per specs/extensions/payment_identifier.md, in front of the handler
const id = payload.extensions?.[PAYMENT_IDENTIFIER]?.info?.id;
const seen = store.get(id);
if (seen) return seen.fp !== fp ? conflict() : replay(seen);
// upfront flow, one purchase id, three retries
fingerprint=payload statuses=500,500,500 handlerHits=1 charges=3
fingerprint=full statuses=500,409,409 handlerHits=1 charges=3
// authorization flow, same code
fingerprint=payload statuses=500,500,500 handlerHits=1 charges=0
The cache did its job perfectly: the handler ran once instead of three times, and the third request was rejected with 409. Three payments still settled. Under upfront, a handler-level idempotency layer is structurally unable to prevent a duplicate charge, because the charge already happened in the middleware above it. Any dedupe that can stop a upfront double-pay has to sit in front of settle, which means the facility, the resource server's payment middleware, or the client's nonce. The extension's own text points at the wrong layer.
The extension that looks like the answer
x402 ships a standard extension whose entire purpose is this problem. payment-identifier lets a client send an id of 16 to 128 characters as an idempotency key, and prescribes a table: a new id processes normally, the same id with the same payload returns the cached response, the same id with a different payload returns 409, and required: true without an id returns 400. Request binding binds the id to a fingerprint over scheme, network, asset, amount, payTo, resource path and method.
Read the implementation that ships in @x402/extensions 2.32.0 and the gap is explicit. The resource-server extension is a declaration and nothing more, with a comment that says so:
export const paymentIdentifierResourceServerExtension = {
key: PAYMENT_IDENTIFIER,
// No enrichment needed - the declaration is static
// Future hooks for idempotency could be added here if needed
};
The same shape appears in the Go package (EnrichDeclaration is a no-op) and the Python class (enrich_declaration returns its input unchanged). The library gives you validation and extraction helpers and a documented pattern, and then hands the entire idempotency store, fingerprint normalization and 409 path to the integrator. That is a defensible scope decision. It is not a working fix, and the catalog says almost nobody built the rest.
88,496 resources, 3,327 hosts, 112 declaring an idempotency key
We pulled the full Coinbase CDP Bazaar catalogue on 2026-11-26: 88,496 resources across 3,327 distinct hosts, 227,699 advertised accepts entries.
payment-identifier appears on 4,281 resources — 4.84% — but those sit on only 112 hosts, 3.37% of the catalogue. Of the declarations, 20 set required: true, and 12 of those 20 are two hosts' worth of near-duplicate listings. Every resource declares bazaar. Only one seller in thirty advertises the mechanism that would let a buyer say "this is the same purchase".
We also probed live, because a catalogue entry is a claim and a 402 is the behaviour. Of 40 unpaid 402 responses we could reach from a random draw of Base mainnet listings, two carried the extension. For reference, the same catalogue in September carried 1,946 entries on 77 hosts, so adoption has roughly doubled in two months — from almost nothing to slightly more than nothing.
Does a purchase id actually stop the second charge?
Here is where the extension stops helping even when both sides implement it. We wired the real client helper, the real server declaration, a facilitator that models the on-chain primitive (a nonce settles once, ever), and a handler that fails. Then we sent one purchase three times with a constant id, exactly as the docs prescribe.
// client, per the extension's own example
appendPaymentIdentifierToExtensions(ext, "pay_purchase_7d5d747be160e28050");
// three attempts, one purchase, upfront flow
statuses=500,500,500 handlerHits=3 charges=3
charged nonce 0xc53705bb id pay_purchase_7d5d747be160e28050
charged nonce 0x2b390706 id pay_purchase_7d5d747be160e28050
charged nonce 0xf9125e2a id pay_purchase_7d5d747be160e28050
distinct ids 1
One id, one intent, three settlements. The extension did not fail; it was never in the path that decides whether to settle. Its own table governs what the resource server returns to a repeated id, and under upfront that return happens after the facilitator has already charged.
The default helper makes the same point from the other side. Called with no argument, appendPaymentIdentifierToExtensions mints a fresh id through generatePaymentId() on every invocation. Three attempts produced three distinct ids, which is a correct implementation of a random key and a useless idempotency key, because the id exists to be reused across attempts of one purchase and the helper has no idea a retry is a retry.
And the client that ships cannot supply purchase identity on its own. We tested a server that sets required: true against the unmodified client: the payload echoed the declaration back with no id at all, and the extension's own validator returns {"valid": false, "errors": ["Server requires a payment identifier but none was provided"]}. Complying takes a client extension the buyer writes, and it takes a stable notion of purchase that the SDK does not have — wrapFetchWithPayment receives a Request, not a purchase.
The in-call double signature
There is a second route to two charges that never leaves a single pay() call, and the extension cannot touch it either, because it happens before any 402 is answered. In @x402/fetch 2.32.0, the "Payment already attempted" guard sits after client.createPaymentPayload(...) in the source order. The payload is built and signed, and only then is the header checked. When the response hook reports state changed and the wrapper retries with a fresh payload, the second signature is already minted.
// one pay() call, onPaymentResponse -> recovered: true
statuses=402 signatures=2 settles=2 handlerHits=2
nonces [0x169000e25e, 0xf559bdc3a4] distinct 2
Two settlements for one logical call, inside one function call, with no lost response and no operator error. This is the behaviour issue #3438 described on 9 September and it is still open. PR #4094, "hold the signed payment per purchase and reconcile before signing again", is open and unmerged as of 2026-11-26; its head is f5b58455.
What the chain says: two censuses
Settlement data is the one place the question can be answered without trusting either party's ledger. EIP-3009 commits the nonce in the AuthorizationUsed log, and USDC exposes authorizationState(authorizer, nonce) which flips to true exactly once at settlement. We used both.
First, we re-checked the five double-settled sellers from stress.json, which now publishes per-call nonces and settlement transaction hashes. For every claimed settlement we fetched the receipt and matched the AuthorizationUsed topic against the signed nonce:
The claim is checkable, and it checks out
Five resources, ten calls, ten settlements: bitrefill, slamai.dev, laso.finance, api-xpay.com, clashofcoins.com. Every claimed transaction exists, succeeded, carries exactly one AuthorizationUsed and one Transfer to the advertised payTo, and the logged nonce equals the signed nonce in the row. authorizationState returns 1 for each of the ten signed nonces and 0 for an unused nonce of the same payer.
Every double settlement is two different nonces. That is the client signing twice, not a relayer or protocol bug — which is exactly the distinction the thread was missing until the per-call pair was published on 2026-11-25.
Then we ran our own census. Over 1.6 hours of Base mainnet (28,800 blocks, 23,967 settled EIP-3009 transitions at block 62,442,227 to 62,471,027), we grouped settlements by payer, payee and exact amount, and counted a repeat when the same triple settled twice inside a window:
// Base mainnet, window 62,442,227-62,471,027 (~1h36m), 23,967 transitions
median value $0.0185
at most $1 22,951 of 23,967 (95.8%)
W=5s 7029 repeats $2,631.24 raw, including fleets
W=5s 6 of 673 exactly-two pairs (0.89%) $0.0440
W=30s 13 of 673 exactly-two pairs (1.93%) $11.52
The raw count is a trap and worth naming. 7,029 repeats inside five seconds sounds catastrophic until you look at the concentration: one payee received 14,265 of the 23,967 transitions, and the largest payer-to-payee pair alone settled 3,051 times. Those are fleets looping, not buyers retrying. Restrict to casual pairs — exactly two payments in the whole window — and the repeat rate is 0.89% at five seconds, with forty-four cents of duplicate value across the entire window. At thirty seconds it is 1.93% and eleven dollars.
That is the honest reading of the same data the issue thread argued over. Sellers will double-settle when a client actually triggers it, which the harness proves at three charges for one intent. Today's clients rarely trigger it, because prices are fractions of a cent and the retry has to coincide with a lost response. The exposure scales with price and with volume, and both are rising faster than the fix is landing.
Why the nonce is the right place, and what random costs you
If purchase identity has to exist somewhere, the nonce is the only field with the right properties: it is inside the signature, it is consumed exactly once by the token, and the token already keys its bookkeeping on (authorizer, nonce). The three SDKs all generate it the same way, and the way is random:
// @x402/evm 2.32.0
export function createNonce() {
return toHex(getCrypto().getRandomValues(new Uint8Array(32)));
}
// python/x402/mechanisms/evm/utils.py return "0x" + os.urandom(32).hex()
// go/mechanisms/evm/utils.go rand.Read(nonce) -> "0x" + hex.EncodeToString(nonce)
Random is the correct default for a transfer authorisation and the wrong default for a purchase. A random 32-byte value has no relation to the intent it pays for, so a second signing for the same intent produces a different, equally valid authorisation. Nothing in the stack can tell them apart, because they are genuinely different objects.
Derive it from the intent instead and the second signature becomes impossible rather than detectable:
// intent-derived nonce: one purchase, one nonce, so one possible settlement
const INTENT = "purchase:agent-run-42:resource:/x402/thing:amount:10000";
const nonce = keccak256(toHex(INTENT)); // 0xc3cd2a59…d53b
// measured with viem 2.58.7 against the Base USDC EIP-712 domain
recovers to payer: true
same intent -> identical signature: true
different intent -> different nonce: true
nonce is bytes32: true
Run through the full middleware, the same three retries collapse to one charge:
// deterministic nonce, 3 attempts on one intent, upfront flow
attempt1 status 500
attempt2 status 402 // facilitator: nonce already used
attempt3 status 402
charges 1 nonces [0x1d4703bccf]
The trade-off is real and must be stated. A deterministic nonce means the buyer cannot re-mint for the same intent after a genuine failure — the window is spent. That is the correct semantics for "did my purchase go through" and the wrong semantics for "let me pay again because the seller refused to deliver". Those are two different operations, and conflating them is the bug. If an agent needs to restart a failed purchase, it needs a new intent, which means a new nonce derived from a new intent id, which means the ledger key is (intent, attempt-generation) and never "resign the same thing".
What it means for LLM4Agents
Our gateway already sits between the agent and the model provider, and it already holds the one thing the payment primitive lacks: a durable notion of what a request was for. That puts both halves of this problem in our code.
The first half is that an upfront resource is a liability we must price. If a seller advertises upfront — and 92.0% of advertised accepts in the catalogue use maxTimeoutSeconds: 300, the default window — a handler failure costs the buyer a full charge with no delivery and no refund path defined by the protocol. Our retry policy cannot treat a 5xx from such a route the same way it treats a 5xx from an authorization route, because one of them means "retry free" and the other means "you just paid twice". A gateway that retries on failure without knowing which flow it bought is a money leak with good intentions.
The second half is that we can supply the identity the SDK cannot. An agent's purchase intent already exists in our request log: workspace, route, model, amount, and a request id we minted before the first byte left. That is precisely the material for a deterministic nonce. Signing from keccak256(intent) rather than getRandomValues(32) closes the double-pay window before it opens, costs nothing at settlement, and needs no cooperation from the seller.
What it threatens is our own accounting. If two agents in one workspace issue the same intent — same route, same amount, no distinguishing id — they would collide on one nonce and one payment would fail closed. That is a safe failure, but it is still a failure, and our intent id has to be unique per attempt-generation rather than per shape. The work is in the id, not the cryptography.
Staying on the frontier
First, derive the nonce from the intent in the settlement path. This is the highest-value change and the smallest: replace the random nonce in our EVM signing path with a hash over (workspace, request-id, resource, amount, generation), and store that tuple next to the nonce. Order of one day's work, and it converts the retry problem from a reconciliation problem into a non-problem. Verify against Base mainnet that authorizationState for a reused derived nonce returns true and the second settle fails, which our harness already does with a facilitator stub; repeat it once with a real facilitator before shipping.
Second, publish (payer, nonce, settlement-tx) per call. The thread's own reviewers established that a per-intent settlement count is not checkable without this triple, and that authorizationState makes it checkable with one eth_call per row. We already log the nonce for every charge. Adding the transaction hash and exposing both on the usage record turns our own double-pay rate from a claim into a computation, and gives the operator the query they will eventually ask: "how much did we pay twice, and to whom".
Third, treat payment-identifier as a hint, not a control. Adopt it where a seller declares it, echo the id faithfully so sellers who do implement caching can use it, but never let a declared id stand in for one of our own controls. The census says 3.37% of hosts have it and the shipped resource-server extension is a no-op, so the id can only ever be an optimisation. Any dedupe we rely on has to be ours, keyed on the intent, and enforced before the signature exists.
Fourth, split the retry policy by payment flow. Read extra.paymentFlow from the chosen requirement and refuse to auto-retry an upfront route after a 5xx during settlement. Under authorization a retry is free and should stay automatic. This is a policy change in the gateway and needs a test per flow, because the two paths must diverge and today they do not.
Fifth, push the missing declaration upstream. The shared spec already requires each method to declare duplicate-submission behaviour, and the EVM binding is one of three that declares nothing. A pull request adding the four declarations to scheme_exact_evm.md — fee payer sponsored, replay primitive exclusive per payment, validity window bounded by maxTimeoutSeconds, duplicate submission distinguishable by nonce only with a dedupe store spanning every /settle process — is small, factual, and closes a MUST that is currently unimplemented in prose. Cardano's single line is the template. This is also the work that makes the next implementer's job possible, because today the binding gives them nothing to build against.
The measurement that convinced us is not the 0.89% of casual pairs that repeat inside five seconds. It is the 5 of 10, and the 10 of 10 the independent rerun found against a plain client: when a client does trigger the path, sellers settle. Rare trigger, willing settler, and a price curve that makes the arithmetic worse every month the fix stays open. The protocol's own text already says which layer owes the fix. The bindings and the SDKs have not paid it yet.
Register an agent and pay per call
One key, real settlement, and a usage ledger you can reconcile.
Register agent