fix(vllm): reset block hash on prefix-cache eviction#363
Open
shipiyouniao wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a correctness issue in the vLLM integration where KVCacheBlock.block_hash could remain stale after prefix-cache eviction/free, causing reused blocks to carry incorrect hash state across prefixes.
Changes:
- Add a
_reset_block_hash()helper to clear vLLM block hash state (preferringreset_hash()when available). - Invoke block-hash reset on eviction/free/reset flows in the patched
ElasticBlockPool. - Extend
tests/test_prefix_cache.pyto regress block-hash clearing across eviction, explicit eviction, reset, and reuse scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
kvcached/integration/vllm/patches.py |
Clears KVCacheBlock hash state when blocks are returned to kvcached via eviction/free/reset paths to prevent stale reuse. |
tests/test_prefix_cache.py |
Strengthens the mock block to enforce write-once hash semantics and adds assertions ensuring hashes are cleared on eviction/free/reset/reuse. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lianghao208
reviewed
Jun 25, 2026
7c90873 to
ab1cdab
Compare
lianghao208
reviewed
Jun 25, 2026
ab1cdab to
c1b6999
Compare
c1b6999 to
3ade28d
Compare
3ade28d to
25b735f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes stale vLLM
KVCacheBlock.block_hashstate when kvcached evicts or frees prefix-cache blocks.Closes #362.
Root Cause
ElasticBlockPoolremoves evicted blocks from kvcached's_cached_blocks,_block_id_to_key, and_evictable_blocksindexes, but the underlying vLLM block object can keep its oldblock_hashvalue. Reusing that block for a different prefix can leave stale block state behind, and newer vLLM block implementations requirereset_hash()before assigning a new hash.What Changed
_reset_block_hash()helper that callsreset_hash()when available and falls back to clearing_block_hashfor older/mock block objects.evict_blocks()andreset_prefix_cache().tests/test_prefix_cache.pyfor eviction, reset, explicit eviction, and reallocation/recache flows.Tests
Result:
28 passed.