Skip to content

Stripe-DB subscription reconciliation: catch missing-webhook drift, auto-remediate #3623

Closed

Description

@bokelley

Triggering incident

Same person as #3589 — [email protected] / "Lina Georg" / "Tsvetelina Georgieva" — Stripe shows an active subscription, $250 paid on 2026-03-30 (Professional tier, cus_UF4bVR6XyNSeSk), customer correctly linked to her org. Our DB row for that org said subscription_status: null, effective_membership.is_member: false. She had been logging in for ~40 days believing she was a paying member because she was a paying member. System had been gaslighting her.

Resolved by calling POST /api/admin/accounts/:orgId/sync manually. Took two seconds.

Why this is separate from #3589

#3589 (entitlement reconciliation) addresses how WorkOS user identity binds to orgs. This is a different problem: once an org has a stripe_customer_id linked, ensure the org row stays consistent with what Stripe says. Webhooks miss. Stripe edits happen out-of-band. Subscriptions get created via flows that don't fire the expected hook. The DB drifts silently.

This issue ships as soon as triage picks it up; it does not block on the user-binding / seat-counting decisions still open on #3589.

What exists today

server/src/audit/integrity/invariants/org-row-matches-live-stripe-sub.ts already detects drift, but only for orgs we already think are subscribed:

WHERE stripe_subscription_id IS NOT NULL
  AND subscription_status IN ('active', 'trialing', 'past_due')

This misses the Lina case entirely — where the webhook was never recorded in the first place, leaving stripe_subscription_id and subscription_status both null while Stripe has an active subscription on the linked customer.

Severity is warning. Lina's case is customer-facing impact (blocked paid content) for a month.

POST /api/admin/accounts/:orgId/sync (server/src/routes/admin/accounts-billing.ts:31) already pulls fresh Stripe state and writes it back to the org row. Tested live — fixes the drift in one call.

Scope

1. Extend the invariant to catch null/missing-state cases

Add a second query branch to org-row-matches-live-stripe-sub.ts:

WHERE stripe_customer_id IS NOT NULL
  AND (stripe_subscription_id IS NULL
       OR subscription_status IS NULL
       OR subscription_status = 'none')

For each, retrieve customer.subscriptions from Stripe; if any are active or trialing, that's a violation.

2. Bump severity for customer-impacting drift

Lina's class of drift blocks a paying customer from access. That's error, not warning.

3. Auto-remediate via the sync endpoint

When the invariant fires for a stripe_customer_id IS NOT NULL + missing-state row, call the same sync code path. Stripe is source of truth; DB only gets written when Stripe has data. Low risk of clobbering correct state.

Out-of-scope for auto-remediation (manual review): cases where DB has live state but Stripe says canceled/deleted (could be a real Stripe-side action that needs admin context).

4. Reverse audit — Stripe-walks-DB

The DB-walks-Stripe path misses orgs without stripe_customer_id set at all. Periodic job:

  • For each Stripe customer with active/trialing subscription
  • If customerToOrg mapping exists → run sync
  • If no linked org → flag as orphan (the cus_UBPcv5SPmqug6s / [email protected] pattern — same person, abandoned-checkout customer, no org link)

Existing infrastructure: /api/admin/stripe-customers already walks all customers and joins to orgs. Reuse that data path.

5. Alerting

Errors go to a human-monitored channel (Slack, ops dashboard). Not silent. Include: org name, Stripe sub ID, what drifted, whether auto-remediation succeeded.

Done state

  • Invariant extended to catch null/missing-state class; tests cover Lina's exact data shape
  • Severity bumped on customer-impacting drift
  • Auto-remediation via sync endpoint wired and gated to safe directions only
  • Reverse audit job ships, runs on cron
  • First run after deploy: report any existing Lina-class drift across the customer base — fixes silently affected paying members
  • Alerting in place

References

Activity

  1. added
    addie
    member-tools
    claude-triaged
    on Apr 30, 2026
  2. bokelley commented on May 16, 2026

    @bokelley
    ContributorAuthor

    Closing — fix shipped in PR #3691 (merged 2026-04-30). Core subscription UPDATE no longer silently swallowed; admin link/unlink integration test added. The original Lina Georg / [email protected] gaslighting scenario is now covered by the catch-block audit.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    addieclaude-triagedmember-tools

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions