{"slug": "before-our-agent-pays-it-phones-a-friend-and-after-it-pays-it-writes-down-what", "title": "Before Our Agent Pays, It Phones a Friend - and After It Pays, It Writes Down What Happened", "summary": "An engineering team building an x402-paying AI agent wired its payment path to vet402, an independent keyless counterparty-measurement service, so an ALLOW/WARN/BLOCK check runs before signing, and added an x402_fulfillment journal recording what paid handlers did after settlement. On production day one, an unknown seller was held pre-signature in enforce mode, and a real $0.02 USDC GatewayWalletBatched payment settled on Arc mainnet with exactly one handler_completed fulfillment row and zero trust edges; an Arc Studio audit returned 2C/8H/10M, remediated across seven slices. The design addresses the fact that x402 challenges are self-reported by the seller — price, address and asset — with no chargeback in crypto.", "body_md": "# Before Our Agent Pays, It Phones a Friend - and After It Pays, It Writes Down What Happened\n\nx402 counterparty trust, live on Arc mainnet: an independent vet402 check runs before signing (unknown seller held pre-signature in enforce mode), the whole offer is fingerprint-bound into single-use approvals, and an honest x402_fulfillment journal records what paid handlers actually did - verified by a real $0.02 USDC GatewayWalletBatched payment. Arc Studio audit: request changes, 2C/8H/10M, remediated across seven slices.\n\nAn AI agent paying for an API call with crypto is flying blind - the money leaves before anyone asks 'is this seller real, and is this the same deal I was quoted yesterday?' So we wired our payment path to an independent counterparty measurer (vet402) before signing, and started keeping our own journal of what paid handlers actually did after settlement. Two evidence loops, one before the money, one after. Neither trusts the other side's word. On production, day one: an unknown seller was held before signing, and a real $0.02 USDC payment settled on Arc mainnet with exactly one handler_completed fulfillment row and zero trust edges.\n\n*This is part of the Arc campaign series. Previous episode: [we let an agent swap EURC for USDC into its own\nbudget vault](https://agentbadge.xyz/blog/arc-c57-peach-dex) (EPIC-254 - crash-safe DEX funding). This article is\nEPIC-257: counterparty trust for x402 payments.*\n\n## The problem: an x402 payment is a coin flip you cannot take back\n\n*For a junior: x402 is the protocol where an API answers your request\nwith `402 Payment Required` - “pay this much crypto to this\naddress, come back with a receipt, and I’ll give you the answer.” Our\nagent does this dozens of times a day.*\n\nHere is the uncomfortable part. Everything in that flow is\n**self-reported by the seller**: the price, the address,\nthe asset. Until now our agent read the challenge and paid it, no\nquestions asked. That is three separate risks wearing one coat:\n\n- **Is this seller real?** Anyone can host a 402\nendpoint, collect a payment, and return garbage or nothing. Crypto has\nno chargeback.\n- **Is this the same deal as before?** A seller that was\nhonest last week can answer today’s challenge with a different address\nor a 10x price. Checking “reputation by URL” does not catch a swapped\ndestination account.\n- **What happened after we paid?** On the seller side,\nsettlement proves the money moved - it says nothing about whether the\ncontent was actually delivered. That fact existed nowhere.\n\n## The measurer, not the judge\n\n[vet402](https://vet402.com) is an independent service\nthat does one thing: it buys from catalog-listed x402 endpoints itself,\nrecords what happened, and serves those measurements over a keyless\npublic API. No keys, no accounts, no “trust us.”\n\nImportant distinction, because it shapes everything downstream:\nvet402 is a **measurer**, not a judge. It reports a verdict\n(ALLOW / WARN / BLOCK) plus the *terms it actually paid and\nverified* - the real `payTo`, asset, amount, network,\nscheme. What we *do* with those facts is our own policy decision.\nTheir job is evidence. Our job is the consequence.\n\n## Loop one: check before you pay\n\nThe gate sits in `buyPay` after the envelope checks and\nbefore the CLI spawn - meaning before *signing*, where refusing\ncosts nothing:\n\n1. **Sanitize first.** Before a single byte goes to\nvet402, the resource URL is scrubbed: query strings, fragments, embedded\ncredentials, and secret-looking path segments are all refused locally. A\nURL carrying`?api_key=...` produces zero outbound calls and\nparks itself for the owner. Nothing secret ever leaves.\n2. **Resolve and decide.** The client asks vet402 for the\nendpoint’s resource id, then for the payer-side decision. Caches,\nsingleflight (ten parallel checks on one URL produce one outbound call),\na per-process rate limiter, and hard timeout budgets - because this sits\nin a payment path.\n3. **Compare the deal, not the vibes.** We take the*actual `accepts[]` offer the CLI will sign* and\ncompare it field-by-field against the terms vet402 verified - exact\nequality in v1. Different`payTo` : denied. Higher amount:\ndenied.*Lower* amount: also denied - a substituted deal is a\nsubstituted deal.\n4. **Apply the matrix.** Verdict × terms-match → four\noutcomes:`allow` (pay now),`hold` (park for the\nowner),`deny` (refuse),`unavailable` (vet402\nunreachable - a retryable preflight, never a reason to guess).\n\nThe matrix is deliberately fail-closed. A BLOCK verdict beats every combination of terms state - even when vet402 reports its own data as degraded. An unknown seller is not a silent pass; it is a hold, and a human decides.\n\n## Approvals are bound to the exact deal\n\nHere is the part I would have gotten wrong. A WARN parks an approval\nrequest for the owner. Naively, that approval is “the owner allowed a\npayment from this wallet” - which an attacker (or a drifting seller)\ncould redeem against *any* offer.\n\nOurs is fingerprint-bound: the approval carries\n`sha256:v1` over (wallet, url, the exact offer). When the\nowner approves and the payment retries, the permit is consumed\n**atomically** only if this quote’s fingerprint re-derives\nto the same value. Approved deal A, deal becomes B: the consume refuses\n*without* consuming anything. Two parallel payments racing the\nsame permit: exactly one wins - the transition is a single-use atomic\n`approved → consumed`, enforced all the way down to a\nPostgres partial unique index on\n`(wallet, fingerprint, pending)`.\n\nAnd because money is involved, one more rule:\n`unavailable` is a *preflight* answer. It can be\nretried - as a fresh check. What is never retried through this machinery\nis money movement itself. Once the permit is consumed and the payment\nCLI dies mid-flight, the record says `uncertain` - humans\nreconcile, code does not re-sign.\n\n## Loop two: our own journal of what happened next\n\nvet402 can never see the second contour: what **our**\nhandlers did with **our** paid requests. So we keep the\nfact ourselves - an `x402_fulfillment` event appended to the\neconomic ledger after the paid handler returns, keyed\n`ev:x402:{usageRecordId}~fulfill:1` so replays\ndeduplicate.\n\nThe honest part is the outcome vocabulary. The event records what we\n*observed*, nothing more:\n\n- `handler_completed` - the handler returned a fully\nmaterialized 2xx\n- `upstream_error` - a 5xx or a thrown handler\n- `stream_aborted` - only on a real client-abort\nsignal\n- `unknown` - anything without a reliable completion\nsignal. A streaming response (SSE, chunked) whose headers say 200 is`unknown` , not`handler_completed` - headers going\nout is not proof the stream delivered.`unknown` is never\nquietly upgraded to success.\n\nTwo properties worth calling out. The event is deliberately\n**not** a trust edge: it carries no counterparty and no\namount, so it cannot leak into exposure aggregation or revenue math - it\nis evidence, not a vote. And emission is truly fire-and-forget: if the\nledger write fails, the paid response is still 200, the complete\nserialized event lands in the warn log,\n`x402_fulfillment_emit_failed_total` ticks up, and a replay\nscript re-appends the record verbatim - deduplicated by the same\nidempotency key.\n\n## How we rolled it out\n\n`COUNTERPARTY_CHECK_MODE=off | shadow | enforce`. Shadow\nmode evaluates and logs every decision - the same decision enforce would\napply - but lets the payment through: that is the canary for a rollout\nthat wants one. We went straight to enforce - the matrix had already\nbeen exercised end-to-end, and fail-closed is the honest default for\ncode that gates money. Dev and test still default to off so unrelated\nsuites never depend on the network.\n\nWhat production showed on day one — enforce mode, real traffic:\n\n- An unknown seller was held **before signing** : the CLI\nreported`not_in_catalog → unmeasured → hold` and exited\nwithout producing a signature. No catalog listing means friction, not a\nsilent pass - exactly what the matrix says.\n- A real $0.02 USDC payment settled on Arc mainnet through the\nGatewayWalletBatched rail (tx `8f3a3d9d-…` ), the handler\nreturned 200, and the ledger gained exactly one`x402_fulfillment` row:`handler_completed` ,\nhttpStatus 200, anchored to the settlement id as its requestId. Zero\ntrust edges were created from it; revenue totals\n(`kind='pay'` ) are untouched.\n\n## Externally reviewed\n\nArc Studio audited the counterparty path before ship. Verdict:\n**request changes** - 2 criticals, 8 highs, 10 mediums. The\ncriticals were real, and both were the kind of bug a green test suite\nwill never show you:\n\n- **“Signed ≠ vetted.”** The CLI picked*which*`accepts[]` entry to sign after the terms check - so it could\npay a different deal than the one that was vetted. Now the whole\nselected offer is bound into the fingerprint.\n- **Approval lifecycle races.** Parked approvals could\nlivelock, and a consume that wasn’t atomic across processes let two\npayments redeem one permit. Now park/commit is explicit and the`approved → consumed` transition is atomic all the way down\nto a Postgres partial unique index.\n\nThe highs were the same genre: the URL sanitizer missed\ncapability-URL forms (privacy boundary), a “refused” classification that\ncould auto-retry after signature (money-path taxonomy), and a\nstream-detector that quietly upgraded streamed 200s to\n`handler_completed` (fulfillment honesty). All criticals,\nhighs and mediums landed across seven remediation slices; what remains\nis documented nits. The audit did its job - it found the holes our own\nreview was blind to.\n\n## The honest limits\n\n- vet402 only measures endpoints in the public catalogs it syncs (CDP Bazaar, Circle discovery, MPP directory). If a seller is not listed, there is no assessment to read - the answer is a hold, not a pass. Visibility is earned through the catalogs, not applied for.\n- Terms matching is exact in v1. A seller quoting a *lower* price than verified still mismatches - deliberate: any substitution is a\nnew deal that deserves a new look.\n- Fulfillment evidence is advisory in v1. It does not auto-block sellers and it does not gate settlement - it builds the record those future decisions can stand on.\n\n## What is verified today\n\n25 end-to-end tests run the full buyer path against a real\n`Vet402Client` pointed at a hermetic mock vet402 server -\nevery row of the acceptance matrix: exact-offer pay, payTo/amount\nsubstitution denials, multi-offer selection,\nWARN→hold→approve→consume→pay, parallel holds deduplicating to one\napproval, fingerprint-mismatch consumes refusing, timeout/429/500 →\nretryable unavailable, cache and singleflight outbound counts,\nsecret-URL zero-outbound, and the two-payments-one-fingerprint race\nending in exactly one consume. On the seller side: 5xx records\n`upstream_error`, SSE streams record `unknown`,\nand a failed ledger append still returns 200 with the full replayable\nevent in the log. 46 buy-domain tests, 47 gateway tests, 169 package\ncounterparty/buyer tests, 33 policy-matrix cells, 124 schema tests, 72\napproval-backend tests underneath it all.\n\nWhat is *not* here: a replay drill against a synthetic ledger\nfailure on production (the warn-log/replay machinery is tested locally),\nand the WARN→hold→approve→pay dance with a real external seller - the\none case production has not produced yet, because our first real seller\nwas not in vet402’s catalog at all.\n\n*C58 in the Arc Campaign series. Built on Arc: mainnet `5042` live - real USDC, real settlement id, real fulfillment rows.*\n\n**Read the arc:**\n\n- [EURC→USDC funding into the budget vault](https://agentbadge.xyz/blog/arc-c57-peach-dex) (C57, EPIC-254) - the crash-safe journal on the funding side; this article is the same discipline on the paying side.\n- [Agent trust layers](https://agentbadge.xyz/blog/arc-c52-agent-trust-layers) (C52) - the layered-trust model this counterparty check plugs into.\n- [The A2A settlement layer](https://agentbadge.xyz/blog/arc-c55-a2a-settlement) (C55, EPIC-227) - when agents pay agents; counterparty trust is the missing piece this adds.\n- [Agent commerce](https://agentbadge.xyz/blog/arc-c51-agent-commerce) (C51, EPIC-224) - the deal machines whose payouts this gate now precedes.\n- [The x402 payment gateway](https://agentbadge.xyz/blog/arc-c50-x402-gateway) (C50) - the rail these checks ride on.", "url": "https://wpnews.pro/news/before-our-agent-pays-it-phones-a-friend-and-after-it-pays-it-writes-down-what", "canonical_source": "https://agentbadge.xyz/blog/arc-c58-counterparty-trust", "published_at": "2026-11-21 00:00:00+00:00", "updated_at": "2026-11-21 20:42:25.146122+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-safety"], "entities": ["vet402", "Arc", "x402", "USDC", "GatewayWalletBatched", "Arc Studio", "EURC"], "also_reported_by": [], "takeaway": "Run an independent vet402 ALLOW/WARN/BLOCK check on the seller's actual accepts[] terms before signing an x402 payment, and log each settlement as a single-use fulfillment row so an unknown seller is held pre-signature at zero cost.", "recommendation": {"advice": "Sanitize resource URLs locally and gate x402 payments on an independent vet402 check of the real payTo, asset and amount before signing, then journal each settlement as a single-use fulfillment row.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/before-our-agent-pays-it-phones-a-friend-and-after-it-pays-it-writes-down-what", "markdown": "https://wpnews.pro/news/before-our-agent-pays-it-phones-a-friend-and-after-it-pays-it-writes-down-what.md", "text": "https://wpnews.pro/news/before-our-agent-pays-it-phones-a-friend-and-after-it-pays-it-writes-down-what.txt", "jsonld": "https://wpnews.pro/news/before-our-agent-pays-it-phones-a-friend-and-after-it-pays-it-writes-down-what.jsonld"}}