feat(usage): replace the two rewrite savings cards with one "Pro Saved" - #601
Conversation
"Rewrite Saved" and "Tokens Saved" were the same number twice: the rewriter-reported prompt tokens removed before the request reached the provider, and those same tokens priced at the request's input rate. Two cards for one fact, neither of which said whether the saving was large. Show one card instead, following the page's Tokens/Costs toggle — removed prompt tokens in Tokens mode, the money they would have cost in Costs mode — with the share of the period it saved in a green tail: saved / (recorded + saved), i.e. what the window would have been without rewriting. The share is suppressed when the baseline is unknown (costs mode with no pricing) so the card never shows a bogus 0%, and sub-0.1% shares render as "<0.1% less" instead of rounding away. Tokens use formatTokensShort like the overview cards and the chart axes below; the exact count, the dollar figure and the share all stay in the tooltip. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Usage dashboard now displays one mode-aware Pro Saved card with token or cost values and optional savings percentages. New helpers calculate these outputs, tests cover the updated behavior, and Pro documentation describes the revised card and metrics. ChangesPro Saved usage reporting
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant UsagePage
participant UsageStatCards
participant UsageHelpers
UsagePage->>UsageStatCards: provide usageSummary and usageMode
UsageStatCards->>UsageHelpers: format Pro Saved title, value, and percentage
UsageHelpers-->>UsageStatCards: return mode-specific display text
UsageStatCards-->>UsagePage: render the Pro Saved card
Possibly related PRs
Suggested reviewers: Poem
🚥 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 |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/pro.mdx`:
- Around line 128-131: Update the dashboard Usage page description in the “Pro
Saved” documentation so the savings share is stated as available in both Tokens
and Costs modes only when pricing is available; clarify that Costs mode omits
the share when the cost baseline is unavailable.
In `@web/dashboard/src/pages/usage/usage-helpers.js`:
- Around line 139-145: Preserve unavailable cost baselines in the usage
percentage calculation by checking the raw recorded value in the helper before
converting it with Number, returning no percentage when total_cost is null or
undefined while retaining existing numeric validation. In
web/dashboard/src/pages/usage/usage-helpers.js lines 139-145, update the
recorded-baseline handling; in web/dashboard/tests/usage.test.js lines 255-260,
add coverage for rewrite_cost_saved greater than zero with total_cost null,
asserting the saved-cost value is formatted and the percentage is empty.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: dac05d90-f0db-4623-8aed-b37f609d5634
⛔ Files ignored due to path filters (3)
internal/admin/dashboard/static/dist/assets/index-DG1xFvad.jsis excluded by!**/dist/**internal/admin/dashboard/static/dist/assets/index-QlB5Ev_G.cssis excluded by!**/dist/**internal/admin/dashboard/static/dist/index.htmlis excluded by!**/dist/**
📒 Files selected for processing (4)
docs/pro.mdxweb/dashboard/src/pages/usage/UsageStatCards.svelteweb/dashboard/src/pages/usage/usage-helpers.jsweb/dashboard/tests/usage.test.js
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The new calculations use the same uncached summary scope as the prior cards, the token baseline correctly excludes separately recorded rewrite savings, cost availability remains consistent with backend pricing calculations, and mode changes reactively update the card.
What T-Rex did
Reviews (1): Last reviewed commit: "feat(usage): replace the two rewrite sav..." | Re-trigger Greptile |
Review catch: `total_cost: null` means the period was never priced, but `|| 0` turned it into a zero baseline, so priced savings against an unpriced period rendered "100.0% less" — the exact bogus share the helper was meant to prevent. Read the raw baseline and bail on null/undefined before coercing, in both modes. A genuinely zero baseline is knowable and still renders, so the two cases no longer collapse into one. Dropping the `|| 0` also makes the `baseline <= 0` guard provably dead — saved is positive and recorded is non-negative by then — so it goes, with the invariant stated instead. docs/pro.mdx claimed both modes always carry the share; it now names the unpriced exception. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Addressed in f55c99b.
362/362 dashboard tests pass, |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/pro.mdx`:
- Around line 128-132: Update the Usage page description around the “Pro Saved”
card to state that the savings percentage is shown only when the relevant token
or cost baseline is available. Preserve the existing Tokens and Costs mode
distinctions, including the value-only behavior when pricing or baseline data is
unavailable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 0a934fc2-1107-4084-bbf0-7ecd228f1807
⛔ Files ignored due to path filters (2)
internal/admin/dashboard/static/dist/assets/index-TxnKYqqn.jsis excluded by!**/dist/**internal/admin/dashboard/static/dist/index.htmlis excluded by!**/dist/**
📒 Files selected for processing (3)
docs/pro.mdxweb/dashboard/src/pages/usage/usage-helpers.jsweb/dashboard/tests/usage.test.js
Description
The Usage page showed "Rewrite Saved" and "Tokens Saved" side by side, but they were the same fact twice: the prompt tokens a request rewriter removed before the request reached the provider, and those same tokens priced at the request's input rate. Neither card answered the question an operator actually has — was that a lot?
This replaces both with a single "Pro Saved" card that follows the page's existing Tokens/Costs toggle:
2.2Kremoved prompt tokens20.0% less$0.003820.0% lessThe green tail is
saved / (recorded + saved)— the share of what the selected period would have been without rewriting, againsttotal_tokensin Tokens mode andtotal_costin Costs mode.Details worth noting:
0%.<0.1% lessrather than rounding away to0.0%.formatTokensShort, matching the overview cards and the chart axes directly below, instead of the previous fullformatNumber. The exact count, the dollar figure and the share all remain in the tooltip.Savings are reported through the public
ext.Result.TokensSavedcontract, so this covers any request rewriter; today that is GoModel Pro's token compression, hence the name.docs/pro.mdxis updated to match.Testing
npm test— 362/362 pass, including a new test covering the value and share in both modes, the short-form thresholds, the unpriced-baseline case and the sub-0.1% floornpm run check— 0 errors, 0 warningsnpm run build— dist rebuilt and committed (pre-commit's dist-in-sync check passes)AI Generated (optional)
Written with Claude Code. The percentage basis (
saved / (recorded + saved)rather thansaved / recorded) was chosen so the number reads as "20% less than you would have paid" — a share of the counterfactual total, which cannot exceed 100%.🤖 Generated with Claude Code
Summary by CodeRabbit