From 0d592c475bca778a06116f2c05ac282b9c6491fa Mon Sep 17 00:00:00 2001 From: metamergebot Date: Fri, 23 Oct 2026 16:47:14 -0700 Subject: [PATCH] [Fix] rust-server: Keep a transfer backend's own bootstrap port on prefill (#46066) Co-authored-by: metamergebot Co-authored-by: shodoco --- .../srt/arg_groups/pd_disaggregation_hook.py | 15 ++++++ python/sglang/srt/managers/disagg_service.py | 15 ++++++ .../entrypoints/test_rust_server_dp_ports.py | 51 +++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/python/sglang/srt/arg_groups/pd_disaggregation_hook.py b/python/sglang/srt/arg_groups/pd_disaggregation_hook.py index a9f297cd08..78237258f5 100644 --- a/python/sglang/srt/arg_groups/pd_disaggregation_hook.py +++ b/python/sglang/srt/arg_groups/pd_disaggregation_hook.py @@ -248,8 +248,23 @@ def _alias_bootstrap_port_to_api_port(server_args: ServerArgs) -> None: consumer (KVManager registration, PrefillBootstrapQueue) reads the resolved field and agrees automatically. Decode is untouched: there the field names the PREFILL side's bootstrap port and must stay as the operator set it. + A transfer backend that brings its own bootstrap server keeps the port as + configured: that server, not the Rust registry, listens there. """ + # Lazy: disagg_service pulls in the disaggregation package. Its helper calls + # disagg_service.get_kv_class, which a transfer backend registered at + # runtime may rebind. + from sglang.srt.managers.disagg_service import rust_server_serves_kv_bootstrap + cfg = resolving_view(server_args) + if not rust_server_serves_kv_bootstrap(cfg.disaggregation_transfer_backend): + logger.info( + "SGLANG_RUST_SERVER: transfer backend %s runs its own KV bootstrap " + "server; keeping disaggregation_bootstrap_port %d", + cfg.disaggregation_transfer_backend, + cfg.disaggregation_bootstrap_port, + ) + return default_port = next( f.default for f in record_fields(type(server_args)) diff --git a/python/sglang/srt/managers/disagg_service.py b/python/sglang/srt/managers/disagg_service.py index 6b5e37082b..3517d77660 100644 --- a/python/sglang/srt/managers/disagg_service.py +++ b/python/sglang/srt/managers/disagg_service.py @@ -51,6 +51,21 @@ def start_disagg_service(): return bootstrap_server +def rust_server_serves_kv_bootstrap(transfer_backend: str) -> bool: + """Whether the embedded Rust server's KV bootstrap registry stands in for + the transfer backend's bootstrap server: it ports ``CommonKVBootstrapServer``, + the HTTP registry the built-in backends run, but not a backend that brings + a bootstrap server of its own.""" + from sglang.srt.disaggregation.common.conn import CommonKVBootstrapServer + + server_class = get_kv_class( + TransferBackend(transfer_backend), KVClassType.BOOTSTRAP_SERVER + ) + return server_class is not None and issubclass( + server_class, CommonKVBootstrapServer + ) + + def maybe_create_ascend_config_store(transfer_backend: TransferBackend) -> None: """Also called directly by the rust-server scheduler: there the KV bootstrap registry is served by the embedded rust server's api listener diff --git a/test/registered/unit/entrypoints/test_rust_server_dp_ports.py b/test/registered/unit/entrypoints/test_rust_server_dp_ports.py index aaedf42504..26bc1bcc54 100644 --- a/test/registered/unit/entrypoints/test_rust_server_dp_ports.py +++ b/test/registered/unit/entrypoints/test_rust_server_dp_ports.py @@ -5,10 +5,17 @@ from unittest.mock import MagicMock, patch import pytest from sglang.srt import rust_extensions +from sglang.srt.arg_groups.overrides import resolving_view +from sglang.srt.arg_groups.pd_disaggregation_hook import handle_pd_disaggregation +from sglang.srt.disaggregation.base.conn import BaseKVBootstrapServer +from sglang.srt.disaggregation.common.conn import CommonKVBootstrapServer from sglang.srt.entrypoints.engine import node_hosts_rust_server +from sglang.srt.environ import envs +from sglang.srt.managers import disagg_service from sglang.srt.runtime_context import get_context, get_parallel from sglang.srt.rust_server import config as rust_config from sglang.srt.rust_server import server as rust_server +from sglang.srt.server_args import ServerArgs from sglang.test.ci.ci_register import register_cpu_ci register_cpu_ci(est_time=3, suite="base-a-test-cpu") @@ -263,5 +270,49 @@ def test_scale_joiner_hosts_listener(): assert node_hosts_rust_server() +class _HttpRegistry(CommonKVBootstrapServer): + pass + + +class _OwnBootstrapServer(BaseKVBootstrapServer): + pass + + +@pytest.mark.parametrize( + "server_class,bootstrap_port,expected", + [ + (_HttpRegistry, 8998, 31000), + (_HttpRegistry, 31000, 31000), + (_HttpRegistry, 33000, ValueError), + (_OwnBootstrapServer, 8998, 8998), + (_OwnBootstrapServer, 33000, 33000), + ], + ids=[ + "http-registry-default", + "http-registry-shared", + "http-registry-separate", + "backend-bootstrap-server-default", + "backend-bootstrap-server-separate", + ], +) +def test_rust_prefill_bootstrap_port_alias(server_class, bootstrap_port, expected): + args = ServerArgs( + model_path="dummy", + port=31000, + disaggregation_mode="prefill", + disaggregation_bootstrap_port=bootstrap_port, + ) + with ( + envs.SGLANG_RUST_SERVER.override(True), + patch.object(disagg_service, "get_kv_class", return_value=server_class), + ): + if expected is ValueError: + with pytest.raises(ValueError, match="conflicts with --port"): + handle_pd_disaggregation(args) + return + handle_pd_disaggregation(args) + assert resolving_view(args).disaggregation_bootstrap_port == expected + + if __name__ == "__main__": raise SystemExit(pytest.main([__file__, "-v"]))