Skip to content

fix(billing): read the AI usage share as it is, to a tenth - #1513

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/ai-usage-label-decimal
Oct 26, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/ai-usage-label-decimal

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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 header meter and its "This page this month" line;
    • the per-feature rows;
    • the 80% banner and toast;
    • the Billing card.
  • 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Use any AI feature once (an Improve suggestion, a brief).
  2. Open the AI meter in the header. The share reads to a tenth, e.g. "1.2%", and moves with each run.
  3. Billing › AI usage shows the same share and the same per-feature rows.
  4. At 1024px, the editor header's compact meter still fits beside the other buttons.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 6 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Web: yarn test and yarn build pass. I haven't checked step 4 in a browser yet; it's in the next batched local test session.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 25, 2026 21:10
…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]>

@gkhngyk gkhngyk 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.

Looks good.

What I checked:

  • The reading. percentLabel rounds 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 / 10 prints 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-valuenow are 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:

  1. ai-usage.ts:59: "<0.1%" can't show.
    • The server rounds each share to the nearest tenth (tenths uses Math.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 percentOf and in the total, as getDraftAiUsage does. Otherwise, drop the branch and its test.
    • Main reads these shares the same way, so this isn't a regression.

@gkhngyk
gkhngyk merged commit 3b034ae into ansvisor:main Oct 26, 2026
6 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.

2 participants