fix(tui): preserve subcent costs during aggregation - #237
Conversation
Signed-off-by: jimyag <git@jimyag.com>
Track cost in microdollars internally so low-cost messages are not rounded to zero before aggregation. Keep the existing costCents JSON contract and the 32-byte single-message cache layout. Signed-off-by: jimyag <git@jimyag.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe change adds exact microdollar cost storage to ChangesMicrodollar cost handling
Estimated code review effort: 4 (Complex) | ~45 minutes Mergeability Score: ⚪ Minimal · up to The PR preserves micro-dollar precision internally while keeping the existing JSON output contract, and no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Stats
participant TuiStats
participant PackedStatsDate
participant Aggregation
Stats->>TuiStats: set_cost(dollars)
TuiStats->>TuiStats: store exact microdollars
TuiStats->>PackedStatsDate: pack cost_micros
PackedStatsDate->>TuiStats: restore with set_cost_micros
Aggregation->>TuiStats: add exact microdollar costs
TuiStats-->>Aggregation: expose precise cost and rounded costCents
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
mike1858
left a comment
There was a problem hiding this comment.
It's really not so small a difference! It's because the project was made at a time when models followed instructions much worse than they do now—like rounding small numbers to zero. 0.04 !== 0.00.


Summary
Prevent low per-message costs from rounding to zero before daily and session aggregation. TUI statistics now retain micro-dollar precision internally while preserving the existing
costCentsJSON output.Changes
TuiStatsadd, subtract, and conversion pathsVerification
cargo build --quietcargo test --quiet(419 passed)cargo clippy --locked --all-targets --quiet -- -D warningscargo doc --quietcargo fmt --all --quietbash scripts/license-checks.shgit diff --checkNotes
TuiStatsgrows from 40 to 48 bytes to retain exact internal cost precision.SingleMessageContributionremains 32 bytes.Summary by CodeRabbit
Improvements
Bug Fixes