Skip to content

fix(ledger): return unused promotional credit to wash on void - #5461

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/fix-promotional-grant-void
Nov 9, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/fix-promotional-grant-void

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5435.

Voiding a promotional grant reversed issuance but left the unused amount on the open customer receivable. For custom currencies that receivable counted toward booked and spendable credit, so the balance could stay the same after a successful void.

Reverse the original promotional settlement and authorization for the voided amount in the same transaction group as the issuance correction. This returns unused credit to wash and preserves the funding for credit already consumed. Previously completed voids require a separate repair.

Verified with PostgreSQL-backed credit grant and customer balance tests, transaction and routing rule tests, and scoped lint. The custom-currency regression checks booked and spendable balances as well as open receivable, authorized receivable, and wash.

Summary by CodeRabbit

  • Bug Fixes
    • Voiding promotional grants now returns unused credit to wash while keeping the customer receivable settled and reducing the booked balance by the voided amount.
    • Voids now correctly handle promotional authorization and settlement transactions, including grants with no cost basis.
    • Corrections to customer receivable authorization and settlement transactions now reverse the requested amount while preserving the original posting details.
    • Receivable routing now supports qualifying reversal entries with matching route and cost-basis currency details.
  • Documentation
    • Clarified how voiding a promotional grant affects wash, receivable, and booked balances.

@GAlexIHU
GAlexIHU requested a review from a team as a code owner November 7, 2026 11:25
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Nov 7, 2026
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Voiding a promotional grant now corrects the issue transaction and, when present, its authorization and settlement transactions. Receivable payment corrections and route validation now support reversal entries. Tests cover balance outcomes across void scenarios.

Changes: Promotional grant voiding

Layer / File(s) Summary
Receivable correction mechanics
openmeter/ledger/transactions/customer.go, openmeter/ledger/transactions/provenance.go, openmeter/ledger/routingrules/routingrules.go, openmeter/ledger/transactions/correction_test.go
Receivable payment templates now use a shared correction helper. Reversal entries preserve original posting addresses and provenance. Route validation accepts a qualifying reversal transition, and dispatch tests check the plan customer FBO breakage template error.
Void transaction resolution
openmeter/ledger/creditvoid/service.go
Void resolution retrieves the issuance transaction group and identifies its issue, authorization, and settlement transactions. It returns corrections for the issue transaction and, when promotional payment legs are present, the authorization and settlement transactions.
Void balance validation and documentation
test/credits/voidgrant_test.go, openmeter/ledger/customerbalance/README.md
Void-grant tests check receivable, wash, booked, and spendable balances for unused, partially consumed, repeated, expiring, and concurrent voids. The documentation describes the balance treatment.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant executeVoid
  participant resolveVoidSlice
  participant originalIssuance
  participant TransactionGroupStore
  executeVoid->>resolveVoidSlice: Resolve void slice
  resolveVoidSlice->>originalIssuance: Find issuance transactions
  originalIssuance->>TransactionGroupStore: GetTransactionGroup
  TransactionGroupStore-->>originalIssuance: Return matching transaction group
  originalIssuance-->>resolveVoidSlice: Return issue and payment legs
  resolveVoidSlice->>resolveVoidSlice: Build issue correction and, when present, authorization and settlement corrections
  resolveVoidSlice-->>executeVoid: Return transaction inputs
  executeVoid->>executeVoid: Append all transaction inputs
Loading

Possibly related PRs

Suggested labels: kind/bug

Suggested reviewers: mark-vass-konghq, turip

Merge Risk: Minimal · up to 539bc

Voiding a promotional grant now also reverses the settlement and authorization legs, so unused credit returns to wash. No concrete merge-blocking risk was identified in the supplied changes.

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 clearly describes the main change: returning unused promotional credit to wash when a grant is voided.
Linked Issues check Passed [#5435] The void service corrects the promotional settlement and authorization for the voided amount with the issuance correction. The custom-currency regression checks that booked and spendable balan…
Out of Scope Changes check Passed [#5435] The correction helper, routing rule, tests, and balance documentation support the promotional void fix. The changes have a clear connection to the linked issue.
Full details: Linked Issues check

Explanation

[#5435] The void service corrects the promotional settlement and authorization for the voided amount with the issuance correction. The custom-currency regression checks that booked and spendable balances fall from 100 to zero and that receivable balances clear. The partial-consumption test checks that consumed funding remains.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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 bfe9a09 and 539bc76.

Files selected for processing: 7

  • openmeter/ledger/creditvoid/service.go
  • openmeter/ledger/customerbalance/README.md
  • openmeter/ledger/routingrules/routingrules.go
  • openmeter/ledger/transactions/correction_test.go
  • openmeter/ledger/transactions/customer.go
  • openmeter/ledger/transactions/provenance.go
  • test/credits/voidgrant_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

return nil, fmt.Errorf("get transaction %s: %w", id.ID, err)
// Only promotional issuance includes payment legs for the same charge in
// this group. External and invoice payments are posted in separate groups.
func findIssuanceTransactions(group ledger.TransactionGroup, issueID models.NamespacedID, chargeID string) (issuanceTransactions, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Helper skips required input type

findIssuanceTransactions takes three related arguments and checks their combined state inside the function. The repository requires a named <Operation>Input with Validate() error for non-trivial operations like this. Group the arguments into an input type and validate it at the function boundary. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/ledger/creditvoid/service.go
Line: 525

Comment:
**Helper skips required input type**

`findIssuanceTransactions` takes three related arguments and checks their combined state inside the function. The repository requires a named `<Operation>Input` with `Validate() error` for non-trivial operations like this. Group the arguments into an input type and validate it at the function boundary. This repository requirement must be satisfied before merging.

**Context Used:** AGENTS.md ([source](https://github.com/openmeterio/openmeter/blob/main/AGENTS.md))

---

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

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!

Fix in Claude Code Fix in Codex

@GAlexIHU
GAlexIHU merged commit 7cba32d into main Nov 9, 2026
33 of 35 checks passed
@GAlexIHU
GAlexIHU deleted the codex/fix-promotional-grant-void branch November 9, 2026 14:42
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.

Voiding a funding-none credit grant leaves the customer balance unchanged

2 participants