fix(kvcache): clone inserted radix keys to release request buffers (#559)

This commit is contained in:
cherry77-cloud
2026-10-05 15:29:44 -07:00
committed by GitHub
parent 93b0a59164
commit 555efd8944
3 changed files with 10 additions and 3 deletions
@@ -98,7 +98,10 @@ class HybridRadixCache:
node, prefix_len = self._walk(input_ids)
if prefix_len != insert_len:
new_node = RadixTreeNode(self.key_fn)
new_node.set_key_value(input_ids[prefix_len:], kv_indices[prefix_len:].clone())
# A view would keep the request's full output-budget token buffer alive.
new_node.set_key_value(
input_ids[prefix_len:].clone(), kv_indices[prefix_len:].clone()
)
new_node.set_parent(node)
self.full_evictable += new_node.length
node = new_node
+4 -1
View File
@@ -167,7 +167,10 @@ class RadixPrefixCache(BasePrefixCache):
node, prefix_len = self._tree_walk(input_ids)
if prefix_len != insert_len: # NOTE: prefix_len < insert_len
new_node = RadixTreeNode(self.key_fn)
new_node.set_key_value(input_ids[prefix_len:], indices[prefix_len:].clone())
# A view would keep the request's full output-budget token buffer alive.
new_node.set_key_value(
input_ids[prefix_len:].clone(), indices[prefix_len:].clone()
)
new_node.set_parent(node)
self.evictable_size += new_node.length
node = new_node
+2 -1
View File
@@ -215,7 +215,8 @@ class SWARadixCache:
# then a live (non-tombstone) leaf for the in-window remainder (never a tombstone leaf --
# the clamp + the free_swa -page_size margin guarantee a live tail).
if total < insert_len:
suffix_ids = input_ids[total:]
# Both suffix nodes can share this copy without retaining the request buffer.
suffix_ids = input_ids[total:].clone()
suffix_kv = kv_indices[total:].clone()
boundary = max(0, min(swa_evicted_seqlen, insert_len) - total)
boundary = min(boundary, max(0, len(suffix_ids) - self.page_size))