Skip to content

fix(ledger): prioritize free grants in collection#4624

Draft
GAlexIHU wants to merge 2 commits into
mainfrom
codex/free-grant-burndown-priority
Draft

fix(ledger): prioritize free grants in collection#4624
GAlexIHU wants to merge 2 commits into
mainfrom
codex/free-grant-burndown-priority

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • prioritizes nil/missing-cost-basis and explicit zero-cost-basis customer FBO sources before paid sources when credit priority ties
  • stamps collection source entries with a priority version annotation for future ordering changes
  • adds focused collector coverage and credits sanity coverage for the new burn-down order

Notes

  • current promotional credit-purchase settlement still maps through the charge adapter as explicit zero cost basis; the collector rule now also handles nil/missing cost basis as free
  • existing correction safety comes from persisted collection source order; old entries do not need migration
  • legacy credit engine grant burn-down history cannot express this cost-basis tie-break because its grant model has no cost-basis field

Validation

  • nix develop --impure .#ci -c env POSTGRES_HOST=127.0.0.1 go vet -tags=dynamic ./openmeter/ledger/collector ./test/credits
  • nix develop --impure .#ci -c env POSTGRES_HOST=127.0.0.1 go test -tags=dynamic -run 'TestCollectCustomerFBOUsesNilCostBasisBeforePaidTieBreaker|TestCollectCustomerFBOUsesPriorityOrder|TestCollectCustomerFBOReleasesBreakageInExpiryOrder' ./openmeter/ledger/collector
  • nix develop --impure .#ci -c env POSTGRES_HOST=127.0.0.1 go test -tags=dynamic -run 'TestSanitySuite/TestFlatFeeCreditThenInvoiceUsesFreeGrantBeforePaidPriorityTie' ./test/credits

@GAlexIHU GAlexIHU added the release-note/ignore Ignore this change when generating release notes label Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d5b5f287-cc13-42d6-8035-a62bcd02f362

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/free-grant-burndown-priority

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates FBO credit collection ordering for tied priorities. The main changes are:

  • Treats free and missing cost basis sources ahead of paid sources.
  • Adds a collection priority version annotation to new source entries.
  • Adds focused collector and credits tests for the new burn-down order.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
openmeter/ledger/collector/collection_fbo.go Adds free-cost-basis classification to both FBO source construction paths.
openmeter/ledger/collector/types.go Orders free or missing cost basis sources before paid sources after credit priority ties.
openmeter/ledger/annotations.go Adds the collection priority version annotation key.
openmeter/ledger/collector/collection_fbo_test.go Adds collector coverage for nil-cost-basis credits at tied priority.
test/credits/sanity_test.go Adds credits sanity coverage for free-before-paid tied priority collection.

Reviews (2): Last reviewed commit: "fix(ledger): treat missing cost basis as..." | Re-trigger Greptile

Comment thread openmeter/ledger/collector/collection_fbo.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant