Skip to content

fix(ui): move attachment sizes to MB when rounding reaches 1024 KB - #3643

Merged
Charlesthebird merged 1 commit into
kagent-dev:mainfrom
kevin9327:fix-format-bytes-rollover
Nov 11, 2026
Merged

Charlesthebird merged 1 commit into
kagent-dev:mainfrom
kevin9327:fix-format-bytes-rollover

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Summary

formatBytes in ui/src/api/chat/attachments.ts (used by the attachment chip and the "would put this message over ..." staging error) chooses KB or MB from the raw byte count and only then rounds to one decimal. A file just under 1 MiB therefore shows as 1024 KB:

formatBytes(1048525) // "1024 KB", should be "1 MB"
formatBytes(1048575) // "1024 KB", should be "1 MB"

The KB value is now rounded first, and the function moves to MB when that rounded value reaches 1024. Everything else prints exactly as before (1048524 is still 1023.9 KB, and whole MiB values are unchanged).

Testing

  • Added a formatBytes table to attachments.test.ts covering the B/KB and KB/MB boundaries. The 1048525 and 1048575 cases fail on main and pass with this change; the rest of the file (62 tests) passes with vitest run src/api/chat/attachments.test.ts.

This PR was prepared with AI assistance; I reviewed the change and ran the tests above.

Signed-off-by: kevin9327 <5299031+kevin9327@users.noreply.github.com>
@github-actions github-actions Bot added the bug Something isn't working label Nov 11, 2026

@timflannagan timflannagan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems reasonable to me. Just triggered CI, we'll see where that lands. FYI @Charlesthebird since it touches the UI in case you wanted to sanity check too

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

This automated review is a first pass. A manual review will follow once the blockers are addressed.


No blockers. The unit is now chosen after rounding, so values that round to 1024 KB read as MB.

✅ What I checked
  • ✅ 1048524 / 1024 = 1023.949, which rounds to 1023.9, so it stays in KB.
  • ✅ 1048525 / 1024 = 1023.950, which rounds to 1024, so it moves to MB. 1048525 / 1048576 rounds to 1.0, printed as 1 MB.
  • ✅ Inputs of 1024 bytes and up, 1048576, and 5 MiB take the same branches as before.
  • ✅ formatBytes has the same signature, and the new cases sit in the existing test file.
  • ✅ The diff has no internal brand terms.

Written by 🤖

@Charlesthebird

Charlesthebird commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Attachment chip, size 1048525 and 1048575 bytes (mock UI, composer): before shows 1024 KB, after shows 1 MB.

reel.mp4

Screenshots

Before: 1048525 bytes shows 1024 KB before-chip-1048525
After: 1048525 bytes shows 1 MB after-chip-1048525
Before: 1048575 bytes shows 1024 KB before-chip-1048575
After: 1048575 bytes shows 1 MB after-chip-1048575

Written by 🤖

@Charlesthebird
Charlesthebird added this pull request to the merge queue Nov 11, 2026
Merged via the queue into kagent-dev:main with commit b1fadd6 Nov 11, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants