Skip to content

fix(cli): pick the duration unit from the rounded value - #29651

Open
artemkulyk wants to merge 1 commit into
google-gemini:mainfrom
artemkulyk:fix/format-duration-unit-boundary
Open

artemkulyk wants to merge 1 commit into
google-gemini:mainfrom
artemkulyk:fix/format-duration-unit-boundary

Conversation

@artemkulyk

Copy link
Copy Markdown

Summary

formatDuration() picked the unit from the raw value and rounded afterwards, so
values just under a boundary printed in the wrong unit: 999.5ms came out as
1000ms and 59950ms as 60.0s. Both are visible in /stats, where the
average latency is usually fractional.

Details

Round to each unit's display precision first (whole ms, tenths of a second,
whole seconds), then pick the unit from the rounded value. Values away from a
boundary are unchanged.

Related Issues

Fixes #29600

How to Validate

formatDuration(999.4)    // '999ms'
formatDuration(999.5)    // '1.0s'     (was '1000ms')
formatDuration(59949)    // '59.9s'
formatDuration(59950)    // '1m'       (was '60.0s')
formatDuration(59999)    // '1m'       (was '60.0s')
formatDuration(3599999)  // '1h'       (was '59m 59s')
formatDuration(3723000)  // '1h 2m 3s' (unchanged)

npx vitest run src/ui/utils/formatters.test.ts in packages/cli passes (35
tests). npm run preflight is green here apart from failures that reproduce on
a clean checkout too: gemini.test.tsx trust errors in headless runs (see
#29634) and two fs/PTY tests.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

@artemkulyk
artemkulyk requested a review from a team as a code owner October 6, 2026 17:40
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where duration formatting incorrectly rounded values near unit boundaries, leading to misleading output like '1000ms' or '60.0s'. By ensuring rounding occurs before unit selection, the utility now correctly handles fractional values and provides more accurate time representations.

Highlights

  • Rounding Logic Improvement: Updated the formatDuration utility to round values to their display precision before selecting the unit, preventing incorrect unit scaling for values near boundaries.
  • Test Coverage: Added new test cases to verify rounding behavior for milliseconds, seconds, and hour transitions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added the size/s A small PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 32
  • Additions: +25
  • Deletions: -7
  • Files changed: 2

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the formatDuration utility in packages/cli/src/ui/utils/formatters.ts to round duration values to their displayed precision before selecting the appropriate unit. This prevents values just below a unit boundary from incorrectly rounding up into the next unit's range. Additionally, corresponding unit tests have been added in formatters.test.ts to verify rounding behavior for milliseconds, seconds, and hours. There are no review comments, and I have no feedback to provide.

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Oct 6, 2026

This branch has not been deployed

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

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant