diff --git a/python/sglang/srt/disaggregation/common/conn.py b/python/sglang/srt/disaggregation/common/conn.py index b1a9990363..5cf9d06089 100644 --- a/python/sglang/srt/disaggregation/common/conn.py +++ b/python/sglang/srt/disaggregation/common/conn.py @@ -1657,9 +1657,12 @@ class CommonKVSender(BaseKVSender): if hasattr(self.kv_mgr, "transfer_infos"): self.kv_mgr.transfer_infos.pop(self.bootstrap_room, None) if hasattr(self.kv_mgr, "_deferred_ack_targets"): - # Drop a held ack target if the room concluded without draining - # (e.g. aborted before any chunk enqueued); else it leaks on prefill. - self.kv_mgr._deferred_ack_targets.pop(self.bootstrap_room, None) + if hasattr(self.kv_mgr, "_staging_outstanding"): + # Preserve the target until in-flight writes drain, even when + # the scheduler has already observed Failed and cleared the room. + self.kv_mgr._maybe_ack_drained_abort(self.bootstrap_room) + else: + self.kv_mgr._deferred_ack_targets.pop(self.bootstrap_room, None) def abort(self): self.kv_mgr.record_failure( diff --git a/python/sglang/srt/disaggregation/mooncake/conn.py b/python/sglang/srt/disaggregation/mooncake/conn.py index c78aa6a234..7c91a3ee0c 100644 --- a/python/sglang/srt/disaggregation/mooncake/conn.py +++ b/python/sglang/srt/disaggregation/mooncake/conn.py @@ -2469,9 +2469,11 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager): # first would let the worker drain+ack while the room is # not yet Failed, so a newly enqueued chunk could still # write to the freed pages. The worker (not this thread) - # acks once its in-flight write drains; if nothing is in - # flight, decode falls back to the release timeout. - if room_active: + # acks once its in-flight write drains. + if ( + room_active + or self._staging_outstanding.get(room_to_be_aborted, 0) > 0 + ): self.update_status(room_to_be_aborted, KVPoll.Failed) self.register_deferred_ack_target( room_to_be_aborted, decode_ip, decode_port diff --git a/test/registered/unit/disaggregation/test_disaggregation_wire.py b/test/registered/unit/disaggregation/test_disaggregation_wire.py index 0a9bc35d4e..e31eaab4e7 100644 --- a/test/registered/unit/disaggregation/test_disaggregation_wire.py +++ b/test/registered/unit/disaggregation/test_disaggregation_wire.py @@ -30,6 +30,7 @@ from sglang.srt.disaggregation.decode_schedule_batch_mixin import ( from sglang.srt.disaggregation.mooncake.conn import ( KVArgsRegisterInfo, MooncakeKVManager, + MooncakeKVSender, TransferInfo, ) from sglang.srt.disaggregation.utils import ( @@ -68,6 +69,25 @@ register_cpu_ci(est_time=11, suite="base-a-test-cpu") class TestDisaggregationWire(unittest.TestCase): + def test_sender_clear_keeps_abort_ack_until_writes_drain(self): + manager = object.__new__(MooncakeKVManager) + sender = object.__new__(MooncakeKVSender) + sender.kv_mgr, sender.bootstrap_room = manager, 42 + for outstanding in (0, 1): + with self.subTest(outstanding=outstanding): + manager.request_status = {42: KVPoll.Failed} + manager._staging_outstanding = {42: outstanding} + manager._deferred_ack_targets = {42: ("127.0.0.1", 1234)} + with patch.object(manager, "_send_abort_ack") as ack: + sender.clear() + if outstanding: + ack.assert_not_called() + manager._staging_outstanding[42] = 0 + manager._maybe_ack_drained_abort(42) + ack.assert_called_once_with("127.0.0.1", 1234, 42) + manager._maybe_ack_drained_abort(42) + ack.assert_called_once() + def test_mooncake_registration_staging_fields(self): msg = [ b"room",