Skip to content

fix(web): prevent formatTime from overflowing units array past 60h - #40145

Open
zl86790 wants to merge 4 commits into
langgenius:mainfrom
zl86790:fix/format-time-hour-unit-overflow
Open

fix(web): prevent formatTime from overflowing units array past 60h#40145
zl86790 wants to merge 4 commits into
langgenius:mainfrom
zl86790:fix/format-time-hour-unit-overflow

Conversation

@zl86790

@zl86790 zl86790 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Found this while looking into how the dataset document metadata panel renders indexing time. formatTime() in web/utils/format.ts walks 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) lets index advance one step past the last valid slot. Once a duration hits 60 hours (216000 seconds) or more, it ends up reading units[3], which is undefined, 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.ts calls formatTime() directly to render indexing_latency on 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 - 1 instead of index < 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 existing formatTime cases in format.spec.ts.

Screenshots

N/A - logic-only fix, nothing changes visually for the normal (< 60h) path.

Checklist

  • This change requires a documentation update
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

@zl86790
zl86790 requested review from iamjoel and zxhlyh as code owners August 7, 2026 08:42
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 7, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Aug 7, 2026

@anujbolewar anujbolewar left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

size:XS This PR changes 0-9 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants