Skip to content

fix(cli): carry rounded-up seconds and kilobytes into the next unit - #5817

Closed
rudycelekli wants to merge 2 commits into
heygen-com:mainfrom
rudycelekli:fix/cli-format-rounding-rollover
Closed

rudycelekli wants to merge 2 commits into
heygen-com:mainfrom
rudycelekli:fix/cli-format-rounding-rollover

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What

formatDuration and formatBytes in packages/cli/src/ui/format.ts print an out-of-range value when rounding reaches the next unit.

Why

  • formatDuration(59_960) prints 60.0s, and formatDuration(119_970) prints 1m 60.0s. The seconds part is rounded after the minute split, so it can reach 60.
  • formatBytes(1_048_575) prints 1024.0 KB instead of 1.0 MB.

These feed hyperframes cloud render progress and upload lines, info size, and Chrome download progress.

Related work

No overlapping PR found.

How

Round formatDuration to tenths of a second before splitting into minutes and seconds. Round the KB value before comparing it with the MB threshold. Output for all other inputs is unchanged.

Test plan

  • Unit tests added: both rollover cases fail on main and pass with the fix (vitest run src/ui/format.test.ts, 26 tests).
  • oxfmt --check and oxlint clean on the changed files.
  • Manual testing performed (not applicable; pure formatting functions)
  • Documentation updated (not applicable)
  • Comments follow CONTRIBUTING.md "Comments".

Not run locally: workspace typecheck, comment citation/ratchet scripts (they failed to start in my minimal install).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@miguel-heygen miguel-heygen 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.

Thanks for this, and welcome. The two rollovers reproduce exactly as you describe: on main formatDuration(59_960) prints 60.0s and formatBytes(1_048_575) prints 1024.0 KB, and with your change they print 1m 0.0s and 1.0 MB. I replayed both the old and new functions side by side over a wide sweep of inputs, and the byte path changes only in the 1048528 to 1048575 band, which is precisely the bug.

One small correction to the description rather than to the code. "Output for all other inputs is unchanged" is not quite true for durations: toFixed rounds the binary double while Math.round rounds half up, so exact half tenths shift, for example 350 ms printed 0.3s before and prints 0.4s now. That is the more correct value and it only affects display, so I am happy to take it, but it would be good to say so in the description so the next reader is not surprised.

I checked the callers too. formatBytes and formatDuration are only ever printed, never parsed, and the padStart(9) alignment in the cloud render output still lines up because no output got wider.

Full CI ran at this head and is green, including the Windows lanes and the CLI suites. Good, well scoped fix.

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

Approving, adding to Miguel's review rather than repeating it. Reviewed at 2bd49648.

I checked it on a local merge with current main. With your change, format.test.ts passes 26 of 26. With the old format.ts put back, the two new rollover tests fail and nothing else does. So the tests guard the fix. I agree with Miguel's note about half tenths now rounding up (350ms reads 0.4s). That's the more accurate output, and it would be worth a line in the description.

Need: yes, both rollovers reproduce on main. Size: ok. Reuse: n/a. Simpler: already minimal.

— Rames

@jrusso1020

Copy link
Copy Markdown
Collaborator

Thanks, @rudycelekli. This one is approved, and it'll go into the merge queue once these are sorted:

Once it's green and signed, we'll queue it at your new head. If you push code changes beyond a rebase, we'll take another look first.

— Rames

@jrusso1020

Copy link
Copy Markdown
Collaborator

This is approved, but main requires signed commits. Could you re-sign (git rebase main --exec 'git commit --amend --no-edit -S') and force-push? We'll re-approve right after.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

This PR has had no activity for 14 days, so it is marked stale and will close in 7 days. Push a commit or leave a comment to keep it open. A maintainer can add keep-open to exempt it.

@jrusso1020

Copy link
Copy Markdown
Collaborator

Thanks, @rudycelekli. Since main requires signed commits and this branch is still unsigned, we have carried your change over unchanged to #7565, with you credited as co-author, so it can merge. We will close this PR once #7565 lands.

— Rames

@jrusso1020

Copy link
Copy Markdown
Collaborator

This change landed on main through #7565 (1826083), with your commit's code and tests unchanged and you credited as co-author. Closing this one in favor of it. Thanks for the fix, @rudycelekli!

— Rames

@jrusso1020 jrusso1020 closed this Nov 11, 2026
auto-merge was automatically disabled November 11, 2026 18:54

Pull request was closed

Leviathangk pushed a commit to Leviathangk/hyperframes that referenced this pull request Nov 11, 2026
…eygen-com#7565)

formatDuration rounded seconds after splitting off minutes, so 59.96s printed
"60.0s" and 119.97s printed "1m 60.0s". formatBytes compared KB against the MB
threshold before rounding, so 1,048,575 bytes printed "1024.0 KB". Round first,
then split or compare.

Takes over heygen-com#5817 by @rudycelekli, whose commits could not be merged unsigned.

Co-authored-by: Rudy Celekli <rudy@gradiahq.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants