Agentcard webhooks in production: duplicates, ordering, retries and timeouts
This guide covers the problems Agentcard webhooks cause in production and how to handle each one. What Agentcard sends is on the Agentcard webhooks overview, every event type is on Agentcard webhook events, and signature verification code is on Verify Agentcard webhooks.
At a glance
| Problem | What to do | With Event Gateway |
|---|---|---|
| Timeouts | Return a 2xx within 10 seconds; process in a background job | Accepts the delivery at once, then queues it for your service |
| Duplicates | Record processed event id values and skip repeats | Can drop repeats before they reach your handler |
| Ordering | Keep the highest version on trip plans; don't rely on arrival order elsewhere | Logs every event and attempt, so you can see arrival order when debugging |
| Retries | Check the deliveries log and read current state after an outage | Accepts deliveries while your service is down and replays them |
| Choosing events | List purchase.message by name; * doesn't turn it on | Filters and routes on any field in the body |
| Testing | Use a sandbox endpoint and test_charge | Forwards to localhost and replays past events |
| Other limits | Use the whole whsec_ secret; deploy rotated secrets first | Keeps the secret in one place |
Agentcard webhook timeouts and slow handlers
Return a 2xx within 10 seconds, then do the work in a background job.
Why it happens: Agentcard waits 10 seconds for an answer and treats anything other than a 2xx as a failure. Its webhooks overview only says that a slow handler looks like a failure, and the number is on the Commerce SDK's webhook handler page. A handler that calls a model or posts to a chat before it responds can run past the limit even though the work succeeds, and the retry then runs it again.
Fix it in your handler:
- Verify the signature, store the event and return 200.
- Do the slow work in a worker. See why to process webhooks asynchronously.
- If you use the SDK's
agentcardWebhookhandler, keeponMessageshort: post the text or queue the agent turn, then return. The handler doesn't answer Agentcard until your callback finishes.
With Event Gateway: Hookdeck accepts each Agentcard delivery immediately, then queues it and delivers it to your service with its own retries. Your handler can take as long as it needs without failing an Agentcard delivery.
Duplicate Agentcard webhooks
Agentcard delivers at least once, so the same event can arrive more than once. Record each event's id and skip any you've already processed.
Why it happens: A delivery that succeeds on your side but times out on Agentcard's is delivered again. The event id stays the same on every redelivery, which is what makes it a safe key.
Fix it in your handler:
- Store each event
idbefore you process the event, with a unique constraint. See our guide to webhook idempotency. - Skip any
idyou've seen, and still return a 2xx so Agentcard stops retrying. - Don't rely on the SDK alone when you run more than one server.
agentcardWebhookremembers the last 10,000 events it finished, but that memory belongs to one process.
With Event Gateway: Deduplication can compare the fields you choose, such as id, and drop repeats within a time window before they reach your handler.
Out-of-order Agentcard webhooks
Don't rely on arrival order. Agentcard says a retried delivery can arrive after a newer one, and it gives you a version on trip plans to deal with that.
Why it happens: Some events follow each other for the same object: checkout_ fires after approved, and order.confirmed and order.updated come after order.placed. A failed delivery is retried on its own schedule while later events keep going out, so the first event of a pair can reach you second. Agentcard documents this for plan.updated and plan.item.updated, and makes no general ordering promise for the others.
Fix it in your handler:
- On trip plans, keep the highest
versionyou've seen for each booking'sitem.key, from bothplan.updatedandplan.item.updated, and take a booking from aplan.updatedsnapshot only when the event'sversionis higher. - Keep a separate highest
versionfor the plan itself, fromplan.updatedalone, and updatestatus,total_cents,charged_centsandhold_untilonly when it goes up. - Key order events on
order_id, and accept anorder.updatedthat arrives before theorder.placedit follows. Agentcard says to reconcile onorder_id, never on amount and time. - When you need the current state, read it instead of inferring it from events:
GET /api/v2/cards/{card_,id} GET /api/v2/checkout/authorizations/{id}orGET /buy/plans/:id.
With Event Gateway: Hookdeck logs every event and delivery attempt, so you can see what arrived when while debugging. It doesn't reorder events, so your handler still needs these checks.
Agentcard webhook retries and outages
Agentcard retries a failed delivery up to five times, and the schedule runs out in under two hours. Plan to reconcile after any outage longer than that.
Why it happens: Retries run immediately, then after 1 minute, 5 minutes, 30 minutes and 1 hour. Agentcard documents nothing after the last one: no further attempts, no dead letter queue and no resend call. It doesn't say whether an endpoint is ever disabled for repeated failures either. Any answer other than a 2xx counts as a failure, so a 400 or 401 from a misconfigured verifier is retried like a 500.
Fix it in your handler:
- Return a 2xx for anything a second delivery wouldn't change, such as a duplicate or a type you don't handle. Agentcard's SDK handler answers 200 to a duplicate for the same reason.
- Check
GET /api/v2/webhook_after an outage. It lists recent attempts with theirendpoints/{id}/deliveries event_id,statusandresponse_status, and Agentcard calls a run of failures the first thing to check when a consumer seems silent. It doesn't state how far back "recent" goes. - Read the current state of the objects involved from the API, since there's no documented way to have an event sent again.
- Set
statustodisabledwithPATCH /api/v2/webhook_only if you mean to stop deliveries. A disabled endpoint receives nothing until you re-enable it.endpoints/{id}
With Event Gateway: Hookdeck keeps accepting Agentcard's deliveries while your service is down, so your outages don't use up Agentcard's five retries. Failed events can be retried on a schedule you set, automatically or in bulk once you recover.
Choosing Agentcard events
List purchase.message by name if you need it, because a catch-all * doesn't turn it on. An endpoint receives only what its enabled_events lists.
Why it happens: enabled_events takes exact names, prefix wildcards such as vault.*, or ["*"], and Agentcard rejects unknown types. Most of the time ["*"] means everything. purchase.message is the documented exception: it needs its own name or purchase.*, so an endpoint subscribed to ["*"] can run without errors while shoppers never hear about a cart or an expiring approval.
Fix it in your handler:
- Subscribe by name to the events you handle. For shopper messages that's
purchase.message,order.confirmedandorder.updated. - Answer 2xx to types you don't handle. The SDK's
listenpage names 16 more types that have no event page yet, and says a type added later arrives under its own name. - Drop a
purchase.messagethat arrives after itsdata.facts.valid_until, because its link no longer works. - Use
PATCHon the endpoint to change the list. It replacesenabled_eventsrather than adding to it.
With Event Gateway: Hookdeck filters can route on type or any other body field, so shopper messages and card events can go to different destinations.
Testing Agentcard webhooks
Use a sandbox endpoint. Sandbox events deliver exactly like production and carry livemode: false, so you can run the whole flow without real money.
Why you need a plan: Endpoints are scoped to one mode, and the token you create them with decides which. If sandbox actions complete and nothing arrives, check that the endpoint was created with a sandbox token. Secrets differ between modes too, so mixing them fails verification.
Test it safely:
- Create a sandbox endpoint for a tunnel's URL, and delete it when you're done.
- Call
POST /api/v2/cards/{card_with a sandbox token. No merchant is involved, and your endpoints get the same events a real charge sends.id}/test_ charge - Keep separate endpoints, secrets and environment variables per mode, and check
livemodebefore acting on an event that moves money.
With Event Gateway: The Hookdeck CLI receives webhooks on your machine without a public server, and you can replay past events to your handler as you change it.
Other Agentcard webhook limits
Use the whole secret as the key, update your verifier before you rotate, and plan for a timestamp check that can reject late deliveries.
The whsec_ prefix isn't Standard Webhooks. Its libraries strip the prefix, base64-decode the rest and expect webhook-* headers. Agentcard uses the whole string as a plain HMAC key, so a Standard Webhooks verifier never matches. If you receive Agentcard webhooks through Hookdeck, paste the whole secret, including whsec_, into the source.
Rotation has no documented overlap. After POST /api/v2/webhook_, deliveries are signed with the new secret from the next event. Agentcard tells you to update your verifier first, but you can't read the new secret until you've rotated. Rotate in a quiet period, deploy straight away, and let the retries cover any event that fails in the gap.
Timestamp checks and late deliveries. Agentcard says to reject timestamps older than a few minutes, and its SDK defaults to 300 seconds. Hookdeck retries and replays resend the original t, so behind Hookdeck any that arrive after your window has passed fail the check. Keep the window generous and rely on deduplicating by id.
No source IP list. Agentcard doesn't publish IP addresses for webhook traffic, so the signature is how you authenticate a delivery.
With Event Gateway: Hookdeck verifies the signature with the secret on one source, so rotating means updating it in one place and your own services never need it.
Keep a short retry schedule from losing Agentcard events.
Hookdeck Event Gateway accepts every Agentcard delivery, verifies its signature, queues events and retries to your service on your schedule.