Repository navigation
fix(cli): Treat 502/503/504 from a model endpoint as still starting - #4108
Conversation
…starting With base_url set, LocalVLLMModel skips its own vLLM launch and reported ready immediately, even if the endpoint was still loading: a load balancer in front of vLLM replicas that are still starting answers 503, so the first rollouts failed against it. Block startup until every base_url answers GET /models with HTTP 200, for at most external_server_ready_timeout_s (default 3600 s; None waits indefinitely), then fail with a clear TimeoutError. The local-launch wait (await_server_ready) and the new external wait now share one helper, wait_for_models_endpoint, so both require HTTP 200, use a per-probe request timeout, and treat any request exception as "not ready". The local path keeps its fail-fast check on the vLLM actor, now a RuntimeError instead of an assert. GenRMModel inherits the behaviour. Signed-off-by: sniverty <[email protected]>
|
/ok to test 2eed8ee |
| if is_alive is not None and not is_alive(): | ||
| raise RuntimeError(f"{server_name} vLLM server spinup failed, see the error logs above!") | ||
| try: | ||
| if requests.get(url=f"{url}/models", timeout=request_timeout_s).status_code == 200: |
There was a problem hiding this comment.
This probe sends GET /models without an Authorization header, and only HTTP 200 counts as ready.
An external vLLM server started with --api-key, or any OpenAI-compatible endpoint that requires a key, answers 401 to this request every time.
Startup then blocks for the full timeout and fails with did not return HTTP 200, even though the endpoint is up and the configured api_key would work.
Before this change, the same config started immediately and served requests normally.
I reproduced this with a small HTTP server that returns 401 unless it sees Authorization: Bearer <key>.
With timeout_s=4, wait_for_models_endpoint raised TimeoutError after 4 seconds.
The existing command-line probe avoids this on purpose.
The docstring of _probe_endpoint in nemo_gym/cli/env.py says that requiring a 200 would reject endpoints that need auth.
Send the configured key with the probe:
headers = {"Authorization": f"Bearer {api_key}"} if api_key else None
requests.get(url=f"{url}/models", headers=headers, timeout=request_timeout_s)Please also add a test where the endpoint returns 401 without the header and 200 with it.
There was a problem hiding this comment.
Understood, thanks for clarifying. I've removed wait_for_models_endpoint for now. I will look at adding a test that checks if a server answers 401 unless it gets Authorization: Bearer .
There was a problem hiding this comment.
Added test_an_endpoint_that_requires_a_key_does_not_hold_startup.
| # backend yet answers 503). Do not report ready until it serves, so no | ||
| # request can reach it early. | ||
| base_urls = self.config.base_url if isinstance(self.config.base_url, list) else [self.config.base_url] | ||
| wait_for_models_endpoint( |
There was a problem hiding this comment.
Gym already waits for model endpoints after the Gym servers start, and that check is where this gap should be fixed.
RunHelper.wait_for_server_readiness calls wait_for_model_endpoints in nemo_gym/cli/env.py.
That function probes every base_url in the config, including a local_vllm_model with base_url set.
It misses the load balancer case only because _probe_endpoint counts any HTTP response as answering, and 503 is a response.
Placing the wait here instead has three side effects:
- Plain
vllm_modelwith an externalbase_urlhas the same 503 problem and is not covered by this change. - The same URL is checked twice with different rules: here it needs a 200 within 3600 seconds, then the head process accepts any response within 600 seconds.
- While this wait runs, the Gym model server has not opened its port yet. A slow judge pool therefore shows up as a Gym server that failed to start.
flowchart TD
A["gym env start"] --> B["Gym model server process runs setup_webserver"]
B --> C["This PR: wait_for_models_endpoint blocks until GET /models returns 200"]
C -->|"up to 3600 s"| D["Gym model server opens its port"]
A --> E["Head process: wait_for_spinup polls Gym server ports"]
E -->|"port still closed after 600 s"| F["RuntimeError: Timed out waiting for Gym servers"]
D --> E
E -->|"all ports open"| G["wait_for_model_endpoints probes every base_url"]
G -->|"any HTTP response, including 503"| H["Head marks the run ready"]
Treat 502, 503 and 504 as "still starting" in _probe_endpoint, and drop the per-server wait and config field.
That covers every model type and keeps 401 and 404 counting as reachable.
It also reuses the existing model_endpoint_readiness_timeout_seconds key.
Does the NeMo-RL integration start Gym servers through RunHelper.start()?
If it uses another path that skips wait_for_server_readiness, a server-side wait may still be needed.
In that case the API key and timeout comments on this PR still apply.
| # With base_url set (an external server, e.g. a load balancer in front of vLLM | ||
| # replicas that may still be loading), startup blocks until every URL answers | ||
| # GET /models with HTTP 200, for at most this many seconds. None waits indefinitely. | ||
| external_server_ready_timeout_s: Optional[float] = 3600.0 |
There was a problem hiding this comment.
The 3600-second default and None cannot take effect under gym env start.
This wait runs inside setup_webserver(), before the Gym model server opens its port.
Meanwhile, the head process waits for every Gym server port with server_spinup_timeout_seconds, which defaults to 600 seconds.
Consider a judge pool that takes 15 minutes to load.
After 10 minutes the head process raises Timed out after 600s waiting for Gym servers to become ready and shuts the run down.
That message points at dependency installation and local model download, so the user goes looking in the wrong place.
Setting this field to None does not change the outcome.
If this wait stays in the model server, document that server_spinup_timeout_seconds must be at least this value.
Also name both settings in the TimeoutError message.
| RuntimeError: ``is_alive`` returned False. | ||
| TimeoutError: A URL was not ready within ``timeout_s``. | ||
| """ | ||
| deadline = None if timeout_s is None else monotonic() + timeout_s |
There was a problem hiding this comment.
timeout_s=0 makes the deadline the current time, so the first probe that is not a 200 raises TimeoutError immediately.
Gym's other startup limits use 0 differently.
server_spinup_timeout_seconds: 0 waits without a limit, and model_endpoint_readiness_timeout_seconds: 0 skips the check.
A user who copies that convention and sets external_server_ready_timeout_s: 0 will see startup fail instead of wait.
Make 0 (or any value at or below 0) mean "no limit" here, matching server_spinup_timeout_seconds.
There was a problem hiding this comment.
Ack, should be fixed now.
| poll_count += 1 | ||
| sleep(3) | ||
| wait_for_models_endpoint( | ||
| [self.config.base_url[0]], |
There was a problem hiding this comment.
The local launch path now requires HTTP 200 and passes no timeout_s.
Before this change, any HTTP response ended the wait.
If a config sets api_key in vllm_serve_kwargs, the local vLLM server answers this probe with 401.
The Ray actor stays alive, so the is_alive check never fires, and startup waits forever.
No checked-in config does this today, but the old code started fine in that setup.
Sending the configured key with the probe, as requested on the external path, fixes this path too.
A load balancer in front of vLLM replicas that are still loading answers 503 (502 if its backends refuse connections), which the model-endpoint startup check counted as "answering", so the first rollouts could reach a judge with no healthy backend. Treat 502, 503 and 504 as "still starting" and wait on them like a refused connection, within the existing model_endpoint_readiness_timeout_seconds bound. 401, 404 and other responses still count as answering, so endpoints that need auth are unaffected. Revert the per-server wait in local_vllm_model from the previous commit: the startup check already covers external base_urls, and the wait ran before the server port opened, so it was cut short by server_spinup_timeout_seconds, required HTTP 200 without the API key, and blocked the local launch path on endpoints that answer 401. Signed-off-by: sniverty <[email protected]>
… check NVIDIA-NeMo/Gym#4108 now holds rollouts in Gym's model-endpoint startup check, which treats a load balancer's 503 (no healthy backend yet) as still starting, instead of in a per-server wait in local_vllm_model. Point the EXTERNAL_VLLM_EARLY_RAY README row and launcher comment at that check, and document its model_endpoint_readiness_timeout_seconds bound (set under env.nemo_gym; 0 skips the check). Signed-off-by: sniverty <[email protected]>
A server started with --api-key answers the probe, which sends no key, with 401. Cover that the startup wait treats this as answering and moves on after one probe instead of waiting until the timeout. Signed-off-by: sniverty <[email protected]>
| """ | ||
| try: | ||
| requests.get(_endpoint_probe_url(base_url), timeout=timeout_seconds) | ||
| response = requests.get(_endpoint_probe_url(base_url), timeout=timeout_seconds) |
There was a problem hiding this comment.
This probe goes through requests, which honours HTTP_PROXY, HTTPS_PROXY and NO_PROXY from the environment.
The rollout traffic it stands in for does not: Gym's shared aiohttp ClientSession (server_utils.py) leaves trust_env at its default of False, so model requests always connect directly.
Before this change, a probe that went through a proxy always passed, so the mismatch was harmless.
Now consider a cluster that exports HTTP_PROXY for internet access, with an internal http:// judge host missing from NO_PROXY.
The proxy cannot reach the judge and answers 502 or 503, so startup waits the full model_endpoint_readiness_timeout_seconds and then fails, even though the direct path that rollouts use would work.
The proxy also hides DNS failures, so a placeholder hostname is waited on for 600 seconds instead of being reported once.
Probing without the environment proxy keeps the check on the same path as the traffic:
| response = requests.get(_endpoint_probe_url(base_url), timeout=timeout_seconds) | |
| with requests.Session() as session: | |
| # Model requests go through Gym's aiohttp client, which ignores proxy environment | |
| # variables, so the probe must not route through a proxy either. | |
| session.trust_env = False | |
| response = session.get(_endpoint_probe_url(base_url), timeout=timeout_seconds) |
A test that sets HTTP_PROXY to an address that refuses connections and expects a local endpoint to still count as answering would pin it.
There was a problem hiding this comment.
Thanks. Fixed in 1e59dbb: _probe_endpoint now uses a requests.Session() with trust_env = False, so it ignores HTTP_PROXY/HTTPS_PROXY/ALL_PROXY and connects directly, matching Gym's aiohttp client.
Added test_proxy_environment_variables_are_ignored test. It runs a real local HTTP server, points all proxy variables at a dead port and clears NO_PROXY, and checks that the probe still reports answering. I confirmed the test fails without the change (it gets refused).
|
|
||
| Nothing accepted a connection there. The server was never started, is still starting up, or the URL | ||
| in your config does not match where it is listening. | ||
| Nothing accepted a connection there, or only a proxy or load balancer answered with 502, 503 or 504. |
There was a problem hiding this comment.
The troubleshooting page still describes the old rule, and the PR checklist marks documentation as updated.
fern/versions/latest/pages/troubleshooting/configuration.mdx needs three edits:
- The sample error at L261-L262 still shows the old first sentence of this message.
- L274 says "Any response, including
401or404, means something is listening." It should say any response other than 502, 503 or 504. - L281 says "Any HTTP answer counts as listening", which is no longer true.
A sentence in that Note explaining that a proxy or load balancer answering 502, 503 or 504 is waited on like a refused connection would also help.
The versioned copies under v0.5.x and v0.6.0 should stay as they are.
There was a problem hiding this comment.
Updated fern/versions/latest/pages/troubleshooting/configuration.mdx in 1e59dbb:
- the sample error message now matches the new text
- "Any response other than 502, 503 or 504, including 401 or 404, means something is listening", plus a note that a gateway status usually comes from a proxy or load balancer whose backend is still starting
- the Note now says 502/503/504 are waited on and that the check ignores proxy variables
| def keyed_server(url, headers=None, **kwargs): | ||
| authorized = (headers or {}).get("Authorization") == "Bearer secret-key" |
There was a problem hiding this comment.
Small nit: the probe never sends an Authorization header, so the 200 branch of keyed_server can never run, and the docstring's "and 200 with it" describes a case the test does not exercise.
The test is still a useful guard that a 401 does not hold startup.
Returning 401 directly would say exactly that:
| def keyed_server(url, headers=None, **kwargs): | |
| authorized = (headers or {}).get("Authorization") == "Bearer secret-key" | |
| def keyed_server(url, **kwargs): | |
| return MagicMock(status_code=401) |
There was a problem hiding this comment.
Fixed in 1e59dbb. The fake server now returns 401 unconditionally.
…/504 Model requests go through Gym's aiohttp client, which ignores proxy environment variables, but the readiness probe used requests, which honours them. With a proxy set, a local endpoint came back as a proxy error or a 502/504 and, now that those mean "still starting", was waited on until the timeout. Probe with a session that has trust_env disabled. Update the troubleshooting page for the new rule (502/503/504 are waited on, the probe bypasses proxies), and simplify the 401 test: the probe never sends a key, so the fake server's 200 branch could not run. Signed-off-by: sniverty <[email protected]>
|
/ok to test 1e59dbb |
|
/ok to test 197296a |
|
/ok to test 197296a |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37795415612 |
No maintained WebVoyager profile enables global_aiohttp_client_trust_env; only the retired BrowserGym route used it. It also contradicted the model endpoint readiness probe (NVIDIA-NeMo#4108), which connects directly because Gym's aiohttp client ignores proxy variables, so an endpoint reachable only through a proxy would have been reported unreachable. The visual browser keeps its own per-context Playwright proxy. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jeff Peng <[email protected]>
What does this PR do?
Gym's model-endpoint startup check (
RunHelper.wait_for_model_endpoints) counted any HTTP answer as ready, including the 503 a load balancer returns while none of its backends is healthy. With judges served by vLLM replicas behind a load balancer that are still loading, the check passed immediately and the first rollouts reached a judge with no healthy backend._probe_endpointnow classifies 502, 503 and 504 as "still starting", and the check waits on them like a refused connection, within the existingmodel_endpoint_readiness_timeout_secondsbound. 401, 404 and every other response still count as answering, so endpoints that need auth are unaffected.Per review, the first commit's per-server wait in
local_vllm_modelis reverted, so that file is back tomain. That wait ran before the server's port opened (cut short byserver_spinup_timeout_seconds), required HTTP 200 without sending the API key, and blocked the local launch path on endpoints that answer 401.Motivation: in NeMo-RL GRPO runs, the judge/reward models (GenRM, NL2Bash, safety judge) run as external vLLM pools behind a load balancer and are reached through
base_url. With this change, the Ray cluster can start while those pools load, and the pools can live in a separate long-lived Slurm job that training jobs attach to. In both cases Gym must not send rollouts before the judges serve.Validation
(Claude-authored testing)
pytest tests/unit_tests/test_cli_endpoint_readiness.py: 19 passed. New tests:test_gateway_statuses_are_still_startingtest_waits_through_a_load_balancer_with_no_ready_backendtest_a_gateway_status_that_never_clears_is_reportedpytest responses_api_models/local_vllm_model/tests/test_app.py: 10 passed (unchanged frommain).pre-commit run --all-files: all hooks pass.Rollouts
End to end with NeMo-RL GRPO (Nemotron-3.5-nano RLVR recipe, 10 nodes), with judge pools (GenRM, NL2Bash, safety) behind load balancers that come up before their vLLM replicas finish loading:
Waiting for 4 model endpoint(s) to answer(3 policy servers plus the GenRM load balancer). The GenRM load balancer answered Gym'sGET /v1/modelswith 503 every 3 s for about 2.5 minutes. Its first replica registered at the next probe, which got 200, and Gym continued (All model endpoints are answering after 169s).3615823e, the NeMo-RL pipeline's pinned version, whose_probe_endpointand model-endpoint wait are identical tomain's, with only this fix applied. Currentmainneedsray>=2.58, and that pipeline's server environments pin Ray 2.56.1.Compatibility and benchmark impact
model_endpoint_readiness_timeout_seconds(default 600 s) passes. It then fails with the existing error, which now mentions the gateway case. Previously such an endpoint passed the check at once.local_vllm_modelis unchanged frommain.Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).