Skip to content

fix(web): a 9.996 KB file reads "10.0 KB", not "10.00 KB" - #42682

Merged
juliusmarminge merged 3 commits into
pingdotgg:mainfrom
only21mil:fix/web-format-bytes-rounding-boundaries
Nov 25, 2026
Merged

juliusmarminge merged 3 commits into
pingdotgg:mainfrom
only21mil:fix/web-format-bytes-rounding-boundaries

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

formatScaled in apps/web/src/lib/formatBytes.ts picked 2, 1, or 0 decimal places from the unrounded value. Values just below 10 or 100 rounded up across the threshold while keeping the extra decimal place: 10,235 B (9.9951 KB) printed "10.00 KB" instead of "10.0 KB", and 102,350 B (99.951 KB) printed "100.0 KB" instead of "100 KB". The same rounding-before-precision bug affects MB, GB, and TB (for example, 10,480,518 B printed "10.00 MB"). This is the same class of bug fixed in #42492, where a 9.96 s workflow step read "10.0s".

Users see formatBytes output in chat file cards (UserFileCard in apps/web/src/components/chat/TimelineUserMessageRow.tsx, shown when a message holds only attached files), Settings > Diagnostics and resource telemetry (memory and I/O), Settings > Storage, and the add-project-to-machine dialog. Desktop uses the same web bundle.

Change

In apps/web/src/lib/formatBytes.ts, I updated formatScaled to round at 2 decimals first. If the rounded value is under 10, it returns that string. Otherwise it rounds at 1 decimal and returns it if under 100, else it rounds to 0 decimals. The unit carry from #26067 (1023.6 KB -> "1.00 MB", not "1024 KB") still holds.

In apps/web/src/lib/formatBytes.test.ts, I added five cases to the existing it.each table: 10_234 ("9.99 KB"), 10_235 ("10.0 KB"), 102_348 ("99.9 KB"), 102_350 ("100 KB"), and 10_480_518 ("10.0 MB").

Scope

Bug fix only, covering the web bundle (and desktop via the shared web bundle). No separate issue was filed because this is a small fix for an obvious bug. Mobile has its own formatBytes helper covered by another author's open PR #41599, so I left mobile untouched. Composer and inline message chips use formatAttachmentSize ("10 KB" / "100 KB"), which does not have this bug and is unchanged.

Verification

Setup: Linux (Ubuntu 26.04), web dev build (vp run dev) in the T3 Code Browser panel at 2560x1600, fresh isolated T3 home with synthetic data only, server labelled "Test machine", and the free Replay (dev) provider.

Steps: Add a throwaway git project → start a new thread → attach notes-10235.txt (10,235 bytes) and notes-102350.txt (102,350 bytes) with a short message and send → attach the same two files with no text and send → read the file cards.

Before (c6c8b205) After (a95df3da)
Base c6c8b205: file cards for 10,235 B and 102,350 B read "TXT · 10.00 KB" and "TXT · 100.0 KB"
Base c6c8b20: file cards for 10,235 B and 102,350 B read "TXT · 10.00 KB" and "TXT · 100.0 KB"
Head a95df3da: file cards for 10,235 B and 102,350 B read "TXT · 10.0 KB" and "TXT · 100 KB"
Head a95df3d: file cards for 10,235 B and 102,350 B read "TXT · 10.0 KB" and "TXT · 100 KB"

Tests (Node 26.13.1): On base c6c8b205 with the new test rows, vp test run src/lib/formatBytes.test.ts fails 3 of 16 tests (received "10.00 KB", "100.0 KB", "10.00 MB"). On head a95df3da, all 16 tests pass across 3 runs, and vp run check:changed passes (format, lint, knip 1/2, knip 2/2, typecheck across 2 packages, test on 1 file, and react compiler on 1 file).

Test and check:changed output
# Base c6c8b205 with new test rows
 FAIL  |unit| src/lib/formatBytes.test.ts > formatBytes > formats 10235 bytes as 10.0 KB
AssertionError: expected '10.00 KB' to be '10.0 KB' // Object.is equality
Expected: "10.0 KB"
Received: "10.00 KB"

 FAIL  |unit| src/lib/formatBytes.test.ts > formatBytes > formats 102350 bytes as 100 KB
