Skip to content

fix(web): use whole-token ticks for low-volume usage charts - #45608

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
saphid:hunter/c-5f57595c10
Nov 30, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
saphid:hunter/c-5f57595c10

Conversation

@saphid

@saphid saphid commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Problem

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):

  1. 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}}}.
  2. 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.
  3. 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

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.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 29, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 4b03562

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.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: macroscopeapp

Merge Risk: Minimal · previous review 4b035

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 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.
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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between dfb903f and 4b03562.

Files selected for processing: 2

  • apps/web/src/components/usage/UsageProviderChart.test.ts
  • apps/web/src/components/usage/UsageProviderChart.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

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

Proven: the scenario fails on base 66cc44d75b and passes on head 13471293d3.

Base 66cc44d75b Head 13471293d3
Result ❌ failed
ASSERTION_FAILED: expected ["0","1","1","2","2"] to equal ["0","1","2"]
✅ passed
overview two tokens Base 66cc44d75b: overview two tokens Head 13471293d3: overview two tokens
model two tokens Base 66cc44d75b: model two tokens Head 13471293d3: model two tokens
failure Base 66cc44d75b: failure

Scenario · Synthetic usage seed

Base runner recording · Head runner recording

Cost axes were not separately verified: this two-token fixture rounds to $0.00.

Not shown:

  • Cost-axis fractional intervals were not separately captured; the supplied two-token fixture has effectively zero cost and rounds to $0.00.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 30, 2026
@juliusmarminge
juliusmarminge merged commit 19c4134 into pingdotgg:main Nov 30, 2026
59 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 30, 2026
juliusmarminge added a commit that referenced this pull request Nov 30, 2026
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]>
lat added a commit to lat/t3code that referenced this pull request Dec 1, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants