Skip to content

fix: byte sizes show "1024 KiB" instead of "1.0 MiB" just below a unit boundary - #196631

Merged
obviyus merged 3 commits into
openclaw:mainfrom
Mahdi-Hasan:fix/byte-size-unit-rollover
Nov 10, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
Mahdi-Hasan:fix/byte-size-unit-rollover

Conversation

@Mahdi-Hasan

@Mahdi-Hasan Mahdi-Hasan commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

formatByteSize chose 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. formatDiskSpaceBytes in src/infra/disk-space.ts already guards against the same "1024 MiB" output locally, and formatCompactTokenCount in the same file already rolls k over to m after rounding.

Behavior that stays the same:

  • maxUnit still caps the unit, so a kilo-capped caller still prints "1024 KiB".
  • Units listed in floorUnits round down, so they never reach the base. doctor-disk-space keeps "1023 MB" and does not cross its warning threshold.

Evidence

Real CLI proof: openclaw doctor

Doctor reports the size of retained update snapshots through formatByteSize (IEC, 1 decimal). Setup for both runs:

  • npm global install into a throwaway prefix (npm install -g ... --prefix <tmp>), Windows 11, Node 24.16.0.
  • One fake snapshot directory <prefix>/node_modules/.openclaw.package-backup-proof.databases/ holding a single 1,073,741,000-byte file (just under 1 GiB).
  • Isolated state: OPENCLAW_HOME and OPENCLAW_STATE_DIR point at a temp dir. Command: openclaw doctor --non-interactive.

Before, published [email protected] from npm:

[warning] core/doctor/update-snapshots - 1 retained pre-migration database snapshot directory: 1073741000 bytes (1024.0 MiB) in regular files.

After, this branch built with pnpm build and packed with pnpm pack:

- 1 retained pre-migration database snapshot directory: 1073741000 bytes (1.0 GiB) in regular files.

The line prefix differs because doctor's output layout changed on main since the release; the size text is the part this PR changes. For the branch install I also packed the workspace @openclaw/ai and placed it in the install tree, because the registry copy of @openclaw/[email protected] predates exports the current main code imports.

Unit and consumer tests

New cases in packages/normalization-core/src/format.test.ts:

  • Without the fix, 3 cases fail: 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'.
  • With the fix, 14/14 tests pass, including the maxUnit cap case and the floored case.

Consumer tests pass with the fix: doctor-disk-space, tool-images, stability-format, register.status, telegram bot-handlers.inbound-pipeline, number-runtime, file-transfer params, and UI lib/format and lib/agents/display.

src/infra/sqlite-readonly-worker.test.ts has 2 failures ("unable to open database file") on my Windows machine. They fail the same way without this change.

pnpm format:check and oxlint on the touched files: clean.

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.
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Promote 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.

  • Before: rss=1024 KiB
  • After: rss=1.0 MiB

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused shared-owner repair with shipped-entry-point evidence, useful regression cases, and no actionable findings; the remaining CI failure is verified on the base.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed normalization-core formatter is exercised through packed-build Doctor output on Windows and exact-head gateway stability and real node-status commands in secretless Docker, showing corrected unit promotion and unchanged control values.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Byte counts just below a unit boundary display as 1024 of the smaller unit after rounding.
Reason: A small shared correction improves multiple existing displays, with collaborator verification of the intended output and retained caller controls.

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
Reviewed head: 1b6691a50c5e22f53c19702d033ed45281e9fb02

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Shared byte-size scaling and rounding changes intended behavior with a stated reason (5af7ba9: Consolidate independent formatters while preserving caller-specific labels, precision, caps, and floor rounding; the PR explicitly explains the narrow boundary-output correction.)
  • Strict indexed access keeps the original intent (e686693: Enable noUncheckedIndexedAccess for normalization-core through the strict-ratchet lane; the patch retains the defined-unit and label checks.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Raw commit 5af7ba9 adds packages/normalization-core/src/format.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5af7ba92cefe; files: packages/normalization-core/src/format.ts)
  • Peter Steinberger: Raw commit e686693 adds packages/normalization-core/src/format.ts:1 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e68669373280; files: packages/normalization-core/src/format.ts)

PR surface

Source +8, Tests 0. Total +8 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 20 12 +8
Tests 1 8 8 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 28 20 +8

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The Plugin SDK-exported formatter intentionally changes boundary output strings; the PR discussion and consumer proof cover the change while preserving caller options and caps.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This corrects rounded diagnostic display text without changing underlying byte counts or operational thresholds.
  • merge-risk: 🚨 compatibility: The Plugin SDK-exported formatter intentionally changes boundary output strings; the PR discussion and consumer proof cover the change while preserving caller options and caps.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-10T11:25:14.916Z sha 9930384 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T12:21:28.100Z sha 9930384 :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 8:39 AM ET / 13:39 UTC (Revision 3).

@Mahdi-Hasan

Copy link
Copy Markdown
Contributor Author

Added real CLI proof to the PR body: openclaw doctor on published 2026.11.2 prints 1073741000 bytes (1024.0 MiB); the same setup on this branch's packed build prints 1073741000 bytes (1.0 GiB).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Proof on built artifacts (node 24.22.1, secretless Docker). main = af37a00, candidate = 1b6691a (this branch with current main merged in; it differs from main only in format.ts and its test). Each build was run twice, and both runs gave the same output.

1. openclaw gateway stability --bundle <file> (KiB/MiB/GiB labels, largest unit GiB). The input is a stability bundle file with byte values one under each unit boundary, plus control values.

bytes main candidate
1,048,575 (rss, bytes=) 1024 KiB 1.0 MiB
1,073,741,823 (heap, bytes=) 1024 MiB 1.0 GiB
1,048,576 (exactly 1 MiB) 1.0 MiB 1.0 MiB
1,047,552 (1023 KiB) 1023 KiB 1023 KiB
1,023,999 1000 KiB 1000 KiB
1 TiB − 1 (already at the largest unit) 1024 GiB 1024 GiB
1023 / 0 1023 B / 0 B 1023 B / 0 B

2. Real Gateway + real openclaw node run host, then openclaw nodes status (KB/MB/GB/TB labels, largest unit TB). A preload in the node process makes the OS report the chosen memory and disk sizes. The node's node.host.stats report is checked in node.list before each status call.

bug   (used 1,048,575 / total 1,073,741,823 / disk free 1 TiB − 1)
  main:      mem 1024 KB/1024 MB · disk 1024 GB free
  candidate: mem 1.0 MB/1.0 GB · disk 1.0 TB free
ctl1  (used 1023 KiB / total exactly 1 GiB / disk free 1 PiB − 1, already at TB)
  both:      mem 1023 KB/1.0 GB · disk 1024 TB free
ctl2  (used 512 B / total exactly 1 MiB / disk free 0)
  both:      mem 512 B/1.0 MB · disk 0 B free

3. Direct formatByteSize calls (supporting): main 1024.0 KiB / 1024.0 MB → candidate 1.0 MiB / 1.0 GB. These were the same on both builds: raw output with fractionDigits: null (1023.9990234375 KiB), maxUnit: "kilo" (1024 KiB stays), floored MB (1023 MB), and 512 B.

The OpenClaw byte formatter has no 1000-based style. Both shipped styles use base 1024, iec (KiB) and legacy-binary (KB), and both are covered above.

Branch changes: I merged current main and folded the new cases into the existing formatByteSize table, so net test lines are 0. The production change is unchanged: +20/−12 in packages/normalization-core/src/format.ts. oxfmt and oxlint pass on both changed files.

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Nov 10, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Nov 10, 2026
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: the one red job is inherited from main. It is not caused by this PR.

@obviyus
obviyus merged commit c0895ab into openclaw:main Nov 10, 2026
163 of 167 checks passed
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Landed in c0895ab. Thanks @Mahdi-Hasan. Byte sizes no longer show 1024 of the smaller unit.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants