Skip to content

feat: remove usage-based legacy realization statuses - #4661

Merged
turip merged 2 commits into
mainfrom
feat/remove-usagebased-legacy-statuses
Jul 15, 2026
Merged

turip merged 2 commits into
mainfrom
feat/remove-usagebased-legacy-statuses

Conversation

@turip

@turip turip commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on #4660.

Removes the temporary usage-based legacy realization status compatibility layer after the consolidated active.realization.* states were introduced.

Details

  • Removes legacy partial/final realization status constants and load-time normalization.
  • Tightens generated Ent enum validation and migration schema to canonical usage-based realization statuses only.
  • Adds a forward-only SQL migration that rewrites persisted active.partial_invoice.* and active.final_realization.* values into active.realization.*.
  • Leaves the down migration intentionally empty so legacy statuses are not restored.

Validation

Not run locally for this draft stack PR.

Summary by CodeRabbit

  • New Features

    • Added a clear “Awaiting Payment Settlement” status for usage-based charges.
    • Consolidated legacy realization statuses into the current canonical status flow.
  • Bug Fixes

    • Improved invoice-run handling when charges transition between realization states.
    • Corrected final-run selection during extended billing periods.
  • Maintenance

    • Removed support for deprecated realization statuses and their compatibility handling.
    • Updated existing data to use the consolidated status values.

Greptile Summary

This PR removes the temporary legacy realization status compatibility layer. The main changes are:

  • Drops legacy partial and final realization status constants.
  • Stops normalizing legacy statuses when building the usage-based state machine.
  • Tightens generated Ent status validation to canonical realization states.
  • Adds a forward SQL migration that rewrites stored legacy statuses.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
tools/migrate/migrations/20260714144104_consolidate_usage_based_realization_statuses.up.sql Adds the forward migration that maps stored legacy realization statuses to canonical realization statuses.
openmeter/billing/charges/usagebased/service/statemachine.go Removes load-time legacy status normalization from usage-based state machine construction.
openmeter/billing/charges/usagebased/statemachine.go Removes legacy realization status constants and keeps only canonical status validation.
openmeter/ent/db/chargeusagebased/chargeusagebased.go Updates generated Ent validation to reject legacy detailed status values.
openmeter/billing/charges/usagebased/service/creditheninvoice.go Updates realization entry behavior and extension handling for the consolidated status flow.

Reviews (2): Last reviewed commit: "feat: remove usage-based legacy statuses" | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Usage-based realization statuses are consolidated under canonical active.realization.* values. Legacy status normalization and constants are removed, persisted statuses are migrated, and state-machine invoice and extension handling is adjusted.

Changes

Usage-based status consolidation

Layer / File(s) Summary
Canonical statuses and data migration
openmeter/billing/charges/usagebased/statemachine.go, tools/migrate/migrations/20260714144104_consolidate_usage_based_realization_statuses.*.sql
Legacy realization statuses and normalization are removed, active.awaiting_payment_settlement is added, and persisted legacy values are remapped to canonical statuses.
State-machine status and realization handling
openmeter/billing/charges/usagebased/service/statemachine.go, openmeter/billing/charges/usagebased/service/creditheninvoice.go
State-machine initialization uses the configured charge directly, invoice-run startup requires the invoice-created trigger, and extend-after-final handling no longer requires a final realization run type.
Test fixture alignment
openmeter/billing/charges/usagebased/service/creditsonly_test.go, openmeter/ledger/chargeadapter/usagebased_test.go
Test imports and local fixtures are updated, and the shared test charge uses the canonical realization processing status.

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

Possibly related PRs

Suggested labels: release-note/feature, area/billing

Suggested reviewers: tothandras

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: removing legacy usage-based realization statuses.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/remove-usagebased-legacy-statuses

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.

Base automatically changed from feat/usagebased-realization-state to main July 8, 2026 08:54
@turip
turip force-pushed the feat/remove-usagebased-legacy-statuses branch from 130ccc1 to 4e16598 Compare July 14, 2026 14:47
@turip
turip marked this pull request as ready for review July 14, 2026 14:47
@turip
turip requested a review from a team as a code owner July 14, 2026 14:47
@turip turip added area/billing kind/refactor Code refactor, cleanup or minor improvement labels Jul 14, 2026
@turip
turip enabled auto-merge (squash) July 14, 2026 14:59
@turip
turip merged commit 9456faa into main Jul 15, 2026
30 of 33 checks passed
@turip
turip deleted the feat/remove-usagebased-legacy-statuses branch July 15, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing kind/refactor Code refactor, cleanup or minor improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants