Skip to content

fix: align context usage display with 1024-based units and ceiled percents - #1771

Merged
liruifengv merged 5 commits into
mainfrom
feat/context-usage-parity
Jul 16, 2026
Merged

fix: align context usage display with 1024-based units and ceiled percents#1771
liruifengv merged 5 commits into
mainfrom
feat/context-usage-parity

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

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)

  • The composer context meter is now the ring only; the full used/max/pct numbers live in the tooltip (still exposed via aria-label).
  • New shared formatTokens helper (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.
  • The usage percent uses Math.ceil (clamped to 0–100) so any non-zero usage shows at least a 1% sliver.

TUI (apps/kimi-code)

  • Shared formatTokenCount is 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.
  • New usagePercent / usagePercentFromRatio helpers: 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.
  • The footer keeps its compact text form: 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) and pnpm -F @moonshot-ai/kimi-code test (2322 passed) both green, plus per-package typecheck.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset. (two changesets included: web-context-usage-display, tui-context-usage-display)
  • Ran gen-docs skill, or this PR needs no doc update. (no docs reference the old formats)

…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-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ba280b7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@ba280b7
npx https://pkg.pr.new/@moonshot-ai/kimi-code@ba280b7

commit: ba280b7

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/kimi-web/src/components/chat/StatusPanel.vue Outdated
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.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/kimi-web/src/lib/formatTokens.ts
@liruifengv
liruifengv merged commit b513975 into main Jul 16, 2026
14 checks passed
@liruifengv
liruifengv deleted the feat/context-usage-parity branch July 16, 2026 08:41
This was referenced Jul 16, 2026
ywh114 pushed a commit to ywh114/kimi-code that referenced this pull request Jul 19, 2026
…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
ywh114 pushed a commit to ywh114/kimi-code that referenced this pull request Jul 27, 2026
…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
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.

1 participant