Skip to content

fix(vllm_model): keep a rollout's calls on one vLLM endpoint - #4262

Closed
cmunley1 wants to merge 1 commit into
mainfrom
cmunley1/vllm-model-rollout-affinity
Closed

cmunley1 wants to merge 1 commit into
mainfrom
cmunley1/vllm-model-rollout-affinity

Conversation

@cmunley1

@cmunley1 cmunley1 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

vllm_model._resolve_client picks the endpoint by hashing the session id, which comes from a cookie. Harness CLIs (Claude Code, OpenCode and other harness_agent / opencode_sandboxed_agent harnesses) never send the cookie back. Each call gets a fresh uuid4 session, lands on a random endpoint, and re-prefills its full context with a cold prefix cache. Only matters with more than one endpoint behind vllm_model.

Fix

These calls already carry /ng-rollout/<rollout_id>/ in their URL, and _CaptureMiddleware strips it before routing.

  • _CaptureMiddleware keeps the rollout id in the ASGI scope as ng_rollout_id.
  • vllm_model._resolve_client routes by rollout:<id> when present, else by the session as before.
  • route_around_failing_endpoints failover is unchanged and sees a stable key.
  • _session_id_to_client now grows per rollout instead of per call for cookie-less clients.

Measured

48 endpoints, Claude Code subagent RL (Lightning 30B-A3B, TP4, 256k context), same config before and after:

before after
output tok/s 22.1k 35.2k
call latency p50 / p90 26.7 s / 424 s 7.2 s / 80 s
errors 0 0

After the change, the busiest of 48 servers peaked at 49 of 64 running sequences, so none hit max_num_seqs. Main agent and subagents of a rollout share an endpoint. Heavy swarms put more sequences on one endpoint, so watch max_num_seqs.

Tests

  • same rollout, fresh sessions: one endpoint, one cache entry
  • 1,536 rollouts spread over 48 endpoints
  • no rollout id: unchanged session routing
  • failover moves a rollout off a failing endpoint and keeps it there
  • middleware exposes the id only for prefixed requests

vllm_model/tests/test_app.py and tests/unit_tests/test_base_responses_api_model.py: 300 passed.

Not covered

Calls without a rollout prefix (for example evals with no rollout id) still scatter.

Harness CLIs never send the session cookie back, so each call got a fresh
session and a random endpoint with a cold prefix cache. Route by the
/ng-rollout/<id> rollout id when present and keep session routing otherwise.

Signed-off-by: Christian Munley <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 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.

@ananthsub

Copy link
Copy Markdown
Contributor

fyi @wprazuch / @cmunley1 for overlap with #4462

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]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:model Model servers, inference providers, and model adapters bug Something isn't working labels Oct 20, 2026
@cmunley1

Copy link
Copy Markdown
Contributor Author

Closing: main already keeps every call of a rollout on one endpoint. vllm_model routes on the rollout id (current_rollout_id() or the session), and main's tests cover it (test_calls_of_one_rollout_share_an_endpoint_whatever_their_session, test_rollouts_spread_across_endpoints).

@cmunley1 cmunley1 closed this Oct 24, 2026
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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants