From cc7e43ad2229f264988125dcc6f6ec409c9013d6 Mon Sep 17 00:00:00 2001 From: Shuwen Wang <47200617+alphabetc1@users.noreply.github.com> Date: Thu, 10 Sep 2026 23:54:08 +0800 Subject: [PATCH] [HiCache] Account for newly pinned ancestors in load-back quota (#38481) --- python/sglang/srt/mem_cache/unified_radix_cache.py | 2 +- .../unit/mem_cache/test_unified_radix_cache_unittest.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/mem_cache/unified_radix_cache.py b/python/sglang/srt/mem_cache/unified_radix_cache.py index 089780bdf..f602d2c52 100644 --- a/python/sglang/srt/mem_cache/unified_radix_cache.py +++ b/python/sglang/srt/mem_cache/unified_radix_cache.py @@ -1594,7 +1594,7 @@ class UnifiedRadixCache(BasePrefixCache): # entirely empty spec (e.g. foreign-pin rejection) must never report # success, even at load_back_threshold <= 0. if (kv_tokens < max(1, self.load_back_threshold) and not comp_xfers) or ( - mem_quota is not None and kv_tokens > mem_quota + result.delta + mem_quota is not None and kv_tokens + result.delta > mem_quota ): self.dec_lock_ref(node_id, ancestor_lock_params) self.dec_host_lock_ref(node_id, host_anchor_params) diff --git a/test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py b/test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py index 2fed5a542..71c8d7e47 100644 --- a/test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py +++ b/test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py @@ -6281,7 +6281,8 @@ class UnifiedRadixCacheSuite: best_match_node=req.best_match_node, host_hit_length=req.host_hit_length, req=req, - mem_quota=-1_000_000, + # Pinning the resident ancestors leaves too little for the tail. + mem_quota=len(tokens) - 1, ) )