fix: align context usage display with 1024-based units and ceiled percents - #1771
Conversation
…only meter - simplify the composer context meter to the ring only; the full used/max/pct numbers live in the tooltip - format token counts with 1024-based k/M units via a shared formatTokens helper (256k context reads "256k", not "262k"), applied to the composer tooltip, status panel, mobile settings sheet, model picker, goal strip, and turn rendering - ceil the usage percent so sub-0.5% usage still shows a sliver instead of an empty meter
- formatTokenCount is now 1024-based ("256k", not "262.1k"); the footer,
/status and /usage panels, subagent cards, and goal stats all share it,
replacing five local 1000-based copies
- the footer and panel percents use an integer ceil (new usagePercent
helper) so any non-zero usage shows at least 1% instead of "0.0%"
🦋 Changeset detectedLatest commit: ba280b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f3dea059e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ctxUsed can momentarily exceed ctxMax (estimates), which could flash a "101%" readout — the composer and mobile sheet already clamp the same ConversationStatus data, so apply the same clamp around the ceiled percentage here.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d063e5d0bf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…cents (MoonshotAI#1771) * fix(web): align context usage display with 1024-based units and ring-only meter - simplify the composer context meter to the ring only; the full used/max/pct numbers live in the tooltip - format token counts with 1024-based k/M units via a shared formatTokens helper (256k context reads "256k", not "262k"), applied to the composer tooltip, status panel, mobile settings sheet, model picker, goal strip, and turn rendering - ceil the usage percent so sub-0.5% usage still shows a sliver instead of an empty meter * fix(tui): render context usage with 1024-based units and ceil percent - formatTokenCount is now 1024-based ("256k", not "262.1k"); the footer, /status and /usage panels, subagent cards, and goal stats all share it, replacing five local 1000-based copies - the footer and panel percents use an integer ceil (new usagePercent helper) so any non-zero usage shows at least 1% instead of "0.0%" * fix(web): clamp the status panel context percent to [0,100] ctxUsed can momentarily exceed ctxMax (estimates), which could flash a "101%" readout — the composer and mobile sheet already clamp the same ConversationStatus data, so apply the same clamp around the ceiled percentage here. * chore: merge the context usage changesets into one * chore: reword the context usage changeset in English
…cents (MoonshotAI#1771) * fix(web): align context usage display with 1024-based units and ring-only meter - simplify the composer context meter to the ring only; the full used/max/pct numbers live in the tooltip - format token counts with 1024-based k/M units via a shared formatTokens helper (256k context reads "256k", not "262k"), applied to the composer tooltip, status panel, mobile settings sheet, model picker, goal strip, and turn rendering - ceil the usage percent so sub-0.5% usage still shows a sliver instead of an empty meter * fix(tui): render context usage with 1024-based units and ceil percent - formatTokenCount is now 1024-based ("256k", not "262.1k"); the footer, /status and /usage panels, subagent cards, and goal stats all share it, replacing five local 1000-based copies - the footer and panel percents use an integer ceil (new usagePercent helper) so any non-zero usage shows at least 1% instead of "0.0%" * fix(web): clamp the status panel context percent to [0,100] ctxUsed can momentarily exceed ctxMax (estimates), which could flash a "101%" readout — the composer and mobile sheet already clamp the same ConversationStatus data, so apply the same clamp around the ceiled percentage here. * chore: merge the context usage changesets into one * chore: reword the context usage changeset in English
Related Issue
No linked issue — the problem is described below.
Problem
Token counts are formatted with 1000-based units across the web UI and the TUI, so a 256k context reads "262k" / "262.1k" and a 1M context reads "1049k" / "1.0M". Usage percentages are rounded (or shown with one decimal), which floors sub-0.5% usage to 0: the composer ring and the status/mobile bars render empty even though usage data is present, and the TUI footer shows a misleading "0.0%". The TUI also carried five drifted local copies of the 1000-based formatter.
On the web, the composer meter additionally duplicated information: the ring plus an inline "12k/256k" readout.
What changed
Web (apps/kimi-web)
formatTokenshelper (1024-based k/M, e.g. 262144 → "256k", 1048576 → "1M") with unit tests, applied to the composer tooltip, status panel, mobile settings sheet, model picker ({size} ctx), goal strip, and turn rendering.Math.ceil(clamped to 0–100) so any non-zero usage shows at least a 1% sliver.TUI (apps/kimi-code)
formatTokenCountis now 1024-based ("256k", not "262.1k"); the footer, the /status and /usage panels, subagent cards, agent groups, and goal completion stats all use it, replacing five local 1000-based copies.usagePercent/usagePercentFromRatiohelpers: integer percent, ceiled so non-zero usage shows at least 1%, clamped to 0–100. The footer percent prefers exact token counts (the ratio can lag a step) and falls back to the ratio when max is unknown.context: 32% (49.4k/256k).Tests asserting the old 1000-based formats were updated to the new semantics. Verified:
pnpm -F @moonshot-ai/kimi-web test(599 passed) andpnpm -F @moonshot-ai/kimi-code test(2322 passed) both green, plus per-package typecheck.Checklist
gen-changesetsskill, or this PR needs no changeset. (two changesets included:web-context-usage-display,tui-context-usage-display)gen-docsskill, or this PR needs no doc update. (no docs reference the old formats)