Skip to content

fix(eval): aggregate execution metrics in the environment server - #5455

Merged
yaoyu-33 merged 17 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:codex/demo-environment-aggregation
Nov 12, 2026
Merged

yaoyu-33 merged 17 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:codex/demo-environment-aggregation

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review follow-up validation (2026-11-09): On ws, python -m pytest --import-mode=importlib environment_servers/single_agent_turn/tests/test_app.py environment_servers/single_agent_turn_legacy/tests/test_app.py tests/unit_tests/metrics/test_aggregate_metrics.py -q: 317 passed. Includes custom unindexed/mixed repeat-row regression coverage. Independent source and patch review found no additional blocker. Full pre-commit run --all-files was attempted: Ruff, formatting and import layering passed; repository-wide guardword findings and a hook Python environment mismatch prevented a clean full run. No new model rollout was run for this guard/naming/docs follow-up; prior smoke scope is recorded below.

single_agent_turn currently loses execution metrics when verification is skipped and delegates their reduction to Resources otherwise. This change makes Env aggregate ng_perf into performance summaries, per-repeat token statistics, and confidence intervals. Resources retains benchmark scoring and task-specific weighting. Regression tests exercise the production path.

flowchart LR
    A["Agent observations + model captures"] --> C["Rollout collection: persisted batch"]
    C --> E["Env /aggregate_metrics"]
    E -->|"benchmark evidence; ng_perf excluded"| R["Resources server: benchmark reducers"]
    E -->|"ng_perf from all supplied rows"| P["Shared performance reducer"]
    R --> M["Env: merged result"]
    P --> M
Loading

The same Env implementation works with different Resources scoring policies. Verification controls whether quality metrics are computed; execution accounting remains available in both cases.

flowchart LR
    E["Same Env implementation"] --> V{"Verification enabled?"}
    V -->|"yes"| R["Configured Resources: task-specific scores"]
    V -->|"no"| N["Quality metrics omitted"]
    E --> P["Execution metrics in either case"]
Loading

Compatibility: single_agent_turn and its legacy subclass now add performance metrics for all supplied rows, including verification-off and fully masked batches. critpt_custom_grader and gdpval comparison mode gain perf_summary and token statistics that their own reducers did not publish. In gdpval multistage runs, quality/sample counts cover the final stage while token statistics cover every supplied stage. Reverification posts directly to the resources server and does not apply this environment-server enrichment, so its performance fields can differ from collection. Custom repeat rows without _ng_rollout_index are preserved and skip the token merge. response.usage, provider metrics, and benchmark fields are preserved.

Remaining paths: legacy_agent still delegates aggregation to the agent and returns empty metrics when verification is skipped. nemo_user_sim delegates to the resources server with ng_perf attached; its skip-verification changes are in #5823. Unifying those paths is separate follow-up work. No new public issue is created by this focused fix.

Validation at 1fe629b94 (main merged at 379ae226d on 2026-11-06; a review team and a second independent review found no correctness problem): environment_servers/single_agent_turn/tests: 191 passed; single_agent_turn_legacy/tests: 43 passed; tests/unit_tests/metrics/: 128 passed, 3 skipped, 3 failed (the same wandb gap); test_session_contract_repo.py + test_global_config.py: 233 passed; pre-commit run --files: clean. CI at d3d4b5df1 failed only main's test_each_cleanup_has_its_own_budget timing test.

