Skip to content

Conversation

zyfy29
Copy link
Contributor

@zyfy29 zyfy29 commented Aug 28, 2025

Pull Request Description

Add unit test for leastExpectedLatencyRouter, with a fix of the bug which my unit test addresses

The code used AvgPromptToksPerReq as divisor without checking is it am empty value. This produces a math.MaxFloat64 causing the router failure and a random pod will be selected.

Related Issues

also a part of #1485

Important: Before submitting, please complete the description above and review the checklist below.


Contribution Guidelines (Expand for Details)

We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:

Pull Request Title Format

Your PR title should start with one of these prefixes to indicate the nature of the change:

  • [Bug]: Corrections to existing functionality
  • [CI]: Changes to build process or CI pipeline
  • [Docs]: Updates or additions to documentation
  • [API]: Modifications to aibrix's API or interface
  • [CLI]: Changes or additions to the Command Line Interface
  • [Misc]: For changes not covered above (use sparingly)

Note: For changes spanning multiple categories, use multiple prefixes in order of importance.

Submission Checklist

  • PR title includes appropriate prefix(es)
  • Changes are clearly explained in the PR description
  • New and existing tests pass successfully
  • Code adheres to project style and best practices
  • Documentation updated to reflect changes (if applicable)
  • Thorough testing completed, no regressions introduced

By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.

@Copilot Copilot AI review requested due to automatic review settings August 28, 2025 12:02
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @zyfy29, 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 a critical bug in the leastExpectedLatencyRouter by preventing division-by-zero errors that could lead to router failures and incorrect pod selection. It introduces robust handling for cases where average prompt or generation token metrics are zero, using sensible fallback values. Additionally, a comprehensive suite of unit tests has been added to validate the router's behavior under various conditions, including those that previously caused the bug.

Highlights

  • Bug Fix for Division by Zero: Corrected an issue in leastExpectedLatencyRouter where division by zero occurred if AvgPromptToksPerReq or AvgGenerationToksPerReq metrics were zero, previously resulting in math.MaxFloat64 and router malfunction.
  • Introduction of Fallback Values: Implemented a mechanism to use predefined guessPromptTokens and guessGenerationTokens as fallback values when the actual average token metrics are zero, ensuring stable latency calculations.
  • Comprehensive Unit Testing: Added a new test file (least_latency_test.go) with extensive test cases for the leastExpectedLatencyRouter, covering scenarios like successful routing, no ready pods, multiple pods with similar latencies, and the newly fixed zero-metric conditions.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a divide-by-zero bug in the least expected latency router by using fallback values when average token metrics are zero or empty. The fix prevents the router from returning math.MaxFloat64 values that cause routing failures.

  • Adds comprehensive unit tests for the leastExpectedLatencyRouter covering various scenarios including zero token values
  • Implements fallback logic to use guessPromptTokens and guessGenerationTokens when metric values are zero or unavailable
  • Prevents divide-by-zero errors that previously caused router failures and random pod selection

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/plugins/gateway/algorithms/least_latency_test.go Adds comprehensive unit tests covering normal operation, edge cases, and the divide-by-zero scenario
pkg/plugins/gateway/algorithms/least_latency.go Implements fallback logic to prevent divide-by-zero errors when token metrics are zero

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 effectively resolves a potential division-by-zero error within the leastExpectedLatencyRouter by implementing a fallback mechanism for token metrics. The change is well-implemented and correctly addresses the bug. Furthermore, the addition of a comprehensive unit test suite for this routing algorithm is a significant improvement, enhancing the robustness and reliability of the codebase. My review includes a minor suggestion aimed at improving code maintainability by reducing duplication.

Signed-off-by: zyfy29 <wasuremono127@gmail.com>
Signed-off-by: zyfy29 <wasuremono127@gmail.com>
Signed-off-by: zyfy29 <wasuremono127@gmail.com>
@Jeffwan Jeffwan force-pushed the fix-least-latency-divide-zero branch from b741f9c to 6a8ba6b Compare September 5, 2025 00:41
@Jeffwan Jeffwan merged commit c46a507 into vllm-project:main Sep 5, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants