improvement(billing): migrate hot path writes away from user_stats#4768
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryHigh Risk Overview Read paths combine the legacy Period rollover ( Reviewed by Cursor Bugbot for commit 784fe70. Configure here. |
Greptile SummaryThis PR migrates the billing hot path away from synchronous
Confidence Score: 4/5Safe to merge after addressing one billing correctness issue with the daily-refresh deduction during the transition period. The migration architecture is sound and the idempotency layer, schema constraints, and ledger aggregation functions are well-constructed. One concrete billing defect exists: computeDailyRefreshConsumed now filters to billing-entity-attributed rows only, which excludes pre-cutover NULL-attributed rows, but every caller simultaneously adds the pre-cutover userStats.currentPeriodCost baseline to rawCost. This asymmetry causes the daily refresh to be under-deducted for all days that had usage before deployment, inflating effective usage for the rest of the current billing period and potentially triggering threshold charges or overage amounts sooner than intended. apps/sim/lib/billing/credits/daily-refresh.ts and all callers that pass billingEntity to computeDailyRefreshConsumed Important Files Changed
|
|
@greptile |
|
bugbot run |
Co-authored-by: Cursor <cursoragent@cursor.com>
|
@greptile |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 784fe70. Configure here.

Summary
Migrate billing away from hot path writes to user_stats table. Source of truth becomes usage logs.
Type of Change
Testing
Tested manually
Checklist