Skip to content

Conversation

@umang-kedia-hpe
Copy link
Contributor

@umang-kedia-hpe umang-kedia-hpe commented Jul 9, 2025

Overview:
This pull request addresses a potential KeyError in the kv_router.py component by ensuring that the active_blocks_dict is properly initialized for new worker_id entries. This improves the robustness of the router when handling dynamic worker registration and prevents runtime errors during distributed inference.

Details:
Updated the _update_and_get_active_blocks method in kv_router.py to check if a worker_id is present in active_blocks_dict.

If the worker_id is not present, it initializes the entry with the current polled_value for both old_value and predictive_value.
This change prevents KeyError exceptions when new workers are added dynamically or when the router encounters previously unseen worker IDs.

Where should the reviewer start?
Review the changes in examples/llm/components/kv_router.py, specifically the _update_and_get_active_blocks method.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of missing worker entries to prevent errors and ensure proper initialization when new workers are encountered.

@copy-pr-bot
Copy link

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

@github-actions
Copy link

github-actions bot commented Jul 9, 2025

👋 Hi umang-kedia-hpe! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions bot added the external-contribution Pull request is from an external contributor label Jul 9, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 9, 2025

Walkthrough

The method _update_and_get_active_blocks in kv_router.py was updated to properly handle cases where a worker_id is not present in the active_blocks_dict. The method now initializes missing entries to avoid key errors and ensure correct behavior on first access.

Changes

File Change Summary
examples/llm/components/kv_router.py Enhanced _update_and_get_active_blocks to initialize missing worker_id entries in the dictionary.

Poem

A rabbit hopped through code so bright,
Ensuring keys were set just right.
No more errors in the night,
When workers new appear in sight.
With careful hops, the bug took flight!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6835dd7 and b0b88c7.

📒 Files selected for processing (1)
  • examples/llm/components/kv_router.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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/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.
examples/llm/components/kv_router.py (1)
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.
⏰ 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). (2)
  • GitHub Check: pre-commit
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (1)
examples/llm/components/kv_router.py (1)

188-191: LGTM! Proper initialization prevents KeyError for dynamic workers.

This fix correctly addresses the core issue by initializing missing worker entries in active_blocks_dict. The approach of setting both old_value and predictive_value to polled_value is appropriate for new workers, ensuring consistent behavior on first access.


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.

@PeaBrane PeaBrane changed the title Fix KeyError in kv_router.py by Initializing active_blocks_dict for New Workers fix: KeyError in kv_router.py by Initializing active_blocks_dict for New Workers Jul 9, 2025
@github-actions github-actions bot added the fix label Jul 9, 2025
@PeaBrane
Copy link
Contributor

PeaBrane commented Jul 9, 2025

@umang-kedia-hpe thanks for your contribution. This is a good change
Can you add a logger.warn on a new key add, and also you may need to lint your changes (or install pre-commit) to pass our CIs

@umang-kedia-hpe
Copy link
Contributor Author

umang-kedia-hpe commented Jul 10, 2025

Update:

  • Added logger.warn when a new key is added.
  • Ran pre-commit to lint and format the code.

Please let me know if there’s anything else I should address. Thank you for your feedback!

@PeaBrane PeaBrane merged commit 8334541 into ai-dynamo:main Jul 10, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants