Repository navigation
fix(billing): preserve charge history during subscription item changes - #5223
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. 📝 WalkthroughWalkthroughSubscription sync now matches flat-fee and usage-based charges by selected billing terms. It validates matched-charge ownership and checks realization invoices before replacement. The change also updates default flat-fee invoice timing and adds reconciliation and sync regression coverage. ChangesSubscription charge reconciliation
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change preserves charge history and blocks replacement when invoice history is immutable or incomplete. No concrete blocking issue remains; merge after normal checks pass. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change strengthens ownership checks and protects immutable invoice history before replacing charges. No expanded external access or demonstrated security regression was found. Risk remains limited but nonzero because recovery from interrupted updates and the complete rollback scope were not fully established. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Overview
Subscription sync can see a new physical subscription item ID for an existing logical item. When its subscription-owned billing terms are equivalent, sync now repairs the charge reference and reconciles period changes in place. This preserves the charge and its invoice history across nonfinancial edits.
When changed terms or an incompatible service-period start require replacement, sync checks all charge realizations, including prior and deleted runs, against their invoices before planning the replacement. An immutable invoice, missing invoice, or failed lookup blocks replacement before any patches are applied. Cancellation deletes and ordinary period adjustments continue through their existing paths.
Notes for reviewer
make test-nocachepassed before the final callback inlining (9,054 passed, 9 skipped); the scopedmake lint-go-fastpassed afterward with 0 issues.Summary by CodeRabbit
The PR does not appear ready to merge because existing and new periods can still receive different invoice schedules, and the new reconciliation subtests must satisfy the repository’s testing convention.
Fix with agent prompt
Summary
The PR changes subscription sync to preserve matched charges when physical item references change but billing terms remain equivalent. It also checks realization invoices before planning charge replacement.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Matched subscription item and charge] --> B{Physical reference changed?} B -- No --> P[Reconcile service period] B -- Yes --> C{Billing terms equivalent and period start compatible?} C -- Yes --> D[Repair reference] D --> P C -- No --> E[Check realization invoices] E -- All mutable --> F[Plan charge replacement] E -- Immutable, missing, or lookup failure --> G[Reject replacement]Reviews (2) · Last reviewed commit: "style(billing): format charge replacemen..."