Skip to content

fix(billing): recover org stripe bootstrap when reload misses - #3361

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixbilling-stop-org-create-stripe-525cbb
Draft

posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixbilling-stop-org-create-stripe-525cbb

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a new org could finish signup with no Stripe customer, no stripe_info trial row, and no trial plan. createStripeCustomer re-selected the org row and threw createStripeCustomer org reload failed when the committed row was not yet visible, which aborted the whole billing bootstrap for that org.
  • The only caller (on_organization_create) already reloads that row and deliberately falls back to the INSERT queue payload, so the helper's re-select made that fallback dead code — it re-ran the same query and threw anyway.
  • Fix: the reload guard now returns null instead of throwing, and createStripeCustomer reuses the org row the caller passed when the reload misses. A stale read no longer aborts provisioning.
  • The race-recovery exception now carries the org id and the underlying Supabase error in its message (error tracking keeps only the message), so a future failure shows which org failed and why.

Test plan

  • bun test:unit — updated tests/stripe-org-customer.unit.test.ts: the reload-miss case now asserts recovery (customer created, plan returned, link uses the passed row) instead of a throw.
  • bun run typecheck:backend and bun run lint:backend pass.

Screenshots

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

createStripeCustomer re-selected the org row and threw when the row was
not yet visible, which aborted the whole billing bootstrap for a new org:
no Stripe customer, no stripe_info trial row, no trial plan. The only
caller already reloads that row and falls back to the INSERT queue
payload, so the re-select made that fallback dead code.

- Make the reload guard return null instead of throwing, and reuse the
  org row the caller passed when the reload misses.
- Carry the org id and the underlying Supabase error in the race-recovery
  exception message so error tracking can tell which org failed.

Generated-By: PostHog Desktop
Task-Id: 90002b6d-354d-4379-a704-5c0244fffa28
@posthog-eu
posthog-eu Bot deployed to deepsec-pr September 17, 2026 01:16 Active
@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 46f2a146-e9ad-4594-a093-2da54354b14c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed

codspeed Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixbilling-stop-org-create-stripe-525cbb (f67c0af) with main (c7d419f)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@sonarqubecloud

Copy link
Copy Markdown

This branch was successfully deployed

1 active deployment
deepsec-pr — f67c0af0 Deployed Sep 17, 2026 by posthog-eu[bot] via Scan PR changes #7172
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.

0 participants