Skip to content

feat(model): route sessions around failing engine endpoints - #3979

Merged
linj-glitch merged 2 commits into
mainfrom
alexandery/vllm-model-route-around-failing-endpoints
Oct 5, 2026
Merged

linj-glitch merged 2 commits into
mainfrom
alexandery/vllm-model-route-around-failing-endpoints

Conversation

@alexandery-nvidia

@alexandery-nvidia alexandery-nvidia commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The vLLM model server pins a session to one engine endpoint by a hash of its session id, for the whole run (_resolve_client). When that engine dies, its HTTP server can keep answering every call with a 500, so every session pinned to it fails every call until the run ends, and new sessions keep hashing onto it. In a training wave this means every rollout pinned to a dead engine spends its whole time budget on retries and scores nothing.

Three new settings, all defaulting to today's behavior:

  • route_around_failing_endpoints (default false). On, the server tracks each endpoint's consecutive 5xx and connection-error answers in _call_endpoint, the one place every engine call now goes through. A 4xx shows the engine alive and resets the count.
  • endpoint_failure_threshold (default 3). An endpoint that reaches it stops receiving sessions. The sessions pinned to it re-pin to a serving endpoint on their next call; the same digest picks among the serving endpoints, so the assignment stays a function of the session id and of which endpoints have failed, and new sessions spread over the serving endpoints only.
  • endpoint_retry_after_s (default 60). Once per interval one call is tried on the failed endpoint; claiming the trial restarts the interval so concurrent callers do not all land on it. A good answer puts the endpoint back in the pool, and a moved session returns to its own endpoint once it serves again.

The three keys are listed in configs/vllm_model.yaml with the other endpoint settings.

Issue

No issue filed; observed in multi-engine training runs where one engine process died mid-run while its HTTP front stayed up.

Validation

  • responses_api_models/vllm_model/tests/test_app.py: 184 passed, including seven new tests: a failing endpoint loses its sessions and takes no new ones, the gate off keeps today's pinning, a good answer resets the count, one trial call per retry interval (with a mocked clock), a moved session returns to its endpoint when it serves again, engine 5xx answers move a session through the real chat_completions path, and an engine 4xx does not count against its endpoint.
  • tests/unit_tests (the telemetry package and the opensandbox/sandbox_stop_retry/profiling tests excluded, which need optional dependencies not installed here): 6228 passed, 27 skipped; the one failure is the test_slurm_script case that needs a system pip.
  • pre-commit run --files <changed files>: clean.
  • Rollout evidence: validated live in a downstream fork training with OpenCode and Codex harnesses through this model server with eight engines. In a wave where three engines had died, the model server logged 36 failed calls with routing on, against 7724 failed calls in the same situation without it; the sessions re-pinned on their next call and the wave scored normally. Off by default, so existing runs are unaffected.

🤖 Generated with Claude Code

Maintainer validation

Reviewed deterministic session routing, failure thresholds, cooldown/recovery, default behavior, and capture integration against current main and the existing model-server contract. No blocking findings remain.

Validation: 221 focused tests passed; full pre-commit suite and git diff --check passed. Model plugin imports were pinned to this review checkout in the shared dependency environment. Additive main merges preserve the author commits and retain the current-main credential-redaction regression tests. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

The vLLM model server pins a session to one engine endpoint by a hash of
its session id, for the whole run. When that engine dies (its HTTP server
can keep answering with a 500 for every call) every session pinned to it
fails every call until the run ends, and new sessions keep hashing onto
it.

With route_around_failing_endpoints on, the server tracks each endpoint's
consecutive 5xx and connection-error answers. An endpoint that reaches
endpoint_failure_threshold stops receiving sessions: the sessions pinned
to it re-pin to a serving endpoint on their next call (the same digest
picks among the serving endpoints, so the assignment stays a function of
the session id and of which endpoints have failed), and new sessions
spread over the serving endpoints only. Once per endpoint_retry_after_s
one call is tried on the failed endpoint; a good answer puts it back in
the pool and a moved session returns to its own endpoint. A 4xx counts
as a live engine and resets the count. All three settings default to
today's behavior (off, 3, 60 s) and are listed in the example config.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Signed-off-by: Lin Jia <[email protected]>

# Conflicts:
#	responses_api_models/vllm_model/app.py
@linj-glitch linj-glitch changed the title feat(model): route sessions around an engine endpoint that keeps failing feat(model): route sessions around failing engine endpoints Oct 5, 2026
@linj-glitch linj-glitch added area:model Model servers, inference providers, and model adapters feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge labels Oct 5, 2026
@linj-glitch
linj-glitch marked this pull request as ready for review October 5, 2026 07:50

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed deterministic session routing, failure thresholds, cooldown/recovery, default behavior, and capture integration against current main and the existing model-server contract. No blocking findings remain.

Validation: 221 focused tests passed; full pre-commit suite and git diff --check passed. Model plugin imports were pinned to this review checkout in the shared dependency environment. Additive main merges preserve the author commits and retain the current-main credential-redaction regression tests. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test dd8a2e1

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37281186164

Merged via the queue into main with commit cce24a1 Oct 5, 2026
48 checks passed
@linj-glitch
linj-glitch deleted the alexandery/vllm-model-route-around-failing-endpoints branch October 5, 2026 08:14
khazic pushed a commit to khazic/Gym-lao that referenced this pull request Oct 13, 2026
…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]>

This branch was previously deployed

1 inactive deployment
public — dd8a2e18 Deployed Oct 5, 2026 by copy-pr-bot[bot] via release / finalize / notify #4269
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants