From 9d5f16d456f551b8a6c29929678c30ed95f5f204 Mon Sep 17 00:00:00 2001 From: Hanming Lu <69857889+hanming-lu@users.noreply.github.com> Date: Wed, 14 Jan 2026 19:28:33 -0800 Subject: [PATCH] [SWA] fix swa radix cache match_len_since_tombstone update when hits swa_tombstone (#17061) --- python/sglang/srt/mem_cache/swa_radix_cache.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/python/sglang/srt/mem_cache/swa_radix_cache.py b/python/sglang/srt/mem_cache/swa_radix_cache.py index 1757f01ed..a5d736145 100644 --- a/python/sglang/srt/mem_cache/swa_radix_cache.py +++ b/python/sglang/srt/mem_cache/swa_radix_cache.py @@ -821,13 +821,12 @@ class SWARadixCache(BasePrefixCache): while len(key) > 0 and child_key in node.children.keys(): child = node.children[child_key] - # update best_value_len and best_last_node if needed - if ( - child.swa_tombstone - and match_len_since_tombstone >= self.sliding_window_size - ): - best_value_len = len(value) - best_last_node = node + if child.swa_tombstone: + # update best_value_len and best_last_node if needed + if match_len_since_tombstone >= self.sliding_window_size: + best_value_len = len(value) + best_last_node = node + # reset match_len_since_tombstone if we hit a tombstone node match_len_since_tombstone = 0 prefix_len = self.key_match_fn(child.key, key)