Skip to content

refactor(billing): load split-line history as persisted facts - #5333

Merged
turip merged 2 commits into
mainfrom
refactor/lightweight-split-line-history
Oct 26, 2026
Merged

turip merged 2 commits into
mainfrom
refactor/lightweight-split-line-history

Conversation

@turip

@turip turip commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Overview

Split-line history reads expand full line and invoice aggregates even though legacy rating and subscription sync need only persisted history facts. Load those facts directly while preserving deleted children, previously billed amounts, ownership, scheduling, and reconciliation behavior.

Notes for reviewer

Follows #5326. Ordinary header-only rating and the full-line transports used elsewhere remain intact. Subscription-reference billing periods retain their stored precision; service-period and gathering InvoiceAt normalization remain.

Validated the affected unit tests and targeted PostgreSQL billing and subscription-sync scenarios, plus go vet and scoped fast lint.

Summary by CodeRabbit

  • Bug Fixes

    • Improved billing history and reconciliation for split-line hierarchies.
    • Deleted child lines remain available for reconciliation, while previously billed amounts exclude deleted lines and invoices.
    • Corrected handling of terminal deleted invoices without deletion timestamps.
    • Improved subscription synchronization for hierarchy changes, ownership, annotations, and billing periods.
  • Tests

    • Expanded coverage for hierarchy cloning, reconciliation, deletion handling, and discount tracking.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable new issue was found.

Summary

The PR loads split-line history as persisted facts instead of full line and invoice aggregates.

  • Billing rating and subscription sync now read stored split-line facts.
  • Subscription sync uses saved child history to reconcile split-line groups.

The latest change maps subscription billing-period endpoints independently. No actionable new issue was found. No previous review threads were supplied.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  DB["Stored split-line groups and children"] --> Adapter["Load persisted history facts"]
  Adapter --> Hierarchy["SplitLineHierarchy"]
  Hierarchy --> Rating["Sum previously billed amounts"]
  Hierarchy --> Sync["Build subscription reconciliation patches"]
  Sync --> Updater["Load canonical lines and apply patches"]
Loading

Reviews (2) · Last reviewed commit: "refactor(billing): map split-line subscr..." · Reviewed by Greptile

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

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 6b4c6fcc-c64e-413a-8128-186e99876125
📥 Commits

Reviewing files that changed from the base of the PR and between b5a3359 and 9a9294d.

📒 Files selected for processing: 1
  • openmeter/billing/adapter/invoicelinesplitgroup.go

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

📝 Walkthrough

Split-line hierarchies now store persisted invoice and line facts directly. Billing calculations, subscription-state loading, and reconciliation use those fields. Tests cover amount calculations, cloning, persisted-state selection, and hierarchy patch behavior.

Changes: Split-line history and reconciliation

Layer / File(s) Summary
Persisted hierarchy model and mapping
openmeter/billing/invoicelinesplitgroup.go, openmeter/billing/adapter/invoicelinesplitgroup.go, openmeter/billing/service/invoicelinesplitgroup.go, openmeter/billing/README.md, openmeter/billing/*_test.go, openmeter/billing/lineengine/rating_test.go, test/billing/*_test.go
The hierarchy stores invoice and line fields directly. The adapter maps expanded invoices to this structure. Amount calculations, child traversal, cloning, and billing callers use persisted values.
Persisted state loading and selection
openmeter/billing/worker/subscriptionsync/service/persistedstate/*
Loading and normalization operate on hierarchy-line fields. Ownership and annotation selection use the first undeleted child. Tests cover normalization and selection order.
Hierarchy patch reconciliation
openmeter/billing/worker/subscriptionsync/service/reconciler/patchhelpers.go, openmeter/billing/worker/subscriptionsync/service/reconciler/patchinvoicelinehierarchy.go, openmeter/billing/worker/subscriptionsync/service/reconciler/patchinvoicelinehierarchy_test.go
Delete, shrink, and extend patch logic reads hierarchy-line fields directly. Tests cover restoring deleted children and suppressing patches for ignored children.

Priority: ➖ Normal

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

Change: Refactor

Suggested reviewers: galexihu, borbelyr-kong

Merge Risk: ⚪ Minimal · up to 9a929

The persisted split-line changes are mergeable based on the verified field alignment and retained deletion and normalization behavior.

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: loading billing split-line history as persisted facts.
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
  • 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.

@turip
turip merged commit 5844169 into main Oct 26, 2026
36 of 38 checks passed
@turip
turip deleted the refactor/lightweight-split-line-history branch October 26, 2026 08:59
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