Repository navigation
Handle NIXL abort notifications #30352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ishandhanani
merged 3 commits into
sgl-project:main
from
yichaolemon:codex/nixl-abort-notifications
Jul 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,6 +330,185 @@ def test_last_zero_page_chunk_is_sent_for_aux_only_completion(self): | |
| self.assertTrue(sender.should_send_kv_chunk(3, last_chunk=False)) | ||
|
|
||
|
|
||
| class TestNixlAbortHandling(CustomTestCase): | ||
| def _make_manager(self, request_status=None): | ||
| mgr = object.__new__(NixlKVManager) | ||
| mgr.request_status = dict(request_status or {}) | ||
| mgr._connect = MagicMock() | ||
| mgr.failure_lock = threading.Lock() | ||
| mgr.failure_records = {} | ||
| return mgr | ||
|
|
||
| def test_given_known_incomplete_room_when_abort_arrives_then_room_fails_without_ack( | ||
| self, | ||
| ): | ||
| mgr = self._make_manager({11: KVPoll.WaitingForInput}) | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"11", b"127.0.0.1", b"5555"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertEqual(mgr.request_status[11], KVPoll.Failed) | ||
| self.assertEqual( | ||
| mgr.failure_records[11], | ||
| "Aborted by decode-side abort notification.", | ||
| ) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
| def test_given_successful_room_when_abort_arrives_then_status_is_preserved(self): | ||
| mgr = self._make_manager({12: KVPoll.Success}) | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"12", b"127.0.0.1", b"5556"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertEqual(mgr.request_status[12], KVPoll.Success) | ||
| self.assertEqual(mgr.failure_records, {}) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
| def test_given_unknown_room_when_abort_arrives_then_status_remains_absent(self): | ||
| mgr = self._make_manager() | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"14", b"127.0.0.1", b"5557"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertNotIn(14, mgr.request_status) | ||
| self.assertEqual(mgr.failure_records, {}) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
| def test_given_malformed_abort_when_handled_then_no_exception_or_ack(self): | ||
| mgr = self._make_manager({13: KVPoll.WaitingForInput}) | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"invalid-room", b"127.0.0.1", b"5558"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertEqual(mgr.request_status[13], KVPoll.WaitingForInput) | ||
|
Comment on lines
+384
to
+391
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. b"13" has poor readability, maybe change it to b"unvalid-room"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| self.assertEqual(mgr.failure_records, {}) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
|
|
||
| class TestNixlUpdateStatus(CustomTestCase): | ||
| def _make_manager(self, request_status): | ||
| mgr = object.__new__(NixlKVManager) | ||
| mgr.request_status = dict(request_status) | ||
| return mgr | ||
|
|
||
| def test_given_failed_room_when_status_is_promoted_then_failed_is_preserved(self): | ||
| for status in (KVPoll.Transferring, KVPoll.Success): | ||
| with self.subTest(status=status): | ||
| mgr = self._make_manager({17: KVPoll.Failed}) | ||
|
|
||
| mgr.update_status(17, status) | ||
|
|
||
| self.assertEqual(mgr.request_status[17], KVPoll.Failed) | ||
|
|
||
| def test_given_missing_room_when_failed_update_arrives_then_room_is_not_resurrected( | ||
| self, | ||
| ): | ||
| mgr = self._make_manager({}) | ||
|
|
||
| mgr.update_status(18, KVPoll.Failed) | ||
|
|
||
| self.assertNotIn(18, mgr.request_status) | ||
|
|
||
|
|
||
| class TestNixlTransferWorker(CustomTestCase): | ||
| def _make_manager(self, room): | ||
| mgr = object.__new__(NixlKVManager) | ||
| mgr.request_status = {room: KVPoll.WaitingForInput} | ||
| mgr.transfer_infos = { | ||
| room: { | ||
| "agent": TransferInfo( | ||
| room=room, | ||
| endpoint="127.0.0.1", | ||
| dst_port=5555, | ||
| agent_name="agent", | ||
| dst_kv_indices=np.array([2], dtype=np.int32), | ||
| dst_aux_index=0, | ||
| required_dst_info_num=1, | ||
| dst_state_indices=[], | ||
| ) | ||
| } | ||
| } | ||
| mgr.decode_kv_args_table = { | ||
| "agent": SimpleNamespace( | ||
| decode_tp_size=1, | ||
| dst_kv_ptrs=[0], | ||
| dst_aux_ptrs=[0], | ||
| gpu_id=0, | ||
| staging=None, | ||
| kv_xfer_segments=None, | ||
| dst_homogeneous_mem_kind="VRAM", | ||
| ) | ||
| } | ||
| mgr.req_to_decode_prefix_len = {room: 4} | ||
| mgr.enable_staging = False | ||
| mgr._staging_ctx = None | ||
| mgr.is_mla_backend = False | ||
| mgr.attn_tp_size = 1 | ||
| mgr.kv_args = SimpleNamespace(engine_rank=0) | ||
| mgr.exceptions = {} | ||
| mgr.failure_lock = threading.Lock() | ||
| mgr.failure_records = {} | ||
|
|
||
| def check_xfer_state(_handle): | ||
| mgr.update_status(room, KVPoll.Failed) | ||
| return "DONE" | ||
|
|
||
| mgr.agent = SimpleNamespace(check_xfer_state=check_xfer_state) | ||
| return mgr | ||
|
|
||
| def _make_chunk(self, room, prefill_kv_indices, is_last_chunk): | ||
| return TransferKVChunk( | ||
| room=room, | ||
| prefill_kv_indices=np.array(prefill_kv_indices, dtype=np.int32), | ||
| index_slice=slice(0, len(prefill_kv_indices)), | ||
| is_last_chunk=is_last_chunk, | ||
| chunk_id=0, | ||
| prefill_aux_index=0 if is_last_chunk else None, | ||
| state_indices=None, | ||
| ) | ||
|
|
||
| def _run_worker_once(self, mgr, chunk): | ||
| queue = SimpleNamespace(get=MagicMock(side_effect=[chunk, SystemExit()])) | ||
| with self.assertRaises(SystemExit): | ||
| mgr.transfer_worker(queue) | ||
|
|
||
| def test_given_last_chunk_aborts_mid_transfer_when_worker_finishes_then_failed_status_is_preserved( | ||
| self, | ||
| ): | ||
| room = 21 | ||
| mgr = self._make_manager(room) | ||
| mgr.send_aux = MagicMock(return_value="aux_handle") | ||
| chunk = self._make_chunk(room, [], is_last_chunk=True) | ||
|
|
||
| self._run_worker_once(mgr, chunk) | ||
|
|
||
| self.assertEqual(mgr.request_status[room], KVPoll.Failed) | ||
| self.assertNotIn(room, mgr.transfer_infos) | ||
| self.assertNotIn(room, mgr.req_to_decode_prefix_len) | ||
|
|
||
| def test_given_non_last_chunk_aborts_mid_transfer_when_worker_finishes_then_failed_status_is_preserved( | ||
| self, | ||
| ): | ||
| room = 22 | ||
| mgr = self._make_manager(room) | ||
| mgr.send_kvcache = MagicMock(return_value="kv_handle") | ||
| chunk = self._make_chunk(room, [1], is_last_chunk=False) | ||
|
|
||
| self._run_worker_once(mgr, chunk) | ||
|
|
||
| self.assertEqual(mgr.request_status[room], KVPoll.Failed) | ||
| self.assertIn(room, mgr.transfer_infos) | ||
| self.assertIn(room, mgr.req_to_decode_prefix_len) | ||
|
|
||
|
|
||
| class TestNixlNotifications(CustomTestCase): | ||
| def _make_manager(self, messages, required=None): | ||
| mgr = object.__new__(NixlKVManager) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe record failure here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done