fix(ui): roll values near 1M over from k to M in compact token format#95485
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 22, 2026, 4:11 AM ET / 08:11 UTC. Summary PR surface: Source +8, Tests +36. Total +44 across 2 files. Reproducibility: yes. Directly importing current main's Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Next step before merge
Security Review detailsBest possible solution: Land the narrow shared Control UI formatter rollover fix with its boundary regression tests after ordinary maintainer review. Do we have a high-confidence way to reproduce the issue? Yes. Directly importing current main's Is this the best way to solve the issue? Yes. Changing the shared Control UI helper is the narrowest maintainable fix because all affected chat surfaces call it, while reusing the core formatter would change casing and precision conventions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4e9dc6b5d5c4. Label changesLabel justifications:
Evidence reviewedPR surface: Source +8, Tests +36. Total +44 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review The edit history on this comment looks tangled - the latest edit shows the Proof rating reverting from "diamond lobster" back to "platinum hermit" with an older timestamp, which looks like two review passes overlapped. Requesting a fresh single-pass review to get a clean, current verdict. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
c84d89c to
1eb4126
Compare
1eb4126 to
7514c82
Compare
0e90e55 to
fe68663
Compare
00727a3 to
e1daf2c
Compare
|
Merged via squash.
Thanks @NarahariRaghava! |
Related: none - found by direct code review, no existing issue.
What Problem This Solves
Fixes an issue where users with a conversation approaching a 1M-token context window would see a nonsensical "1000k" token count instead of "1M" in the Control UI's chat surfaces. This affects the per-message token badges (the small ↑input / ↓output counters shown on each chat message), the context usage notice banner, and slash command output (e.g. /usage, /context), all of which share the same formatCompactTokenCount helper.
Why This Change Was Made
formatCompactTokenCountcheckstokens >= 1_000_000before rounding to decide whether to format in millions or thousands. For values between 999,500 and 999,999, rounding to one decimal place produces "1000.0", which crosses the million threshold only after the branch decision was already made, so the function displays "1000k" instead of rolling over into the millions branch and showing "1M". The fix re-checks the rounded thousands value before formatting, matching the pattern an existing sibling formatter elsewhere in the codebase (src/utils/token-format.ts) already uses to avoid this exact issue. Scope is limited to this one display helper, no change to how tokens are counted or tracked.User Impact
Token counts approaching 1,000,000 now display consistently as "1M" instead of the confusing "1000k", matching the format already used for every other value at or above the million threshold. No functional or data change, this only affects the displayed label.
Evidence
Verified directly with the function logic before and after the fix on a real machine.
Before fix - rounding boundary values (999,949 to 999,999):
Before fix - inconsistent with adjacent million values:
After fix - rounding boundary values now roll over correctly:
After fix - consistent with adjacent million values:
Tests:
Added 5 regression tests in
ui/src/ui/chat/token-format.test.tscovering the rounding boundary. Rannode scripts/run-vitest.mjs run ui/src/ui/chat/token-format.test.ts— 5 passed. Also ran the two existing test files for the surfaces that consume this formatter (grouped-render.test.ts,slash-command-executor.node.test.ts) to confirm no regressions — 98 tests passed.