Skip to content

chore(server): declare Ray usage for environment servers and GPQA-Diamond - #4244

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/declare-ray-env-servers
Oct 8, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/declare-ray-env-servers

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What changed

Declare ray_enabled = False on three environment servers that never declared it: legacy_agent, single_agent_turn and single_agent_turn_legacy. nemo_user_sim already declared it. The Ray source audit in tests/unit_tests/test_ray_opt_out.py now also covers environment_servers/, so a new environment server without a declaration fails the audit.

GPQA-Diamond only inherited ray_enabled = False from the mcqa server. It now declares it on its own class, and its entry is removed from the audit's list of inherited declarations.

Why

#3728 declared Ray usage for resources, agent and model servers, but not for environment servers. Those servers still take the compatibility default, so each one connects to Ray and logs the migration warning even though none of them use Ray.

The GPQA-Diamond declaration supports the stacked follow-up, which decides whether the orchestrator starts Ray by reading each entrypoint's own source. A declaration inherited from another module isn't visible there, so it would count as using Ray.

Part of #3669.

Validation

  • pytest tests/unit_tests/test_ray_opt_out.py. With the declarations reverted, the extended audit names each undeclared environment server.
  • Each changed server's own tests, run from its directory: environment_servers/legacy_agent, environment_servers/single_agent_turn, environment_servers/single_agent_turn_legacy and resources_servers/gpqa_diamond.
  • pre-commit run scoped to the changed files.

Rollout evidence

N/A for model behavior. This only declares that these servers don't use Ray. It doesn't change prompts, model requests, trajectories, verification or rewards. The stacked PR includes a gym env start smoke run in which the legacy_agent environment server starts without connecting to Ray.

Compatibility

These servers stop connecting to Ray and stop logging the undeclared-Ray warning. None of them call Ray.

…mond

The environment servers under environment_servers/ were added without a
ray_enabled declaration, so they still connected to Ray and logged the
migration warning. None of them use Ray. Declare them non-Ray and extend
the source audit to environment_servers/ so new ones must declare it.

GPQA-Diamond inherited ray_enabled = False from the mcqa server. Declare
it on the class itself so the declaration is visible in its own source,
which a static pre-spawn check can read.

Part of #3669.

Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ananthsub
ananthsub enabled auto-merge October 8, 2026 16:59
@ananthsub
ananthsub added this pull request to the merge queue Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit 4137cf7 Oct 8, 2026
51 of 54 checks passed
@ananthsub
ananthsub deleted the ananthsub/declare-ray-env-servers branch October 8, 2026 17:32
ananthsub added a commit to jiwasawa/Gym that referenced this pull request Oct 8, 2026
…-NeMo#4245)

## What changed

`RunHelper.start()` now starts or joins Ray only when a configured
server may use it. Previously `RunHelper._start` called
`initialize_ray()` unconditionally. That started a local Ray cluster, or
connected to `ray_head_node_address`, even when every configured server
declared `ray_enabled = False`.

This applies to every path that launches servers through `RunHelper`:
- `gym env start`, including dry runs (`++dry_run=true`)
- `gym eval run` without `--no-serve`
- programs that import and call `RunHelper` themselves

How it works:

- **The check:** a new `entrypoint_may_use_ray()` in
`nemo_gym/server_utils.py` reads each server entrypoint's source without
importing it, because each server runs in its own venv. It finds the
classes the entrypoint calls `run_webserver()` on and reads their
`ray_enabled` declarations.
- **When it skips Ray:** only when every such class literally declares
`ray_enabled = False`.
- **When it still starts Ray:** when a declaration is missing,
inherited, computed, or on a class imported from another module, or when
the entrypoint can't be read. This matches the runtime default for
undeclared servers.
- **Logging:** when Ray starts, Gym prints which servers caused it. It
prints nothing when Ray is skipped.
- **Refactor:** the config walk moves into `_configured_servers()`, so
the Ray decision and the launch loop use the same server list.

## Why

A local Ray cluster costs host memory, an object store in `/dev/shm`,
background processes, and several seconds of startup. Starting one here
took about 9 seconds. Configs whose servers all opted out of Ray in
NVIDIA-NeMo#3622, NVIDIA-NeMo#3728 and NVIDIA-NeMo#4244 still paid that cost on every launch. That hurts
most in memory-limited containers and in image builds that use a dry run
to prebuild server venvs, which then had to stop the leftover cluster
with `ray stop`.

The check itself takes about 2 ms per server. Across all built-in
entrypoints the median is 1.8 ms and the slowest is 40 ms.

This is step 7 of NVIDIA-NeMo#3669.

## Guidance

**For server authors:** declare `ray_enabled` on the class your
entrypoint calls `run_webserver()` on, even when a parent class already
declares it. The check reads only that class's own source, so an
inherited `False` still starts Ray. To see why Ray started for a config,
look for the log line naming the servers that may use it.

**For programs that embed Gym:**
- **Gym starts Ray itself:** when your process hasn't initialized Ray
before calling `RunHelper.start()`, a config whose servers all declare
`ray_enabled = False` now runs without any Ray cluster.
- **Your process already runs Ray:** when Ray is initialized before
`RunHelper.start()`, for example inside a Ray actor, nothing changes.
`initialize_ray()` already returned immediately in that case, and Gym
never started a cluster of its own. Servers that use Ray still join the
cluster named by `ray_head_node_address`, and servers that declare
`ray_enabled = False` don't connect, as since NVIDIA-NeMo#3622.

**For image builds:** a dry run of a config whose servers all declare
`ray_enabled = False` no longer starts Ray, so a following `ray stop` is
unnecessary. It's harmless to keep as a guard for configs that include
servers that use Ray.

## Validation

- `pytest tests/unit_tests/test_cli.py
tests/unit_tests/test_server_utils.py
tests/unit_tests/test_ray_opt_out.py
tests/unit_tests/test_cli_endpoint_readiness.py
tests/unit_tests/h2_ping_sidecar`, rerun after rebasing onto the HTTP/2
ping sidecar change (NVIDIA-NeMo#4079).
- **New tests:**
- the source check, covering declared, undeclared, inherited, imported,
multiple-class, missing and unparseable entrypoints;
- a test that every built-in entrypoint's result matches the audited
declarations;
- a `RunHelper` test that Ray is skipped for `False` and started for
`True` or undeclared. The skip case fails on the previous code.
- `pre-commit run` scoped to the changed files.

## Rollout evidence

**Smoke run:**

```
gym env start "+config_paths=[resources_servers/example_single_tool_call/configs/example_single_tool_call.yaml,responses_api_models/openai_model/configs/openai_model.yaml]"
```

- Gym did not start or join a Ray cluster.
- `gym env status` reported all four servers healthy: the resources
server, the simple agent, the legacy agent environment server and the
OpenAI model server.
- No new `raylet` or `gcs_server` processes appeared.
- No server logged the undeclared-Ray warning.

No model requests were sent. This change only decides whether Ray
starts, so it can't affect prompts, trajectories, verification or
rewards.

## Compatibility

- **Configs with any Ray-backed or undeclared server:** unchanged. Ray
starts or connects exactly as before.
- **Configs whose servers all declare `ray_enabled = False`:** Gym
doesn't start a local Ray cluster. If `ray_head_node_address` is set,
the `gym` process no longer connects to it, since none of the servers
use Ray. A process that already initialized Ray before calling
`RunHelper` is unaffected.
- **A subclass that only inherits `ray_enabled = False` from another
module:** still starts Ray until it declares the value on its own class.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
@linear-code linear-code Bot mentioned this pull request Nov 12, 2026
8 of 26 tasks

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants