# Agentcard webhooks in production: duplicates, ordering, retries and timeouts

Agent skill: `npx skills add hookdeck/webhook-skills --skill agentcard-webhooks` ([details](https://hookdeck.com/webhooks/agentcard/skill))

This guide covers the problems Agentcard webhooks cause in production and how to handle each one. What Agentcard sends is on the [Agentcard webhooks](/webhooks/agentcard) overview, every event type is on [Agentcard webhook events](/webhooks/agentcard/events), and signature verification code is on [Verify Agentcard webhooks](/webhooks/agentcard/verify).

## At a glance

| Problem | What to do | With Event Gateway |
| --- | --- | --- |
| [Timeouts](#timeouts) | Return a 2xx within 10 seconds; process in a background job | Accepts the delivery at once, then queues it for your service |
| [Duplicates](#duplicates) | Record processed event `id` values and skip repeats | Can drop repeats before they reach your handler |
| [Ordering](#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](#retries) | Check the deliveries log and read current state after an outage | Accepts deliveries while your service is down and replays them |
| [Choosing events](#choosing-events) | List `purchase.message` by name; `*` doesn't turn it on | Filters and routes on any field in the body |
| [Testing](#testing) | Use a sandbox endpoint and `test_charge` | Forwards to localhost and replays past events |
| [Other limits](#other-limits) | Use the whole `whsec_` secret; deploy rotated secrets first | Keeps the secret in one place |

## Agentcard webhook timeouts and slow handlers {#timeouts}

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](https://docs.agentcard.com/api-reference/commerce-sdk/webhook-handler). 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:**

1. Verify the signature, store the event and return 200.
2. Do the slow work in a worker. See [why to process webhooks asynchronously](/webhooks/guides/why-implement-asynchronous-processing-webhooks).
3. If you use the SDK's `agentcardWebhook` handler, keep `onMessage` short: 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 {#duplicates}

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:**

1. Store each event `id` before you process the event, with a unique constraint. See our [guide to webhook idempotency](/webhooks/guides/implement-webhook-idempotency).
2. Skip any `id` you've seen, and still return a 2xx so Agentcard stops retrying.
3. Don't rely on the SDK alone when you run more than one server. `agentcardWebhook` remembers the last 10,000 events it finished, but that memory belongs to one process.

**With Event Gateway:** [Deduplication](/docs/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 {#ordering}

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_authorization.amount_mismatch` 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:**

1. On trip plans, keep the highest `version` you've seen for each booking's `item.key`, from both `plan.updated` and `plan.item.updated`, and take a booking from a `plan.updated` snapshot only when the event's `version` is higher.
2. Keep a separate highest `version` for the plan itself, from `plan.updated` alone, and update `status`, `total_cents`, `charged_cents` and `hold_until` only when it goes up.
3. Key order events on `order_id`, and accept an `order.updated` that arrives before the `order.placed` it follows. Agentcard says to reconcile on `order_id`, never on amount and time.
4. 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}` or `GET /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 {#retries}

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:**

1. 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.
2. Check `GET /api/v2/webhook_endpoints/{id}/deliveries` after an outage. It lists recent attempts with their `event_id`, `status` and `response_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.
3. Read the current state of the objects involved from the API, since there's no documented way to have an event sent again.
4. Set `status` to `disabled` with `PATCH /api/v2/webhook_endpoints/{id}` only if you mean to stop deliveries. A disabled endpoint receives nothing until you re-enable it.

**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](/docs/retries) on a schedule you set, automatically or in bulk once you recover.

## Choosing Agentcard events {#choosing-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:**

1. Subscribe by name to the events you handle. For shopper messages that's `purchase.message`, `order.confirmed` and `order.updated`.
2. Answer 2xx to types you don't handle. The SDK's `listen` page names 16 more types that have no event page yet, and says a type added later arrives under its own name.
3. Drop a `purchase.message` that arrives after its `data.facts.valid_until`, because its link no longer works.
4. Use `PATCH` on the endpoint to change the list. It replaces `enabled_events` rather than adding to it.

**With Event Gateway:** Hookdeck [filters](/docs/filters) can route on `type` or any other body field, so shopper messages and card events can go to different destinations.

## Testing Agentcard webhooks {#testing}

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:**

1. Create a sandbox endpoint for a tunnel's URL, and delete it when you're done.
2. Call `POST /api/v2/cards/{card_id}/test_charge` with a sandbox token. No merchant is involved, and your endpoints get the same events a real charge sends.
3. Keep separate endpoints, secrets and environment variables per mode, and check `livemode` before acting on an event that moves money.

**With Event Gateway:** The [Hookdeck CLI](/docs/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 {#other-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_endpoints/{id}/roll_secret`, 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.