Skip to content

cp: fix(scaffold): move a reused scorer's environment server with its agent (4085) into r0.7.0 - #4203

Merged
kajalj22 merged 3 commits into
r0.7.0from
cherry-pick-4085-r0.7.0
Oct 8, 2026
Merged

kajalj22 merged 3 commits into
r0.7.0from
cherry-pick-4085-r0.7.0

Conversation

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

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!

…nt (#4085)

## 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](https://docs.nvidia.com/nemo/gym/latest/contribute/environments/new-environment#onboarding-commands)
failed for all of them:

```bash
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:

```yaml
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

- #4053 (open) changes the migration script to repoint declared servers
in place, to keep names that `environment_server_routes` uses. This PR
does not touch the files #4053 changes. The scaffold inherits instead
because of the multi-workload case above, and it refuses the routed case
rather than renaming a routed server. `_agent_reference_fields` uses the
same reference rule that #4053 introduces as
`environment_server_agent_refs`: `agent_server` may omit its type, and
any other field must be typed `responses_api_agents`.
- `r0.7.0` contains both #2442 and #3724, so the release branch has the
same defect. This fix is a cherry-pick candidate.

### 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](https://claude.com/claude-code)

Signed-off-by: qiaochuz <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: NeMo Bot <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation label Oct 8, 2026
@copy-pr-bot

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

@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working cherry-pick 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 Run CICD labels Oct 8, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor Author

/ok to test 077ea5a

@kajalj22

kajalj22 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

/ok to test ff28010

@kajalj22

kajalj22 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

/ok to test ac78fef

@kajalj22
kajalj22 merged commit fb456a3 into r0.7.0 Oct 8, 2026
43 checks passed
@kajalj22
kajalj22 deleted the cherry-pick-4085-r0.7.0 branch October 8, 2026 01:05

This branch was previously deployed

1 inactive deployment
public — ac78fef4 Deployed Oct 8, 2026 by copy-pr-bot[bot] via release / finalize / notify #4659
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 cherry-pick 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 Run CICD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants