Skip to content

fix(billing): resolve persisted split history during invoice simulation - #5360

Merged
turip merged 1 commit into
mainfrom
feat/fix-simulation-split-history
Oct 26, 2026
Merged

turip merged 1 commit into
mainfrom
feat/fix-simulation-split-history

Conversation

@turip

@turip turip commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Overview

Invoice simulation with a split-group ID currently requires a separate supplied hierarchy even when the group's history is persisted. Resolve referenced groups through the legacy engine's existing namespaced history resolver, preserving supplied quantities and pending line edits without persisting the simulated invoice.

Remove the simulation-specific hierarchy map and explicit-history rating facade. Ordinary simulation retains prior-usage offsets, clone isolation, and validation results.

Notes for reviewer

The public HTTP simulation input is unchanged. Missing groups fail explicitly through the existing resolver.

Validated with targeted billing, rating, and HTTP tests; PostgreSQL simulation and persisted legacy-calculation invariants; affected-consumer vet; and scoped make lint-go-fast.

Summary by CodeRabbit

  • Bug Fixes
    • Invoice simulations now use persisted split-group history when a supplied line references a split group, while preserving supplied quantities and line details.
    • Simulations return an error when the referenced split group cannot be found, rather than calculating a result without its history.
    • Simulation continues to leave supplied line data unchanged and does not create an invoice.

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Invoice simulation now resolves persisted split-group history through the legacy engine.

  • Invoice simulations use saved history for lines with split-group IDs.

turip explicitly describes removing the transient hierarchy map as intentional. No actionable issues were found. Tests were inspected, not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Supplied simulation lines] --> B[Clone and set namespace]
  B --> C[RateStandardLines]
  C --> D{Split-group IDs?}
  D -->|No| F[Rate cloned snapshots]
  D -->|Yes| E[Resolve persisted history in namespace]
  E -->|Found| F
  E -->|Missing| G[Return error]
  F --> H[Calculate invoice totals]
  H --> I[Return invoice without saving]
Loading

Reviews (1) · Last reviewed commit: "fix(billing): resolve persisted split hi..." · Reviewed by Greptile

@turip
turip requested a review from a team as a code owner October 26, 2026 12:16
@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 172a323 and dbc978e.

Files selected for processing: 8
  • openmeter/billing/README.md
  • openmeter/billing/httpdriver/invoiceline_test.go
  • openmeter/billing/lineengine/rating.go
  • openmeter/billing/lineengine/rating_test.go
  • openmeter/billing/service/invoice.go
  • openmeter/billing/stdinvoice.go
  • test/billing/invoice_test.go
  • test/billing/legacycalculation_test.go
Files with no reviewable changes: 1
  • openmeter/billing/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

Standard-line rating now resolves split-line hierarchies from persisted history using a namespace and context. Invoice simulation no longer accepts transient hierarchy input. Tests cover supplied snapshots, history resolution, missing groups, and input preservation.

Changes: Persisted split-line history

Layer / File(s) Summary
Resolve hierarchies during standard-line rating
openmeter/billing/lineengine/rating.go, openmeter/billing/lineengine/rating_test.go
RateStandardLines now accepts a context, namespace, and lines. It resolves hierarchies before rating and returns resolution errors. Tests use the new API and internal hierarchy pairs.
Use persisted history in invoice simulation
openmeter/billing/stdinvoice.go, openmeter/billing/service/invoice.go, openmeter/billing/README.md, openmeter/billing/httpdriver/invoiceline_test.go, test/billing/invoice_test.go, test/billing/legacycalculation_test.go
SimulateInvoiceInput no longer includes SplitLineHierarchies. Simulation calls RateStandardLines; tests verify supplied snapshots, persisted history, missing-group errors, and input preservation.

Priority: Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant SimulateInvoice
  participant RateStandardLines
  participant PersistedSplitGroupHistory
  participant LineRating
  SimulateInvoice->>RateStandardLines: namespace and grouped lines
  RateStandardLines->>PersistedSplitGroupHistory: resolve hierarchies
  PersistedSplitGroupHistory-->>RateStandardLines: hierarchy or error
  RateStandardLines->>LineRating: rate resolved lines
  LineRating-->>RateStandardLines: rated lines
  RateStandardLines-->>SimulateInvoice: rated lines or error
Loading

Possibly related PRs

Suggested labels: area/billing, kind/bug, release-note/bug-fix

Suggested reviewers: borosr

Merge Risk: Minimal · up to dbc97

The supplied evidence identifies no actionable issue blocking the simulation change. Merge 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: resolving persisted split history during invoice simulation.
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 added release-note/bug-fix Release note: Bug Fixes area/billing labels Oct 26, 2026
@turip
turip enabled auto-merge (squash) October 26, 2026 12:27
@turip
turip merged commit ba0cb19 into main Oct 26, 2026
34 of 37 checks passed
@turip
turip deleted the feat/fix-simulation-split-history branch October 26, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants