Repository navigation
fix(billing): read the AI usage share as it is, to a tenth - #1513
Merged
Merged
Conversation
…f flooring to whole percents Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ve the header (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
gkhngyk
approved these changes
Oct 26, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good.
What I checked:
- The reading.
percentLabelrounds down to a tenth (ai-usage.ts:58-62).- The small nudge stops a tenth the server sent from rounding down below itself (2.3 × 10 is 22.999…).
- It's far too small to lift 99.9 to 100. Until the allowance is spent, the server sends at most 99.9 (
getAiUsage). n / 10prints with one decimal at most, and a whole share prints without one ("28%").
- Every place that shows the share uses it: the header meter and its page line, the feature rows, the 80% banner and toast, and the Billing card. The bar widths and
aria-valuenoware unchanged. - Width.
- The number is at least 2.25rem wide and right-aligned, so the button keeps its width as the tenths change.
- The placeholder shown before the first read matches the button's new widths. In the compact meter, the padding, the border and the number add up to 3.625rem.
- API. No API change is needed. The API has sent tenths since #1386, and the label formats whatever share it gets, so this works on the API that's live now.
- Merge. It merges cleanly on main and alongside #1511. CI passes.
Low, follow-up:
ai-usage.ts:59: "<0.1%" can't show.- The server rounds each share to the nearest tenth (
tenthsusesMath.round). A feature that used less than 0.05% arrives as 0 and reads "0%". Only the page share has a 0.1 floor (getDraftAiUsage). - If a feature that was used should never read "0%", give every non-zero share a 0.1 floor in
percentOfand in the total, asgetDraftAiUsagedoes. Otherwise, drop the branch and its test. - Main reads these shares the same way, so this isn't a regression.
- The server rounds each share to the nearest tenth (
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The AI usage percent now reads as it is, to the tenth the server already sends: "1.1%", "4.9%", "28.3%", "99.9%" ("28%" when whole). It used to floor to whole percents, with "<1%" under 1%.
In the live editor test (2026-10-25), the meter read "1%" while the real share was 1.5% (the bar's own width). After seven agent runs it looked frozen. Now each run shows.
percentLabel(web/src/lib/billing/ai-usage.ts) floors to a tenth, so it never reads as all of it before it is. The server still sends 100 only once the allowance is spent, and 99.9 just under it.A sliver under a tenth reads "<0.1%", not "0%".
Every place that shows the share uses the same function:
The meter's percent is as wide as "99.9%" (
min-w-9, right-aligned), so the header doesn't move as the tenths change (21.4% → 22% → 22.1%). The box shown while the first read runs is widened to match, so the header doesn't shift when the meter appears.Not changed here: the Improve tab's tooltip (
plan-guard.js/prompt-improve-tab.tsx) still rounds its "… left" to whole percents, as before. The decimal point is the UI's English one; the Turkish UI (LOC) will need "21,4%".Related issue
Editor test findings 2026-10-25 (group G).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings are in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Web:
yarn testandyarn buildpass. I haven't checked step 4 in a browser yet; it's in the next batched local test session.🤖 Generated with Claude Code