From bb2900599792494daa456e42dd251a27f47e331e Mon Sep 17 00:00:00 2001 From: kate bonner Date: Tue, 28 Jul 2026 19:10:45 -0400 Subject: [PATCH] fix(run): fidelity readout never rounds a near-unity F to a bare 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit formatFidelity's toFixed(4) collapsed any F ≥ 0.99995 to "1" in the run chip, ring-2 Run hero, and Run modal — hiding exactly the number that matters. Precision now extends a digit at a time (cap 10) until the gap from 1 (or 0) survives rounding; ordinary values keep the 4-decimal form and only a true 1 renders bare. Co-Authored-By: Claude Fable 5 --- packages/ui/src/amicode/problem.test.ts | 14 ++++++++++++++ packages/ui/src/amicode/problem.ts | 13 +++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/amicode/problem.test.ts b/packages/ui/src/amicode/problem.test.ts index a26833e1c..ff669a05e 100644 --- a/packages/ui/src/amicode/problem.test.ts +++ b/packages/ui/src/amicode/problem.test.ts @@ -118,6 +118,20 @@ describe("runChipText", () => { test("solving f outside [0,1] renders no F readout (objective ≠ fidelity)", () => { expect(runChipText([{ runId: "r", status: "solving", fidelity: 79.3, iteration: 0 }])).toBe("solving…") }) + test("near-unity fidelity never rounds to a bare 1 — precision extends until the gap shows", () => { + expect(runChipText([{ runId: "r", status: "finished", fidelity: 0.99997, iteration: 60 }])).toBe( + "F=0.99997 · 60 iter", + ) + expect(runChipText([{ runId: "r", status: "finished", fidelity: 0.99999997, iteration: 60 }])).toBe( + "F=0.99999997 · 60 iter", + ) + // solving mirror: a tiny live objective is a near-unity F + expect(runChipText([{ runId: "r", status: "solving", fidelity: 0.00003, iteration: 12 }])).toBe( + "solving… F=0.99997", + ) + // a true 1 (and only a true 1) still renders bare + expect(runChipText([{ runId: "r", status: "finished", fidelity: 1, iteration: 60 }])).toBe("F=1 · 60 iter") + }) }) describe("railState", () => { diff --git a/packages/ui/src/amicode/problem.ts b/packages/ui/src/amicode/problem.ts index 7fa599346..1dc0e847e 100644 --- a/packages/ui/src/amicode/problem.ts +++ b/packages/ui/src/amicode/problem.ts @@ -244,8 +244,17 @@ export function mergeChips(entities: Record>, sc // --- run chip ---------------------------------------------------------------- function formatFidelity(value: number): string { - // up to 4 significant decimals, trailing zeros trimmed - return String(Number(value.toFixed(4))) + // 4 decimals for ordinary values (trailing zeros trimmed) — but NEVER let + // rounding collapse a near-unity or near-zero fidelity into exactly "1"/"0": + // the gap from perfect IS the result (Kate 2026-07-28, a 0.99997 run showed + // "F = 1"). Precision extends one digit at a time until the gap survives, + // capped at 10; only a true 1 or 0 renders bare. + if (value === 1 || value === 0) return String(value) + for (let digits = 4; digits <= 10; digits++) { + const rounded = Number(value.toFixed(digits)) + if (rounded !== 1 && rounded !== 0) return String(rounded) + } + return String(value) } export function runChipText(statuses: RunStatusView[]): string | undefined {