Skip to content

fix(server-runtime): set up Ray server venvs on every Ray node - #6336

Open
puneeshkhanna wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
puneeshkhanna:fix/server-venvs-on-every-ray-node
Open

puneeshkhanna wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
puneeshkhanna:fix/server-venvs-on-every-ray-node

Conversation

@puneeshkhanna

@puneeshkhanna puneeshkhanna commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Servers that declare ray_enabled = True run Ray tasks with their own venv's interpreter (py_executable=sys.executable), but the supervisor only sets up that venv on the node where gym runs. On a multi-node Ray cluster with node-local venvs, tasks scheduled on other nodes fail because the interpreter does not exist there.

Before spawning servers, run each Ray server's venv setup on every other alive Ray node (one zero-CPU task per node, pinned with node affinity). Nodes that share the venv's storage with the head node are detected with a probe file and skipped. The step is a no-op on a single-node cluster and is bounded by server_spinup_timeout_seconds.

What does this PR do?

Servers that declare ray_enabled = True (e.g. harbor_agent, swe_agents, mini_swe_agent) run Ray tasks with their own venv's interpreter (py_executable=sys.executable), but Gym sets that venv up only on the node gym runs on. On a multi-node Ray cluster with node-local venvs, tasks scheduled on other nodes fail because the interpreter is missing there.

This adds an opt-in step, enabled with setup_venvs_on_every_ray_node: true (default off). Before spawning servers, ServerSupervisor sets up each Ray server's venv on every other alive Ray node:

  • One task per node, pinned with node affinity and requesting no CPUs from Ray.
  • A node that can see a shared-storage marker written next to the venv shares that storage, so it skips the venv. If the marker can't be written (read-only prebuilt venvs), each node's own setup check decides.
  • Only UV_*, NEMO_GYM_ALLOW_PRERELEASE, NEMO_GYM_EXTRA_ROOTS and NEMO_GYM_ALLOWED_COMPONENT_ROOTS are forwarded, as a task argument (not runtime_env, which Ray logs).
  • The setup time counts against server_spinup_timeout_seconds. A timeout raises ServerSpinupTimeoutError and a failed node raises ServerStartFailedError, both naming the nodes and servers; the readiness timeout reports how much of the limit the setup used.
  • Nodes that can no longer run tasks (TaskUnschedulableError, e.g. draining) are skipped. Each node writes its own setup log (<server>@<node ip>).

