Skip to content

Don't recreate a deleted subscription when a late subscription.updated arrives - #2585

Open
ohad6k wants to merge 1 commit into
boxyhq:mainfrom
ohad6k:root1-late-updated-recreates
Open

ohad6k wants to merge 1 commit into
boxyhq:mainfrom
ohad6k:root1-late-updated-recreates

Conversation

@ohad6k

@ohad6k ohad6k commented Nov 18, 2026

Copy link
Copy Markdown

Stripe doesn't guarantee webhook order. In handleSubscriptionUpdated, when no subscription row is found but the team exists, the handler calls handleSubscriptionCreated. If customer.subscription.deleted is processed before an older customer.subscription.updated, the updated handler finds no row and recreates the cancelled subscription with active: true.

Fix: in the missing-row branch, re-read the subscription from Stripe (stripe.subscriptions.retrieve) and return when its status is canceled or incomplete_expired. Otherwise the row is created as before.

Test: npm run test:race runs the two deliveries in every order on a real Postgres. 0/56 orders broken with the fix, 4/56 without the Stripe check (the spec models the Stripe re-read as a stripe_truth table). It uses viberaven race (open source). The race test now runs in npm test (jest && npm run test:race), so future webhook changes stay covered. The existing jest suite also passes (4/4).

Limits: the Stripe call is modelled, not executed. The update branch still writes the event payload as-is, so an older updated after a newer one can overwrite price or dates; not changed here. npm test now needs network access for npx.

…deleted subscription

Adds a race test (npm run test:race, in npm test) that runs the webhook writes in every order.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 18, 2026

Copy link
Copy Markdown

@ohad6k is attempting to deploy a commit to the BoxyHQ Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant