Skip to content

fix(scaffold): move a reused scorer's environment server with its agent - #4085

Merged
ananthsub merged 1 commit into
mainfrom
qiaochuz/fix_scaffold_reuse_env_server
Oct 8, 2026
Merged

ananthsub merged 1 commit into
mainfrom
qiaochuz/fix_scaffold_reuse_env_server

Conversation

@qiaochuz-nv

Copy link
Copy Markdown
Contributor

What does this PR do?

gym env init --reuse-verifier <scorer> now produces a workload that validates and runs when the scorer's config bundles an agent behind an environment server. Every shipped scorer that exports VERIFIER_FIXTURE does since #3724, so the documented reuse command in the New Environment guide failed for all of them:

gym env init --benchmark my_benchmark --profile custom-gym-verifier \
  --reuse-verifier example_single_tool_call --reward-range 0 1 --higher-is-better
gym env validate my_benchmark
# Error: In server instance 'example_single_tool_call_environment_server', field 'agent_server' references
# responses_api_agents/'example_single_tool_call_simple_agent', which is not defined in the merged config.

Cause

The scaffold derives the workload's agent with _inherit_from: <scorer>_simple_agent, which moves that agent to the new name. #3724 added <scorer>_environment_server to every shipped scorer config, naming the original agent, and made the scaffold write a fresh <name>_environment_server. After the move, the scorer's server named an agent that no longer existed.

Running the same repro against Gym before and after #3724 confirms the window: 65943edd (its parent) validates, and 016bb6b8 (#3724) fails. Every later commit through 325fb49d fails too. test_reuse_supports_a_bundled_default_agent did not catch it because its synthetic scorer has no environment server.

Fix

When the reused config has an environment server in front of its bundled agent, the scaffold moves that server with the agent. It inherits the server under the workload's name and points it at the renamed agent:

my_benchmark_agent:
  _inherit_from: example_single_tool_call_simple_agent
  ...
my_benchmark_environment_server:
  _inherit_from: example_single_tool_call_environment_server
  environment_servers:
    legacy_agent:
      agent_server:
        name: my_benchmark_agent

This is the shape the shipped benchmarks that reuse a scorer already use (for example benchmarks/aegis_v4_safety/config.yaml), and the INHERITED block in scripts/add_legacy_agent_environment_servers.py. Each agent ends up behind exactly one environment server, which rollout collection requires (AmbiguousEnvironmentServerError otherwise).

Two alternatives were tried and rejected:

  • Keep the fresh server and repoint the scorer's server as well. Static validation passes, but two servers then front one agent, so every agent-routed row fails at rollout time.
  • Repoint the scorer's server in place. Two workloads that reuse the same scorer in one run both edit that one server, and the second wins. The first agent is left without a server, so Gym generates a deprecated relay for it, or fails with error_on_agent_without_environment_server. Inheriting gives each workload its own server. This also applies to a workload named after its scorer: it now inherits under <name>_catalog_environment_server, mirroring the existing <name>_catalog_agent fallback.

The scaffold now rejects three reused configs it cannot inherit safely, each with an error that says to compose the config by hand:

  • the bundled agent is fronted by more than one environment server;
  • that environment server is itself derived with _inherit_from or _copy (inheriting it again leaves its own source unresolved);
  • environment_server_routes in the reused config names that server (inheriting retires the name).

No config in the repository hits any of these. Reused configs without a bundled environment server keep the previous behavior, a fresh legacy_agent server.

Related work

Known limitation, unchanged

With --profile custom-gym-agent-loop or external-agent-loop, reusing a scorer that bundles an agent still fails validation (AlmostServerError). The generated agent adds a second implementation key to the inherited simple_agent. This fails on main too, is independent of this change, and is left for a separate fix.

No GitHub issue exists. NeMo Gym QA found this while adding coverage for the onboarding commands from #1029; an NVBug is being filed with the same repro.

Validation

  • tests/unit_tests/test_environment_scaffold.py: 14 new or extended reuse tests. Each one resolves the generated config as a run does, with error_on_agent_without_environment_server: true, and checks rollout_collection._environment_servers_by_agent. They cover the following:

    • typed and untyped agent_server references;
    • a workload named after its scorer;
    • three workloads reusing one scorer composed in one run;
    • instance-name collisions, with a fallback and a rejection;
    • the three rejections above;
    • both shipped fixture scorers, pinned to the inherit path.

    13 of the new tests fail against main's scaffold.py. 9 fail against a first draft of this fix that repointed in place for a workload named after its scorer.

  • pytest tests/unit_tests/test_environment_scaffold.py tests/unit_tests/test_global_config.py tests/unit_tests/test_cli_main.py tests/unit_tests/test_cli.py tests/unit_tests/test_environment_validation.py tests/unit_tests/test_environment_onboarding.py tests/unit_tests/test_environment_publication.py tests/unit_tests/test_add_legacy_agent_environment_servers.py: 657 passed.

  • pre-commit run --all-files: all hooks pass.

  • Standalone repro, run on main and on this branch:

    • It scaffolds the documented command for example_single_tool_call and equivalence_llm_judge.
    • Before this change: 2 of 2 fail gym env validate.
    • After: 0 of 2 fail.

