fix: roll back partial KV allocation on page miss#365
Open
shipiyouniao wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a failure mode in KVCacheManager._alloc() where a PageAllocator.alloc_page() RuntimeError could escape after partially allocating block IDs, leaking those IDs instead of returning an allocation miss (None).
Changes:
- Catch
RuntimeErrorfrompage_allocator.alloc_page()/page.init()and returnNone(allocation miss) instead of propagating the exception. - Attempt to roll back any partially allocated block IDs via
free()before returningNone, and log rollback failures without masking the miss. - Add regression tests covering partial allocation followed by a page-allocation failure.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
kvcached/kv_cache_manager.py |
Adds exception handling + rollback for partial allocations when physical page allocation fails. |
tests/test_kvcache_manager_alloc_miss.py |
Adds regression tests for allocation-miss rollback scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6e32f61 to
2940cb1
Compare
This was referenced Jul 1, 2026
2940cb1 to
cf0d799
Compare
cf0d799 to
11738b1
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 #364.
Fixes a lower-level allocation failure path in
KVCacheManager.alloc()wherePageAllocator.alloc_page()can raise after some block ids have already been reserved for the current allocation request.Root Cause
available_size()and physical page allocation are not atomic across multiple instances sharing the same physical pool. A caller may pass the capacity check, consume reserved blocks or blocks from an existing page, and then fail when requesting a new physical page.Before this change, that
RuntimeErrorescaped without rolling back the partially allocated block ids.What Changed
RuntimeErroraroundpage_allocator.alloc_page().Noneas an allocation miss instead of crashing the allocation path.None._free(..., release_empty_pages=False)rollback path so a partial-allocation rollback does not unmap/release physical pages that were not intentionally returned to the physical pool.free()behavior unchanged for real releases.Tests