Repository navigation
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openmeterio/openmeter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChangesThe collection API removes Collection timing contract
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The booking-time credit selection change is mergeable after normal checks; no concrete remaining issue is established. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The change affects financial balances and invoice amounts. The normal billing flow supplies a service-period-derived booking time, and no introduced security issue was established. Direct-caller access and retry behavior remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings
🧪 Generate unit tests (beta)
🛠️ Fix failing CI checks 💡
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 |
| } | ||
|
|
||
| selections, err := c.collectCustomerFBOSelections(ctx, c.customerID(input), input.Currency, ledger.Route{Filters: input.Filters}, amount, input.SourceBalanceAsOf) | ||
| selections, err := c.collectCustomerFBOSelections(ctx, c.customerID(input), input.Currency, ledger.Route{Filters: input.Filters}, amount, input.BookedAt) |
There was a problem hiding this comment.
Backdated collection spends credit twice
When an in-advance flat fee is collected late, its booking time is the earlier service start. Using that time to select credits hides any charge booked afterward, even if that charge has already spent the same credit. The flat fee can then spend it again: the ledger does not check that the resulting balance remains sufficient, so the customer’s credit balance can become negative.
Knowledge Base Used: Credit and ledger accounting
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/ledger/collector/collect.go
Line: 226
Comment:
**Backdated collection spends credit twice**
When an in-advance flat fee is collected late, its booking time is the earlier service start. Using that time to select credits hides any charge booked afterward, even if that charge has already spent the same credit. The flat fee can then spend it again: the ledger does not check that the resulting balance remains sufficient, so the customer’s credit balance can become negative.
**Knowledge Base Used:** [Credit and ledger accounting](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/credit-and-ledger-accounting.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Overview
In-advance flat fees added mid-period could ignore credits granted after the billing-period start, leaving the credit balance untouched and invoicing the full converted amount. Collect credits at the charge's booking time instead of its invoice scheduling time.
Use a single
BookedAtinput for both credit eligibility and ledger posting in the accrued and receivable collectors. RemoveSourceBalanceAsOfand update callers, fixtures, and domain documentation.Validation
Summary by CodeRabbit
The PR is not safe to merge until delayed flat-fee collection cannot spend credit already consumed by another charge.
Fix with agent prompt
Summary
The PR makes
BookedAtthe sole timestamp for credit selection and ledger posting, removesSourceBalanceAsOf, and adds flat-fee credit-allocation regressions.Diagram
Reviews (1) · Last reviewed commit: "test(credits): keep booking-time regress..."