Skip to content

Conversation

@biswapanda
Copy link
Contributor

@biswapanda biswapanda commented Jul 25, 2025

Overview:

When nvext.backend_instance_id is set, forward request directly the pre-scheduled worker instance.
This by-passes the routing logic.

Details:

Where should the reviewer start?

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • New Features

    • Added support for specifying a targeted backend instance ID in requests, allowing for direct routing to a chosen backend instance when provided.
    • Requests now recognize and utilize the backend instance ID from the request extension field if available.
  • Bug Fixes

    • Improved instance selection logic to prioritize a provided backend instance ID, ensuring more accurate routing behavior.

@biswapanda biswapanda requested a review from a team as a code owner July 25, 2025 17:53
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jul 25, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Walkthrough

The changes introduce an optional backend_instance_id field to several request-related structs and update the request preprocessing and routing logic to utilize this field if present. When provided, the backend instance ID is extracted and used directly for routing, bypassing the previous best-match logic.

Changes

File(s) Change Summary
lib/llm/src/protocols/common/preprocessor.rs Added optional backend_instance_id field to PreprocessedRequest struct.
lib/llm/src/protocols/openai/nvext.rs Added optional backend_instance_id field to NvExt struct with serialization and builder support.
lib/llm/src/preprocessor.rs Updated preprocess_request to extract and set backend_instance_id from nvext if present.
lib/llm/src/kv_router.rs Modified routing logic to use backend_instance_id directly if set; otherwise, use best-match.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Preprocessor
    participant Router
    participant Chooser

    Client->>Preprocessor: Send request (may include nvext.backend_instance_id)
    Preprocessor->>Preprocessor: Extract backend_instance_id from nvext (if present)
    Preprocessor->>Router: Pass PreprocessedRequest (with or without backend_instance_id)
    alt backend_instance_id is present
        Router->>Router: Use backend_instance_id for routing (overlap_amount = 0)
    else
        Router->>Chooser: find_best_match(token_ids)
        Chooser-->>Router: Return best matching instance and overlap_amount
    end
    Router-->>Client: Return response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A hop and a skip, a new field appears,
Routing by instance, the logic now steers.
If you know where to go, just set the ID,
The router will follow, as quick as can be.
With builder and serde, the structs now align—
A bunny’s delight, in code so fine! 🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
lib/llm/src/kv_router.rs (1)

347-347: Undefined variable: context_id not in scope.

The variable context_id is referenced but doesn't appear to be defined in the current scope. This should likely be extracted from the request context or derived from another available variable.

#!/bin/bash
# Description: Check for context_id definition and usage in the method
# Expected: Should find where context_id is defined or how it should be obtained

echo "=== Context ID definitions ==="
rg -B 5 -A 5 'context_id.*=' 

echo -e "\n=== Available context variables ==="
ast-grep --pattern 'let ($_, context) = request.into_parts();'
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2cb1c3 and 030b063.

📒 Files selected for processing (4)
  • lib/llm/src/kv_router.rs (1 hunks)
  • lib/llm/src/preprocessor.rs (1 hunks)
  • lib/llm/src/protocols/common/preprocessor.rs (1 hunks)
  • lib/llm/src/protocols/openai/nvext.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: Build and Test - vllm
  • GitHub Check: pre-merge-rust (lib/bindings/python)
  • GitHub Check: pre-merge-rust (.)
🔇 Additional comments (3)
lib/llm/src/protocols/common/preprocessor.rs (1)

59-61: Well-implemented addition of backend instance ID field.

The new backend_instance_id field is correctly added with appropriate builder annotations and follows the existing pattern in the struct. The Option<i64> type is suitable for an optional backend instance identifier.

lib/llm/src/protocols/openai/nvext.rs (1)

65-70: Excellent implementation with clear documentation.

The new backend_instance_id field is properly implemented with:

  • Appropriate serde annotations for optional serialization
  • Consistent builder pattern with other fields
  • Clear documentation explaining the routing behavior
  • Proper typing with Option<i64>
lib/llm/src/preprocessor.rs (1)

254-257: Clean implementation of backend instance ID extraction.

The logic correctly extracts the backend_instance_id from the nvext extension when present and safely sets it on the request builder. The implementation follows good practices with proper null checking.

@biswapanda biswapanda changed the title feat: pre-route feat: skip router when worker id is pre-determined Jul 28, 2025
@biswapanda biswapanda self-assigned this Aug 16, 2025
@biswapanda biswapanda force-pushed the bis/pre-routed-worker branch from 030b063 to 4e5e264 Compare August 18, 2025 04:40
@biswapanda
Copy link
Contributor Author

Changes are merged as part of #2450

@biswapanda biswapanda closed this Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants