Skip to content

Keep a router's existing registration when an engine registers again - #2483

Merged
zhuzilin merged 2 commits into
THUDM:mainfrom
key4ng:fix/router-reregister-409
Oct 27, 2026
Merged

zhuzilin merged 2 commits into
THUDM:mainfrom
key4ng:fix/router-reregister-409

Conversation

@key4ng

@key4ng key4ng commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With external engines (--rollout-external-engine-addrs), slime registers each engine with the router on every run (_init_external → _register_to_router). shutdown() returns before unregister_worker, because the external cluster owns those processes. So the engines stay registered after the run, which is intended: they outlive it. A run that ends uncleanly leaves its launched engines registered the same way.

The next run POSTs the same URLs again. sglang_router 0.3.2 answers a repeat with 202, so this goes unnoticed with the default router. A router whose POST /workers is create-only answers 409 WORKER_ALREADY_EXISTS, and raise_for_status() aborts the run before its first rollout. One such router is SMG, whose POST /workers stays create-only (smg-project/smg#3976 was declined).

Reproduced with two engines served outside slime, SMG as the router, and two short runs back to back:

run 1: 3 steps
run 2: 0 steps
ray.exceptions.RayTaskError(HTTPError): ray::SGLangEngine.init() ...
requests.exceptions.HTTPError: 409 Client Error: Conflict for url: http://127.0.0.1:30100/workers

Fix

Registration goes through a new server_control.register_worker(), next to unregister_worker().

  • On 409 with code: WORKER_ALREADY_EXISTS, it reads GET /workers. If the router lists the URL with the same payload slime would post (url, worker_type, and bootstrap_port for a prefill engine), it keeps that registration and logs it.
  • Any other refusal raises as before: a registration that differs, another 409 code such as WORKER_CREATE_IN_PROGRESS, or another status.

Routers that answer 2xx, including sglang_router, see no change.

Tests

tests/test_server_control.py, CPU-only, with a fake router:

  • test_register_worker_posts_the_payload: 200 and 202;
  • test_register_worker_keeps_the_registration_an_earlier_run_left: a matching prefill registration with its bootstrap_port;
  • test_register_worker_refuses_a_registration_that_differs: another worker type, another or missing bootstrap_port;
  • test_register_worker_raises_any_other_refusal: another 409 code, a 409 without a code, a 500.
$ python -m pytest -q tests/test_server_control.py tests/test_external_sglang_engines.py
26 passed

End to end on 4x H100: two engines served outside slime (--rollout-external-engine-addrs), Qwen3-0.6B, SMG as the router, and two 3-step runs back to back against the same router. The patch was cherry-picked onto 5bec7a10; slime/backends/sglang_utils/ is unchanged between that commit and main.

slime 5bec7a10:              run 1: 3 steps   run 2: POST /workers -> 409, 0 steps
slime 5bec7a10 + this PR:    run 1: 3 steps   run 2: POST /workers -> 409, registration kept, 3 steps

An external engine (--rollout-external-engine-addrs) is registered with the router on every run, and shutdown() leaves it registered because the external cluster owns it. A run that ends uncleanly leaves its engines registered too. A router whose POST /workers is create-only, such as SMG, answers the next run's POST with 409 WORKER_ALREADY_EXISTS, and raise_for_status() aborts that run.

register_worker() now keeps the router's registration when the 409 says WORKER_ALREADY_EXISTS and GET /workers lists that URL with the same payload (worker_type, and bootstrap_port for prefill). Any other refusal, including a registration that differs, is still raised.

Signed-off-by: Keyang Ru <rukeyang@gmail.com>
@key4ng

key4ng commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@zhuzilin could you take a look when you have a moment?

With --rollout-external-engine-addrs, slime registers each engine on every run but leaves it registered at shutdown, because the external cluster owns it. A router whose POST /workers is create-only then answers the next run with 409 WORKER_ALREADY_EXISTS, and the run aborts before its first rollout. This change keeps the router's registration when it matches what slime would post. It is the registering counterpart of unregister_worker in server_control.py. Any other refusal still raises.

The CPU tests are in tests/test_server_control.py, and the GPU repro (stock slime fails, patched slime trains) is in the description. Thanks!

Signed-off-by: Keyang Ru <rukeyang@gmail.com>
@zhuzilin
zhuzilin merged commit cd55985 into THUDM:main Oct 27, 2026
113 checks passed
@zhuzilin

Copy link
Copy Markdown
Contributor

sorry for the late reply. thank you so much for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants