Skip to content

[TODO] fix billing advancement issues - #5228

Closed
turip wants to merge 4 commits into
mainfrom
temp/invoice-issues
Closed

turip wants to merge 4 commits into
mainfrom
temp/invoice-issues

Conversation

@turip

@turip turip commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Overview

Add regression coverage for invoice advancement failures and recovery from lifecycle progress persisted before line-engine attempts became atomic.

The tests now separate current behavior from historical recovery:

  • Fresh invoice-issued, payment-authorized, payment-settled, and combined payment failures assert that the whole line-engine attempt rolls back.
  • Tests that need partial historical state create it explicitly through the real line-engine callbacks and explain why that setup is required.
  • Passing regressions cover deleted-line issuance, combined payment recovery from historical authorization, and preservation of unsupported correction history.
  • Intentionally failing reproducers remain for partial finalization recovery, historical settlement recovery, stale provider errors, and missing validation context.

TODO.md groups the remaining work by lifecycle boundary and records which earlier failures are now fixed on main.

Notes for reviewer

This remains a draft containing reproducers and follow-up work. Production fixes for the intentionally failing recovery and diagnostics cases are still pending.

Validation:

  • Full configured Go lint passes for the affected credit and charge state-machine packages.
  • The passing regression slice succeeds against PostgreSQL.
  • The remaining lifecycle cases fail only at their documented finalization, stale-error, and historical-settlement recovery assertions.

RetriggerConfidence Score: 4/5

The PR is not ready to merge because its ungated, intentionally failing reproducers still break the ordinary test run.

Fix All in Claude CodeFindings

  1. P1 Ungated reproducers fail CI ▶
  2. P2 Clock freeze lacks scoped cleanup ▶
Fix with agent prompt
### Issue 1
openmeter/billing/charges/statemachine/machine_test.go:undefined-188
These tests run in the ordinary `go test ./...` CI job, but the production fixes they expect are not in this PR. Here, validation conversion drops the wrapped `invoice_issued` context, so the assertion fails. The new credit lifecycle tests also assert recovery behavior that the PR documents as still broken. Without gating the reproducers or landing the fixes, the normal CI test job fails.

### Issue 2
test/credits/credit_then_invoice_issuing_test.go:undefined-264
`setupChargeBookingInvoice` freezes the global clock here but restores the caller’s time only after `AdvanceInvoice` succeeds. The later freezes in `TestIssuingSkipsDeletedChargeLine` and `TestIssuingFailedInvoicePreservesUnsupportedCorrectionHistory` follow the same pattern. Repository guidance requires each `clock.FreezeTime(...)` to be paired immediately with `defer clock.UnFreeze()` in the same scope. Please satisfy that requirement before merging while preserving the caller’s frozen test time.

---

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

Summary

This PR adds billing lifecycle regression tests and a TODO describing recovery work. The tests distinguish atomic rollback in current attempts from explicitly recreated historical partial progress; several recovery and diagnostic reproducers remain intentionally failing.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Invoice lifecycle attempt] --> B{Line-engine result}
  B -->|Success or warnings| C[Commit attempt]
  B -->|Critical issue| D[Roll back attempt]
  D --> E[Persist retryable failed invoice]
  E --> F[Retry against historical progress]
Loading

Reviews (3) · Last reviewed commit: "test(billing): align retry reproducers w..."

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · 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

Comment @coderabbitai help to get the list of available commands.

require.Equal(t, component, issues[0].Component)
require.Contains(t, issues[0].Message, "unsupported operation")
// TODO: Add invoice-line context assertions when line engines attach invoice and line ID attributes.
assert.Contains(t, issues[0].Message, "invoice_issued")

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.

P1 Ungated reproducers fail CI

These tests run in the ordinary go test ./... CI job, but the production fixes they expect are not in this PR. Here, validation conversion drops the wrapped invoice_issued context, so the assertion fails. The new credit lifecycle tests also assert recovery behavior that the PR documents as still broken. Without gating the reproducers or landing the fixes, the normal CI test job fails.

Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/billing/charges/statemachine/machine_test.go
Line: 188

Comment:
**Ungated reproducers fail CI**

These tests run in the ordinary `go test ./...` CI job, but the production fixes they expect are not in this PR. Here, validation conversion drops the wrapped `invoice_issued` context, so the assertion fails. The new credit lifecycle tests also assert recovery behavior that the PR documents as still broken. Without gating the reproducers or landing the fixes, the normal CI test job fails.

---

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

Fix in Claude Code Fix in Codex

@turip
turip force-pushed the temp/invoice-issues branch 3 times, most recently from cab7dc8 to 406e8ca Compare October 5, 2026 13:25
require.Equal(t, billing.StandardInvoiceStatusDraftWaitingForCollection, invoice.Status)
// The clock stores one global frozen value, so restore the caller's test time.
callerTime := clock.Now()
clock.FreezeTime(invoice.DefaultCollectionAtForStandardInvoice())

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 Clock freeze lacks scoped cleanup
setupChargeBookingInvoice freezes the global clock here but restores the caller’s time only after AdvanceInvoice succeeds. The later freezes in TestIssuingSkipsDeletedChargeLine and TestIssuingFailedInvoicePreservesUnsupportedCorrectionHistory follow the same pattern. Repository guidance requires each clock.FreezeTime(...) to be paired immediately with defer clock.UnFreeze() in the same scope. Please satisfy that requirement before merging while preserving the caller’s frozen test time.

Context Used: CLAUDE.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/credits/credit_then_invoice_issuing_test.go
Line: 264

Comment:
**Clock freeze lacks scoped cleanup**
`setupChargeBookingInvoice` freezes the global clock here but restores the caller’s time only after `AdvanceInvoice` succeeds. The later freezes in `TestIssuingSkipsDeletedChargeLine` and `TestIssuingFailedInvoicePreservesUnsupportedCorrectionHistory` follow the same pattern. Repository guidance requires each `clock.FreezeTime(...)` to be paired immediately with `defer clock.UnFreeze()` in the same scope. Please satisfy that requirement before merging while preserving the caller’s frozen test time.

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

---

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

Fix in Claude Code Fix in Codex

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant