From c9153da5dca5fb1ee1a0bd765432dd56e1fc0e5b Mon Sep 17 00:00:00 2001 From: Yuhao Yang <47235274+yhyang201@users.noreply.github.com> Date: Fri, 22 May 2026 15:28:54 +0800 Subject: [PATCH] Fix SWA double-free in disagg decode with MTP speculation (#25805) Co-authored-by: Ke Bao --- python/sglang/srt/mem_cache/swa_memory_pool.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/sglang/srt/mem_cache/swa_memory_pool.py b/python/sglang/srt/mem_cache/swa_memory_pool.py index bd1205708..6fab812af 100644 --- a/python/sglang/srt/mem_cache/swa_memory_pool.py +++ b/python/sglang/srt/mem_cache/swa_memory_pool.py @@ -561,6 +561,8 @@ class SWATokenToKVPoolAllocator(BaseTokenToKVPoolAllocator): self.full_to_swa_index_mapping[alloc_full_indices[-swa_tail_len:]] = ( alloc_swa_indices ) + if swa_tail_len < extend_num_tokens: + self.full_to_swa_index_mapping[alloc_full_indices[:-swa_tail_len]] = 0 return alloc_full_indices def alloc_decode(