Repository navigation
fix(tui): roll the compact form over to M at the rounding boundary - #55871
Merged
Merged
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
Contributor
There was a problem hiding this comment.
The bug is fixed. I ran the #55256 reproduction from source with the simulated model reporting 999,950 prompt tokens. The status bar context counter shows 1000.0K (781%) on the base and 1.0M (781%) with this change (screenshots below). The new tests fail on the base and pass here, and the packages/tui type check passes.
The 999,950 threshold is exactly where (n / 1000).toFixed(1) first reaches "1000.0". Both callers (formatContextUsage and the session in · out line) only get token counts, so no fractional value lands on the boundary.
The public API is unchanged: this only affects TUI display formatting.
I found no problems with the change.
opencode-agent
Bot
force-pushed
the
compact-number-rollover
branch
from
October 15, 2026 23:27
0ad9e52 to
72720b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Issue for this PR
Closes #55256
Type of change
What does this PR do?
Locale.numberpicks its unit before it rounds, so a value that the K branch rounds up to four digits prints as four digits.number(999_950)is"1000.0K"where"1.0M"is meant, and the status bar's context counter shows the same thing throughformatContextUsage.The K branch is
(num / 1000).toFixed(1), so its result first reaches"1000.0"at999_950(999_949 gives"999.9"). That is the whole fix:Everything below the boundary is unchanged:
999_949still reads999.9K,1000still reads1.0K, and1_000_000still reads1.0M, which it already did.numberhas two callers, both fixed by the same line: the token line inroutes/session/index.tsx(N in · N out) andformatContextUsageinutil/session.ts, which is what the reporter and the bot's reproduction script saw in the footer (mini/footer.view.tsxandfeature-plugins/prompt/footer.tsxboth render it through that helper).Not in this PR: the same shape at the top of the scale. There is no unit above
M, sonumber(999_999_999)still prints1000.0M. That is the end of the scale rather than a missing rollover — adding aBunit is a formatting decision the issue does not ask for, and this PR stays on the reported boundary.The two earlier attempts at this, #48969 and #47523, were both closed by the periodic automated stale-PR sweep rather than on their merits, and
devstill carries the bug, so this is not a resurrection of a rejected fix.How did you verify your code works?
Two tests, both of which fail on the unmodified source with exactly the reported string:
packages/tui/test/util/locale.test.ts—rolls the compact form over at the rounding boundarypins999,1000,999949,999950,999999,1000000,2500000. Without the change it fails at999949 → 999.9Kbeing fine but999950coming back as"1000.0K".packages/tui/test/util/session.test.ts—reports the context counter a million tokens in as 1.0Mcovers the path the reporter actually sees, throughformatContextUsage. Without the change it returns"1000.0K (101%)"instead of"1.0M (101%)".Both directions were measured by reverting only
locale.tsand re-running: 2 fail on the old source, 5 pass on the new one.tsgo -binpackages/tuiexits 0, and is a real gate here (it was confirmed to reject a deliberate type error first).oxlintreports 0 warnings and 0 errors on the three files — note thatpackages/tuiis not in the anti-slop override list in.oxlintrc.json, so the only rule reaching these files is the globalno-restricted-globals, which was shown to fire before being trusted.Full
packages/tuisuite: 1487 tests, 7 failures, all in the plugin/watcher family (a component layer ends …,failed setup reports batched layer errors …,Node reloads the local ESM graph …,setup layers before and after await …). A pristineupstream/devcheckout of the same tree fails 8, including every one of those, plusreal watchers observe atomic saves to nested, outside-root, and symlinked helpers— so the failures are pre-existing and environment-dependent, this branch's set is a strict subset of the pristine one, and nothing inutil/locale.tsis reachable from those files.Screenshots / recordings
Not a layout change — this changes the text a counter renders, and the exact string is pinned by the tests above (
1000.0K→1.0Mat the reported boundary). The reproduction the bot posted on the issue shows the same counter.Checklist