Skip to content

fix(limits): floor the token display, never round it up - #49

Merged
sre-helmcode merged 5 commits into
mainfrom
fix/format-tokens-floor
Sep 11, 2026
Merged

sre-helmcode merged 5 commits into
mainfrom
fix/format-tokens-floor

Conversation

@sre-helmcode

Copy link
Copy Markdown
Contributor

UX non-blocking on #48, and it closes a pair that was left half-done: the member portal guards this with Math.floor, and the public site did not.

maximumFractionDigits: 0 rounds, it does not truncate

value       before   after
1048576     1M       1M
1500000     2M       1M      <- would advertise more than allowed
1900000     2M       1M

Harmless at today's window, which rounds down anyway. But this page is read by people who have not paid yet, so it must never advertise more than the backend allows — which is exactly the reasoning already written into cloud-ui's formatContextWindow. I put the guard on the private surface and not on the public one.

roundingMode: 'floor', one option, no published number changes. Other figures unaffected: 3,000M / 3.000M and 400M render as before.

Tests

npm run build clean; vitest 727 passed across 50 files.

🤖 Generated with Claude Code

barckcode and others added 5 commits September 10, 2026 23:45
UX non-blocking on #48, and it closes a pair that was left half-done: the
member portal guards this with `Math.floor` and the PUBLIC site did not.

`maximumFractionDigits: 0` truncates nothing — it ROUNDS. Measured before and
after:

    value       before   after
    1048576     1M       1M
    1500000     2M       1M
    1900000     2M       1M

Harmless at today's window, which rounds down anyway. But this page is read by
people who have not paid yet, so it must never advertise MORE than the backend
allows — and that is exactly the reasoning already written into
cloud-ui's formatContextWindow. The guard belonged on the more public surface
too, and I only put it on the private one.

`roundingMode: 'floor'`, one option, no change to any published number. The
other figures are unaffected: 3,000M / 3.000M and 400M render as before.

`npm run build` clean; vitest 727 passed across 50 files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
UX follow-up, same sentence as devops#312 and enterprise-api#48.

"exactly what the Novita primary serves" was the wrong frame: Novita's
`context_size` covers input AND output together, so 1,048,576 is the
provider's total budget, not a servable input window. A prompt at the very top
leaves no room for the reply, nothing on our side filters for it
(`_pre_call_checks` is off), and the caller gets the provider's error on a
number this page publishes.

Comment only, no published number changes.

`npm run build` clean; vitest 727 passed across 50 files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
QA blocker, and it is the rule I have been applying all chain turned back on
me: a guard that cannot fail is not a guard.

`formatTokens(1_048_576)` renders "1M" whether the formatter floors or rounds,
so the 727 green tests said nothing about the fix — they pass identically if
`roundingMode: 'floor'` is deleted. There was no test anywhere referencing
`1_500_000`, `floor` or `roundingMode`.

It matters more here than in the member portal, which QA also spotted:
`roundingMode` is an Intl.NumberFormat option, and a runtime that does not
support it IGNORES IT SILENTLY — no error, just rounding again. So the
question is not "is the word still in the source" but "does this runtime
actually floor", and only an assert answers that.

Verified by removing the option: `expected '2M' to be '1M'`. Restored: green.
The second test pins the figures that must NOT change (1,048,576 → 1M,
3,000M / 3.000M, 400M), so a future rounding change cannot quietly move them.

Also closed a seam QA found, the third of this shape in the chain: inserting
the caveat paragraph left "It renders as" dangling at the end of the new
block. The heuristic worth keeping — when you insert a block, read the
sentence immediately before and immediately after it.

`npm run build` clean; vitest 729 passed across 50 files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@sre-helmcode
sre-helmcode merged commit f0b538c into main Sep 11, 2026
1 check 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