You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(billing): configurable minimum age for auto-advance candidates - #5507
Adds an optional MinimumAge to the auto-advancer config and passes it to ListStandardInvoicesPendingAdvancement. The default is zero, so existing behavior is unchanged.
Why
Invoices created with ForceAsyncAdvance are saved with an advance action cached, and an AdvanceStandardInvoiceEvent is published for them. With MinimumAge = 0, a periodic poller built on ListInvoicesToAdvance lists these invoices immediately. If the poller publishes its own advance trigger, as an event-driven deployment does, every run re-publishes the invoices whose original event is still queued. When the consumer falls behind, the duplicates grow with each poll. Once the original event has been handled, each duplicate ends in ErrInvoiceCannotAdvance.
ListStandardInvoicesPendingAdvancementInput already supports MinimumAge, and the pending-advancement metrics use it. This change lets advancer callers use it too.
The cutoff applies to every candidate branch, so with a non-zero value the time-gated transitions (draft_until, collection_at) also wait up to MinimumAge longer before the poller picks them up.
Testing
New TestAutoAdvancerSkipsCandidatesYoungerThanMinimumAge: an invoice created moments ago is not listed with MinimumAge: 1h, and it is listed once updated_at is two hours old.
go build ./..., go vet, golangci-lint run on the touched packages.
Summary by CodeRabbit
New Features
Invoice advancement can now exclude invoices that have not yet reached a configured minimum age. Negative minimum-age values are rejected.
Confidence Score: 5/5
The PR appears safe to merge.
Summary
Adds optional MinimumAge to the invoice auto-advancer.
Invoice polling can wait before listing newly eligible candidates.
Acknowledged behavior: tothandras explicitly states that a nonzero value also delays the scheduled draft_until and collection_at transitions. This is intentional.
No actionable comments were generated in the recent review.
Walkthrough
AutoAdvancer now accepts a configurable minimum invoice age and passes it to the pending-advancement query. The constructor rejects negative values. A test checks that recent invoices are excluded and older invoices are listed.
Changes: Invoice advancement age filter
Layer / File(s)
Summary
Configure and validate minimum age openmeter/billing/worker/advance/advance.go
Config exposes MinimumAge. NewAdvancer rejects negative values and stores nonnegative values in AutoAdvancer.
Apply age to candidate listing openmeter/billing/worker/advance/advance.go, test/billing/invoice_test.go
ListInvoicesToAdvance passes the configured age to the billing service. The test checks that a recent invoice is excluded and an invoice updated two hours ago is listed with a one-hour minimum age.
This adds an optional minimum-age filter for invoice auto-advancement. The default of zero preserves existing behavior. No merge-blocking risk was found; apply a release-note label to satisfy the label check.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: a configurable minimum age for auto-advance candidates in billing. The raw summary confirms a new MinimumAge field in the advance Config, validation in NewAdvancer, an…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: a configurable minimum age for auto-advance candidates in billing. The raw summary confirms a new MinimumAge field in the advance Config, validation in NewAdvancer, and a filter passed to the billing service. The objectives describe the same change. The title is concise, specific, and follows the conventional commit style. It does not cover the test addition, which is expected.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
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.
Reviewing files that changed from the base of the PR and between d538903 and 3d1d2fe.
Files selected for processing: 2
openmeter/billing/worker/advance/advance.go
test/billing/invoice_test.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
MinimumAgeto the auto-advancer config and passes it toListStandardInvoicesPendingAdvancement. The default is zero, so existing behavior is unchanged.Why
Invoices created with
ForceAsyncAdvanceare saved with anadvanceaction cached, and anAdvanceStandardInvoiceEventis published for them. WithMinimumAge = 0, a periodic poller built onListInvoicesToAdvancelists these invoices immediately. If the poller publishes its own advance trigger, as an event-driven deployment does, every run re-publishes the invoices whose original event is still queued. When the consumer falls behind, the duplicates grow with each poll. Once the original event has been handled, each duplicate ends inErrInvoiceCannotAdvance.ListStandardInvoicesPendingAdvancementInputalready supportsMinimumAge, and the pending-advancement metrics use it. This change lets advancer callers use it too.The cutoff applies to every candidate branch, so with a non-zero value the time-gated transitions (
draft_until,collection_at) also wait up toMinimumAgelonger before the poller picks them up.Testing
TestAutoAdvancerSkipsCandidatesYoungerThanMinimumAge: an invoice created moments ago is not listed withMinimumAge: 1h, and it is listed onceupdated_atis two hours old.go build ./...,go vet,golangci-lint runon the touched packages.Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge.Summary
Adds optional
MinimumAgeto the invoice auto-advancer.Acknowledged behavior:
tothandrasexplicitly states that a nonzero value also delays the scheduleddraft_untilandcollection_attransitions. This is intentional.Reviews (1) · Last reviewed commit: "feat(billing): configurable minimum age ..." · Reviewed by Greptile