Repository navigation
fix(core): bound internal retries by the retry cap - #3914
Conversation
Signed-off-by: Abhishree <[email protected]>
Signed-off-by: Abhishree <[email protected]>
Signed-off-by: Abhishree <[email protected]>
Signed-off-by: Abhishree <[email protected]>
Signed-off-by: Abhishree <[email protected]>
Signed-off-by: Abhishree <[email protected]>
|
/review |
|
/claude review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM — no reliability concerns. The retry branch now counts internal generic-error attempts for the explicit connection cap while preserving silent uncapped internal retries, the external default limit, and _max_num_tries behavior.
The regression tests cover tracing on/off and the neighboring retry behaviors, with a bounded mock that prevents runaway retry tests.
Static review only; tests were not executed.
Review generated by codex
|
SHIP — no reliability concerns. Reviewed the retry-branch refactor in What changed / why it's correct: Moving Tests: The three new cases trace exactly against the code — Nit (NOTE, author's call): the comment at lines 667-669 now says internal calls "still count tries so |
Signed-off-by: Abhishree <[email protected]>
|
/review |
|
/ok to test c14c70d |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM — no reliability concerns.
The retry-branch change advances num_tries for internal generic errors, allowing the explicit connection cap to terminate retries. Uncapped internal calls remain silent and unbounded; external default limits, explicit _max_num_tries behavior, and connection-error branches are preserved. Traced and untraced forwarding retain the retry parameters.
The regression tests check the capped internal path with tracing on/off, uncapped internal recovery, and external attempt limits. The bounded mock prevents runaway retry tests without masking the expected exceptions.
Static review only; tests were not executed.
Review generated by codex
|
/ok to test 5387291 |
|
/ok to test 5387291 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38320500691 |
…DIA-NeMo#4365) ## What does this PR do? `VLLMModel._post_init` builds one `NeMoGymAsyncOpenAI` client per `base_url` and passes `endpoint_connection_retries` as the client's `max_connection_retries` only when `endpoint_file` is configured. On `main` the condition reads `self.config.endpoint_connection_retries if self.config.endpoint_file else None` (`responses_api_models/vllm_model/app.py:466-468` on `main`). A deployment that enables `route_around_failing_endpoints` over a static `base_url` list has no endpoint file, so its clients are built with `max_connection_retries=None`. `None` means retry forever. `NeMoGymAsyncOpenAI` forwards the value as `_max_connection_retries` on every request (`nemo_gym/openai_utils.py:1378-1384` and `nemo_gym/openai_utils.py:1468`), and in `_request_with_retries` the `except ClientOSError` branch, which a refused connection reaches as `aiohttp.ClientConnectorError`, re-raises only when `_max_connection_retries` is set (`nemo_gym/server_utils.py:638-654`). Otherwise it sleeps 0.5 s and loops. The endpoint health accounting that NVIDIA-NeMo#3979 added depends on the call raising. `_call_endpoint` awaits the engine call and counts a `ClientConnectionError` against the endpoint only in its `except` branch (`responses_api_models/vllm_model/app.py:1835-1853`), and `_note_endpoint_failure` moves sessions off the endpoint once `endpoint_failure_threshold` consecutive calls have failed (`responses_api_models/vllm_model/app.py:1855-1873`). With an unbounded client the call never returns from the retry loop, the endpoint never records a failure, and every session pinned to a dead endpoint hangs on it for the rest of the run. The feature cannot react to the failure mode it was built for. The change: - `responses_api_models/vllm_model/app.py:469-473`: the clients receive `endpoint_connection_retries` when `endpoint_file` or `route_around_failing_endpoints` is set. A static list without either setting still gets `None`, and the endpoint-file rebind path already passed the bound unconditionally (`responses_api_models/vllm_model/app.py:1756`). - `responses_api_models/vllm_model/app.py:338-342`: the comment on `endpoint_connection_retries` states the condition and why an unbounded client defeats the route-around. - `responses_api_models/vllm_model/tests/test_app.py:6116-6135`: a new test builds the model over a two-URL static list with `route_around_failing_endpoints=True`, no endpoint file and `endpoint_connection_retries=3`, and checks that both clients carry `max_connection_retries == 3`. The same list without either setting yields `None` for both clients. The existing assertion at `responses_api_models/vllm_model/tests/test_app.py:6114` already pinned the single-URL default; only its comment changed, because "static clients retry forever" now holds only without route-around. ## Issue - NVIDIA-NeMo#3979 added `route_around_failing_endpoints`. This PR fixes its static-URL configuration. - NVIDIA-NeMo#2216 reports that the `ServerDisconnectedError` and `ClientOSError` branches of `_request_with_retries` never compare their counter against `MAX_NUM_TRIES`, so a permanently unreachable server loops forever. That unbounded loop is what hides a dead endpoint here. This PR does not change the loop; it makes `vllm_model` pass the per-client bound that the loop does honor. - NVIDIA-NeMo#3914 makes an explicit `_max_connection_retries` cap stop internal callers in the generic `except Exception` branch of the same loop. The `vllm_model` clients are external callers (`internal=False`), so this PR does not depend on it; both concern the same cap. - Draft NVIDIA-NeMo#4262 changes `_resolve_client` in the same file. This PR does not touch those lines, so the two compose. ## Validation - `pytest -q -p no:cacheprovider -o addopts= responses_api_models/vllm_model/tests/test_app.py` with the repository root on `PYTHONPATH` (Python 3.13.14, pytest 9.1.1, aiohttp 3.14.3): 254 passed, 0 failed. The same command on `main` at f128d43 gives 253 passed; the difference is the new test. - The new test fails against the `main` version of `responses_api_models/vllm_model/app.py` with `[None, None] == [3, 3]`. - `pytest -q -p no:cacheprovider -o addopts= responses_api_models/vllm_model/tests/` (the whole directory, three test files): 406 passed, 0 failed. - Unit suite (`pytest tests/unit_tests`, with `test_collect_downstream_junit.py` excluded for a missing local package): 7752 passed, 56 skipped, 17 failed, 5 errors; the 22 failures are the same 22 as on `main` in this environment (telemetry, opensandbox, and local-vLLM tests that need packages this machine lacks). Each other `responses_api_models/<server>/tests` directory, run as its own session, matches `main`. - `ruff check` and `ruff format --check` on both changed files: clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: alexandery <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
What does this PR do?
Follow-up to #3632, split out as requested in #3632 (comment).
In
_request_with_retries(), the genericexcept Exceptionbranch handles every error exceptServerDisconnectedErrorandClientOSError, which have their own branches. This includes aiohttp timeouts. When the caller does not pass_max_num_tries, this branch counted tries only for external callers. So an internal caller (_internal=True) that set_max_connection_retriesto 2 or more never reached the cap and retried forever.#3415 already counts tries for callers that pass
_max_num_tries. This PR fixes the remaining path, where_max_num_triesis not passed._max_connection_retriesstops them.MAX_NUM_TRIES;_max_num_triesare unchanged.MAX_NUM_TRIES;MAX_NUM_TRIESand print one retry message per try.test_request_retry_cap_bounds_internal_callers, replacestest_retry_cap_bounds_internal_callers, which was removed from feat(core): expose aiohttp pool wait telemetry #3632._mock_global_client(added in feat: judge endpoint resiliency #2383) now takes the error to raise.request()callspytest.fail()once it is called more often than any test needs.pytest.fail()raises aBaseException, which the loop'sexcept Exceptiondoes not catch. So the test fails at once, even if the loop never sleeps.test_explicit_transport_attempt_cap_disables_request_retryandtest_request_caps_generic_errors_at_the_lower_attempt_limit. Before, if the generic branch ignored_max_num_tries, the first test hung, sleeping a real 0.5 s per retry.No caller in this repo sets both
_internal=Trueand_max_connection_retriestoday:ServerClient, the simple agent's direct tool calls to Resources servers (tool_access), the Terminus 2 sandboxed agent's model client (NeMoGymAsyncOpenAI(internal=True)), the OpenHands capture route, and the LiteLLM version check.endpoint_fileuses a default of 8._max_num_triesonly whenupstream_max_num_triesormodel_server_transport_max_attemptsis set. Neither passes_max_connection_retries, so neither changes.Related:
_max_num_triesand counts tries on that path.ServerDisconnectedErrorandClientOSErrorbranches, which this PR does not change.Validation
All runs used an activated venv from
uv sync --extra dev --extra sandbox --extra openshell --extra telemetry --extra mlflow --extra wandb(the extras infull-test-suite.yml). Every installed package matchesuv.lock(192 packages, including aiohttp 3.14.4, nemo-lens 0.2.0+b0f977d, and pytest 9.0.3).pytest tests/unit_tests/test_server_utils.py responses_api_agents/remote_agent/tests/test_app.py tests/unit_tests/telemetry/: 465 passed.test_request_retry_cap_bounds_internal_callersfails in under a second withFailed: retry loop did not stopinstead of hanging. It fails the same way when the retry sleep is also removed.test_server_utils.pytook about 3 s, and none hung:MAX_NUM_TRIES;MAX_NUM_TRIESraise is removed;_max_num_triesattempts;_max_num_tries;_internalor_max_connection_retries.pytest -n 16 tests/unit_tests responses_api_agents/remote_agent/tests: 8089 passed, 5 skipped. The per-test results matchmainat a3cf403 (8085 passed, 5 skipped). The 4 extra results are the new tests, with the cap test run twice (tracing off and on).main(feat(core): run Gym without Ray installed #4300), which changes no package versions.pre-commit run --all-files: passed.Rollouts
N/A. This changes a retry counter in the shared HTTP helper. No caller in this repo changes behavior, and no model, agent, environment, or verifier logic is involved.
Compatibility and benchmark impact
None for callers in this repo. A caller that sets
_internal=Trueand_max_connection_retriesto 2 or more, without_max_num_tries, now stops after that many tries on errors that reach the genericexcept Exceptionbranch, including timeouts, instead of retrying forever. This includes code outside this repo that usesNeMoGymAsyncOpenAI(internal=True, max_connection_retries=N).ServerDisconnectedErrorandClientOSErrorkeep their own count, as before.Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).