Skip to content

fix(nemo-gym): score multi-step episodes and keep step evidence - #860

Merged
rng1995 merged 10 commits into
NVIDIA:mainfrom
deepujain:fix/846-normalize-multi-step-nemo-gym
Nov 24, 2026
Merged

rng1995 merged 10 commits into
NVIDIA:mainfrom
deepujain:fix/846-normalize-multi-step-nemo-gym

Conversation

@deepujain

@deepujain deepujain commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

NeMo Gym records multi-step verifier results on each turn, not on the episode. SkillEvaluator used to report that the verifier never ran, even when every step succeeded. For the example in #846, the report now shows the two step scores, 0.25 and 1.0, and their mean, 0.625.

The live case grid and the finished report use the same scoring rules. A final task uses the last turn’s score and applicable metrics, but a failed or ungraded earlier turn still leaves the attempt unscored. The report keeps the evidence for steps that ran, even if a later step failed. It masks the arm’s configured credential values in combined, per-step, and single-step trajectories, as well as verifier output and failure messages, including values that span lines. Single-step scoring is unchanged.

Gym does not report per-step agent usage, so multi-step token totals remain unavailable. Detecting an early stop still depends on Gym’s stopped_after_turn. The live-model acceptance check in #846, inspecting JSON and HTML reports for successful and failing two-step runs, is still outstanding.

Refs #846.

Verification

  • Reviewed the Contributing Guidelines.
  • Added focused tests. Four regression cases failed on 5ec001b, with three controls passing. All seven passed on 3cd61c6. The full multi-step test module and the two turn-diagnostic cases passed (46 tests).
  • On the parent commit, scored and failed single-step trajectories both contained the synthetic credential. Both masked it on a5d7512. The never-started and verdict-only controls also passed.
  • Updated the NeMo Gym and report documentation.
  • Ran make lint.
  • Did not complete make test locally. A broader run timed out. A progress test rejected its temporary key inside the checkout on both 5ec001b and 3cd61c6. On a5d7512, 242 tests passed and 2 skipped across the two affected modules; all 27 provenance-guard failures also occurred on the parent. GitHub’s Python 3.12, 3.13, and 3.14 jobs passed on a5d7512.
  • Ran make build; the source distribution and wheel built successfully.
  • Used synthetic fixtures only. No credentials, private datasets, or proprietary benchmarks were added.

Release Impact

  • No user-visible release note needed.
  • Updated CHANGELOG.md.

@AdemVessell

Copy link
Copy Markdown
Contributor

Thanks for working on this. I checked the reviewed cases locally against c1d9929 using saved Gym/Codex rollouts and small offline fixtures; they reproduce the three review findings. A verified early stop remains scored at 0.25, while the missing-verifier case stays unscored.

One additional compatibility case may be worth covering: Gym exports each turn's transcript separately, but this adapter sets native resume_trajectory for turn_sessions="continue". Using Gym's actual Codex parser and ATIF exporter with synthetic events, an independently repeated prefix with reused item IDs merges to three steps instead of five. Changing only the resume flag preserves all five; distinct-ID controls also preserve all five. Our saved fresh-session traces show ID reuse, but I have not reproduced that exact repeated-content case in a live continued session.

Could we verify the continued-session transcript shape before relying on native resume here? I have the small regression fixtures available if useful.

@deepujain
deepujain marked this pull request as ready for review November 21, 2026 09:54
@deepujain
deepujain force-pushed the fix/846-normalize-multi-step-nemo-gym branch from 2b81260 to c1d9929 Compare November 21, 2026 10:07
@deepujain

Copy link
Copy Markdown
Contributor Author

@AdemVessell Thanks for running these against your saved rollouts. You're right that native resume was the wrong fit here. As of 2b81260 the adapter no longer sets resume_trajectory for Gym multi-step results, turn_sessions: continue included, because Gym exports each turn's own input and new output under the episode's one session id.

test_continued_sessions_keep_each_turns_own_transcript covers your case: the second turn repeats the first turn's two steps with the same step IDs and adds one more, and the merged trajectory keeps all five steps. On c1d9929 the same test merges them to three.

I haven't checked this against a live continued Gym session either. If your fixtures from Gym's Codex parser give a shape this test doesn't cover, I'd be glad to add them.

@AdemVessell

Copy link
Copy Markdown
Contributor

Thanks for the fix and the regression test—that covers the repeated-prefix case I raised. My parser/exporter fixture adds provenance rather than a different failure case, so I don't think extra files are needed here. I agree the live continued-session check remains open.

@deepujain

Copy link
Copy Markdown
Contributor Author

@AdemVessell Thanks for checking, and agreed that no extra fixture files are needed. The live continued-session check is still open, since it needs a real multi-step Gym run. The commits since my last reply (4cd828f and 203a089) only change the live pass/fail status shown during a run, so the continued-session handling is unchanged and test_continued_sessions_keep_each_turns_own_transcript still passes on 203a089.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for contributing multi-step Gym scoring and evidence retention. I ran 484 focused tests covering result normalization, live case status, backend reporting, and report links. I reproduced the inline redaction issue with a Gym-shaped fixture and a synthetic credential. Live validation with Docker and a model endpoint remains outstanding. GitHub also reports a merge conflict.

