From fb178457231acffc0259c2b9aa1aa78f05e4cff5 Mon Sep 17 00:00:00 2001 From: shuwenn <47200617+alphabetc1@users.noreply.github.com> Date: Fri, 19 Dec 2025 16:33:34 +0800 Subject: [PATCH] fix: unreachable error check in retraction (#15433) Co-authored-by: Liangsheng Yin --- python/sglang/srt/managers/schedule_batch.py | 28 ++++++-------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/python/sglang/srt/managers/schedule_batch.py b/python/sglang/srt/managers/schedule_batch.py index 7445c5fcc..0140d62d1 100644 --- a/python/sglang/srt/managers/schedule_batch.py +++ b/python/sglang/srt/managers/schedule_batch.py @@ -1746,21 +1746,7 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin): ) ): if len(sorted_indices) == 1: - # Corner case: only one request left - if self.is_hybrid_swa: - full_available_size = ( - self.token_to_kv_pool_allocator.full_available_size() - ) - swa_available_size = ( - self.token_to_kv_pool_allocator.swa_available_size() - ) - assert ( - full_available_size > 0 and swa_available_size > 0 - ), f"No space left for only one request in SWA mode {full_available_size=}, {swa_available_size=}" - else: - assert ( - self.token_to_kv_pool_allocator.available_size() > 0 - ), f"No space left for only one request, {self.token_to_kv_pool_allocator.available_size()=}" + # Always keep at least one request break first_iter = False @@ -1770,11 +1756,13 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin): # release memory and don't insert into the tree because we need the space instantly self.release_req(idx, len(sorted_indices), server_args) - if len(retracted_reqs) == 0: - # Corner case: only one request left - raise ValueError( - "Failed to retract any request. No space left for only one request." - ) + if len(sorted_indices) <= 1 and not self.check_decode_mem( + selected_indices=sorted_indices, buf_multiplier=buf_multiplier + ): + # Retracting loops ends and still not enough memory + raise ValueError( + "Out of memory even after retracting all other requests in the decode batch." + ) self.filter_batch(keep_indices=sorted_indices)