Repository navigation
Description
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/trialingsubscription - If
customerToOrgmapping 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
- Triggering: same incident as Entitlement reconciliation: bind Stripe to workos_user_id, surface link flow at signup + access-block #3589 (Addie escalation Add docker network prune to workspace setup #296, 2026-04-29)
- Existing infrastructure:
server/src/audit/integrity/invariants/org-row-matches-live-stripe-sub.ts,POST /api/admin/accounts/:orgId/syncatserver/src/routes/admin/accounts-billing.ts:31,/api/admin/stripe-customersatserver/src/routes/billing.ts:525 - Companion: Entitlement reconciliation: bind Stripe to workos_user_id, surface link flow at signup + access-block #3589 (orthogonal — user/org binding for new subscriptions)
Activity
feat(audit): add stripe-sub-reflected-in-org-row invariant (#3623 det…
scripts(billing): add Stripe + dev-DB reconciliation sandbox (#3623 p…
test(billing): add membership lookup_key to /sync integration fixture
fix(billing): /sync picks membership sub, not subscriptions.data[0] (#…
feat(billing): lazy reconcile on certification paywall hit (#3623 ste…
fix(billing): clear subscription state on unlink + filter membership …
fix(billing): re-throw on core subscription UPDATE failure + relink i…
bokelley commentedon May 16, 2026
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.