@chrisknvidia chrisknvidia mentioned this pull request Nov 23, 2026
10 tasks done

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checked the redaction follow-up with a synthetic key: on the previous head it reached the returned result, the arm summary, the trial failure record, step stdout, the run result.json and report.html; at this head every one of those shows the placeholder and stdout keeps its line structure. The redaction is value-based with the pattern pass kept, and it stays inert for an unset, empty or very short value, so nothing gets blanked by accident. The new test fails on the previous head and passes here; the eleven NeMo Gym test files show the same failure set at both heads (environment only), CI is green and both commits are signed.

Not blocking, and the same as the single-step path on main: the raw rollouts.jsonl and the Gym log folders kept in the run directory still get only the pattern pass, so a configured key can remain there even though every report is clean. Worth a follow-up rather than a change here.

@deepujain

Copy link
Copy Markdown
Contributor Author

@mosheabr @rmalani-nv, could you review #860 at c892aab when you have a chance? The inline findings are resolved, including credential redaction in retained report evidence, and the hosted CI run passed. The successful and partial/failing two-step Gym runs in #846 still have not run against a live model, so their JSON/HTML acceptance evidence is outstanding. Could you review the scoring and evidence-retention changes and let us know whether you need those live reports before approval? Thanks.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for extending Gym scoring and retaining step evidence. All 488 focused tests passed, including the existing verifier-output redaction regression. Local runner and collector replays uncovered two remaining credential-redaction cases and a final-turn scoring issue. I left the details inline. The replays used synthetic credentials and local fixtures.

A NeMo Gym run of a native multi-step task reported every attempt as
"SkillEvaluator verifier did not run in the NeMo Gym sandbox", even when
each step's verifier ran and wrote its rewards. Gym reports each step on
`turns` and leaves the top-level verifier fields unset, and the adapter
only read the top level.

The adapter now copies each step's verifier files and trajectory to
steps/<name>/, lists the steps in order as step_results, and rolls up
the attempt's reward with the task's strategy: the last step's rewards
for final, or each key's mean over the steps that ran for mean, with a
key a step did not report counted as 0. The shared collector then scores
the attempt once and merges the step trajectories, as it does for Harbor.

An attempt stays unscored, with its step evidence kept, when a step was
masked, failed or has no verifier result, when Gym marked the episode
failed, or when the turns, strategy or stop point are malformed. Gym's
mean would count an ungraded step as 0 and Harbor's would leave it out,
so neither result is presented as a score. An episode that stopped early
because a step missed its min_reward is scored over the steps that ran,
as on Harbor. Single-step rollouts keep their current layout.

Refs NVIDIA#846

Signed-off-by: Deepak Jain <[email protected]>
Three tests built a click.Context for the root CLI or the Tier 3
workflow by hand, without the command's context_settings. Click 8.2 and
later create a command's help option once, from the first context that
asks for it, and keep it on the command. When one of these tests was
the first to render help on a pytest-xdist worker, the cached option
only knew --help, and every later `skillevaluator -h` on that worker
exited 2 with "No such option".

Which test a worker runs first depends on the total test count, so the
failure came and went as PRs added tests. With 43,803 tests the fourth
worker starts at test_nested_help_does_not_show_banner, and the -h case
of test_noninteractive_invocations_preserve_streams_and_exit_codes fails
on Python 3.12, 3.13 and 3.14.

The tests now build these contexts with cli.make_context, or as children
of such a context, which is how Click builds them for a real invocation.

Signed-off-by: Deepak Jain <[email protected]>
Review of the multi-step change found four places where a Gym episode
lost what the adapter had recorded.

Judge attribution read the reward strategy only from a staged task.toml,
which Gym trials do not reference. When every step had the same score,
the collector could not tell final from mean and credited the judges of
every step. It now uses the strategy Gym reported, so a final attempt
names only the last step's judges.

The shared collector published a trial's top-level diagnostics and its
merged trajectory but not its steps/<name>/ folders, and a Gym run
removes its job folders after collection. A partial attempt has no
merged trajectory, so the steps that ran left nothing behind. Published
multi-step trials, scored or not, now keep each named step's redacted
trajectory and test-stdout.txt under steps/<name>/. Harbor multi-step
trials get the same folders.

The live case status read only the top-level verifier logs, which Gym
leaves unset for a multi-step episode, so every such attempt showed as
an error while the run was in progress. The episode rules now live in
one function that the result writer and the live status both use; the
live status reads the step rewards where Gym wrote them.

For turn_sessions "continue" the adapter set Harbor's resume flag, which
tells the collector that each step's trajectory repeats the earlier
steps. Gym exports each turn's own input and new output under the
episode's single session id, so a turn that opened with the same steps
as the one before it lost them in the merged trajectory: two turns of
two and three steps merged to three. The adapter no longer sets the
flag, and the merged trajectory keeps all five.

Refs NVIDIA#846

