fix: account for legacy spend in single-type credit balances - #1050
think-in-universe wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified.
Pull request overview
Updates single-type credit balance reporting to include legacy unattributed spend while preserving ambiguity for multi-type organizations.
Changes:
- Fold legacy spend into the sole active credit type.
- Add regression coverage for balance consistency.
File summaries
| File | Description |
|---|---|
crates/database/tests/credit_allocation.rs |
Adds regression coverage for legacy spend. |
crates/database/src/repositories/organization_limits_repository_impl.rs |
Adjusts single-type balance calculations. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review — no blocking issuesI verified the correctness claim end to end rather than just the diff:
Prior review on this PR (Copilot, lite) generated no comments; nothing to build on there. Non-blocking notes1. Concrete case — payment-only org, ceiling reduced from 200 to 100 by a refund sync through ```json `available` is correctly floored and matches aggregate `remaining`, but `consumed` exceeds `amount`. Clamping `consumed` to `amount` in the repository would restore the identity at the cost of hiding real overage, so leaving it is defensible — just make sure the UI clamps. 2. Only the single-type branch is covered. 3. Pre-existing, not introduced here: ✅ |
Review · Status🟩 CompletedIronLoop completed the review and posted it to GitHub. ResultRun detailsAutomatic trigger · attempt 1 of 3 · completed in 3m 23s |
There was a problem hiding this comment.
Review · Summary
🟢 No actionable findings
No actionable issues found in the reviewed change.
Validation
- ✅ Single-type accounting inspection — Static tracing confirmed the breakdown applies legacy spend only for one active credit type and computes the same remaining capacity as the aggregate balance.
Review details
- Run:
d6d1e117-3dcf-4223-80e8-55c581ba4293 - Attempts: 1
Summary
legacy_unattributed_amounton the organization balance API so multi-type clients can reconcile their per-type totalsFor a payment-only organization with 100 credited, 90 consumed before the credit-allocation rollout, and 1 consumed afterward, the balance now reports 91 consumed and 9 remaining instead of 1 consumed and 99 remaining.
For organizations with multiple active credit types, clients can reconcile the response as
sum(credit type available) - legacy_unattributed_amount = aggregate remaining.Validation
cargo fmt --all -- --checkcargo test -p database --test credit_allocation(18 passed)cargo check -p apicargo clippy -p api -p database -p services -- -D warningsFollow-up to #1048 and supports the per-type balance display in nearai/nearai-cloud-ui#347.