Repository navigation
fix(ledger): zero historical live balances - #4726
Conversation
📝 WalkthroughWalkthroughHistorical credit balance queries now return ChangesHistorical credit balance semantics
Development workflow guidance
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant APIClient
participant GetCustomerCreditBalanceHandler
participant CustomerBalanceFacade
participant CustomerBalanceService
APIClient->>GetCustomerCreditBalanceHandler: Request with optional timestamp
GetCustomerCreditBalanceHandler->>CustomerBalanceFacade: GetBalances with HistoricalAsOf
CustomerBalanceFacade->>CustomerBalanceService: Calculate balance
CustomerBalanceService-->>CustomerBalanceFacade: Historical live balance is zero
CustomerBalanceFacade-->>GetCustomerCreditBalanceHandler: Return balances
GetCustomerCreditBalanceHandler-->>APIClient: Response with RetrievedAt
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
68694b5 to
b2fdce2
Compare
|
@tothandras @turip i'd actually prefer if response type was changed so |
b2fdce2 to
74f00f1
Compare
Summary
live: "0"for customer credit balance requests with an explicittimestamptimestampis omittednix developverification race discovered during this changeWhy
Historical requests previously mixed ledger balances at the requested timestamp with current open-charge impacts and current usage totals. That could produce a live balance that never represented a coherent point in time.
Open-charge state cannot currently be reconstructed historically, so historical responses now return zero instead of presenting a misleading value.
Impact
Current balance requests are unchanged. For requests with an explicit
timestamp:settledandpendingretain their historical behaviorliveis always zero and is not calculatedValidation
go test -tags=dynamic ./openmeter/ledger/customerbalancego vet -tags=dynamic ./openmeter/ledger/customerbalancego test -tags=dynamic ./api/v3/handlers/customers/creditsgo vet -tags=dynamic ./api/v3/handlers/customers/creditsgo test -tags=dynamic ./test/creditsmake lint-api-specmake test-go-sdkgit diff --checkSummary by CodeRabbit
Bug Fixes
timestamp/point-in-time parameter.Documentation
liveis always zero for historical balance responses.Tests
Greptile Summary
This PR makes historical customer credit balances return a zero live amount. The main changes are:
timestampis provided.timestampis omitted.Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (3): Last reviewed commit: "fix(ledger): zero historical live balanc..." | Re-trigger Greptile
Context used (3)