# Fetch current subscription state when Polar webhooks arrive out of order

When a Polar `subscription.updated` arrives after `subscription.revoked`, fetch the subscription from Polar before writing access. Process the fetch and write in a single sequence for each subscription ID so a slow worker cannot put an older result back.

## From the research

3 of 388 payment and webhook repair commits were labeled event order or state.

- [Event order and state count](https://github.com/ohad6k/viberaven-research/blob/2d45c586d8d73b8913651894f4451b8071086daf/data/fixcommits-subclasses.csv#L27)

## Apply the fix

### Queue the verified delivery

Verify the signature with the Polar SDK. For a Standard Webhooks endpoint, store `webhook-id` under a unique key scoped to the destination and acknowledge after queueing durably. Use `data.id` as the subscription key for the worker. It stays the same across different events for that subscription.

### Reconcile the current subscription

For `subscription.updated`, `subscription.canceled` and `subscription.revoked`, fetch `GET /v1/subscriptions/{id}` in the owning organization and environment. Serialize the fetch through the commit by subscription ID. Retry temporary API or database failures.

### Keep cancellation and revocation distinct

Read `cancel_at_period_end` and `ends_at` together with the current subscription status. A scheduled cancellation can leave access intact through the paid term. When Polar revokes the subscription, end access for that subscription ID.

## Verify the change

Run `npx viberaven check` from your repo root. The webhook check starts in VibeRaven 1.15. To run the current release explicitly, run `npx viberaven@1.20.1 check`. Review `payment_webhook_order` warnings in the handler. In a test environment, deliver a revocation followed by an older update for the same subscription. Check that stored access still reflects the current Polar subscription.

## Research and sources

We labeled 3 of 388 payment and webhook repair commits as event order or state. The sample counts repairs in Git history across payment providers, so the denominator is repair commits across providers.

- [Fix commit study and counting rules](https://github.com/ohad6k/viberaven-research/blob/2d45c586d8d73b8913651894f4451b8071086daf/studies/fix-commits/README.md)
- [Total payment and webhook repair commits](https://github.com/ohad6k/viberaven-research/blob/2d45c586d8d73b8913651894f4451b8071086daf/data/fixcommits-summary.csv#L4)
- [Polar webhook delivery and retries](https://polar.sh/docs/integrate/webhooks/delivery)
- [Polar Standard Webhooks and idempotency](https://github.com/polarsource/agent-toolkit/blob/main/skills/polar-integration/SKILL.md)
- [Polar subscription.revoked event](https://polar.sh/docs/api-reference/2026-10/subscription_revoked)
- [Polar Get Subscription](https://polar.sh/docs/api-reference/2026-10/subscriptions/get-subscription)

## Related guide

- [Compare Stripe webhook ordering](https://viberaven.dev/answers/stripe-webhook-events-out-of-order)

Source: https://viberaven.dev/answers/polar-webhook-out-of-order

Site index: https://viberaven.dev/llms.txt
