Skip to content

fix(cli): check Environment Server configs in gym env validate - #5008

Merged
weijiac0619 merged 2 commits into
mainfrom
fix/validate-environment-server-configs
Oct 29, 2026
Merged

weijiac0619 merged 2 commits into
mainfrom
fix/validate-environment-server-configs

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Found while test-driving the harness onboarding guide on LangChain DeepAgents (#5003). The guide relies on gym env validate and gym env resolve before a real run, but neither checks an Environment Server block against its server's own config class. That check happens only in load_config_from_global_config, when gym env start launches the server, after the other servers are already up.

Reproduction on main: in resources_servers/reasoning_gym/configs/reasoning_gym_langchain_deepagents_agent_model_server.yaml, switch the legacy_agent block to single_agent_turn_legacy without adding its other fields. Before this PR:

$ gym env validate --config repro.yaml +policy_base_url=… +policy_api_key=… +policy_model_name=… +tavily_api_key=…
✓ Config is valid.

gym env start then failed at that server's launch with pydantic's SingleAgentTurnEnvironmentServerConfig … Field required. With this PR:

Error: Environment Server config is invalid, so `gym env start` would fail when the server launches.
'reasoning_gym_langchain_deepagents_agent_model_server_environment_server' (environment_servers/single_agent_turn_legacy/app.py) does not match SingleAgentTurnEnvironmentServerConfig:
  reasoning_gym_langchain_deepagents_agent_model_server_environment_server.environment_servers.single_agent_turn_legacy.cleanup_timeout_seconds: Field required
  reasoning_gym_langchain_deepagents_agent_model_server_environment_server.environment_servers.single_agent_turn_legacy.resources_server: Field required

(exit 1). Each line is the field's full path in the merged config, so it can be fixed in the YAML or with a ++ override. cleanup_timeout_seconds is reported too, because the launch would reject the block for it as well.

Changes

  • gym env validate (nemo_gym/cli/env.py): for each Environment Server, it imports the server's entrypoint, finds the config class of the server class the entrypoint calls run_webserver() on, and validates the block against it exactly as load_config_from_global_config does at launch. Every invalid field is reported, and the command exits 1 with EnvironmentServerConfigError, a new ConfigError.
  • Servers that don't import here. An entrypoint that fails to import in the gym environment (because its own venv has a package this one lacks) is not an error. Validation warns that it could not check that server and leaves the check to its launch.
  • gym env resolve still prints the config, since it is a debugging tool, and reports the same fields as a warning on stderr.
  • nemo_gym/server_utils.py: entrypoint_server_class_names() is factored out of entrypoint_class_flag(), so ray_enabled detection and this check use the same rule to find the launched class.
  • Docs: reference/cli-commands.mdx (validate and resolve) and a new troubleshooting entry, "Environment Server Config Does Not Match Its Server".

Why import instead of a static schema

Environment Servers ship with Gym, and all six shipped ones import in Gym's development environment, so the config class comes straight from the server's code. A copied or AST-derived schema would drift from it. Resources servers and agents are out of scope: their entrypoints pull in heavy, venv-only dependencies.

Coordination with #4952

#4952 makes SingleAgentTurnEnvironmentServerConfig.resources_server optional, so the server falls back to its agent's resources server. This check reads the config class from the server's code, so it follows that change without edits. With #4952's field change applied locally, the reproduction above (whose agent names reasoning_gym) passes validation, which matches the fallback. On main it still reports the field. The regression tests use only fields that stay required under #4952 (cleanup_timeout_seconds, plus a misspelled field), so they pass on both. #4952's other new check, that neither the server nor its agent names a resources server, runs in the server's model_post_init, which this offline check does not run.

Validation

  • tests/unit_tests/test_cli.py::TestValidate, 3 new tests against the real validate() parse path:

    • a single_agent_turn_legacy block missing cleanup_timeout_seconds and with a misspelled resources_tool_transport exits 1 and names both full field paths and the config class;
    • the complete block passes;
    • a local Environment Server whose entrypoint imports a package missing here passes, with the "could not check" warning.

    With the check disabled, the first and third fail.

  • Same TestValidate with feat(scripts): switch simple_agent relays to single_agent_turn_legacy #4952's resources_server: ResourcesServerRef | None = None applied locally: 5 passed.

  • Sweep over every shipped config with an environment_servers block (538 files, each with openai_model.yaml): 450 parse, and all 450 pass the new check, with no false positives and no server that fails to import. The other 88 fail to parse before reaching the check (missing secrets or interpolations, configs that need companion files), as they do on main.

  • Time: the check takes about 0.01 s in-process on the original reasoning_gym config. gym env validate on it takes about 4 s end to end.

  • pytest tests/unit_tests -n 8 (macOS): 10157 passed, 40 failed, 2 collection errors. Rerunning those 42 on unmodified main gives the same failures (OpenSandbox, Slurm launcher, wandb and telemetry imports in this local environment). The exceptions are two test_docker_compose.py cases that pass when run alone either way, and a test_harbor_package_store.py socket test that passes and fails on reruns of the same code. test_cli.py, test_cli_main.py and test_ray_opt_out.py, which cover entrypoint_class_flag, pass except test_memory_profiler_uses_spawned_server_metadata, which also fails on main here.

  • pre-commit run --all-files: clean. fern check: 0 errors.

Rollout evidence

N/A: this changes only offline config checks (gym env validate and gym env resolve). It does not change how servers launch or how episodes run. The CLI reproduction above uses the shipped DeepAgents config.

Compatibility

A config whose Environment Server block gym env start would reject now fails gym env validate (exit 1) instead of passing. gym env resolve keeps exit 0 and only adds a stderr warning. Valid configs are unaffected, as the sweep shows.

🤖 Generated with Claude Code

`gym env validate` and `gym env resolve` checked only type-level fields and
server references. An Environment Server block was checked against its
server's own config class only when `gym env start` launched that server,
after the other servers were up. A `single_agent_turn_legacy` block without
`resources_server` therefore passed validation and failed at launch.

Validate now imports each Environment Server entrypoint, takes the config
class of the server class it calls run_webserver() on, and validates the
block as load_config_from_global_config does at launch. It reports every
invalid field by its path in the merged config and exits 1. A server whose
entrypoint does not import in the gym environment gets a warning and is left
to its launch. `gym env resolve` still prints the config and reports the same
fields as a warning.

Because the schema comes from the server's own code, the check follows
changes such as #4952's optional resources_server without edits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

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

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test a9f1f31

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:cli Command-line interfaces and user-facing command behavior bug Something isn't working labels Oct 23, 2026
@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 28, 2026 22:21
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 2026
Skip top-level mappings without a recognized server type before indexing their contents. Cover validate and resolve with empty and nested-empty auxiliary overrides, including preservation in resolved YAML.

Validation: all four regression cases fail before the fix and pass after it. test_cli.py, test_cli_main.py and test_ray_opt_out.py: 445 passed; one Linux-procfs memory-profiler test fails on macOS, reproduced with the original PR code. pre-commit run --all-files passed. No model rollout needed for offline configuration handling.
Signed-off-by: yaoyu-33 <[email protected]>
@weijiac0619
weijiac0619 enabled auto-merge October 29, 2026 17:28
@weijiac0619

Copy link
Copy Markdown
Contributor

/ok to test 702016e

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit 6d48307 Oct 29, 2026
53 of 56 checks passed
@weijiac0619
weijiac0619 deleted the fix/validate-environment-server-configs branch October 29, 2026 22:40

This branch was previously deployed

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

Labels

area:cli Command-line interfaces and user-facing command behavior bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants