Skip to content

fix(billing): accept persisted charge validation issues - #5168

Merged
turip merged 1 commit into
mainfrom
feat/persisted-charge-validation-noop
Sep 21, 2026
Merged

turip merged 1 commit into
mainfrom
feat/persisted-charge-validation-noop

Conversation

@turip

@turip turip commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Overview

Treat usage-charge advancement failures as a successful blocked state when the same product-catalog validation issue is already persisted on the charge. This prevents expected missing-feature or missing-meter state from failing the billing worker and being sent to the DLQ, while preserving existing error behavior for unpersisted validation and operational failures.

Adds regression coverage for subscription-created meterless usage charges and documents the lifecycle contract.

Notes for reviewer

The match uses the stable validation component and code because subscription creation records the issue before the charge has an identity path, while advancement reports the same issue with the charge path attached.

Validation:

  • affected charge service and subscription sync package tests
  • existing credit-only missing-meter retry test
  • configured fast Go linter

Summary by CodeRabbit

  • Bug Fixes

    • Usage-based charges with previously persisted product catalog validation issues no longer block advancement of other charges.
    • Affected charges remain unchanged, preserving their validation issues for later repair and retry.
    • Other advancement failures continue to be reported normally.
  • Documentation

    • Added guidance explaining how persisted product catalog validation issues affect automatic charge advancement.

RetriggerConfidence Score: 4/5

The behavioral change appears safe, but the repository’s explicit lifecycle-test documentation convention must be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 Missing Given Intent Comment ▶
Fix with agent prompt
### Issue 1
openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go:257
This non-trivial lifecycle subtest starts with `when` and `then` comments but omits the required concise `given` comment. Repository guidance requires lifecycle subtests to begin with `given`, `when`, and `then` intent comments, so this requirement must be satisfied before merging.

```suggestion
	s.Run("charge advancement accepts the persisted validation issue", func() {
		// given:
		// - the unresolved charge has a persisted product-catalog validation issue
```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR allows usage-charge advancement to treat an already-persisted product-catalog validation issue as a successful blocked state rather than a worker failure.

  • Matches validation failures against durable issues using stable component and code fields.
  • Leaves blocked charges unchanged while allowing independent charge processing to continue.
  • Adds regression coverage for meterless subscription-created usage charges.
  • Documents retry and repair behavior for blocked charges.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Advance usage charge] --> B{AdvanceCharge returns error?}
  B -- No --> C[Process charge and invoice patches]
  B -- Yes --> D{Validation-only error?}
  D -- No --> E[Return operation failure]
  D -- Yes --> F{Every component and code already persisted?}
  F -- No --> E
  F -- Yes --> G[Keep charge blocked and unchanged]
  G --> H[Continue processing other charges]
  H --> I[Later advancement or collection retries after repair]
Loading

Reviews (1) · Last reviewed commit: "fix(billing): accept persisted charge va..."

@turip
turip requested a review from a team as a code owner September 21, 2026 09:27
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: bd5545f3-56a0-4abf-aa4a-b23b1209a348

📥 Commits

Reviewing files that changed from the base of the PR and between 6d76d8a and 9832c17.

📒 Files selected for processing (3)
  • openmeter/billing/charges/README.md
  • openmeter/billing/charges/service/advance.go
  • openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Automatic charge advancement now skips usage-based charges with matching persisted product-catalog validation issues. The charge remains unchanged, later attempts can resume after repair, and regression coverage verifies the behavior.

Changes

Persisted validation handling

Layer / File(s) Summary
Validation classification and skip handling
openmeter/billing/charges/service/advance.go
AdvanceCharges continues when a usage-based charge has matching persisted product-catalog validation issues. Other errors still abort the operation.
Regression coverage and documented behavior
openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go, openmeter/billing/charges/README.md
The regression test verifies that the charge remains created, unrealized, unassigned, and unchanged. The README documents the blocked state and retry behavior.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: galexihu

🚥 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: billing now accepts persisted charge validation issues during advancement.
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 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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 added release-note/bug-fix Release note: Bug Fixes area/billing labels Sep 21, 2026
@turip
turip enabled auto-merge (squash) September 21, 2026 09:38
@turip
turip disabled auto-merge September 21, 2026 09:41
@turip
turip merged commit fae5526 into main Sep 21, 2026
30 of 33 checks passed
@turip
turip deleted the feat/persisted-charge-validation-noop branch September 21, 2026 09:41
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