Skip to content

fix(ui): roll values near 1M over from k to M in compact token format#95485

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
NarahariRaghava:fix/token-format-million-boundary-rounding
Jun 22, 2026
Merged

fix(ui): roll values near 1M over from k to M in compact token format#95485
vincentkoc merged 3 commits into
openclaw:mainfrom
NarahariRaghava:fix/token-format-million-boundary-rounding

Conversation

@NarahariRaghava

Copy link
Copy Markdown
Contributor

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

formatCompactTokenCount checks tokens >= 1_000_000 before 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):

before1

Before fix - inconsistent with adjacent million values:

before2

After fix - rounding boundary values now roll over correctly:

after1

After fix - consistent with adjacent million values:

after2

Tests:

Added 5 regression tests in ui/src/ui/chat/token-format.test.ts covering the rounding boundary. Ran node 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.

@clawsweeper

clawsweeper Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 22, 2026, 4:11 AM ET / 08:11 UTC.

Summary
The PR updates the shared Control UI chat token formatter to roll rounded thousands at the 1M boundary into M output and adds focused Vitest coverage.

PR surface: Source +8, Tests +36. Total +44 across 2 files.

Reproducibility: yes. Directly importing current main's ui/src/ui/chat/token-format.ts returns 1000k for 999950 and 999999, matching the reported display bug.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • [P2] No repair lane is needed because the PR already contains the narrow fix, focused tests, and sufficient real behavior proof; the remaining action is maintainer review and normal merge handling.

Security
Cleared: The patch only changes pure UI formatting logic and colocated tests, with no concrete security or supply-chain concern.

Review details

Best 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 ui/src/ui/chat/token-format.ts returns 1000k for 999950 and 999999, matching the reported display bug.

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 changes

Label justifications:

  • P3: This is a narrow Control UI display-formatting bug with no data, auth, message delivery, availability, config, or compatibility surface.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR body includes inspected terminal screenshots showing before and after output for the exact formatter boundary values.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes inspected terminal screenshots showing before and after output for the exact formatter boundary values.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body includes inspected terminal screenshots showing before and after output for the exact formatter boundary values.
Evidence reviewed

PR surface:

Source +8, Tests +36. Total +44 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 1 36 0 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 45 1 +44

What I checked:

  • Repository policy read: Root AGENTS.md and the scoped UI guide were read fully; root PR review rules affected the depth of source, caller, proof, and history inspection, while the UI guide added no formatter-specific constraint. (AGENTS.md:1, 4e9dc6b5d5c4)
  • Current main reproduces the display bug: A direct current-main import returns 1000k for 999950 and 999999, with 1000000 already in the million branch as 1M. (ui/src/ui/chat/token-format.ts:7, 4e9dc6b5d5c4)
  • Latest release is not already fixed: v2026.6.9 predates the shared helper and still has the same raw-threshold thousand formatter inline in Control UI chat surfaces, so the PR is not obsolete due to a shipped fix. (ui/src/ui/chat/grouped-render.ts:688, c645ec4555c0)
  • PR patch fixes the shared helper: The PR stores the rounded thousands string, checks whether that rounded value reaches 1000, and reroutes those boundary values through the million formatter before returning a k label. (ui/src/ui/chat/token-format.ts:7, 7514c823cb02)
  • Focused regression tests added: The new colocated test file covers normal sub-1k, thousands, millions, rollover inputs 999_950 and 999_999, and adjacent non-rollover inputs. (ui/src/ui/chat/token-format.test.ts:22, 7514c823cb02)
  • Caller surface checked: Message metadata, context notices, and slash-command usage all import the same Control UI helper on current main, making the helper the right fix point for the affected displays. (ui/src/ui/chat/grouped-render.ts:696, 4e9dc6b5d5c4)

Likely related people:

  • vincentkoc: Path history shows 45f935887769 created ui/src/ui/chat/token-format.ts and rewired the affected grouped-render, context-notice, and slash-command callers to the shared helper. (role: introduced shared formatter / recent UI contributor; confidence: high; commits: 45f935887769, 402e2bb81a73; files: ui/src/ui/chat/token-format.ts, ui/src/ui/chat/grouped-render.ts, ui/src/ui/chat/context-notice.ts)
  • BunsDev: GitHub commit history ties the persistent context usage notice consumer to 5a90179e8fdf and related freshness work, making this a relevant routing candidate for the context notice display surface. (role: context notice feature contributor; confidence: medium; commits: 5a90179e8fdf, da773175f2eb; files: ui/src/ui/chat/context-notice.ts, ui/src/ui/chat/run-controls.test.ts)
  • jbetala7: Recent status-format work touched src/utils/token-format.ts, the sibling formatter whose rollover guard is the closest current-code precedent for this PR. (role: adjacent token-format contributor; confidence: medium; commits: e8b35a82801e; files: src/utils/token-format.ts, src/commands/status.format.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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 keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Jun 21, 2026
@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

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

@clawsweeper

clawsweeper Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper

clawsweeper Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 21, 2026
@vincentkoc
vincentkoc force-pushed the fix/token-format-million-boundary-rounding branch 3 times, most recently from c84d89c to 1eb4126 Compare June 22, 2026 06:38
@vincentkoc vincentkoc self-assigned this Jun 22, 2026
@vincentkoc
vincentkoc force-pushed the fix/token-format-million-boundary-rounding branch from 1eb4126 to 7514c82 Compare June 22, 2026 07:51
@vincentkoc
vincentkoc requested a review from a team as a code owner June 22, 2026 08:16
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: mattermost Channel integration: mattermost channel: signal Channel integration: signal cli CLI command changes scripts Repository scripts channel: irc extensions: moonshot extensions: venice extensions: vercel-ai-gateway labels Jun 22, 2026
@github-actions github-actions Bot removed the dependencies-changed PR changes dependency-related files label Jun 22, 2026
@vincentkoc
vincentkoc force-pushed the fix/token-format-million-boundary-rounding branch 8 times, most recently from 0e90e55 to fe68663 Compare June 22, 2026 10:34
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts commands Command implementations agents Agent runtime and tooling extensions: vllm size: L and removed size: XS labels Jun 22, 2026
@vincentkoc
vincentkoc force-pushed the fix/token-format-million-boundary-rounding branch from 00727a3 to e1daf2c Compare June 22, 2026 11:14
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation scripts Repository scripts commands Command implementations agents Agent runtime and tooling labels Jun 22, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

Thanks @NarahariRaghava!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui extensions: elevenlabs gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants