Skip to content

fix(billing): return minimal invoice advancement targets - #4923

Merged
turip merged 1 commit into
mainfrom
feat/minimal-invoice-advance-targets
Aug 12, 2026
Merged

turip merged 1 commit into
mainfrom
feat/minimal-invoice-advance-targets

Conversation

@turip

@turip turip commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • return lightweight invoice advancement candidates containing only invoice and customer identifiers
  • select only namespace, id, and customer_id during candidate discovery
  • keep actual invoice advancement ID-only and avoid sharing error state between worker goroutines
  • lock collection and advancement discovery against unresolvable invoice workflow references

This lets event dispatchers publish advancement work without hydrating a full invoice and resolving its workflow apps.

Follow-up

Cloud should consume InvoiceAdvancementCandidate directly and remove the per-candidate GetStandardInvoiceById call from SendInvoiceAdvanceEvents.

Jira: no ticket yet; follow-up tickets are pending for the broader incident work.

Verification

  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./test/billing -run 'TestInvoicing/(TestListCustomerIDsPendingCollectionReturnsUniqueCustomersAcrossNamespaces|TestListPendingAdvancementDoesNotResolveWorkflowReferences)$' -count=1
  • go test -tags=dynamic ./openmeter/billing/... ./cmd/jobs/billing/advance ./openmeter/server
  • nix develop --impure .#ci -c make lint-go-fast

Greptile Summary

The PR introduces lightweight invoice-advancement candidates so discovery can return invoice and customer identifiers without hydrating workflow dependencies.

  • Selects only namespace, invoice ID, and customer ID during pending-advancement discovery.
  • Updates service, adapter, worker, CLI, and test interfaces to use the candidate type.
  • Keeps advancement keyed by the namespaced invoice ID and removes shared goroutine error state.
  • Adds integration coverage for unresolved cross-namespace workflow references.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness, security, or compatibility defects identified.

The changed interfaces and callers remain aligned, the partial projection includes every mapped non-nullable field, and concurrent advancement uses each candidate’s namespaced invoice ID with goroutine-local error state.

Important Files Changed

Filename Overview
openmeter/billing/adapter/invoice_advancement.go Projects the three required identifier columns and maps them into lightweight advancement candidates without loading invoice relationships.
openmeter/billing/stdinvoice.go Adds the candidate contract containing a namespaced invoice ID and its customer ID.
openmeter/billing/worker/advance/advance.go Adapts batching to the candidate type while preserving ID-only advancement and making goroutine errors local.
cmd/jobs/billing/advance/advance.go Updates candidate listing output to read the nested namespaced invoice identifier.
test/billing/invoice_test.go Verifies lightweight discovery returns both identifiers and does not resolve invalid workflow references.

Sequence Diagram

sequenceDiagram
  participant Job as Billing advance job
  participant Worker as AutoAdvancer
  participant Service as Billing service
  participant Adapter as Billing adapter
  participant DB as PostgreSQL
  Job->>Worker: ListInvoicesToAdvance(filters)
  Worker->>Service: ListStandardInvoicesPendingAdvancement
  Service->>Adapter: List pending candidates
  Adapter->>DB: SELECT namespace, id, customer_id
  DB-->>Adapter: Lightweight rows
  Adapter-->>Worker: InvoiceAdvancementCandidate[]
  loop Candidate batches
    Worker->>Service: AdvanceInvoice(candidate.InvoiceID)
  end
Loading

Reviews (1): Last reviewed commit: "fix(billing): return minimal invoice adv..." | Re-trigger Greptile

Context used:

Summary by CodeRabbit

  • New Features

    • Improved automatic invoice advancement by including the customer identity with each eligible invoice.
    • Invoice processing now continues reliably when workflow configuration resides in a different namespace.
    • Pending invoice listings provide complete, uniquely identified invoice and customer information.
  • Bug Fixes

    • Corrected invoice identification when displaying and processing invoices eligible for advancement.
    • Reduced reliance on workflow and tax-code configuration during pending invoice collection and advancement.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d0e11403-7911-4c0d-b1ed-33cc5c43d34a

📥 Commits

Reviewing files that changed from the base of the PR and between 2064f94 and 9980563.

📒 Files selected for processing (9)
  • cmd/jobs/billing/advance/advance.go
  • openmeter/billing/adapter.go
  • openmeter/billing/adapter/invoice_advancement.go
  • openmeter/billing/service.go
  • openmeter/billing/service/stdinvoice.go
  • openmeter/billing/stdinvoice.go
  • openmeter/billing/worker/advance/advance.go
  • openmeter/server/server_test.go
  • test/billing/invoice_test.go

📝 Walkthrough

Walkthrough

Pending invoice advancement now returns structured candidates with invoice and customer identities. The adapter retrieves customer IDs without resolving workflow or tax-code references. Service, worker, command, test, and no-op implementations use the new candidate type.

Changes

Invoice advancement candidate contract and listing

Layer / File(s) Summary
Candidate contract and database listing
openmeter/billing/stdinvoice.go, openmeter/billing/adapter.go, openmeter/billing/adapter/invoice_advancement.go, test/billing/invoice_test.go
InvoiceAdvancementCandidate contains invoice and customer identities. The adapter selects and maps both values. Tests cover cross-namespace workflow references and structured results.

Service and worker propagation

Layer / File(s) Summary
Service and worker candidate propagation
openmeter/billing/service.go, openmeter/billing/service/stdinvoice.go, openmeter/billing/worker/advance/advance.go, cmd/jobs/billing/advance/advance.go, openmeter/server/server_test.go
Service and worker methods return candidates. Advancement uses each candidate’s embedded InvoiceID. The command and no-op service use the updated fields and signatures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: release-note/bug-fix, area/billing

Suggested reviewers: tothandras, rolosp, chrisgacsal

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: returning minimal invoice advancement targets.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/minimal-invoice-advance-targets

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.

@turip
turip marked this pull request as ready for review August 12, 2026 16:30
@turip
turip requested a review from a team as a code owner August 12, 2026 16:30
@turip turip added release-note/bug-fix Release note: Bug Fixes area/billing labels Aug 12, 2026
@turip
turip merged commit d6d4cd2 into main Aug 12, 2026
29 of 32 checks passed
@turip
turip deleted the feat/minimal-invoice-advance-targets branch August 12, 2026 16:40
@tothandras

Copy link
Copy Markdown
Contributor

approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants