Skip to content

feat(usage): replace the two rewrite savings cards with one "Pro Saved" - #601

Merged
SantiagoDePolonia merged 2 commits into
mainfrom
feat/usage-pro-saved-card
Jul 27, 2026
Merged

feat(usage): replace the two rewrite savings cards with one "Pro Saved"#601
SantiagoDePolonia merged 2 commits into
mainfrom
feat/usage-pro-saved-card

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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:

Mode Value Tail
Tokens 2.2K removed prompt tokens 20.0% less
Costs $0.0038 20.0% less

The green tail is saved / (recorded + saved) — the share of what the selected period would have been without rewriting, against total_tokens in Tokens mode and total_cost in Costs mode.

Details worth noting:

  • The share is suppressed (value renders alone) when the baseline is unknown — costs mode with no pricing — so the card never shows a bogus 0%.
  • Sub-0.1% shares render <0.1% less rather than rounding away to 0.0%.
  • Tokens use formatTokensShort, matching the overview cards and the chart axes directly below, instead of the previous full formatNumber. The exact count, the dollar figure and the share all remain in the tooltip.
  • Visibility is unchanged: the card stays hidden until a rewriter reports savings, and savings still come off the uncached summary.

Savings are reported through the public ext.Result.TokensSaved contract, so this covers any request rewriter; today that is GoModel Pro's token compression, hence the name. docs/pro.mdx is 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% floor
  • npm run check — 0 errors, 0 warnings
  • npm 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 than saved / 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

  • New Features
    • Replaced separate “Rewrite Saved” and “Tokens Saved” cards with a unified Pro Saved card.
    • Pro Saved values and messaging now adapt to the selected Tokens vs Costs view.
    • Added “share saved” percentages, including proper handling for very small savings and unavailable pricing.
  • Documentation
    • Updated Pro dashboard/metrics docs to refine Prometheus counter naming and adjust “Pro Saved” card wording for Tokens vs Costs modes.
  • Tests
    • Expanded Usage-page coverage for Pro Saved titles, values, and percentage rendering in both modes.

"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>
Copilot AI review requested due to automatic review settings July 27, 2026 18:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread web/dashboard/src/pages/usage/usage-helpers.js Fixed
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Pro Saved usage reporting

Layer / File(s) Summary
Mode-aware savings helpers
web/dashboard/src/pages/usage/usage-helpers.js
Adds mode-specific value, percentage, and title helpers for token and cost savings.
Usage card integration
web/dashboard/src/pages/usage/UsageStatCards.svelte, docs/pro.mdx
Replaces separate savings cards with a single Pro Saved card and updates dashboard metrics documentation.
Savings behavior validation
web/dashboard/tests/usage.test.js
Tests visibility, token and cost formatting, percentage calculations, missing pricing, and small percentages.

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
Loading

Possibly related PRs

Suggested reviewers: copilot

Poem

A rabbit hops where saved tokens gleam,
Costs and percentages join the stream.
One Pro card now tells the tale,
Tiny shares trail softly in its wake.
“Less!” I twitch, and dashboards sing.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: merging the two rewrite savings cards into one Pro Saved card.
Description check ✅ Passed The description follows the template, explains the change and why, and adds useful testing notes.
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-pro-saved-card

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.

@mintlify

mintlify Bot commented Jul 27, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
gomodel 🟢 Ready View Preview Jul 27, 2026, 6:33 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ea68d2 and 5d24de4.

⛔ Files ignored due to path filters (3)
  • internal/admin/dashboard/static/dist/assets/index-DG1xFvad.js is excluded by !**/dist/**
  • internal/admin/dashboard/static/dist/assets/index-QlB5Ev_G.css is excluded by !**/dist/**
  • internal/admin/dashboard/static/dist/index.html is excluded by !**/dist/**
📒 Files selected for processing (4)
  • docs/pro.mdx
  • web/dashboard/src/pages/usage/UsageStatCards.svelte
  • web/dashboard/src/pages/usage/usage-helpers.js
  • web/dashboard/tests/usage.test.js

Comment thread docs/pro.mdx Outdated
Comment thread web/dashboard/src/pages/usage/usage-helpers.js Outdated
@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The 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.

T-Rex T-Rex Logs

What T-Rex did

  • Validated that the before and after videos use the same real gateway data and repository UI/styles.
  • Reviewed browser logs, confirming 200 responses from the real usage APIs and that the rendered card text matches expectations.
  • Captured and inspected screenshots for priced Tokens, priced Costs, and unpriced Costs states to verify UI states.
  • Organized and uploaded the associated artifacts (two videos, multiple images, and several logs) to support the proof.

View all artifacts

T-Rex Ran code and verified through T-Rex

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>
Copilot AI review requested due to automatic review settings July 27, 2026 18:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@SantiagoDePolonia

Copy link
Copy Markdown
Contributor Author

Addressed in f55c99b.

  • total_cost: null treated as a zero baseline (CodeRabbit, major) — real bug, fixed. || 0 collapsed "not priced" into "cost nothing", so priced savings against an unpriced period rendered 100.0% less. The raw baseline is now read and rejected on null/undefined before coercion, in both modes. A genuinely zero baseline is knowable and still renders its share, so the two cases no longer collapse. Test added per the suggestion (rewrite_cost_saved > 0 with total_cost: null → formatted value, empty share), plus the missing-total_tokens and zero-baseline cases.
  • baseline <= 0 is always false (github-code-quality) — correct, and it stayed dead after the fix above: saved is positive and recorded non-negative by that point. Removed, with the invariant stated in a comment instead.
  • Docs overstated the share (CodeRabbit, minor) — docs/pro.mdx now names the unpriced exception rather than implying both modes always show a percentage.

362/362 dashboard tests pass, svelte-check clean, dist rebuilt.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d24de4 and f55c99b.

⛔ Files ignored due to path filters (2)
  • internal/admin/dashboard/static/dist/assets/index-TxnKYqqn.js is excluded by !**/dist/**
  • internal/admin/dashboard/static/dist/index.html is excluded by !**/dist/**
📒 Files selected for processing (3)
  • docs/pro.mdx
  • web/dashboard/src/pages/usage/usage-helpers.js
  • web/dashboard/tests/usage.test.js

Comment thread docs/pro.mdx
@SantiagoDePolonia
SantiagoDePolonia merged commit 7e974d6 into main Jul 27, 2026
20 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.

3 participants