Skip to content

bug(cli): formatDuration shows "1000ms" and "60.0s" just below a unit boundary #29600

Description

@SajalDevX

What happened?

formatDuration() in packages/cli/src/ui/utils/formatters.ts chooses the unit from the raw value and only rounds afterwards, so values just under a boundary round up to a reading that the next unit should have taken:

formatDuration(999.4);  // '999ms'
formatDuration(999.5);  // '1000ms'  expected '1.0s'
formatDuration(59949);  // '59.9s'
formatDuration(59950);  // '60.0s'   expected '1m'
formatDuration(59999);  // '60.0s'   expected '1m'

ms < 1000 is checked before Math.round, and seconds < 60 is checked before toFixed(1).

This is visible in /stats and /stats model: average latency is totalLatencyMs / totalRequests, so it is usually fractional and can print as "1000ms", and agent active / API / tool time can print as "60.0s".

Checked on current main (c9096a8) by calling the function directly under vitest.

What did you expect to happen?

Values that round up to the next unit should be shown in that unit: "1.0s" instead of "1000ms", and "1m" instead of "60.0s".

Client information

Client Information

Found by reading the code and confirmed with a unit test on main (c9096a8), Linux, Node 22. The function is pure, so it does not depend on platform or auth.

Login information

Not relevant (pure formatting helper).

Anything else we need to know?

Possible fix: round to each unit's display precision first (Math.round(ms) for ms, tenths for seconds, whole seconds for the minutes/hours branch), then choose the unit from the rounded value. I have a small patch with a regression test ready and can open a PR if this gets the help wanted label.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/coreIssues related to User Interface, OS Support, Core Functionalityeffort/small1 day or less: trivial logic, UI adjustments, docshelp wantedWe will accept PRs from all issues marked as "help wanted". Thanks for your support!kind/bugpriority/p3Backlog - a good idea but not currently a priority.status/bot-triaged

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions