authorgravatar for 97411838+luke2x@users.noreply.github.comluke <97411838+luke2x@users.noreply.github.com> 2026-10-12 09:13:54+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-12 05:13:54-03:00
log58d253231d83f669a2cdfefa5fe479751d22c582
tree8b072c9e1f9f89adf7b3917730b5400d291b930a
parenta27cf8af51ec6a369dcd25c1c1f3ef520e22894d
signature Signed by PGP key B5690EEEBB952194

fix(web): context meter no longer reads 1000k just under a million tokens (#17539)


2 files changed, 12 insertions(+), 1 deletions(-)

apps/web/src/lib/contextWindow.test.ts+10
...@@ -58,6 +58,16 @@ describe("V2 context window presentation", () => {...@@ -58,6 +58,16 @@ describe("V2 context window presentation", () => {
58 it("formats compact token values", () => {58 it("formats compact token values", () => {
59 expect(formatContextWindowTokens(1_500)).toBe("1.5k");59 expect(formatContextWindowTokens(1_500)).toBe("1.5k");
60 });60 });
61
62 it.each([
63 [999_499, "999k"],
64 [999_500, "1m"],
65 [999_999, "1m"],
66 [1_000_000, "1m"],
67 [1_100_000, "1.1m"],
68 ])("formats %d tokens as %s at the million boundary", (tokens, expected) => {
69 expect(formatContextWindowTokens(tokens)).toBe(expected);
70 });
61});71});
6272
63describe("live provider-turn usage (#8144)", () => {73describe("live provider-turn usage (#8144)", () => {
apps/web/src/lib/contextWindow.ts+2-1
...@@ -171,7 +171,8 @@ export function formatContextWindowTokens(value: number | null): string {...@@ -171,7 +171,8 @@ export function formatContextWindowTokens(value: number | null): string {
171 if (value < 10_000) {171 if (value < 10_000) {
172 return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;172 return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
173 }173 }
174 if (value < 1_000_000) {174 // Anything from 999,500 rounds to 1000k, so it belongs to the next unit.
175 if (value < 999_500) {
175 return `${Math.round(value / 1_000)}k`;176 return `${Math.round(value / 1_000)}k`;
176 }177 }
177 return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;178 return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;