Repository navigation
fix(server-runtime): retry the head server on a fresh port when another Gym run already answers on its port - #6849
Conversation
When another Gym run held the head server's port, its head server answered the readiness poll while ours had failed to bind. The wait returned, the existing move-to-a-fresh-port retry never ran, and the run died later with "Head server finished unexpectedly!", the bind error buried in the log. Count the head server ready only once this process's own uvicorn server has started, and check its thread before trusting an answer, so a taken port becomes the typed EADDRINUSE start failure that start() already retries on a fresh port. Say so while waiting, instead of "not up yet (status success)". Signed-off-by: Chris Wing <[email protected]>
…up timeout; test the real path Review follow-ups: the timeout said the head server "is running (last status success)" when it never started and another server answered on its port; say that instead. Drop a redundant liveness re-check. Add an end-to-end test on real sockets: a foreign HTTP server holds and answers on the port, uvicorn fails to bind on its thread, and the wait reports EADDRINUSE. Signed-off-by: Chris Wing <[email protected]>
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM. No BLOCKER, RISK, or NOTE findings.
I reviewed both changed files and traced head-server creation, status polling, port reassignment, shutdown and the CLI/in-process callers. The readiness check now distinguishes this run's uvicorn instance from another server answering on the same port, without changing the existing one-retry policy.
Validation:
- CI on
d3cf9702b8d3eb22e9fbd45f726a1761d7825c59: lint, all four core-test shards, combined core coverage, all eight server-suite shards and both test aggregators passed. Changed-server tests and session-routing end-to-end were skipped, not passed. - The overall CI workflow is red. The optional
openclawandminiswe_sandboxedharness-conformance checks failed on both this head and the admitted base; they are separate from the passing test aggregators. - I ran
leader/startup_integration.pyagainst base and head using real head servers, HTTP clients and sockets. Base accepted the foreign server; head moved to a fresh port and served its own endpoint. Normal free-port startup passed on both revisions. Managed child-server spawning was omitted. - Focused delegated probes passed for startup/death interleavings and real successful startup with thread cleanup. All four new regression-test bodies failed against base for the expected reasons.
Local probes used 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:847e81f03fd364da697c53eca5bc9d35f9df3576, a successful default-branch CI image because this head has no container build. Its pyproject.toml and uv.lock match the reviewed head. I relied on CI for the existing suites rather than rerunning them. No model or GPU workloads ran.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45972299346 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45977957675 |
RL picks the Gym head-server port and writes it into Gym's config. If the head server cannot bind it, Gym's RunHelper.start() moves it to a fresh port in its global config and restarts every server, but RL kept building its rollout client from the port it picked. With this Gym bump (NVIDIA-NeMo/Gym#6849) that also happens when another Gym run already answers on the port, so RL could send rollouts to the other run. Read the port back from Gym's global config right after start(), before the rollout client is built. Test: a fake RunHelper.start() moves the head port; the head server config and the rollout client must use the new port. It fails without the fix (11000 != 11500). Signed-off-by: Terry Kong <[email protected]>
What does this PR do?
Bug. When two Gym runs on one machine use the same head server port (both on the default 11000, or the same
++head_server.port), the second run doesn't recover. It logs(Errno 98 on Linux), starts its other servers anyway, and later dies with
Cause. Gym already handles a taken port: a server whose bind fails with EADDRINUSE is moved to a fresh port and every server is started again once (
ServerSupervisor._move_to_a_fresh_port). That retry never runs for the head server here, because_wait_for_head_serveronly checks whether something answers HTTP on the head server's address, and checks it before checking the head server's thread. The other run's head server answers, so the wait returns "ready" although our head server's thread has already died on the bind.poll()notices later and raises a plainRuntimeError, which isn't retried.Fix.
_wait_for_head_servercounts the head server ready only once this process's own uvicorn server has started (uvicorn.Server.started), and reads its thread's liveness before trusting an answer. A taken port now ends the wait with the typed EADDRINUSE start failure thatstart()already retries on a fresh port.success)" and "although it is running (last statussuccess)".How to reproduce
On one machine, from a Gym checkout with
uv syncdone. No model is needed: the bug shows before any model call (the placeholder endpoint is never reached).Terminal 1, start a first run and leave it running:
Wait until it prints
Waiting for servers to spin up.Terminal 2, start a second run with the same command.
On
main: terminal 2 printsWaiting for head server to spin up, theaddress already in useerror for port 11600, startsmcqa,mcqa_simple_agent,mcqa_environment_serverandpolicy_model, and then exits withRuntimeError: Head server finished unexpectedly!.With this PR: terminal 2 prints
starts every server again, and goes on to
Waiting for servers to spin uplike the first run.Stop both with Ctrl-C.
Validation
python:3.13.14): fails onmainas described, recovers on this branch.tests/unit_tests/server_runtime/supervisor/test_head_server_start.py, each failing onmainand passing here. One runs on real sockets: a foreign HTTP server holds and answers on the port, uvicorn fails to bind on its thread asHeadServer.run_webserverruns it, and the wait reports EADDRINUSE.pytest tests/unit_tests/server_runtime/supervisor/: all pass except two existing tests intest_server_start_failed.pythat hard-code Linux's errno 98 and fail on macOS (also failing onmain, unrelated).pre-commit run --from-ref origin/main --to-ref HEADpasses.Not in scope
gym eval run --no-serve,gym env status) look for a moved head server on the configured port.Rollouts
N/A: server startup only; no environment or agent behavior changes.
Compatibility and benchmark impact
None. Runs whose head server binds normally behave as before.
Checklist
pre-commit run --all-files) (so CI lint/format checks pass). Run on the changed files.git commit -s) (so the DCO check passes).