Repository navigation
fix: byte sizes show "1024 KiB" instead of "1.0 MiB" just below a unit boundary - #196631
Conversation
formatByteSize picked the unit before rounding, so values just under a unit boundary printed as 1024 of the smaller unit (1048575 bytes became "1024 KiB"). Promote to the next allowed unit when the rounded value reaches the base. Floored units never round up, so they keep their unit.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesPromote rounded byte sizes to the next permitted unit while preserving caller-selected precision, unit caps, and floor rounding. Example: Gateway stability displays an RSS value of 1,048,575 bytes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it fixes a current display defect with a focused shared-owner change and verified CLI evidence; no actionable patch defects were found, and the failing CI assertion also fails on the base. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe normalization-core formatter converts byte counts and caller-owned presentation options into strings consumed by CLI diagnostics, Doctor, UI displays, and Plugin SDK callers. flowchart LR
A[Byte counts] --> B[Caller presentation options]
B --> C[Shared byte formatter]
C --> D[Rounding and permitted unit promotion]
D --> E[CLI and Doctor output]
D --> F[UI and plugin displays]
Technical reviewBest possible solution: Land the shared formatter correction once the inherited CI failure is handled through the repository’s existing landing policy. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the rounding defect directly, and supplied Doctor, stability, and node-status output demonstrates it against the release or pinned base; this read-only review ran no target code. Is this the best way to solve the issue? The patch fixes unit selection in its existing shared owner, preserves distinct caller policies, and adds focused boundary cases without unnecessary modules or scaffolding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0fd8c138f5bc. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +8, Tests 0. Total +8 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 10, 2026, 8:39 AM ET / 13:39 UTC (Revision 3). |
|
Added real CLI proof to the PR body: @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Proof on built artifacts (node 24.22.1, secretless Docker). 1.
2. Real Gateway + real 3. Direct The OpenClaw byte formatter has no 1000-based style. Both shipped styles use base 1024, Branch changes: I merged current |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer override: the one red job is inherited from main. It is not caused by this PR.
|
|
Landed in c0895ab. Thanks @Mahdi-Hasan. Byte sizes no longer show 1024 of the smaller unit. |
…t boundary (openclaw#196631) fix(format): byte sizes just below a unit boundary show the next unit formatByteSize chose the unit before rounding, so values just under a boundary printed impossible sizes such as "1024 KiB", "1024 MB" or "1024 GB free". It now promotes to the next unit when rounding reaches 1024, so 1,048,575 bytes prints "1.0 MiB". Exact boundaries, values already at the largest unit, raw output and small values are unchanged, and no text is new. Evidence: built main and this change on node 24.22.1 in Docker, two runs each. openclaw gateway stability --bundle printed 1024 KiB and 1024 MiB on main and 1.0 MiB and 1.0 GiB with this change. With a real Gateway and a real openclaw node run host, openclaw nodes status showed "mem 1024 KB/1024 MB · disk 1024 GB free" on main and "mem 1.0 MB/1.0 GB · disk 1.0 TB free" with this change. Exactly 1 MiB, 1023 KiB, 1000 KiB, the largest unit, small values, raw output and floored output are identical on both. Details: openclaw#196631 (comment). The remaining red job is inherited from main: openclaw#196631 (comment) Thanks @Mahdi-Hasan. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: byte sizes just under a unit boundary print as "1024 KiB", "1024 MB" or "1024.0 MiB" instead of "1.0 MiB" / "1.0 GiB".
User Impact
User impact: sizes in
openclaw nodes status, gateway stability lines (bytes=,rss=,heap=), update snapshot capacity messages, doctor update-snapshot cleanup text and SQLite WAL health warnings now show the next unit instead of an impossible "1024 " value.Why This Change Was Made
formatByteSizechose the unit before rounding. A value like 1,048,575 bytes stays in KiB (1023.999…) and then rounds to "1024". The shared formatter now moves to the next allowed unit when the rounded value reaches the base.formatDiskSpaceBytesinsrc/infra/disk-space.tsalready guards against the same "1024 MiB" output locally, andformatCompactTokenCountin the same file already rolls k over to m after rounding.Behavior that stays the same:
maxUnitstill caps the unit, so a kilo-capped caller still prints "1024 KiB".floorUnitsround down, so they never reach the base.doctor-disk-spacekeeps "1023 MB" and does not cross its warning threshold.Evidence
Real CLI proof:
openclaw doctorDoctor reports the size of retained update snapshots through
formatByteSize(IEC, 1 decimal). Setup for both runs:npm install -g ... --prefix <tmp>), Windows 11, Node 24.16.0.<prefix>/node_modules/.openclaw.package-backup-proof.databases/holding a single 1,073,741,000-byte file (just under 1 GiB).OPENCLAW_HOMEandOPENCLAW_STATE_DIRpoint at a temp dir. Command:openclaw doctor --non-interactive.Before, published
[email protected]from npm:After, this branch built with
pnpm buildand packed withpnpm pack:The line prefix differs because doctor's output layout changed on
mainsince the release; the size text is the part this PR changes. For the branch install I also packed the workspace@openclaw/aiand placed it in the install tree, because the registry copy of@openclaw/[email protected]predates exports the currentmaincode imports.Unit and consumer tests
New cases in
packages/normalization-core/src/format.test.ts:expected '1024 KiB' to be '1 MiB',expected '1024.0 KiB' to be '1.0 MiB',expected '1024.0 MiB' to be '1.0 GiB'.maxUnitcap case and the floored case.Consumer tests pass with the fix:
doctor-disk-space,tool-images,stability-format,register.status, telegrambot-handlers.inbound-pipeline,number-runtime, file-transferparams, and UIlib/formatandlib/agents/display.src/infra/sqlite-readonly-worker.test.tshas 2 failures ("unable to open database file") on my Windows machine. They fail the same way without this change.pnpm format:checkandoxlinton the touched files: clean.