Repository navigation
fix(billing): acknowledge Stripe webhooks whose subscription references a missing organization - #8809
Conversation
…es a missing organization instead of retrying for days
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
…ry; drop the logging-only update catch
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
…he previous amount
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
customer.subscription.updated/createdwebhook return 400: the Enterprise reconcile threw "Enterprise organization not found", and the usage-limit step after it threw for the same reference. Stripe retried for ~3 days and then dropped the event; a retry can never succeed because a deleted organization does not come backorganization-missingoutcome from its locked transaction (before any write) and the handler logs it at error level with the Stripe subscription, customer, reference, event type and status, then acknowledges. Every transient case — issuance not yet matching Stripe, lease/lock, DB errors, seat/entitlement conflicts — still throws so Stripe retries. Organizations are always committed before their Stripe subscription is created, so "missing" is never "not yet"SubscriptionReferenceNotFoundError(reference is neither an organization nor a user):syncSubscriptionUsageLimitsthrows it andhandleSubscriptionUsageUpdateacknowledges only that type; other errors still fail the webhookensureOrganizationForTeamSubscriptiontreated a reference that is not an organization as a user id, so a dangling organization id tried to create a new organization owned by that id (failing on the member foreign key every time). It now checks the user exists first and throws the typed error;onSubscriptionUpdatelogs it and returnsType of Change
Testing
lib/billing/webhooks/enterprise-missing-organization.integration.ts(real Postgres, the real Better Auth Stripe plugin over HTTP, in-memory Stripe): renewal for a row with a missing organization returns 200 and still records the Stripe period; no organization/member is created for the dangling reference; a dashboard-created subscription naming a missing organization is acknowledged and records nothing; an issuance Stripe hasn't caught up with still fails the webhook (guard against over-acknowledging). The first three fail on the previous code; each fix reverted alone turns its test redlib/billingintegration suites, rootbun run test,bun run lint,bun run type-check,bun run check:audits,bun run docs-manifest:check, block-registry checkChecklist
test-auditauthoring gate)