Repository navigation
fix(billing): bill the lowest graduated tier on zero usage - #5369
arian-gogani wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Sorted tier selection and regression test openmeter/billing/rating/service/rate/tieredgraduated.go, openmeter/billing/rating/service/rate/tieredgraduated_test.go |
Range construction and zero-quantity selection use the sorted tiers. The test reverses the tier order and checks that zero usage totals 100.0. |
Priority:
Estimated code review effort: 2 (Simple) | ~5 minutes
Change: Bug fix
Possibly related PRs
- openmeterio/openmeter#5347: Changes the same zero-usage tier selection and adds a reversed-tier regression test.
Suggested labels: kind/bug, release-note/bug-fix
Suggested reviewers: turip
Merge Risk: 
Minimal · up to 22e9f
-
The fix correctly bills the lowest tier for zero usage regardless of tier order.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title names the main change: the zero-usage fallback for graduated tiers now bills the lowest tier. The raw summary says the code now selects the zero-quantity tier from the sorted order instead of the original order, which matches the title. The title is specific, concise, and free of file lists or vague terms. It uses the conventional commit prefix fix(billing), which fits a bug fix.
-
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
|
Closing as a duplicate. This is the same change as #5347, which merged this morning and is already on main. I opened this against a stale base by mistake. Sorry for the noise. |
Summary
GraduatedTiered.TieredPriceCalculatorwalks tiers throughWithSortedTiers(), then, when quantity is zero, billsTiers[0]from the unsorted slice and labels that rangeTierIndex: 0.TieredPrice.Validate()does not require ascendingUpToAmount.WithSortedTiers()exists because storage order is not an invariant. The zero-usage fallback was the one direct read of the unsorted slice, so a reversed tier list billed the open-ended tier instead of the lowest tier's flat fee.Control
TestTieredOrderIndependenceuses the same four tiers as the existing graduated fixture.Validate()still accepts the reversed list, andTiers[0]is the open-ended tier, which has a unit price and no flat fee.sortedPrice.Tiers[0]: 100.Both orders now bill 100. I ran
go test ./openmeter/billing/rating/service/rate/ -run TestTieredOrderIndependence.Limits
This is the zero-usage path only. I did not run the billing database tests.
Made with Cursor


Confidence Score: 5/5
This PR appears safe to merge.Summary
Fixes zero-usage graduated billing to charge the lowest tier’s flat fee regardless of stored tier order.
Reviews (1) · Last reviewed commit: "test: consolidate graduated tier order r..." · Reviewed by Greptile
Summary by CodeRabbit