Docs: the requirements (same absolute paths on every node, uv on the Ray processes' PATH) are on the "Scale CPU work with Ray" page, and the troubleshooting page notes that the setup counts against the spin-up timeout.

No linked issue; found running harbor_agent on a multi-node KubeRay cluster with node-local venvs.

Validation

  • Unit tests in tests/unit_tests/server_runtime/supervisor/test_server_venvs_on_ray_nodes.py (fake ray module) and tests/unit_tests/cli/test_cli.py (shared budget, key gating); each fails when the line it covers is reverted.
  • Two-node KubeRay smoke (CPU head + GPU worker, Ray 2.55.1):
    • node-local uv_venv_dir: the venv is built on the worker, and a Ray task pinned there runs with that venv's interpreter;
    • shared uv_venv_dir: the worker skips setup and the markers are removed;
    • an uninstallable requirement raises ServerStartFailedError naming the worker's IP;
    • a NEMO_GYM_* token set on the driver appears in no Ray log on either node; the worker's runtime_env_agent.log shows only py_executable.
  • ruff check / ruff format --check on the changed files.

Rollouts

N/A: only server startup changes, and only with the new key set. Agent, verifier and scoring behavior are unchanged.

Compatibility and benchmark impact

None by default: setup_venvs_on_every_ray_node defaults to false, and startup is then unchanged. With it set, startup additionally sets up Ray servers' venvs on the other Ray nodes alive at startup (nodes that join later are not covered), within server_spinup_timeout_seconds.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 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.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Nov 18, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:core Shared APIs, servers, telemetry, health, and registries needs-review PR is ready for code review and waiting on a reviewer labels Nov 18, 2026
@ananthsub

Copy link
Copy Markdown
Contributor

Thanks for tracking this down. The cross-node interpreter gap is real for multi-node Ray clusters whose venvs live on node-local storage.

The main decision is scope. As written, the step runs on every start, for every Ray-enabled server, on every other node, and nothing turns it off. That changes startup for setups that work on main today, including NeMo RL's, which bakes venvs into its image or keeps them on shared storage (see the comment on the call site in _start). I'd make the step opt-in with a config key that defaults to off. The default path then stays exactly as it is on main, and clusters with node-local venvs turn it on.

Before merge, the step also needs to:

  • keep forwarded variables out of runtime_env, which Ray writes to every node's logs;
  • tolerate read-only prebuilt venvs;
  • fail with an error that names the node, the server, and the timeout key;
  • come with unit tests.

A fake ray module covers both functions without a cluster. Each of these has an inline comment with a concrete fix.

Servers that declare `ray_enabled = True` run Ray tasks with their own venv's
interpreter (`py_executable=sys.executable`), but the supervisor only sets up
that venv on the node where `gym` runs. On a multi-node Ray cluster with
node-local venvs, tasks scheduled on other nodes fail because the interpreter
does not exist there.

Before spawning servers, run each Ray server's venv setup on every other alive
Ray node (one task per node, pinned with node affinity and requesting no
CPUs from Ray, so nodes with all CPUs reserved still run it). Nodes that
share the venv's storage with the head node are detected with a probe file and
skipped. The step is a no-op on a single-node cluster and is bounded by
`server_spinup_timeout_seconds`.

Signed-off-by: Puneesh Khanna <[email protected]>
…review

- Opt-in via `setup_venvs_on_every_ray_node` (default off), so default
  startup is unchanged.
- Pass forwarded env vars (UV_* and three NEMO_GYM_* names) as a task
  argument instead of runtime_env, which Ray logs.
- Tolerate read-only venv storage; rename the probe file to a
  shared-storage marker and ignore it in git.
- Raise ServerSpinupTimeoutError / ServerStartFailedError naming the nodes
  and servers; the setup time counts against server_spinup_timeout_seconds.
- Skip nodes that can no longer run tasks; per-node setup log names.
- Unit tests with a fake ray module; document the requirements.

Signed-off-by: Puneesh Khanna <[email protected]>
@puneeshkhanna
puneeshkhanna force-pushed the fix/server-venvs-on-every-ray-node branch from dc0482d to cdc8c71 Compare November 19, 2026 11:46
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 19, 2026
@puneeshkhanna

Copy link
Copy Markdown
Contributor Author

@ananthsub - All points addressed in cdc8c71:

  • Opt-in via setup_venvs_on_every_ray_node (default off); default startup is unchanged.
  • Forwarded vars (UV_*, NEMO_GYM_ALLOW_PRERELEASE, NEMO_GYM_EXTRA_ROOTS,
  • NEMO_GYM_ALLOWED_COMPONENT_ROOTS) go as a task argument, not runtime_env.
  • An unwritable marker (read-only venvs) is skipped; renamed to a shared-storage marker and added to .gitignore.
  • Timeout → ServerSpinupTimeoutError, failed node → ServerStartFailedError, both naming the nodes, servers and key; setup time is subtracted from the readiness budget; troubleshooting doc updated.
  • Nodes failing with TaskUnschedulableError are skipped; per-node log names (server@node_ip).
  • Fake-ray unit tests, pragmas removed; requirements documented on the Ray page.

…tup failures

- The readiness timeout says how long venv setup on other Ray nodes took
  from the budget.
- Tests: the readiness timeout counts that setup time; a failed per-node
  setup command names the server and node; the per-node step runs only
  with setup_venvs_on_every_ray_node set.

Signed-off-by: Puneesh Khanna <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test 0d323d9

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 20, 2026 07:09
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

ananthsub
ananthsub previously approved these changes Nov 20, 2026
@ananthsub

Copy link
Copy Markdown
Contributor

please fix the linting error so we can merge

@puneeshkhanna

Copy link
Copy Markdown
Contributor Author

please fix the linting error so we can merge

@ananthsub - Can you point to the specific lint error ?. Failing check seems "Harness conformance (non-blocking)", whose failures are in the claude_code, terminus_2_sandboxed and miniswe_sandboxed probes. That job fails the same way on main's latest CICD run (1883e25)

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 23, 2026
yaoyu-33
yaoyu-33 previously approved these changes Nov 23, 2026

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

harbor_agent is deprecated. For new Harbor workloads, please use the harbor environment server.

Which benchmark or task set, agent harness, and sandbox backend are you running on the KubeRay cluster? Is there anything in that setup that you still need harbor_agent for?

One configuration detail for the current run: use an absolute uv_venv_dir. If the driver and worker start in different directories, a relative path can install the venv somewhere other than where the task expects its interpreter.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 23, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 25, 2026
…-every-ray-node

Signed-off-by: Puneesh Khanna <[email protected]>

# Conflicts:
#	nemo_gym/server_runtime/supervisor/server_supervisor.py
@puneeshkhanna
puneeshkhanna dismissed stale reviews from yaoyu-33 and ananthsub via d9e330a November 27, 2026 10:09
@ffrujeri

Copy link
Copy Markdown
Contributor

/ok to test d9e330a

@nemo-pr-automation
nemo-pr-automation Bot requested review from a team November 30, 2026 14:49
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 30, 2026
@ffrujeri

ffrujeri commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@puneeshkhanna could you answer @yaoyu-33's questions from 2026-11-23: which benchmark or task set, agent harness and sandbox backend you run on the KubeRay cluster, and whether anything there still needs harbor_agent? Gym is moving servers off Ray (for example #6440), so the answer decides whether per-node venv setup is still needed, or whether the harbor environment server covers your case. CI is green at d9e330a.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working community-request Issue reported or requested by someone from the community needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants