Skip to content

feat(billing): configurable minimum age for auto-advance candidates - #5507

Merged
turip merged 1 commit into
mainfrom
feat/billing-advancer-minimum-age
Nov 13, 2026
Merged

turip merged 1 commit into
mainfrom
feat/billing-advancer-minimum-age

Conversation

@tothandras

@tothandras tothandras commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.

RetriggerView in GreptileConfidence 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.

Reviews (1) · Last reviewed commit: "feat(billing): configurable minimum age ..." · Reviewed by Greptile

@tothandras
tothandras requested a review from a team as a code owner November 13, 2026 01:57
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested labels: kind/feature, area/billing

Suggested reviewers: turip, galexihu

Merge Risk: Minimal · up to 3d1d2

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

Commits

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.

@turip turip added the release-note/bug-fix Release note: Bug Fixes label Nov 13, 2026
@turip
turip merged commit ba5c514 into main Nov 13, 2026
34 of 35 checks passed
@turip
turip deleted the feat/billing-advancer-minimum-age branch November 13, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants