From aec4b799e61af971701d960e19d9d3062a6eb5ee Mon Sep 17 00:00:00 2001 From: Shuwen Wang <47200617+alphabetc1@users.noreply.github.com> Date: Thu, 1 Oct 2026 01:50:44 +0800 Subject: [PATCH] [PD][Mamba] fix: free the COW mamba slot of decode requests dropped before preallocation (#41451) Co-authored-by: Shangming Cai --- python/sglang/srt/disaggregation/decode.py | 3 +++ .../unit/disaggregation/test_decode_queue_cleanup.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/disaggregation/decode.py b/python/sglang/srt/disaggregation/decode.py index 2ee23a9730..5ccbf0de97 100644 --- a/python/sglang/srt/disaggregation/decode.py +++ b/python/sglang/srt/disaggregation/decode.py @@ -1713,6 +1713,9 @@ class DecodePreallocQueue(DecodeHiCachePreallocMixin): self.pending_reqs = [ r for r in self.pending_reqs if id(r) not in failed_ids ] + for decode_req in failed_reqs: + if decode_req.req.kv.holds_mamba and not decode_req.req.kv.holds_kv: + release_kv_cache(decode_req.req, self.tree_cache, is_insert=False) self.queue = [ entry for i, entry in enumerate(self.queue) if i not in indices_to_remove diff --git a/test/registered/unit/disaggregation/test_decode_queue_cleanup.py b/test/registered/unit/disaggregation/test_decode_queue_cleanup.py index 9a5fac4570..a997377e70 100644 --- a/test/registered/unit/disaggregation/test_decode_queue_cleanup.py +++ b/test/registered/unit/disaggregation/test_decode_queue_cleanup.py @@ -11,7 +11,7 @@ from sglang.srt.disaggregation.decode import ( ) from sglang.srt.disaggregation.fake.conn import FakeKVManager, FakeKVReceiver from sglang.srt.disaggregation.utils import DisaggregationMode -from sglang.srt.managers.schedule_batch import FINISH_ABORT +from sglang.srt.managers.schedule_batch import FINISH_ABORT, ReqKvInfo from sglang.srt.managers.scheduler import Scheduler from sglang.srt.runtime_context import get_context, publish, reset_context from sglang.srt.server_args import ServerArgs @@ -110,6 +110,7 @@ class TestDecodeQueueCleanup(CustomTestCase): req = SimpleNamespace( rid="abort-prealloc", bootstrap_room=42, + kv=ReqKvInfo(), finished_reason=None, return_logprob=False, ) @@ -173,6 +174,7 @@ class TestDecodeQueueCleanup(CustomTestCase): req = SimpleNamespace( rid="abort-shared", finished_reason=FINISH_ABORT("aborted"), + kv=ReqKvInfo(), return_logprob=False, ) decode_req = SimpleNamespace(req=req, kv_receiver=receiver) @@ -214,6 +216,7 @@ class TestDecodeQueueCleanup(CustomTestCase): req = SimpleNamespace( rid="swa-reclaim-failed", origin_input_ids=[1, 2, 3], + kv=ReqKvInfo(), output_ids=[], finished_reason=None, return_logprob=False,