Skip to content

formatDiskSpaceBytes emits "1024 MiB" instead of "1.0 GiB" at the GiB boundary #90245

Description

@jbetala7

Summary

formatDiskSpaceBytes in src/infra/disk-space.ts can render the impossible unit string "1024 MiB" instead of "1.0 GiB". This string is operator-facing — it appears in the low-disk-space warning shown during setup/update staging (createLowDiskSpaceWarning).

Current behavior on main (ec3aa5def4)

export function formatDiskSpaceBytes(bytes: number): string {
  const mib = bytes / (1024 * 1024);
  if (mib < 1024) {
    return `${Math.max(0, Math.round(mib))} MiB`;
  }
  const gib = mib / 1024;
  return `${gib.toFixed(gib < 10 ? 1 : 0)} GiB`;
}

The unit branch tests the unrounded mib < 1024, but the MiB branch then Math.round(mib)s. For any value with mib ∈ [1023.5, 1024) the guard is true (stays in MiB) yet the rounded number is 1024, so it prints "1024 MiB".

Verified by exercising the real exported function:

formatDiskSpaceBytes(Math.round(1023.7 * 1024 * 1024)) => "1024 MiB"   // bug

and the resulting user-facing warning:

Low disk space near <path>: 1024 MiB available; the update may fail.

Expected behavior

A value that rounds up to 1024 MiB should be promoted to "1.0 GiB" (the function should never emit 1024 MiB):

formatDiskSpaceBytes(Math.round(1023.7 * 1024 * 1024)) => "1.0 GiB"

Duplicate search

  • No open PR touches src/infra/disk-space.ts (scanned all open PRs by file).
  • No open issue for disk-space formatting / formatDiskSpaceBytes / low-disk-warning wording.
  • git log origin/main -- src/infra/disk-space.ts shows no prior fix for this.

Candidate fix

Round MiB first, then choose the unit on the rounded value so roundedMib === 1024 falls through to the GiB branch. Add a regression test for the [1023.5, 1024) boundary in the existing src/infra/disk-space.test.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions