Skip to content

fix: promote a size that rounds up to a full unit in two more formatters - #556

Merged
rominf merged 1 commit into
mainfrom
fix/format-bytes-unit-promotion-twins
Oct 6, 2026
Merged

rominf merged 1 commit into
mainfrom
fix/format-bytes-unit-promotion-twins

Conversation

@rominf

@rominf rominf commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #503, which fixed rocm_core::format_bytes printing a size just below a unit boundary as "1024.0 KiB". Review there found the same defect in two more formatters, and this fixes both the same way.

  • format_bytes_for_user (rocm binary) formats the size in the download: approved up to … line of the automations view. Sizes of 1,048,525–1,048,575 bytes printed as "1024.0 KB", and 1,073,689,396–1,073,741,823 as "1024.0 MB". They now print "1.0 MB" and "1.0 GB".
  • mib / mib_pair (dashboard VRAM): 1,048,525–1,048,575 MiB, just under 1 TiB, printed as "1024.0 GiB" and now prints "1.0 TiB". The two now share one unit-picking helper, so the pair can't pick a different unit from the single value.

Unit labels and the "bytes" wording are unchanged; the KB/MB versus KiB/MiB naming is a separate question.

Why

Each formatter promoted on the raw value (>= 1024) but printed with {:.1}, which rounds 1023.95 and above up to 1024.0, so the loop stopped one unit early. As in #503, they now promote while the value as printed would reach 1024: (value * 10.0).round() >= 10_240.0.

Test plan

  • Pinned boundary examples for each function, covering the last input that stays in the smaller unit and the first that rounds up. They fail before the fix and pass after.
  • The same two-edge property as fix(disk-space): promote a size that rounds up to a full unit #503's format_bytes_renders_a_size_in_its_own_unit, pointed at format_bytes_for_user, at mib, and at mib_pair's total.
    • Upper edge: below the top unit, the printed value is under 1024.0.
    • Lower edge: above the base unit, it is at least 1.0, and the next smaller unit would have printed 1024.0 or more.
  • proptest is added as a dev-dependency of rocm and rocm-dash-tui, with the version and features rocm-core already uses. No new crate enters the lockfile, and nothing ships.
  • The automations render test now uses a 1,048,575-byte download cap, so the user-facing download: approved up to 1.0 MB line is checked at the boundary through the real renderer.
  • Mutation-checked:
    • Restoring the old raw >= 1024.0 comparison fails both the examples and the properties, at 1,048,525.
    • Promoting slightly early fails the lower edge.
    • Both were checked with the saved seeds removed, so the generator finds them on its own.
  • No new e2e scenario: the download: approved up to line is only reached through the assistant's in-process, read-only automations command, and no current scenario seeds automation proposals. Coverage is the render-level test above.
  • Verified locally: cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo test -p rocm --bin rocm, cargo test -p rocm-dash-tui --lib (ui::format), cargo test -p xtask, cargo xtask manifest --check.

Independent of #503's code; it can land in either order.

  • Bug fix: no xfail rows reference this area.
  • No new subcommand or subsystem.
  • The changed output line is asserted with its rendered value through the real renderer.

`rocm_core::format_bytes` printed sizes just below a unit boundary as
"1024.0 KiB": it promoted on the raw value (`>= 1024`) but printed with
`{:.1}`, which rounds 1023.95 and up to 1024.0. Two other formatters
carry the same shape:

- `format_bytes_for_user` in the `rocm` binary, behind the
  `download: approved up to …` line: 1_048_525..=1_048_575 bytes
  printed "1024.0 KB" and 1_073_689_396..=1_073_741_823 printed
  "1024.0 MB".
- `mib` and `mib_pair` in the dashboard, for VRAM: 1_048_525..=1_048_575
  MiB printed "1024.0 GiB".

Both now promote while the value as printed would reach 1024, comparing
the rounded tenths exactly as the rocm-core fix does. `mib` and
`mib_pair` share one helper, so the pair's unit can no longer drift from
the single value's. Unit labels and the "bytes" wording are unchanged.

Each fix carries pinned boundary examples and a two-edge property test
(never a unit the size has outgrown; never one it has not reached), with
proptest added as a dev-dependency of both crates at the version and
features rocm-core already uses.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
@rominf
rominf requested a review from a team as a code owner October 6, 2026 07:49
@rominf
rominf requested a review from r0x0r October 6, 2026 07:49

@jussielo-amd jussielo-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, tightly-scoped fix — matches the #503 pattern exactly where it needs to. The promoted_mib_unit extraction for mib/mib_pair is a good call: it structurally prevents the pair from picking a different unit than the single value would.

Checked the boundary math by hand and ran both test suites locally (rocm-dash-tui's ui::format and rocm's format_bytes_for_user tests) — all pass, including the new proptest properties and their saved regression seeds. Updating the automations render test to hit the boundary through the real renderer instead of just the helper function is a nice touch.

One non-blocking FYI: apps/rocm/src/main.rs::format_bytes (behind rocm storage) already had this same defect fixed, but with a different style (a hardcoded 1023.95 cutoff vs. the rounded-tenths loop used here) — pre-existing, out of scope for this PR, just worth a note for whoever's next in that neighborhood.

@rominf
rominf added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 4ee6161 Oct 6, 2026
30 of 31 checks passed
@rominf
rominf deleted the fix/format-bytes-unit-promotion-twins branch October 6, 2026 10:24
juhovainio pushed a commit that referenced this pull request Oct 7, 2026
…ers (#556)

`rocm_core::format_bytes` printed sizes just below a unit boundary as
"1024.0 KiB": it promoted on the raw value (`>= 1024`) but printed with
`{:.1}`, which rounds 1023.95 and up to 1024.0. Two other formatters
carry the same shape:

- `format_bytes_for_user` in the `rocm` binary, behind the
  `download: approved up to …` line: 1_048_525..=1_048_575 bytes
  printed "1024.0 KB" and 1_073_689_396..=1_073_741_823 printed
  "1024.0 MB".
- `mib` and `mib_pair` in the dashboard, for VRAM: 1_048_525..=1_048_575
  MiB printed "1024.0 GiB".

Both now promote while the value as printed would reach 1024, comparing
the rounded tenths exactly as the rocm-core fix does. `mib` and
`mib_pair` share one helper, so the pair's unit can no longer drift from
the single value's. Unit labels and the "bytes" wording are unchanged.

Each fix carries pinned boundary examples and a two-edge property test
(never a unit the size has outgrown; never one it has not reached), with
proptest added as a dev-dependency of both crates at the version and
features rocm-core already uses.

Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
Signed-off-by: Juho Vainio <juho.vainio@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants