Skip to content

refactor(billing): remove embedded split-line history - #5356

Merged
turip merged 1 commit into
mainfrom
feat/remove-line-hierarchy-embedding
Oct 26, 2026
Merged

turip merged 1 commit into
mainfrom
feat/remove-line-hierarchy-embedding

Conversation

@turip

@turip turip commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Overview

Ordinary invoice reads still attach split-line history to every line even though the legacy engine resolves that history explicitly. Remove the embedded hierarchy fields, automatic adapter expansion, and the gathering-preview reload that existed solely to obtain history. Lines retain their split-group IDs, and calculation continues to use the engine-owned full-history resolver.

Simulation now accepts supplied transient histories on the Go service input, keyed by split-group ID, so association survives generated line IDs and namespace normalization without group reads or persistence.

Notes for reviewer

Follows #5341. The public HTTP simulation contract is unchanged; complete supplied-history simulation remains an internal Go service capability. Internal invoice event snapshots omit the former optional hierarchy expansions. No schema changes or changes to the documented legacy cancellation-ordering limitation.

Validation: PostgreSQL billing and subscription-sync suites; billing domain, legacy engine, rating, HTTP, and notification-event contract tests; affected-consumer and e2e-module vet; scoped fast Go lint.

Summary by CodeRabbit

  • Bug Fixes
    • Previously billed amounts now exclude deleted invoice lines and invoices, including deleted invoices without a recorded deletion time.
    • Invoice calculations and simulations use split-line history associated with the relevant split group, helping progressive billing calculate totals consistently.
    • Invoice reads and line listings no longer fetch split-group history unless it is explicitly requested, reducing unnecessary history lookups.
    • Public invoice and notification representations no longer include internal split-history expansions.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Removes embedded split history from invoice lines while keeping SplitLineGroupID.

  • Invoice reads keep split history out of line snapshots.
  • Simulation matches supplied split history by group ID.

Review was based on code and tests; no tests were executed.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Ordinary invoice read] --> B[Line snapshots with split-group IDs]
  C[Persisted calculation or gathering preview] --> D[Legacy engine]
  D --> E[Load persisted split history]
  E --> F[Snapshot quantities and rate]
  G[Go simulation input] --> H[Normalize line IDs and namespaces]
  H --> I[Find supplied history by split-group ID]
  I --> J[Rate cloned lines without group reads]
Loading

Reviews (1) · Last reviewed commit: "refactor(billing): remove embedded split..." · Reviewed by Greptile

@turip
turip requested a review from a team as a code owner October 26, 2026 10:32
@turip turip added the kind/refactor Code refactor, cleanup or minor improvement label Oct 26, 2026
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f7b0487 and 0ec8376.

Files selected for processing: 26
  • openmeter/billing/README.md
  • openmeter/billing/adapter/gatheringinvoice.go
  • openmeter/billing/adapter/invoice.go
  • openmeter/billing/adapter/invoicelinesplitgroup.go
  • openmeter/billing/adapter/stdinvoicelines.go
  • openmeter/billing/gatheringinvoice.go
  • openmeter/billing/lineengine/engine_test.go
  • openmeter/billing/lineengine/rating_test.go
  • openmeter/billing/lineengine/stdinvoice.go
  • openmeter/billing/rating/clampedstandardline_test.go
  • openmeter/billing/rating/service/detailedline_test.go
  • openmeter/billing/rating/service/mutator/unitconfig_test.go
  • openmeter/billing/service/invoice.go
  • openmeter/billing/stdinvoice.go
  • openmeter/billing/stdinvoiceline.go
  • openmeter/billing/worker/subscriptionsync/service/base_test.go
  • openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/patch.go
  • openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/patch_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_test.go
  • test/billing/discount_test.go
  • test/billing/invoice_test.go
  • test/billing/legacycalculation_test.go
  • test/credits/usagebased_invoice_discount_test.go
  • test/credits_billing_compat/discount_test.go
  • test/credits_billing_compat/invoice_test.go
Files with no reviewable changes: 10
  • openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/patch_test.go
  • test/credits_billing_compat/discount_test.go
  • openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/patch.go
  • test/credits/usagebased_invoice_discount_test.go
  • openmeter/billing/lineengine/engine_test.go
  • openmeter/billing/adapter/invoicelinesplitgroup.go
  • openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go
  • openmeter/billing/adapter/stdinvoicelines.go
  • test/credits_billing_compat/invoice_test.go
  • openmeter/billing/lineengine/stdinvoice.go

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

Walkthrough

Invoice lines no longer carry embedded split-line history. Ordinary reads return lines without loading persisted history, while explicit consumers retrieve groups by ID. Simulation receives transient history through its input.

Changes: Split-line history handling

Layer / File(s) Summary
Invoice-line history contract
openmeter/billing/stdinvoiceline.go, openmeter/billing/gatheringinvoice.go, openmeter/billing/lineengine/*, openmeter/billing/rating/*, openmeter/billing/README.md
Standard and gathering lines no longer store split-line hierarchies. Rating tests provide history separately. The README describes changes to event and public representations.
Invoice reads and explicit history lookup
openmeter/billing/adapter/*, openmeter/billing/service/invoice.go, openmeter/billing/worker/subscriptionsync/*, test/billing/*, test/credits/*
Invoice read paths no longer expand split-line history. Subscription-sync and test paths retrieve persisted groups by split-group ID when needed. Tests check that ordinary reads do not query history.
Transient simulation history
openmeter/billing/stdinvoice.go, openmeter/billing/service/invoice.go, test/billing/invoice_test.go
SimulateInvoiceInput accepts hierarchies keyed by split-group ID. Tests verify simulation behavior without persisted-history queries or invoice writes.

Priority: Normal

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

Change: Refactor

Possibly related PRs

  • openmeterio/openmeter#5333: Changes persisted split-line history records and hierarchy mapping used by explicit history reads.
  • openmeterio/openmeter#5341: Adds legacy rating support for supplied split-line history, which this change continues through simulation input.

Suggested reviewers: galexihu, borosr

Merge Risk: Minimal · up to 0ec83

No actionable issue is established in the supplied changes; the PR appears mergeable after normal checks.

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 and concisely describes the main change: removing embedded split-line history from billing models and flows.
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
📝 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

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.

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

Labels

kind/refactor Code refactor, cleanup or minor improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants