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.
What happened?
formatDuration()inpackages/cli/src/ui/utils/formatters.tschooses 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:ms < 1000is checked beforeMath.round, andseconds < 60is checked beforetoFixed(1).This is visible in
/statsand/stats model: average latency istotalLatencyMs / 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 thehelp wantedlabel.