Validation at d3d4b5df1 (main merged on 2026-11-05; the flat aggregate test moved to tests/unit_tests/metrics/ with main's test layout):

  • environment_servers/single_agent_turn/tests/test_app.py: 159 passed. environment_servers/single_agent_turn_legacy/tests/test_app.py: 43 passed.
  • tests/unit_tests/metrics/: 128 passed, 3 skipped, 3 failed. The 3 failures need wandb, which the local environment lacks; they fail the same way on main.
  • tests/unit_tests/test_public_api.py and test_public_api_facades.py: 935 passed.
  • Full tests/unit_tests/: the remaining failures (sandbox, orchestration resume scripts and similar) all come from 49 files that fail the same way on an untouched main checkout in this environment. None is in metrics, rollouts or the environment servers.
  • pre-commit run --files <changed files> passed.

Scripted-model smoke at the current head (no real model). example_single_tool_call + Simple Agent + single_agent_turn_legacy, with a local stub of the Responses API (one get_weather call, then a final message, fixed usage), observability on, 5 tasks x 2 repeats, through gym env start and gym eval run --no-serve:

Arm Rollouts Quality metrics perf_summary Per-repeat token rows
Verification on 10 mean/reward 1.0 120 completion tokens, coverage 1.0 2 rows, 12.0 each, with across-repeat CI
skip_verification=true 10 (reward 0.0, verification_skipped) none (key_metrics is {}) 120 completion tokens, coverage 1.0 2 rows, 12.0 each, with across-repeat CI

On main, the skipped arm returns empty aggregate metrics. Real-model smoke at the current head is still pending.

Earlier validation at 377d74a37521a7140ba414dc0d2f15ddc864d013: 808 tests passed, 24 comparisons against the pre-change reducer passed, and four real NIM rollouts passed through the production Collector and HTTP servers. Both verified runs scored 1.0; verification-off runs published no quality score. Every rollout executed one weather tool call over two model turns, with full token capture coverage. Replay was deterministic and Resources sessions were released.

Real-model arm Rollouts Completion tokens Quality metrics
Verification enabled 2 36, 38 Mean reward 1.0
Verification skipped 2 38, 38 Omitted
Exact checks and smoke scope at 377d74a

Python 3.13.14; isolated checkout imports verified. With PYTHONPATH set to the checkout and dependency site-packages, bypassing the shared environment's editable install:

python -S -m pytest --import-mode=importlib -o addopts= -o log_cli=false \
  tests/unit_tests/test_aggregate_metrics.py \
  tests/unit_tests/metrics/test_reward_profile.py \
  environment_servers/single_agent_turn/tests/test_app.py \
  environment_servers/single_agent_turn_legacy/tests/test_app.py \
  tests/unit_tests/test_public_api_facades.py -q
# 667 passed
python -S -m pytest -o addopts= -o log_cli=false tests/unit_tests/test_compare.py -q
# 141 passed
pre-commit run --all-files
git diff --cached --check

Pre-commit passed; the guardwords hook reported its private catalog unavailable. Commit includes DCO sign-off. Independent source review found no material issue. The 24 baseline comparisons cover one/two repeats, unmasked/mixed/fully masked batches, and absent/empty/partial/full observations.

Smoke: example_single_tool_call + simple_agent + single_agent_turn + inference_provider, using nvidia/nemotron-3.5-lightning-30b-a3b via NVIDIA NIM. Two repeats per verification mode; real model/tool/verifier calls, persisted observations, Collector capture joins, and HTTP aggregation. All smoke servers stopped. Initial setup lacked a required cleanup timeout; after correction, the first model choice returned account-level 404s with no generations. The completed Lightning run supplies the evidence above. This is a focused smoke, not benchmark re-baselining or full repository CI. Full CI still requires maintainer authorization; the PR remains draft.

🤖 Generated with Claude Code

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

@yaoyu-33 yaoyu-33 added feature New capabilities, enhancements, or enablement work area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters labels Nov 2, 2026
@yaoyu-33 yaoyu-33 changed the title design(eval): demonstrate environment-owned aggregation fix(eval): aggregate execution metrics in the environment server Nov 2, 2026
yaoyu-33 and others added 2 commits November 2, 2026 20:03
Review follow-ups for the Env-side execution aggregation:

- Update the single_agent_turn README, which still said skip_verification
  returns empty aggregate metrics, and the legacy README, which still said
  /aggregate_metrics is forwarded unchanged; the legacy server inherits the
  new behavior.
- Return early from _add_completion_token_metrics when no row carries
  ng_perf, so repeat rows a Resources server published without
  _ng_rollout_index pass through instead of raising KeyError in the Env.
- State in the add_execution_metrics docstring that it replaces
  perf_summary, strips agent_ref from repeat rows, and what it requires of
  existing repeat rows.
- Pin the agent_ref removal and repeat ordering for repeats the Env adds,
  stripping of non-dict ng_perf from the Resources body, and the
  pass-through case above.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8b4ea78

yaoyu-33 and others added 2 commits November 2, 2026 21:15
- Keep a perf_summary that Resources published itself when no row carries
  ng_perf; observed batches still replace it.
- Share one helper for the perf summary between add_execution_metrics and
  the fully masked early return of compute_aggregate_metrics.
- Run the Env's CPU-bound execution reduction in a worker thread so it
  does not stall the server's event loop.
- Note in the aggregate-metrics page that ng_perf token statistics add
  per-repeat rows even for a single repeat.
- Freeze the direct-path result of a mixed batch as a regression oracle
  (the values also hold on origin/main's reducer) and pin the perf_summary
  keep-or-replace behavior.
- Collapse the redundant skipped-and-masked parametrization and rename the
  test to match the case that has valid scores.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	environment_servers/single_agent_turn/app.py
#	environment_servers/single_agent_turn/tests/test_app.py
@yaoyu-33

yaoyu-33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 089d732

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

yaoyu-33 and others added 3 commits November 5, 2026 12:58
Main now names the bound resources server through config.resources_server
and raises boundary failures with raise_boundary_failure; the environment
aggregation keeps both.

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

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c396405

@yaoyu-33
yaoyu-33 marked this pull request as ready for review November 5, 2026 21:13
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 5, 2026 21:14
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 10, 2026
…eduction

Merge main to include the agentic-if-realworld reporting contract. Expect only ng_perf to be removed on the Environment-to-Resources hop while retaining exact final artifact equality and benchmark evidence checks.

Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 16232f3

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 10, 2026 22:40
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 5091249

@yaoyu-33
yaoyu-33 requested a review from a team as a code owner November 10, 2026 23:33
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 595eeb3

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

Re-approving after the stale-review dismissal. The PR's own commits are unchanged since the earlier approval except the release-rehearsal changelog commit and a sync with main, and CI is green on this head. (Delta check done with Claude Code on Adil's behalf.)

@yaoyu-33
yaoyu-33 enabled auto-merge November 11, 2026 23:08
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 12, 2026
@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/43259683611

Merged via the queue into NVIDIA-NeMo:main with commit 19740d3 Nov 12, 2026
68 checks passed
@yaoyu-33
yaoyu-33 deleted the codex/demo-environment-aggregation branch November 12, 2026 16:48

This branch was previously deployed

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

Labels

area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters 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.

5 participants