Skip to content

feat(cli): report each entry's resources and agent servers by one rule in gym list environments - #5446

Merged
yuhezhang-ai merged 8 commits into
mainfrom
yuhez/list-environments-json-servers
Nov 7, 2026
Merged

yuhezhang-ai merged 8 commits into
mainfrom
yuhez/list-environments-json-servers

Conversation

@yuhezhang-ai

@yuhezhang-ai yuhezhang-ai commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #5392; merge that first. This PR targets its branch so the diff contains only the server-name changes. Supports #3946; no separate issue is needed for this focused catalog improvement.

What and why

gym list environments --json now includes resources_server and agent_server. List and inspect use the same selection rule:

  1. Use the manifest's declared implementation names when a manifest exists.
  2. Otherwise resolve the config's server wiring. This still needs an unambiguous dataset owner and agent, but skips manifest-only dataset checks such as requiring a benchmark preparation script. For agent-owned datasets, follow the taskset route, the explicit flat-row route (environment_routing_mode: legacy with environment_server_name), or the unique Environment Server fronting the agent. Session-based Environment Servers supply their resources binding; legacy_agent relays use the agent's binding. Resource-owned datasets retain their selected owner.
  3. If resolution fails, fall back to implementation names written directly in the file, independently for each server kind and only when exactly one distinct name is present.
  4. Unknown names are null in list JSON and omitted from inspect output. Successfully resolved but ambiguous, conflicting, or unbound resources routes stay unknown without falling back to raw names.

For example, a session-based Environment Server using demo reports demo even if its agent has no resources binding or still names another server. Conversely, a malformed policy_model: {port: 12345} no longer aborts the entire catalog: the lookup records a debug traceback and uses the existing fallback. Lookup catches ordinary exceptions at this best-effort boundary; manifest validation keeps its existing errors. Discovery and inspection share defensive dataset-shape handling.

The lookup suppresses its own almost-server banner and rejects invalid server blocks even with error_on_almost_servers: false. Other parser compatibility warnings and metadata fallback diagnostics can still go to stderr; the docstrings now state that accurately.

Compatibility

  • The two JSON keys contain implementation names such as simple_agent, unlike agent_name in gym list benchmarks --json, which identifies a config instance.
  • Inspect keeps its existing keys, but can intentionally report fewer names: resources_servers/legal_agent_bench no longer reports the resources server its agent does not bind; when swe_together/opencode falls back to raw names, its two distinct agent implementations leave the agent unknown instead of choosing the first.
  • Configs without a supported, unambiguous dataset owner, including the legacy biomnibench_da and labbench2_pdf environment configs, still fall back to names written in the file.
  • Resolving configs without manifests adds work to JSON listing. Yu's measurement at 56e819ec96d0edfd6bd36dec1f8fda92c0d56da8 found approximately five extra CPU seconds over 468 entries, roughly doubling that listing's CPU time. This is the reviewer's measurement of that revision, not a fresh benchmark of the current head.
  • Table output and lightweight discovery are unchanged. Python callers of discover_environment_catalog() still receive None for both server attributes on entries without manifests; CLI resolution does not mutate those objects.
  • The internal read_environment_details helper returns an agents list instead of the first agent, preserving ambiguity. Manifest composition, explicit dataset_owner handling, rollout execution, and benchmark results are unchanged.

Validation

Validation at 6f548db19da17f049ad92148f117a33ce46b0b07 with Python 3.13.14 and locked development dependencies:

pytest tests/unit_tests/cli/test_cli.py tests/unit_tests/cli/test_cli_main.py \
  tests/unit_tests/environment/test_registry.py \
  tests/unit_tests/environment/test_environment_validation.py \
  tests/unit_tests/environment/test_environment_manifest.py \
  tests/unit_tests/environment/test_environment_scaffold.py \
  tests/unit_tests/environment/test_environment_publication.py \
  tests/unit_tests/test_moved_paths.py tests/unit_tests/test_public_api.py \
  tests/unit_tests/test_public_api_facades.py tests/unit_tests/test_import_linter_coverage.py \
  tests/unit_tests/config/test_environment_resources_binding.py \
  -q -o addopts='' -o log_cli=false
  • 1,770 passed, no failures or skips; three existing warnings. Scheduler step 21336149.3 completed with exit 0:0.
  • The focused regression selection produced 4 failures and 17 passes against the unchanged implementation at 328ec09e297fc1aba321039b99f5d04ca9ee5bcb; all 21 passed after the fix. This covers StopIteration, home-expansion RuntimeError, and recursive-alias RecursionError, debug traceback retention, and unchanged strict manifest errors. The list/inspect integration regression includes healthy and malformed entries together.
  • Added coverage for environments fronting another agent; explicit routes to the wrong agent, a missing instance, or a non-environment server; taskset-only mode with flat rows; a routed dataset followed by an unroutable one; duplicate/distinct resources implementation names in both catalog views; and unreferenced invalid server blocks with either value of error_on_almost_servers.
  • pre-commit run --all-files: passed. The guardwords hook skipped its private scan because the private catalog was unavailable locally.
  • cd fern && npm run check -- --warnings: zero errors; one warning that authenticated missing-redirect checking was skipped because no Fern login was available.

