fix(billing): scope subscription limit syncs to the exact payer - #7695
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR corrects billing reconciliation so subscription updates affect only the billing pool referenced by the persisted subscription.
Confidence Score: 5/5The PR appears safe to merge; no blocking billing-reconciliation failure remains. The current implementation reloads the persisted payer reference through the retryable Stripe event hook, propagates reconciliation failures, and cleanly separates personal and organization billing pools. The earlier lookup-failure finding is fully fixed. icecrasher321 accepted the Search test’s reduced regression coverage because the removed case depended on event-loop timing, and Greptile conceded that tradeoff.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/auth/auth.ts | Moves subscription-update usage reconciliation from the non-retryable lifecycle callback into the Stripe event hook. |
| apps/sim/lib/billing/core/subscription.ts | Restricts organization resolution to an exact organization reference and removes membership-based inference. |
| apps/sim/lib/billing/core/usage.ts | Synchronizes personal usage limits from personal subscriptions without clearing them for organization members. |
| apps/sim/lib/billing/organization.ts | Synchronizes only the subscription’s directly referenced billing pool and removes organization-member fan-out. |
| apps/sim/lib/billing/webhooks/subscription-usage.ts | Reloads the persisted subscription during retryable Stripe update handling before reconciling its usage pool. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Stripe[Stripe subscription update] --> Lifecycle[Subscription lifecycle callback]
Lifecycle --> Persisted[(Persisted subscription)]
Stripe --> OnEvent[Retryable onEvent hook]
OnEvent --> Reload[Reload by Stripe subscription ID]
Reload --> Scope{Exact reference type}
Scope -->|User reference| Personal[Sync personal usage pool]
Scope -->|Organization reference| Organization[Sync organization usage pool]
Personal --> Success[Webhook succeeds]
Organization --> Success
Reload -->|Lookup failure| Retry[Webhook fails for redelivery]
Personal -->|Sync failure| Retry
Organization -->|Sync failure| Retry
Reviews (4): Last reviewed commit: "chore(billing): merge staging and preser..." | Re-trigger Greptile
|
@cubic-dev-ai review this PR |
@icecrasher321 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@icecrasher321 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@icecrasher321 I have started the AI code review. It will take a few minutes to complete. |
Summary
onEventhook so lookup or limit-sync failures fail the webhook and can be retried.Type of Change
Testing
Checklist