You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(web): use whole-token ticks for low-volume usage charts - #45608
On the Usage page's Tokens chart (overview and model detail), a low-volume period gets fractional Y-axis ticks, and formatTokens rounds each one to a whole number. A chart peaking at two tokens shows five grid lines labeled 0, 1, 1, 2, 2, so the line at 0.5 tokens says "1".
Deterministic repro on origin/main (5dd58c09c0703a48e4cabfd64c2768239d2014f6):
Use an isolated home (HOME=$(mktemp -d), which isolates both T3 state and Claude transcripts), then seed one Claude transcript, $HOME/.claude/projects/demo/session-1.jsonl, with a single assistant line, timestamped inside the Usage page's default range, in the same shape as apps/server/src/usage/usageTranscriptReader.test.ts: {"type":"assistant","timestamp":"<today, UTC>T10:00:00Z","requestId":"req_1","sessionId":"session-1","message":{"id":"msg_1","model":"claude-haiku-5-5","usage":{"input_tokens":1,"output_tokens":1}}}.
Start a dev server against that home, open Usage for the local environment, keep the default range, and switch the chart to Tokens. This gives one provider (Claude) with a 2-token peak.
Read the Y-axis labels. They are the aria-hidden<span>s in the w-14 column beside the chart SVG, not SVG text.
Code path: UsageProviderChart → buildChart(..., "tokens", ...) → chartScale → niceScale(2, 4) returns ticks [0, 0.5, 1, 1.5, 2], and the axis labels each one with formatTokens.
Observed (base): five gridlines labeled 0, 1, 1, 2, 2.
Expected (head): three gridlines labeled 0, 1, 2. The Cost chart keeps fractional dollar steps.
Change
niceScale now takes a minimum step. buildChart passes 1 for the token metric and 0 for cost, so token axes never step below one token. The cost scale stays the same. The change is in the shared chart builder, so both the Usage overview and the model-detail charts get it, on web and desktop.
Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
Added a buildChart case to apps/web/src/components/usage/UsageProviderChart.test.ts with a single 2-token / $2 day. On base it fails with expected [ +0, 0.5, 1, 1.5, 2 ] to deeply equal [ +0, 1, 2 ]. On head it passes, and the cost metric still returns [0, 0.5, 1, 1.5, 2].
vp run check:changed exited 0 on b7acd476ee78dac58011c182adeb1728ddf4921b (format, lint, knip, typecheck, tests, React compiler). The summary is in the gist below.
Not shown: rendered before/after screenshots of the axis, and a runnable scenarios:prove scenario. The recipe above is a manual recipe that I have not run in a client. The unit test proves the tick values through the same buildChart call the component uses, and the label spans render exactly scale.ticks through formatTokens. Mobile is not covered because this chart is web/desktop only.
Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).
Not shown
.github/pull_request_template.md:27 — Rendered before/after screenshots are not shown; the reported base labels are derived from the tick values and formatter, not observed in a running client.
apps/web/src/components/usage/UsageProviderChart.test.ts:62 — The regression test covers the chart builder, not a runnable scenarios:prove flow. The manual recipe remains unverified in a client; clear or explicitly set CLAUDE_CONFIG_DIR when automating it so it uses the seeded transcript.
Macroscope's review found this PR approvable — Low-volume token charts now use whole-token tick intervals, while cost scaling remains unchanged. The change is limited to visualization and does not affect usage totals or charges.
You can add or adjust custom eligibility rules. Learn more.
Reviewing files that changed from the base of the PR and between 4b03562 and 1347129.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The chart scale now supports a minimum tick step. Token charts use a minimum step of 1, while cost charts use 0. A test checks the resulting ticks for a one-day, low-volume input.
Changes: Usage chart tick scaling
Layer / File(s)
Summary
Scale calculation and test apps/web/src/components/usage/UsageProviderChart.tsx, apps/web/src/components/usage/UsageProviderChart.test.ts
niceScale clamps its calculated step to a minimum. buildChart supplies 1 for token metrics and 0 for cost metrics. The test checks whole-number token ticks and half-unit cost ticks.
Token usage charts now use whole-number tick steps at low volumes, which avoids duplicate or misleading labels. Cost charts keep fractional steps. The change is small and covered by a regression test, so merge-readiness risk is minimal.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(web): use whole-token ticks for low-volume usage charts" matches the main change. The PR makes token charts use whole-token tick steps by passing a minimum step of 1 through niceScale/c…
Description check
The description follows the repository template. It has Problem, Change, Scope, and Verification sections. The Problem section gives the expected and observed behavior with a reproduction recipe. The …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix(web): use whole-token ticks for low-volume usage charts" matches the main change. The PR makes token charts use whole-token tick steps by passing a minimum step of 1 through niceScale/chartScale/buildChart. The title is specific, follows the conventional commit format, and does not describe unrelated work.
Full details: Description check
Explanation
The description follows the repository template. It has Problem, Change, Scope, and Verification sections. The Problem section gives the expected and observed behavior with a reproduction recipe. The Change section explains the fix and why it is limited to token metrics. The Scope section explains why no issue is linked, which the template allows for small obvious fixes. The Verification section lists a focused unit test with base and head results and a check run. It also states what was not verified: rendered before/after screenshots and a runnable scenario. The template asks for screenshots for UI changes, so this gap is noted, but the description is otherwise mostly complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Environment: real web dev app, headless Chromium 156 on Linux, 1280×800, light theme; separate commit worktrees and fresh isolated databases, T3CODE_DEV_SEED=0, isolated CLAUDE_CONFIG_DIR.
On each fresh isolated database, seed one Claude assistant JSONL record timestamped one hour before the run: session-1, req_1, msg_1, claude-haiku-5-5, input_tokens=1 and output_tokens=1. Enable Claude and Codex usage providers, open /usage, select Tokens, leave Claude on and turn Codex off at the access prompt, then Allow. Keep the default 30-day range. Wait for usage refresh to finish, capture the overview, click the claude-haiku-5-5 model row, and capture its detail chart.
Observed in both overview and model detail: base ticks 0, 1, 1, 2, 2; head ticks 0, 1, 2. Both sides show 2 tokens from 1 session. scenarios:prove exited 0.
Scenario: Two-token usage charts have whole-token ticks
Main now sets a one-token minimum tick step (#45608); combine it with
this branch's one-cent minimum for cost.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fork's DailyTotals carries byModel; the buildChart tests merged from
upstream (pingdotgg#45608, pingdotgg#45947) lacked it and broke typecheck.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:S10-29 changed lines (additions + deletions).vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the Usage page's Tokens chart (overview and model detail), a low-volume period gets fractional Y-axis ticks, and
formatTokensrounds each one to a whole number. A chart peaking at two tokens shows five grid lines labeled0, 1, 1, 2, 2, so the line at 0.5 tokens says "1".Deterministic repro on
origin/main(5dd58c09c0703a48e4cabfd64c2768239d2014f6):HOME=$(mktemp -d), which isolates both T3 state and Claude transcripts), then seed one Claude transcript,$HOME/.claude/projects/demo/session-1.jsonl, with a single assistant line, timestamped inside the Usage page's default range, in the same shape asapps/server/src/usage/usageTranscriptReader.test.ts:{"type":"assistant","timestamp":"<today, UTC>T10:00:00Z","requestId":"req_1","sessionId":"session-1","message":{"id":"msg_1","model":"claude-haiku-5-5","usage":{"input_tokens":1,"output_tokens":1}}}.aria-hidden<span>s in thew-14column beside the chart SVG, not SVG text.Code path:
UsageProviderChart→buildChart(..., "tokens", ...)→chartScale→niceScale(2, 4)returns ticks[0, 0.5, 1, 1.5, 2], and the axis labels each one withformatTokens.0, 1, 1, 2, 2.0, 1, 2. The Cost chart keeps fractional dollar steps.Change
niceScalenow takes a minimum step.buildChartpasses1for the token metric and0for cost, so token axes never step below one token. The cost scale stays the same. The change is in the shared chart builder, so both the Usage overview and the model-detail charts get it, on web and desktop.Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
buildChartcase toapps/web/src/components/usage/UsageProviderChart.test.tswith a single 2-token / $2 day. On base it fails withexpected [ +0, 0.5, 1, 1.5, 2 ] to deeply equal [ +0, 1, 2 ]. On head it passes, and the cost metric still returns[0, 0.5, 1, 1.5, 2].vp run check:changedexited 0 onb7acd476ee78dac58011c182adeb1728ddf4921b(format, lint, knip, typecheck, tests, React compiler). The summary is in the gist below.Not shown: rendered before/after screenshots of the axis, and a runnable
scenarios:provescenario. The recipe above is a manual recipe that I have not run in a client. The unit test proves the tick values through the samebuildChartcall the component uses, and the label spans render exactlyscale.ticksthroughformatTokens. Mobile is not covered because this chart is web/desktop only.Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).
Not shown