Skip to content

feat(ui): show model usage price metrics - #389

Merged
w0wl0lxd merged 13 commits into
mainfrom
feat/usage-pricing
Aug 19, 2026
Merged

w0wl0lxd merged 13 commits into
mainfrom
feat/usage-pricing

Conversation

@w0wl0lxd

Copy link
Copy Markdown
Owner

Summary

  • show effective input, output, cache-read, and cache-write prices per 1M tokens in /usage
  • compute session estimates from each model attribution instead of repricing everything as the current model
  • keep zero-priced providers unchanged and label coding-plan values as API-equivalent estimates
  • preserve provider-qualified model specs for accurate cross-provider attribution

Research

  • verified the existing provider catalog already carries input/output/cache rates and provider discovery can override them
  • retained quota displays separately because coding/subscription plans do not report request-level dollar charges
  • reused the existing token categories and cost arithmetic, including fast-mode cache multipliers

Validation

  • cargo fmt --all
  • cargo check --all
  • cargo clippy --all --tests -- -D warnings
  • cargo nextest run --workspace (5,234 passed, 4 skipped)

@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@w0wl0lxd, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: caa51252-164e-47b3-b70b-6e78869d7c93

📥 Commits

Reviewing files that changed from the base of the PR and between c718208 and cf1d987.

📒 Files selected for processing (1)
  • n00n-ui/src/components/usage_modal.rs
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Usage details now show effective pricing, estimated costs, and savings for each model.
    • Session totals more accurately attribute usage across models.
    • Fast-tier pricing and cache rates are reflected in cost and savings calculations.
    • Pricing details include API-equivalent rate guidance.
  • Bug Fixes

    • Zero-priced or unrecognized models remain visible without inflating cost or savings totals.
    • Completion events now include complete model specifications instead of only model IDs.

Walkthrough

The agent now reports full model specifications in completion events. Pricing calculations use centralized effective rates, including fast-tier cache rates. The usage modal attributes costs by model, displays effective pricing, and omits cost metrics for zero-priced models.

Changes

Model and Usage Reporting

Layer / File(s) Summary
Agent event model specification
n00n-agent/src/agent/compaction.rs, n00n-agent/src/agent/run.rs
Turn-complete events now report the full model specification for normal turns and compaction.
Effective pricing resolution
n00n-providers/src/model.rs
ModelPricing::effective resolves standard or fast rates, derives cache rates, and supports centralized cost and savings calculations. Tests cover fast-rate resolution.
Usage pricing attribution and display
n00n-ui/src/app/mod.rs, n00n-ui/src/components/usage_modal.rs, changelog.d/389.added.md
Usage costs use per-model pricing. Zero-priced models retain token usage but omit cost metrics. The modal displays effective rates and labels estimated costs. Tests cover pricing display and provider-qualified model resolution. The changelog records the pricing and attribution changes.

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

Merge Risk: 🟡 Moderate · up to c7182

The usage view can underreport mixed-session prices when a zero-priced model is present, while unresolved model parsing can omit attribution and provider-qualified models can appear under the same label. These bounded correctness and display issues should be fixed or explicitly accepted before merge.

Sequence Diagram(s)

sequenceDiagram
  participant UsageModal
  participant ModelPricing
  participant TokenUsage
  UsageModal->>ModelPricing: resolve pricing for each model
  ModelPricing-->>UsageModal: return effective rates
  UsageModal->>TokenUsage: calculate attributed cost and savings
  TokenUsage-->>UsageModal: return usage metrics
  UsageModal-->>UsageModal: render pricing lines and usage rows
Loading

Poem

A rabbit checks each model’s rate,
Fast cache totals calculate.
Full specifications appear,
Priced usage stays clear.
Zero-cost rows remain in view—
Hop, hop, the estimates are true!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding model usage price metrics to the UI.
Description check ✅ Passed The description directly explains the pricing metrics, attribution changes, preserved behavior, research, and validation for this changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/usage-pricing

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.

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Criterion

Details
Benchmark suite Current: cf1d987 Previous: 691fed3 Ratio
fib/jit_mlua_hook 6676050 ns/iter (± 93564) 6701811 ns/iter (± 35999) 1.00
fib/jit_watchdog 2283757 ns/iter (± 4831) 2224119 ns/iter (± 7964) 1.03
fib/jit_none 2275518 ns/iter (± 5992) 2224757 ns/iter (± 35783) 1.02
fib/interp_mlua_hook 8101782 ns/iter (± 85662) 8044330 ns/iter (± 279594) 1.01
fib/interp_watchdog 4300616 ns/iter (± 128693) 4276374 ns/iter (± 47848) 1.01
fib/interp_none 4281445 ns/iter (± 25713) 4307278 ns/iter (± 13919) 0.99
buffer_rw/jit_mlua_hook 582242 ns/iter (± 1650) 583948 ns/iter (± 1500) 1.00
buffer_rw/jit_watchdog 191360 ns/iter (± 365) 191598 ns/iter (± 379) 1.00
buffer_rw/jit_none 191348 ns/iter (± 5857) 191424 ns/iter (± 574) 1.00
buffer_rw/interp_mlua_hook 1037466 ns/iter (± 11334) 1074818 ns/iter (± 8303) 0.97
buffer_rw/interp_watchdog 583569 ns/iter (± 1098) 584134 ns/iter (± 14691) 1.00
buffer_rw/interp_none 582813 ns/iter (± 13743) 584099 ns/iter (± 1057) 1.00
splash_render_120x40 81172 ns/iter (± 356) 64280 ns/iter (± 6088) 1.26
splash_render_200x60 112086 ns/iter (± 4277) 192819 ns/iter (± 8009) 0.58

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Criterion'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 2f5dbe1 Previous: 45121b8 Ratio
buffer_rw/jit_mlua_hook 882685 ns/iter (± 48192) 430010 ns/iter (± 4387) 2.05

This comment was automatically generated by workflow using github-action-benchmark.

@codecov

codecov Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.74648% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
n00n-ui/src/components/usage_modal.rs 98.04% 6 Missing ⚠️
n00n-agent/src/agent/run.rs 50.00% 1 Missing ⚠️
n00n-ui/src/app/mod.rs 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@w0wl0lxd
w0wl0lxd marked this pull request as ready for review August 16, 2026 00:09
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@w0wl0lxd
w0wl0lxd enabled auto-merge (squash) August 16, 2026 00:11
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

A single zero-priced model in the session made attributed_costs return
None for the whole fold, hiding the estimate even when another model in
the same session had a real cost. Skip zero-priced models instead, and
report no estimate only when no priced model contributed at all.
@w0wl0lxd

Copy link
Copy Markdown
Owner Author

Applied the zero-priced-model finding in d68fbd7: attributed_costs now skips zero-priced models instead of discarding the whole fold, and returns None only when no priced model contributed. Added attributed_costs_skip_zero_priced_models_without_dropping_the_estimate covering the mixed priced/free session and the all-free session. 16/16 usage_modal tests pass.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

assert_eq! on f64 trips clippy::float_cmp, which is denied by just lint,
so the effective-pricing test failed the Lint job on all three
platforms.
devin-ai-integration[bot]

This comment was marked as resolved.

@w0wl0lxd

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment thread n00n-ui/src/components/usage_modal.rs
@w0wl0lxd
w0wl0lxd merged commit 3cce8bb into main Aug 19, 2026
30 checks passed
@linear-code

linear-code Bot commented Aug 19, 2026

Copy link
Copy Markdown

N00N-402

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.

1 participant