Skip to content

fix(tui): preserve subcent costs during aggregation - #237

Merged
mike1858 merged 2 commits into
Piebald-AI:mainfrom
jimyag:fix/tui-subcent-costs
Aug 13, 2026
Merged

fix(tui): preserve subcent costs during aggregation#237
mike1858 merged 2 commits into
Piebald-AI:mainfrom
jimyag:fix/tui-subcent-costs

Conversation

@jimyag

@jimyag jimyag commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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 costCents JSON output.

Changes

  • retain micro-dollar precision in TuiStats add, subtract, and conversion paths
  • repack single-message contribution costs in microdollars without increasing the 32-byte cache entry
  • add regression coverage for daily, session, packed-message, and JSON serialization paths
  • include the same model-filter conversation assertion correction as feat(analyzers): add DeepSeek Harness support #236 so both PRs remain independently green; the duplicate patch should merge cleanly whichever lands first

Verification

  • cargo build --quiet
  • cargo test --quiet (419 passed)
  • cargo clippy --locked --all-targets --quiet -- -D warnings
  • cargo doc --quiet
  • cargo fmt --all --quiet
  • bash scripts/license-checks.sh
  • git diff --check

Notes

  • TuiStats grows from 40 to 48 bytes to retain exact internal cost precision.
  • SingleMessageContribution remains 32 bytes.
  • Reviewer focus: micro-dollar rounding and the revised packed bitfield boundaries.

Summary by CodeRabbit

  • Improvements

    • Cost tracking now preserves sub-cent precision when aggregating message and session costs.
    • Larger cost values are handled safely without overflow.
    • Existing cent-based cost displays and serialized output remain compatible, with values rounded appropriately.
  • Bug Fixes

    • Corrected rounding and accumulation for small costs across conversations, sessions, and statistics.

jimyag added 2 commits August 13, 2026 23:31
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>
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 21e6c4de-fa78-4854-9130-2bf30a7ebfbb

📥 Commits

Reviewing files that changed from the base of the PR and between c843248 and a4d7588.

📒 Files selected for processing (7)
  • src/contribution_cache/single_message.rs
  • src/contribution_cache/tests/compact_stats.rs
  • src/contribution_cache/tests/single_session.rs
  • src/tui.rs
  • src/tui/tests.rs
  • src/types.rs
  • src/utils/tests.rs

📝 Walkthrough

Walkthrough

The change adds exact microdollar cost storage to TuiStats, preserves costCents serialization, expands packed cost capacity, and updates contribution, session, date aggregation, conversion, and regression tests for sub-cent precision.

Changes

Microdollar cost handling

Layer / File(s) Summary
Exact TuiStats cost model
src/types.rs, src/tui.rs, src/tui/tests.rs
TuiStats stores microdollars internally, rounds cents for serialization, and uses saturating arithmetic. Model conversion and tests use the updated cost path.
Packed contribution cost round-trip
src/contribution_cache/single_message.rs, src/contribution_cache/tests/compact_stats.rs
PackedStatsDate stores a 30-bit cost_micros field. Packing and unpacking preserve microdollar values and saturate at the field limit.
Aggregate precision regression coverage
src/contribution_cache/tests/single_session.rs, src/utils/tests.rs
Session and date aggregation tests verify that sub-cent costs remain precise while cent totals round correctly.

Estimated code review effort: 4 (Complex) | ~45 minutes

Mergeability Score: ⚪ Minimal · up to a4d75

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
Loading

Possibly related PRs

Suggested reviewers: mike1858, basekevin

Poem

I’m a rabbit with microdollars to spare,
Packing small costs with careful repair.
Sub-cent crumbs stay in the sum,
While cents round neatly for everyone.
Hop, hop—precision has come!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
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: preserving sub-cent costs during TUI aggregation.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@jimyag

jimyag commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

before
image

after
image

@mike1858 mike1858 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mike1858
mike1858 merged commit d269ecd into Piebald-AI:main Aug 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants