Repository navigation
chore: refactor state machines - #4133
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (2)
👮 Files not reviewed due to content moderation or server errors (4)
📝 WalkthroughWalkthroughRefactors credit realization and run mechanics into dedicated services (flat-fee realizations and usage-based run services), extracts rating into a rating service, and adapts state machines to delegate orchestration to these services instead of inlining realization/lineage logic. Changes
Sequence Diagram(s)mermaid SM->>Runs: Request Allocate / Create / Correct (charge, amounts, asOf) Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
37ec4c5 to
e6948ab
Compare
e6948ab to
e907953
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/billing/charges/flatfee/service/statemachine.go (1)
145-155: Consistent state machine base with usage-based pattern.The structure mirrors the usage-based state machine nicely, which helps maintainability.
One small difference:
refetchChargehere doesn't pass any expands, while the usage-based version atstatemachine.go:139-142passesmeta.Expands{meta.ExpandRealizations}. If flat-fee realizations are needed after refetch (e.g., inDeleteCharge), you might want to add similar expand options. But if the current callers don't need them, this is fine as-is.🔧 Optional: Add expands if realizations are needed after refetch
func (s *stateMachine) refetchCharge(ctx context.Context) error { charge, err := s.Adapter.GetByID(ctx, flatfee.GetByIDInput{ ChargeID: s.Charge.GetChargeID(), + Expands: meta.Expands{meta.ExpandRealizations}, })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/charges/flatfee/service/statemachine.go` around lines 145 - 155, The refetchCharge method currently calls s.Adapter.GetByID without any expand options; if downstream handlers like DeleteCharge need flat-fee realizations, update refetchCharge to pass meta.Expands{meta.ExpandRealizations} into GetByID (i.e., adjust the GetByID invocation inside stateMachine.refetchCharge to include the expands param) so s.Charge returned contains realizations after refetch; otherwise leave as-is if realizations are truly unnecessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/billing/charges/flatfee/service/statemachine.go`:
- Around line 145-155: The refetchCharge method currently calls
s.Adapter.GetByID without any expand options; if downstream handlers like
DeleteCharge need flat-fee realizations, update refetchCharge to pass
meta.Expands{meta.ExpandRealizations} into GetByID (i.e., adjust the GetByID
invocation inside stateMachine.refetchCharge to include the expands param) so
s.Charge returned contains realizations after refetch; otherwise leave as-is if
realizations are truly unnecessary.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9cdb65bd-1d6f-49a3-8b93-26a82f903743
📒 Files selected for processing (24)
.agents/skills/charges/SKILL.mdopenmeter/billing/charges/flatfee/service/creditsonly.goopenmeter/billing/charges/flatfee/service/invoice.goopenmeter/billing/charges/flatfee/service/lineage.goopenmeter/billing/charges/flatfee/service/realizations/service.goopenmeter/billing/charges/flatfee/service/service.goopenmeter/billing/charges/flatfee/service/statemachine.goopenmeter/billing/charges/flatfee/service/triggers.goopenmeter/billing/charges/service/invoicable_test.goopenmeter/billing/charges/usagebased/service/creditheninvoice.goopenmeter/billing/charges/usagebased/service/creditsonly.goopenmeter/billing/charges/usagebased/service/currenttotals.goopenmeter/billing/charges/usagebased/service/lineage.goopenmeter/billing/charges/usagebased/service/lineengine.goopenmeter/billing/charges/usagebased/service/mutations.goopenmeter/billing/charges/usagebased/service/rating/quantitysnapshot.goopenmeter/billing/charges/usagebased/service/rating/service.goopenmeter/billing/charges/usagebased/service/run/correct.goopenmeter/billing/charges/usagebased/service/run/create.goopenmeter/billing/charges/usagebased/service/run/credits.goopenmeter/billing/charges/usagebased/service/run/service.goopenmeter/billing/charges/usagebased/service/service.goopenmeter/billing/charges/usagebased/service/statemachine.goopenmeter/billing/charges/usagebased/service/triggers.go
💤 Files with no reviewable changes (3)
- openmeter/billing/charges/flatfee/service/lineage.go
- openmeter/billing/charges/usagebased/service/mutations.go
- openmeter/billing/charges/usagebased/service/lineage.go
Overview
Refactor the existing usage based and flatfee services to have the same structure of state-machines.
Logical steps are split into subpackages so that the state-machine is not swamped with all the low level details.
Notes for reviewer
Summary by CodeRabbit