Rollout evidence: N/A. This changes CLI/catalog error handling and metadata only; no agent execution, model inference, or verifier behavior changes.

@yuhezhang-ai yuhezhang-ai added feature New capabilities, enhancements, or enablement work area:cli Command-line interfaces and user-facing command behavior labels Nov 2, 2026
@copy-pr-bot

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

@yuhezhang-ai
yuhezhang-ai added this pull request to stack #5448 November 2, 2026 16:35
@yuhezhang-ai yuhezhang-ai changed the title feat(cli): include resources and agent servers in gym list environments --json feat(cli): report each entry's resources and agent servers by one rule in gym list environments Nov 2, 2026
@yuhezhang-ai

Copy link
Copy Markdown
Contributor Author

/ok to test 3378284

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-paths branch from 8379ebf to f649fd7 Compare November 4, 2026 03:22
@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-servers branch from 18a0415 to 66caea9 Compare November 4, 2026 03:22
@yuhezhang-ai
yuhezhang-ai marked this pull request as ready for review November 4, 2026 03:33

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE

Server-name lookup can omit or misidentify the Resources Server for sessions-based workloads. The inline RISK describes the failure and required correction.

I reviewed all seven changed files and traced the affected CLI, discovery, parser, manifest-validation, and runtime-routing contracts. This was a static review; I couldn't execute tests.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

Comment thread nemo_gym/environment/validation.py Resolved
@yuhezhang-ai

Copy link
Copy Markdown
Contributor Author

/ok to test 56e819e

@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.

Stacked on #5392. Reports each entry's resources_server and agent_server in gym list environments --json and the inspect view by one selection rule (manifest names, then resolved config wiring, then names written in the file, then unknown), and follows the Environment Server's resources binding that the earlier automated review asked for.

The route-aware lookup holds up on what we probed: on the 468 real catalog entries it returns the same names as the previous head, and the new cases the body says fail on 66caea93 do fail there (11 of 13). No scoring, verifier or rollout path is touched. One robustness gap, one docstring/behavior mismatch, missing tests and a compatibility note are inline.

Optional, for the author to weigh:

  • The lookup parses configs strictly, so 38 of the 256 entries without a manifest fall back to file names, and one entry's JSON depends on the caller's environment (hle_diamond/opencode_reference reports equivalence_llm_judge only when TAVILY_API_KEY and POLICY_API_KEY are set). read_config_metadata already has a listing-tolerant parser (_parse_no_environment_tolerating_unset_values, discovery.py:79-105); in a scratch prototype, reusing it cut the fallbacks to 22 and made the output independent of those variables. The fallback is the documented rule, so this is a suggestion, not a request.
  • _catalog_resources_server mirrors the route precedence in rollout_collection.py without a shared helper, and spells out "legacy_agent", "environment_servers" and "resources_servers" where global_config.py has constants. The tests requested inline are the cheapest guard against the two drifting.

Process: the red preview check fails parsing the generated judge_profile.mdx, which this PR does not touch (fixed on main by #5602), and the non-blocking harness-conformance failures (kilocode, Publish check) are unrelated.

Overall: ship with care.

Comment thread nemo_gym/environment/validation.py Outdated
try:
wiring = _resolve_config_wiring(config_path, parser=_ServerLookupParser())
resources_server = _catalog_resources_server(wiring)
except _CONFIG_LOOKUP_ERRORS:

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.

validation.py:438

This allowlist lets some odd configs abort the whole gym list environments --json and the inspect view, which listed them fine before this PR (the body says malformed input no longer aborts the listing). At this head, a config with policy_model: {port: 12345} raises StopIteration from the dummy-model cleanup (global_config.py:1599; the lookup merges a dummy policy_model that read_config_metadata only adds when the file has none), results_dir: "~nosuchuser/out" raises RuntimeError from expanduser, and a recursive YAML alias raises RecursionError. Could you catch Exception here, as read_config_metadata and read_environment_details already do, and log it at debug level so a bug in the new routing code does not silently turn into the file-name fallback? A regression case with the policy_model shape would pin it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6f548db. The best-effort catalog boundary now catches Exception around the complete server-name lookup, records the config path and traceback at debug level, and returns None for the existing fallback. Manifest composition still raises the original errors.

Added regressions for the policy_model port shape, failed home expansion, and a recursive YAML alias, plus list/inspect coverage containing healthy and malformed entries together. Before the fix the focused selection had 4 failures and 17 passes; afterward all 21 passed. The broader CLI/environment/manifest/public API suite passed all 1,770 tests.

class _ServerLookupParser(GlobalConfigDictParser):
"""Fails on an almost-server without printing the run-time warning, since a lookup starts nothing."""

def detect_and_report_almost_servers(self, global_config_dict: DictConfig) -> list[tuple[str, ValidationError]]:

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.

validation.py:203

Could you correct the resolve_config_servers docstring ("nothing is printed") or silence the rest of the lookup's output? This subclass skips only the almost-server banner: a config whose agent has no Environment Server still prints the ~25-line "DEPRECATED: agents without an environment server" warning (global_config.py:1584), and the file-name fallback re-parses through read_config_metadata, which prints the almost-server banner again. It also raises on almost-servers when the config sets error_on_almost_servers: false, so such a config always falls back to file names. No shipped catalog entry prints anything today (stderr is empty over all 468), so this only affects custom or older-style configs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 6f548db using the docstring correction option. Removed the blanket “nothing is printed” claim and documented that parser compatibility warnings and metadata fallback can still emit stderr diagnostics. The lookup deliberately rejects invalid server blocks even with error_on_almost_servers: false, rather than selecting from only the valid subset.

Added tests for an unreferenced invalid block with both true and false: lookup returns None without its almost-server banner. Runtime validation and warning behavior are unchanged.

assert resolve_config_servers(config_path) == (expected, "simple_agent")


def test_resolve_config_servers_does_not_guess_between_environment_routes(tmp_path: Path) -> None:

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.

test_environment_validation.py:202

Could you add cases for the routing branches that no test pins? Mutating each of these leaves every test in test_environment_validation.py, test_cli.py and test_registry.py green: an Environment Server that fronts only another agent, next to the real one (validation.py:386-390 and the guard at :408), environment_routing_mode: taskset with a flat dataset (:400, expecting unknown resources), the file-name fallback when the file names two different resources servers (None) or the same one twice (env.py:1034-1038), and an unreferenced almost-server (_ServerLookupParser, expecting None). A legacy route that names a missing or non-environment server, and a routed dataset next to an unroutable one, are worth adding if cheap.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 6f548db: an unrelated environment fronting another agent; an explicit route to that wrong agent, a missing instance, or a resources server; taskset-only mode with flat rows; a routed taskset followed by an unroutable flat dataset; and an unreferenced invalid server with either error_on_almost_servers value. The raw-name fallback test now covers one, repeated, and distinct resources implementation names alongside the existing agent cases, for both list JSON and inspect JSON.

The focused selection passes all 21 cases, and the broader validation passes all 1,770 tests. The tests assert the selected implementation names or unknown results, including retaining the known agent when resources are unresolved.

gym list environments --json | jq '.[].name'
```

The inspect view and `--json` report the resources server and agent an entry runs with. An entry with a manifest takes them from the manifest. Otherwise Gym resolves which servers the config wires, without the dataset rules a manifest adds. For agent-owned datasets, this follows the taskset route, explicit flat-row route, or unique Environment Server fronting the agent. Session-based Environment Servers supply their own resources binding; `legacy_agent` relays use the agent's binding. Ambiguous routes or routes selecting different resources leave the resources field unknown. Resource-owned datasets retain their selected owner. When the config does not resolve on its own, because it needs values that only a run supplies, such as a judge model server, or because it is malformed, Gym uses the names written in the config file, each only when the file names exactly one. A server that none of these identifies is omitted from the inspect view and `null` in `--json`.

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.

cli-commands.mdx:269

Could you tighten this paragraph and the compatibility note? "Without the dataset rules a manifest adds" is too strong, because resolution still needs exactly one dataset-bearing agent (so biomnibench_da and labbench2_pdf fall back to file names); "explicit flat-row route" means environment_routing_mode: legacy with environment_server_name; and the values are implementation names (simple_agent), unlike the instance name in gym list benchmarks --json's agent_name. Two entries show less than before this PR and are not in the compatibility section: resources_servers/legal_agent_bench no longer reports its resources server (an unbound agent behind a legacy_agent relay, which looks intended) and swe_together/opencode no longer reports an agent (it has two). Also worth stating there: the --json listing takes about 5 s more CPU over the full catalog (roughly double), and Python callers of discover_environment_catalog() still get None for resources_server/agent_server on entries without a manifest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the CLI reference and PR compatibility section in 6f548db. They now state the remaining dataset-owner/agent requirement, spell out environment_routing_mode: legacy with environment_server_name, distinguish implementation names from benchmark agent_name instance names, and describe the Python discovery API boundary.

The compatibility section explicitly records the omitted legal_agent_bench resources binding and the ambiguous swe_together/opencode agent during raw-name fallback. It also attributes the approximately five extra CPU seconds over 468 entries to your measurement at 56e819e, rather than presenting it as a fresh measurement of this head. Fern validation passed with zero errors; only the unauthenticated redirect check was skipped.

@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-paths branch from c103d1e to 3dd1833 Compare November 4, 2026 20:39
@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-servers branch from 56e819e to 3c7ec0c Compare November 4, 2026 20:39
@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-paths branch from 3dd1833 to 763a10b Compare November 4, 2026 23:20
@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-servers branch from 3c7ec0c to 328ec09 Compare November 4, 2026 23:20
yuhezhang-ai and others added 7 commits November 6, 2026 17:40
The inspect view read servers from the config file's text, which misses a
resources server the file inherits (aime24 showed none instead of
math_with_judge), while --json resolved the config. Both views now take
the manifest's servers, else the resolved config's, else the names the
config file states when it states exactly one of a kind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yuhe Zhang <[email protected]>
Looking up an entry's servers went through the manifest resolver, which
also converts datasets to manifest form. A benchmark without
prepare_script, which Gym runs, raised a pydantic ValidationError, and a
malformed config raised OmegaConf or decoding errors; neither was caught,
so one such entry stopped gym list environments --json and its inspect
view. The lookup now resolves only the wiring, falls back on any error a
config file can cause, and fails on an almost-server without printing the
run-time warning. Manifest validation is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yuhe Zhang <[email protected]>
A field of the wrong type, such as `config_paths: 1`, `_inherit_from: 1` or a
server block that is a string, made Gym's config parser raise TypeError or
AttributeError, which the server lookup did not catch. An agent with
`datasets: 1` made the scan of the file's server names raise while iterating
the number. Either stopped `gym list environments --json` for every entry.

The lookup now treats those errors as "does not resolve", and the scan skips
a datasets value that is not a list, as its docstring promises.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yuhe Zhang <[email protected]>
… list

Discovery looped over an agent's `datasets` in each resources-server config to
decide whether it is runnable. A config with `datasets: 1` raised TypeError
there and stopped catalog discovery, so every listing failed. This has been on
main since #2443; the listing tests in this PR now cover it.

Discovery and the file scan behind the inspect view now share one helper that
returns the dataset blocks a server declares, and none when `datasets` is not a
list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yuhe Zhang <[email protected]>
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 6, 2026
@yuhezhang-ai
yuhezhang-ai force-pushed the yuhez/list-environments-json-servers branch from 6f548db to 165aa3d Compare November 6, 2026 22:49
@yuhezhang-ai
yuhezhang-ai requested a review from a team as a code owner November 6, 2026 22:49
@yuhezhang-ai
yuhezhang-ai removed this pull request from stack #5448 November 6, 2026 22:50
@yuhezhang-ai
yuhezhang-ai changed the base branch from yuhez/list-environments-json-paths to main November 6, 2026 22:50
@yuhezhang-ai

Copy link
Copy Markdown
Contributor Author

/ok to test 165aa3d

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 6, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 7, 2026
@yuhezhang-ai
yuhezhang-ai added this pull request to the merge queue Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit 69a5149 Nov 7, 2026
67 checks passed
@yuhezhang-ai
yuhezhang-ai deleted the yuhez/list-environments-json-servers branch November 7, 2026 06:49
rimashahbazyan added a commit that referenced this pull request Nov 9, 2026
…ools

Brings in 42 commits from main (bd6f5f0..363af5e), including #5709
(centralized resources lifecycle and verification ownership), #5551 (MCP
tools of extra tool servers granted to session agents), #5763 (HLE agent
loop bounded with max_steps 1) and #5446 (gym list environments).

Only README.md overlapped textually; the environment table was
regenerated with scripts/update_env_list.py and the Hle Web Tools row is
preserved.

Signed-off-by: Rima Shahbazyan <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 165aa3d3 Deployed Nov 6, 2026 by copy-pr-bot[bot] via release / finalize / notify #10769
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 feature New capabilities, enhancements, or enablement work 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