Signed-off-by: Deepak Jain <[email protected]>
The live case grid for a Gym run still passed any attempt whose overall
score cleared the threshold. The finished run also applies standard
grading's goal check and checks that the verifier scored the staged
case. So an attempt with overall 0.95 and Goal Accuracy 0.5 showed as a
pass while the run was active and as a failure once it finished, and a
verifier reward that named a different case passed live but was left
unscored at collection.

The live poller now marks each Gym attempt, single-step or multi-step,
with the attempt verdict the finished grid uses. It reads the rewards
through the normalizer's case check against the staged task's
[metadata].entry_id. A single-step rollout's reward sidecars are merged
in as the collector merges them, so a goal the verifier recorded as not
applicable is not read as 0. Once the run has removed its staged tasks
the case can no longer be looked up, so the live view skips that one
check rather than turning a correctly scored attempt into an error.

Signed-off-by: Deepak Jain <[email protected]>
Two cases still made the live case grid of a Gym run disagree with the
finished run. Once the run removed its staged tasks, the live view could
no longer look up the case each task was staged as, so an attempt whose
verifier named another case showed as a pass and then finished unscored.
The live view also applied only part of the collector's checks. When a
required judge fails, the built-in verifier still writes its other
scores and an overall of 0, so a mean episode could reach the threshold
live and a single-step rollout showed as failed, while collection leaves
both unscored.

The runner now writes each arm's task to case map to
_nemo-gym/<agent>-<arm>/task_case_ids.json when it stages the arm. That
folder is kept after the staged tasks are removed, and the live view
takes its case ids from it. Each live attempt is judged by the collector
itself: the rollout is written to a scratch job the way the runner
writes it, read with the collector's reward extraction and scoreability
checks, and marked with the attempt verdict, as harbor_job_passed reads
a job. Gym never rewrites a rollout line, so each is judged once and its
scratch job is removed.

Signed-off-by: Deepak Jain <[email protected]>
The live case grid judged each Gym attempt in a scratch job that it
created under _nemo-gym in the run folder, and it filled that job with
everything the runner publishes, including every step's trajectory and
verifier stdout. When the poll could not write to _nemo-gym, it showed
no case rows. When it could, its first poll of each rollout copied
trajectories and logs that the verdict never reads.

The scratch job now lives in the system temporary folder, so the live
view only reads the run folder. It holds only the files the attempt
verdict reads: the reward files, and a single-step trajectory small
enough for the collector to read, which it checks for an agent that
never started. Step trajectories and verifier stdout are left out. The
verdict still comes from the collector's own checks, so the live grid
and the finished grid still agree.

Signed-off-by: Deepak Jain <[email protected]>
The live case grid kept every Gym verdict in one cache and cleared all
of it once it reached 65,536 entries. Each poll walks every rollout in
order, so a run with more rollouts than that refilled the cache from
the start on every refresh and built a scratch job again for rollouts
it had already judged.

The cache now holds each run's verdicts for the rollouts its last poll
read, so a poll judges only the rollouts Gym appended since the one
before, however many the run holds. Once the kept verdicts pass the
cap, the runs polled longest ago are dropped. The run being polled is
never dropped, and it keeps one verdict per rollout it holds.

Signed-off-by: Deepak Jain <[email protected]>
A verifier that wrote no reward could leave a configured credential in the run summary and published trial even though the launch error masked it. Apply the arm’s credential redaction when building failure records and copying verifier stdout. Keep the diagnostic text and line breaks so the failed step can still be investigated.

Signed-off-by: Deepak Jain <[email protected]>
Mask configured values in decoded trajectory text and in turn failures before whitespace is collapsed. Keep ATIF schema tags and the single-step startup check intact.

When the final verifier marks a metric not applicable, use that decision for the final score without discarding a failed earlier turn.

Signed-off-by: Deepak Jain <[email protected]>
@deepujain
deepujain force-pushed the fix/846-normalize-multi-step-nemo-gym branch from 5ec001b to 3cd61c6 Compare November 24, 2026 14:58
@deepujain

Copy link
Copy Markdown
Contributor Author

Thanks for the replays, @rng1995. Commit 3cd61c6 masks configured credentials in retained trajectories and redacts multiline values before formatting failure messages. Final scoring now uses the last turn to decide which metrics apply, but a failed earlier turn still leaves the attempt unscored.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The masking follow-up checks out: step trajectories are value-masked in memory before they are written (no unmasked window, inert for an empty or invalid value), multiline secrets are masked before whitespace collapsing, and the final strategy only restores a not-applicable verdict from the last step's own sidecar; across a 40-cell matrix of strategies and outcomes nothing flips from fail to pass. Tests pass at this head with the same environment-only failures as before, CI green, all commits signed. One note inline on the single-step path.

Mask configured credential values before saving a single-step trajectory, whether the verifier scored the rollout or failed. Check the original message for startup failures so masking cannot change the verdict.

Signed-off-by: Deepak Jain <[email protected]>
@rng1995
rng1995 merged commit c2a4714 into NVIDIA:main Nov 24, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants