fix(web): prevent formatTime from overflowing units array past 60h - #40145
Open
zl86790 wants to merge 4 commits into
Open
fix(web): prevent formatTime from overflowing units array past 60h#40145zl86790 wants to merge 4 commits into
zl86790 wants to merge 4 commits into
Conversation
anujbolewar
reviewed
Aug 7, 2026
anujbolewar
left a comment
There was a problem hiding this comment.
Correct — the guard now stops the loop before it overflows past the hours unit, so 216000 seconds correctly renders as 60.00 h instead of wrapping to 1.0 h. The added boundary test is good. Worth also covering the value just below the next threshold (for example 215999 becomes 59.99 h) to guard the rounding at the transition, since that is the exact spot floating-point drift tends to show up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Found this while looking into how the dataset document metadata panel renders indexing time.
formatTime()inweb/utils/format.tswalks a['sec', 'min', 'h']array, dividing by 60 and bumping an index each time, until the value drops below 60. Problem is the loop condition (index < units.length) letsindexadvance one step past the last valid slot. Once a duration hits 60 hours (216000 seconds) or more, it ends up readingunits[3], which isundefined, so instead of"60.00 h"you get"1.00 undefined"printed straight into the UI.It's not just a theoretical edge case either —
use-metadata.tscallsformatTime()directly to renderindexing_latencyon the document metadata panel, so any dataset document whose indexing takes 60+ hours will show this broken string to users.Fix is a one-liner: cap the loop at
index < units.length - 1instead ofindex < units.length, so once we're on the last unit (h) we stop advancing the index and just keep dividing the value down. Everything under 60h formats exactly the same as before —30 -> "30.00 sec",60 -> "1.00 min",3600 -> "1.00 h".Added a test case for the 60h boundary (
216000 -> "60.00 h") alongside the existingformatTimecases informat.spec.ts.Screenshots
N/A - logic-only fix, nothing changes visually for the normal (< 60h) path.
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods