Skip to content

[Router][Bugfix] Select longest LMCache prefix match - #1055

Merged
Shaoting-Feng merged 2 commits into
vllm-project:mainfrom
dsxyy:codex/c-006-kvaware-layout-selection
Sep 2, 2026
Merged

[Router][Bugfix] Select longest LMCache prefix match#1055
Shaoting-Feng merged 2 commits into
vllm-project:mainfrom
dsxyy:codex/c-006-kvaware-layout-selection

Conversation

@dsxyy

@dsxyy dsxyy commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • select the LMCache layout_info entry with the largest matched_prefix_length
  • use that same instance for the KV-aware threshold check and backend selection
  • add a regression test covering both direct misrouting and incorrect fallback when a later entry is the longest match

LMCache defines layout_info as instance_id -> (location, matched_prefix_length), but does not define dictionary order as a best-match ordering. Its controller builds the mapping while walking chunks, so the first inserted instance is not necessarily the longest match.

Tests

57 passed in 3.27s

The regression test fails twice on current main and passes with this change.

Static checks run on the changed files:

  • black 25.1.0
  • isort 6.0.0
  • ruff 0.12.0
  • codespell 2.4.1
  • git diff --check

All passed.


  • Make sure the code changes pass the pre-commit checks.
  • Sign off the commit using git commit -s.
  • Classify the PR title.

Signed-off-by: 姚远 <asmile.yy@gmail.com>

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

Copy link
Copy Markdown
Contributor

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 updates the KV-cache-aware routing logic to route requests to the instance with the longest matched prefix (maximum matched tokens) instead of simply picking the first instance in the layout info, and adds corresponding unit tests. The review feedback identifies a potential KeyError if the matched instance ID is not found in the active endpoints mapping, suggesting a fallback mechanism to session or QPS routing. Additionally, it recommends stubbing QueryInstMsg in the test suite to prevent potential NameError exceptions when lmcache is not installed.

Comment thread src/vllm_router/routers/routing_logic.py Outdated
Comment thread src/tests/test_kvaware_router.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e06a69e64d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/vllm_router/routers/routing_logic.py Outdated
Signed-off-by: 姚远 <asmile.yy@gmail.com>

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

dsxyy commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@ruizhang0101 Thanks for the approval! All checks are green now. Could you help merge this?

@Shaoting-Feng
Shaoting-Feng merged commit fc00f98 into vllm-project:main Sep 2, 2026
16 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