fix patch billing feat/phase-2g-bundle
AI Agent git-import/068377df · 115 days ago · Apr 2, 2026 · Diff

fix(billing): eliminate pack-token overwrite by collapsing to single mutateBillingDb per webhook

The old pattern called mutateBillingDb twice per webhook event — once to apply the business change (e.g. add pack tokens) and once to mark the event as processed. With eventual consistency, the second load could return the pre-write state and save it back, silently zeroing out pack token balances that had just been credited.

Subscription events survived because Stripe fires follow-up events (customer.subscription.updated) that re-apply the tier; one-time pack payments have no follow-up, so their balance stayed at 0.

Fix: separate async preparation (Stripe API calls, token resolution) from synchronous blob mutation. Each webhook now performs exactly one mutateBillingDb call that atomically applies the business change AND marks the event processed in the same read-modify-write cycle.

sha256:84e61e3868d56741f0944bd54cc564e53d5bb3a5d2ce6d7bd8ed4bd033d5c0f2 sha
sha256:cc8396e2598cdb759e827dc84bc5705b982fc3b2b790a6ddb87d88d1ae72b758 snapshot
← Older Oldest on feat/phase-2g-bundle
All commits
Newer → Latest on feat/phase-2g-bundle

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:84e61e3868d56741f0944bd54cc564e53d5bb3a5d2ce6d7bd8ed4bd033d5c0f2 --body "your comment"