Skip to content

Conversation

@biswapanda
Copy link
Contributor

@biswapanda biswapanda commented Jul 6, 2025

Overview:

Why:

This change supports inference gateway integration integration

Gateway extension applies filters/scorers to identify target worker which will handle an incoming request.

  1. In scheduling path, we want to extract the worker_id and don't want to route the request yet.
    2.In service path , we want to enforce the worker_id which will bypass the router

What:

  • Added early-return in KvPushRouter::generate to emit routing info if "query_instance_id" annotation is present.
  • Modified logic to set comment only if event is not already set in OpenAIPreprocessor.

closes: https://linear.app/nvidia-dynamo/issue/DEP-161

Details:

The changes introduce a conditional early-return path in the KvPushRouter's generate method to respond with routing information when a specific annotation (query_instance_id) is present.

Additionally, the logic for setting the comment field in OpenAIPreprocessor is refined to prevent overwriting it when an event is already set.

Where should the reviewer start?

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

  • closes GitHub issue: #xxx

Summary by CodeRabbit

  • New Features

    • Added support for requests to receive routing information directly when a specific annotation is present, returning the matched instance ID in the response.
  • Bug Fixes

    • Improved handling of response comments to prevent overwriting existing comments when an event is already set.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 6, 2025

Walkthrough

The changes introduce a conditional early-return path in the KvPushRouter's generate method to respond with routing information when a specific annotation is present. Additionally, the logic for setting the comment field in OpenAIPreprocessor is refined to prevent overwriting it when an event is already set.

Changes

File(s) Change Summary
lib/llm/src/kv_router.rs Added early-return in KvPushRouter::generate to emit routing info if "query_instance_id" annotation is present.
lib/llm/src/preprocessor.rs Modified logic to set comment only if event is not already set in OpenAIPreprocessor.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant KvPushRouter
    participant InnerEngine

    Client->>KvPushRouter: generate(request)
    alt request has "query_instance_id" annotation
        KvPushRouter-->>Client: response with "worker_instance_id" annotation
    else
        KvPushRouter->>InnerEngine: direct(updated_request, instance_id)
        InnerEngine-->>KvPushRouter: response stream
        KvPushRouter-->>Client: response stream
    end
Loading

Poem

A rabbit hopped through code anew,
Routing secrets now in view.
If you query for the instance key,
The answer comes back, quick as can be!
Comments are safe, events take the lead—
Hopping forward, fulfilling each need.
🐇✨

Warning

Review ran into problems

🔥 Problems

Check-run timed out after 90 seconds. Some checks/pipelines were still in progress when the timeout was reached. Consider increasing the reviews.tools.github-checks.timeout_ms value in your CodeRabbit configuration to allow more time for checks to complete.


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: 0

🧹 Nitpick comments (1)
lib/llm/src/kv_router.rs (1)

254-266: LGTM: Well-structured conditional routing logic.

The early-return pattern when query_instance_id annotation is present is a clean approach that avoids unnecessary processing and provides direct routing information. The response structure with the worker_instance_id annotation is appropriate.

Consider using instance_id.to_string() directly in the annotation call to avoid the intermediate variable:

-                let instance_id_str = instance_id.to_string();
-                let response =
-                    Annotated::from_annotation("worker_instance_id", &instance_id_str)?;
+                let response =
+                    Annotated::from_annotation("worker_instance_id", &instance_id.to_string())?;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1630f8b and 60ff1f6.

📒 Files selected for processing (2)
  • lib/llm/src/kv_router.rs (1 hunks)
  • lib/llm/src/preprocessor.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
lib/llm/src/preprocessor.rs (1)
Learnt from: ishandhanani
PR: ai-dynamo/dynamo#1626
File: lib/llm/src/preprocessor.rs:238-239
Timestamp: 2025-06-24T20:59:35.725Z
Learning: In lib/llm/src/preprocessor.rs, the `sampling_options` call in the `preprocess_request` method is placed in the common section after the match statement on `request.prompt_input_type()`, meaning it applies to both `PromptInput::Tokens` and `PromptInput::Text` request types.
lib/llm/src/kv_router.rs (4)
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1392
File: lib/llm/src/kv_router/scoring.rs:35-46
Timestamp: 2025-06-05T01:02:15.318Z
Learning: In lib/llm/src/kv_router/scoring.rs, PeaBrane prefers panic-based early failure over Result-based error handling for the worker_id() method to catch invalid data early during development.
Learnt from: alec-flowers
PR: ai-dynamo/dynamo#1181
File: lib/llm/src/kv_router/publisher.rs:379-425
Timestamp: 2025-05-29T00:02:35.018Z
Learning: In lib/llm/src/kv_router/publisher.rs, the functions `create_stored_blocks` and `create_stored_block_from_parts` are correctly implemented and not problematic duplications of existing functionality elsewhere in the codebase.
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1285
File: lib/llm/src/kv_router/scoring.rs:58-63
Timestamp: 2025-05-30T06:38:09.630Z
Learning: In lib/llm/src/kv_router/scoring.rs, the user prefers to keep the panic behavior when calculating load_avg and variance with empty endpoints rather than adding guards for division by zero. They want the code to fail fast on this error condition.
Learnt from: PeaBrane
PR: ai-dynamo/dynamo#1285
File: lib/llm/src/kv_router/scheduler.rs:260-266
Timestamp: 2025-05-30T06:34:12.785Z
Learning: In the KV router scheduler code, PeaBrane prefers fail-fast behavior over silent failure handling. When accessing worker metrics data that could be out-of-bounds (like dp_rank indexing), explicit panics are preferred over graceful degradation with continue statements to ensure data integrity issues are caught early.
⏰ 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: Build and Test - vllm
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
🔇 Additional comments (2)
lib/llm/src/preprocessor.rs (1)

415-415: LGTM: Improved conditional comment assignment.

This change maintains the existing logic to set the comment field only when no event is already present, preventing overwriting of existing response metadata. The conditional assignment aligns well with the surrounding logic that checks response.event.is_none().

lib/llm/src/kv_router.rs (1)

249-249: LGTM: Clear annotation check for routing query.

The annotation check is straightforward and matches the PR objective of querying instance_id based on routing strategy.

@biswapanda biswapanda marked this pull request as draft July 7, 2025 17:37
@biswapanda biswapanda force-pushed the bis/dep-161-query-router branch from 3afdfaf to 21fd272 Compare July 15, 2025 21:23
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jul 15, 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.

@pull-request-size pull-request-size bot added size/L and removed size/S labels Jul 15, 2025
@biswapanda biswapanda force-pushed the bis/dep-161-query-router branch from 21fd272 to 5aba407 Compare July 23, 2025 09:28
@biswapanda biswapanda marked this pull request as ready for review July 23, 2025 09:30
@biswapanda biswapanda requested a review from a team as a code owner July 23, 2025 09:30
@grahamking
Copy link
Contributor

The comment tells me what you did but not why you did it. Could you add to the description?

@biswapanda
Copy link
Contributor Author

The comment tells me what you did but not why you did it. Could you add to the description?

Thanks @grahamking , updated the intro section with why.
#1787 (comment)

@grahamking
Copy link
Contributor

How does inference gateway know the worker_instance_id?

@biswapanda
Copy link
Contributor Author

How does inference gateway know the worker_instance_id?

inference gateway forwards the chat completion request to Frontend with added nv_ext annotation query_instance_id and respose contains the worker_id.

This PR implements the same.

curl -d '{... ,"nvext": { "annotations": ["query_instance_id"]}}'

@biswapanda biswapanda merged commit f3d784f into main Jul 23, 2025
11 checks passed
@biswapanda biswapanda deleted the bis/dep-161-query-router branch July 23, 2025 21:51
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.

3 participants