Rollout evidence

The live smoke test ran against this branch, using the inference_provider model type with nvidia/nvidia/Nemotron-3-Nano-30B-A3B:

  1. gym env init --environment qa_reuse_smoke --reuse-verifier example_single_tool_call --reward-range 0 1 --higher-is-better, with the sample row replaced by one row from the scorer's own data/example.jsonl.
  2. gym env validate qa_reuse_smoke.
  3. gym env start --environment qa_reuse_smoke --search-dir <workspace>.
  4. gym eval run --no-serve --agent qa_reuse_smoke_agent --limit 1.

Results:

  • Four servers started: example_single_tool_call, qa_reuse_smoke_agent, qa_reuse_smoke_environment_server, and policy_model.
  • The rollout went through the inherited environment server, and the model called get_weather.
  • The reused verifier scored it 1.0, and the failures file was empty.

The QA suite case that runs the documented reuse command for both shipped fixture scorers fails on main and passes on this branch.

Compatibility and docs

  • For a scorer that bundles an environment server, gym env init --reuse-verifier now generates a config with an inherited environment server. Workloads previously generated this way did not validate, so nothing that worked before changes. No runtime, config-engine, or benchmark-result change.
  • Docs: N/A. The guide already documents this command. This change makes it behave as documented, and the guide's description of the scaffold's environment server stays accurate for every shipped scorer.

🤖 Generated with Claude Code

`gym env init --reuse-verifier <scorer>` derives the workload's agent with
`_inherit_from: <scorer>_simple_agent`, which moves that agent. Since #3724
every shipped scorer config also bundles `<scorer>_environment_server`
naming the original agent, so the generated workload failed
`gym env validate` with a dangling `agent_server` reference.

Inherit the scorer's environment server under the workload's own name and
point it at the renamed agent, as the shipped benchmarks that reuse a scorer
do, so each agent keeps exactly one environment server. A workload named
after its scorer inherits under `<name>_catalog_environment_server`, so
several workloads reusing one scorer can run together. Reject reused configs
whose agent has several environment servers, whose server is itself derived
with `_inherit_from` or `_copy`, or whose server is a taskset route target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv qiaochuz-nv added bug Something isn't working QA_fix Fix implemented by a QA team member area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation needs-review PR is ready for code review and waiting on a reviewer complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 6, 2026
@copy-pr-bot

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

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test bc1fcd5

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

POR Test Summary — Reused Scorer Environment Server

Verdict: PASS — clean red-before / green-after regression

A new black-box QA case runs the documented benchmark scaffold command against both shipped fixture-bearing scorers and requires the generated workload to pass static validation.

Revision Result Evidence
main 325fb49 FAIL (expected reproduction) Both example_single_tool_call and equivalence_llm_judge generated a dangling environment-server agent reference and failed gym env validate
PR head bc1fcd5 PASS Both scorers generated benchmarks that validated successfully

The case also verifies that each generated manifest still names the reused scorer, so the green result cannot come from silently replacing or dropping the requested verifier.

  • QA testcase: environment_scorer_reuse
  • Before run: 20261006T032706388444Z-43ddea8b — 0/1, 1m 27s
  • After run: 20261006T045337607596Z-9e672a86 — 1/1, 1m 27s
  • Defect tracking: NVBug 6877172
  • Execution: disposable checkout; no product source patches

The QA registry intentionally remains expected-fail against main until this fix lands; after merge, that metadata can be flipped to the normal passing state.

@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 7, 2026
@anwithk
anwithk requested review from init-nikhil and zyzhou5 October 7, 2026 16:06
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 7, 2026

@init-nikhil init-nikhil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fix makes sense 👍

@ananthsub ananthsub added the r0.7.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge. label Oct 7, 2026
@ananthsub
ananthsub enabled auto-merge October 7, 2026 23:58
@ananthsub
ananthsub added this pull request to the merge queue Oct 7, 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/37705352991

Merged via the queue into main with commit 70f6d51 Oct 8, 2026
51 checks passed
@ananthsub
ananthsub deleted the qiaochuz/fix_scaffold_reuse_env_server branch October 8, 2026 00:14
kajalj22 added a commit that referenced this pull request Oct 8, 2026
…s agent (4085)` into `r0.7.0` (#4203)

beep boop [🤖]: Hi @qiaochuz-nv 👋,

    we've cherry picked #4085 into `r0.7.0` for you! 🚀

    Please review and approve this cherry pick by your convenience!

Signed-off-by: qiaochuz <[email protected]>
Signed-off-by: NeMo Bot <[email protected]>
Co-authored-by: Qiaochu Zhu US <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: kajalj22 <[email protected]>
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

Retrospective QA-fix tracking issue: #4356. It records the fix authored by @qiaochuz-nv and delivered by this merged PR.

This branch was previously deployed

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

Labels

area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer QA_fix Fix implemented by a QA team member r0.7.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants