Skip to content

[Frontend] Add request_id to the Request object so they can be controlled better via external load balancers #21009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2025

Conversation

kouroshHakha
Copy link
Collaborator

@kouroshHakha kouroshHakha commented Jul 15, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

This PR adds a usability feature to protocol so that the external load balancers or systems like Prefill desegregation can better control the request id based on their internal design decisions. This capability already exists for ChatRequests but not for Embedding and Completions.

Test Plan

Test Result

(Optional) Documentation Update

Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the frontend label Jul 15, 2025
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 introduces a request_id field to the CompletionRequest and EmbeddingRequest objects, allowing external systems to control request identifiers. The implementation correctly integrates this new field into the request ID generation logic. My main feedback is to address the code duplication of the request_id field definition across multiple classes in vllm/entrypoints/openai/protocol.py to improve long-term maintainability.

Comment on lines +988 to +994
request_id: str = Field(
default_factory=lambda: f"{random_uuid()}",
description=(
"The request_id related to this request. If the caller does "
"not set it, a random_uuid will be generated. This id is used "
"through out the inference process and return in response."),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The definition for the request_id field is duplicated across CompletionRequest, EmbeddingCompletionRequest, and EmbeddingChatRequest in this PR. A similar definition also exists in ChatCompletionRequest. This duplication can lead to maintenance issues in the future (e.g., if the description or default factory needs to be updated, it must be changed in multiple places).

To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, I suggest defining the Field object once and reusing it in all relevant request classes.

For example, you could define a shared field at the module level:

# At an appropriate module-level scope
_REQUEST_ID_FIELD = Field(
    default_factory=lambda: f"{random_uuid()}",
    description=(
        "The request_id related to this request. If the caller does "
        "not set it, a random_uuid will be generated. This id is used "
        "through out the inference process and return in response."),
)

# In each request class
class CompletionRequest(OpenAIBaseModel):
    # ...
    request_id: str = _REQUEST_ID_FIELD
    # ...

This change should be applied to EmbeddingCompletionRequest and EmbeddingChatRequest as well.

Comment on lines +1219 to +1225
request_id: str = Field(
default_factory=lambda: f"{random_uuid()}",
description=(
"The request_id related to this request. If the caller does "
"not set it, a random_uuid will be generated. This id is used "
"through out the inference process and return in response."),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This is a duplicated definition of the request_id field. Please apply the same refactoring suggested for CompletionRequest to avoid code duplication and improve maintainability.

Comment on lines +1282 to +1288
request_id: str = Field(
default_factory=lambda: f"{random_uuid()}",
description=(
"The request_id related to this request. If the caller does "
"not set it, a random_uuid will be generated. This id is used "
"through out the inference process and return in response."),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This is a duplicated definition of the request_id field. Please apply the same refactoring suggested for CompletionRequest to avoid code duplication and improve maintainability.

@kouroshHakha kouroshHakha added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 15, 2025
@kouroshHakha kouroshHakha marked this pull request as ready for review July 15, 2025 21:01
@kouroshHakha kouroshHakha requested a review from aarnphm as a code owner July 15, 2025 21:01
@aarnphm aarnphm changed the title [protocol] Add request_id to the Request object so they can be controlled better via external load balancers [Frontend] Add request_id to the Request object so they can be controlled better via external load balancers Jul 16, 2025
@aarnphm aarnphm enabled auto-merge (squash) July 16, 2025 22:43
@vllm-bot vllm-bot merged commit 9fe98d4 into vllm-project:main Jul 25, 2025
63 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants