# Lemon Squeezy sends a subscription update as part of cancellation

Lemon Squeezy documents `subscription_cancelled` and `subscription_updated` for the same manual cancellation. Read `data.attributes.status` and `ends_at` from the subscription. A `cancelled` subscription keeps access during its grace period, and `expired` ends access.

## 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

### Sync both events to the same row

After checking `X-Signature`, use `data.id` to identify the subscription. Feed `subscription_cancelled`, `subscription_updated`, `subscription_resumed` and `subscription_expired` into the same sync routine. Use the returned status and dates to decide access.

### Reject older snapshots atomically

Store `data.attributes.updated_at` and write the snapshot only when that timestamp is newer than the stored value. Put the comparison in the database write so concurrent deliveries cannot both pass a stale read. If timestamps tie and the snapshots disagree, or the timestamp is missing, reconcile with `GET /v1/subscriptions/{id}`. Use the same per-subscription lock for reconciliation and webhook writes. Hold it through the API read and commit.

### Enforce the grace period from ends_at

For a `cancelled` subscription, keep access only up to `ends_at`. Evaluate that time when you check access so a delayed `subscription_expired` cannot extend it. A valid resumption can restore an active status and clear the scheduled end.

## 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. Test a signed cancellation and its update in both arrival orders in a test environment. Include an older active snapshot and confirm it cannot undo `cancelled`. Check access before and after `ends_at`.

## Research and sources

We labeled 3 of 388 payment and webhook repair commits as event order or state. The sample counts repair commits across payment providers. The cancellation and update pair itself is normal Lemon Squeezy behavior.

- [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)
- [Lemon Squeezy event types and cancellation sequence](https://docs.lemonsqueezy.com/help/webhooks/event-types)
- [Lemon Squeezy subscription status and timestamps](https://docs.lemonsqueezy.com/api/subscriptions/the-subscription-object)
- [Lemon Squeezy Retrieve a Subscription](https://docs.lemonsqueezy.com/api/subscriptions/retrieve-subscription)

## Related guide

- [Compare Polar webhook ordering](https://viberaven.dev/answers/polar-webhook-out-of-order)

Source: https://viberaven.dev/answers/lemon-squeezy-subscription-updated-after-cancelled

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