AssertionError: expected '100.0 KB' to be '100 KB' // Object.is equality
Expected: "100 KB"
Received: "100.0 KB"

 FAIL  |unit| src/lib/formatBytes.test.ts > formatBytes > formats 10480518 bytes as 10.0 MB
AssertionError: expected '10.00 MB' to be '10.0 MB' // Object.is equality
Expected: "10.0 MB"
Received: "10.00 MB"

 Test Files  1 failed (1)
      Tests  3 failed | 13 passed (16)
   Duration  6.02s (transform 89%, setup 11%)

# Head a95df3da (3 runs)
 Test Files  1 passed (1)
      Tests  16 passed (16)
   Duration  4.42s (transform 87%, setup 12%)

 Test Files  1 passed (1)
      Tests  16 passed (16)
   Duration  3.00s (transform 71%, setup 22%, import 6%)

 Test Files  1 passed (1)
      Tests  16 passed (16)
   Duration  2.77s (transform 78%, setup 19%, import 2%)

# vp run check:changed
check:changed summary
  pass  format  0.8s
  pass  lint  0.8s
  pass  knip 1/2  10.4s
  pass  knip 2/2  18.4s
  pass  typecheck (2 packages)  7.6s
  pass  test (1 files)  13.0s
  pass  react compiler (1 files)  12.1s

Not checked: macOS and Windows hosts, the desktop app shell, mobile (separate helper), and Settings diagnostics screens (same function, covered by unit tests).

Who tested: An AI agent ran every check.

Generated with Gemini 4 Neon in T3 Code Nightly

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

formatScaled now selects decimal precision based on rounded values. The formatBytes tests add cases for 10,235 bytes and 102,350 bytes.

Changes: Byte Formatting

Layer / File(s) Summary
Precision selection and boundary tests
apps/web/src/lib/formatBytes.ts, apps/web/src/lib/formatBytes.test.ts
formatScaled selects two, one, or zero decimal places based on rounded values. Tests add expected outputs for 10,235 bytes and 102,350 bytes.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to efbb5

This change fixes byte-size labels so values that round across the 10 or 100 threshold no longer show an extra decimal place. The change is small and covered by boundary tests, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a fix so that a 9.996 KB file shows "10.0 KB" rather than "10.00 KB". It matches the formatBytes.ts precision change and the added test rows. The conventional commit p…
Description check Passed The description follows the template. It states the problem with expected behavior and examples, the change in formatScaled, and the scope as a bug fix with no issue, explaining why. Verification give…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a fix so that a 9.996 KB file shows "10.0 KB" rather than "10.00 KB". It matches the formatBytes.ts precision change and the added test rows. The conventional commit prefix and plain wording follow the template guidance.

Full details: Description check

Explanation

The description follows the template. It states the problem with expected behavior and examples, the change in formatScaled, and the scope as a bug fix with no issue, explaining why. Verification gives focused test results before and after the change, an output log, and screenshots. It also lists what was not checked and names the agent that ran the checks. The template asks for an agent's model and harness, and the description gives 'Gemini 4 Neon in T3 Code Nightly'. The description does not link a bug issue, but it explains why none was filed, which the template allows.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a95df3d and efbb515.

Files selected for processing: 1

  • apps/web/src/lib/formatBytes.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 25, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Attached text files of exactly 10,235, 102,350 and 10,480,518 bytes and sent without message text using Replay (dev) / Command output. Captured settled sent-message cards in Chromium, 1280×800, dark theme, with fresh synthetic state on both commits.

Before After
16acd71825 efbb515ec1
Before: 10.00 KB, 100.0 KB and 10.00 MB After: 10.0 KB, 100 KB and 10.0 MB

Scenario driver · Before recording · After recording

The scenario fails on base and passes on head; scenarios:prove exited 0.

Not shown:

  • Desktop Electron build and other formatBytes consumers were not exercised; this proof covers the reported web sent-message file cards.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 25, 2026
@juliusmarminge
juliusmarminge merged commit 072611f into pingdotgg:main Nov 25, 2026
57 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants