Repository navigation
fix(terminal_bench_2_1): grade failing pytest runs 0 when test.sh exits before writing reward.txt - #6174
Conversation
…ts before writing reward.txt Many task test.sh scripts run pytest under `set -euo pipefail` and write reward.txt only on the following lines. A failing pytest ends the script first, so a failed rollout produced no reward.txt and was returned with evaluation_completed false, which training masks as an incomplete evaluation, while a passing one scored 1: those tasks trained on successes only. When test.sh exits non-zero without a readable reward.txt and its output ends in a pytest summary that counts failures or errors, the rollout is now graded 0 with evaluation_completed true and reward_from_pytest_summary true. Exits without such a summary (a failed download, a setup crash) stay ungraded, and a verifier infrastructure failure is still masked by the outcome policy. The score_pytest_failures_without_reward config key (default true) turns the grading off. Co-authored-by: Jiaqi Zeng <[email protected]> Signed-off-by: Ananth Subramaniam <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
…ve timed-out runs ungraded The summary parser now accepts the borderless summary that pytest -q prints, and strips terminal color codes and carriage returns before matching. Bare lines must start with pytest's counts, so tool output such as "Prepared 2 packages in 1.20s" is not read as a summary. A test run that timed out did not exit, so its partial output says nothing about the test run: it stays ungraded even when a failing pytest summary was printed before the timeout. Tests now cover a failing summary with a zero exit, a timed-out run, and the -q, color and CRLF summary forms. Signed-off-by: Ananth Subramaniam <[email protected]>
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
RISK — Add the required before/after reward-profile evidence
This changes verification logic for a fixed evaluation benchmark. The pinned review rubric requires a measured before/after reward-profile comparison for that change. The description supplies representative real-model smoke results, but no baseline profiling result or measured comparison. The trusted contribution guidance also distinguishes this requirement from training-environment smoke validation.
Could you record profiles on base and head using matching representative inputs and run settings? Include the missing-reward pytest failure and ordinary reward-file success/failure cases, and report sample count, mean reward, zero/one counts, masked count, and incomplete count. This is a validation gap, not a demonstrated reward regression: the new fallback branch changes completion and provenance without assigning a new reward.
Acceptance: the comparison should show unchanged rewards and masking. The affected missing-reward failure should remain reward 0 and unmasked, changing only from incomplete to completed with summary provenance. Valid reward files should retain their 0/1 grades without summary provenance; timeouts should remain incomplete, and infrastructure failures should retain their configured outcome policy. No broader implementation change is requested.
I inspected both changed files and traced the affected sandbox, response, observability, recovery, and profiling contracts. I found no additional qualifying code defect. This was a read-only review; I didn't execute tests or independently reproduce the reported rollouts.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
yaoyu-33
left a comment
There was a problem hiding this comment.
Team review at 2fec54b1ef. Verdict: SHIP WITH CARE. The grading logic is sound. The asks are inline: Agentic IF's evidence and impact, corrections to the PR body, and two test and comment fixes. One more inline item predates this PR and suits a follow-up issue.
What we checked about the new branch (app.py#L746-L757):
- It cannot raise a reward.
rewardis still 0.0 whenever the branch runs, and it requiresfailure_cause is None, somask_sampleis the same as on main for every input. - Infrastructure failures stay where they were:
- A sandbox or exec error, or a typed provider error, sets
failure_causebefore the branch is reached and stays masked. - A timeout stays ungraded.
- A failed download of a reward.txt that exists stays masked.
- A failed
uvorcurlstep underset -eexits before pytest prints a summary, so it stays ungraded. - Each of these guards has a test that fails when the guard is removed. We checked this by removing each guard and re-running the tests on Linux.
- A sandbox or exec error, or a typed provider error, sets
- Pytest collection and fixture errors ("1 error") are graded 0. We think that is right. The public TB2.1 and TBLite
test.shalready write 0 from pytest's exit code in the same case. It is also hard to tell such an error apart from a task the model broke. - The parser holds up on real output. We compared it with pytest 8.4/9 output in bordered,
-q,--color=yes,-rA, xdist and collection-error form. Its misses all fall back to main's behaviour (ungraded): pytest 9 subtests lines such as2 failed, 2 subtests passed,-qq, and pre-5.1in 0.10 seconds. Text the model prints can only push a row back to ungraded.
Reward profile. We don't think a before/after gym eval profile is needed for TB2.1 or TBLite.
- The benchmark guide accepts before/after numbers or proof that the distribution did not move, and the code gives that proof.
- Reward and
mask_sampledon't change on this path, andselect_measuredsplits only onmask_sample. - No pinned TB2.1 task (89) and no pinned TBLite task (100) reaches the branch; we checked each
test.sh.
The one consumer whose distribution does move is Agentic IF, so the evidence ask is there, inline.
CI is green at this head, including the changed-server tests. The new tests also pass on Linux (88 passed, 13 skipped). Not run: real sandboxes or models, or Agentic IF with its private terminal tests.
| and getattr(eval_result, "error_type", None) is None | ||
| and pytest_reported_failure(test_output) | ||
| ): | ||
| evaluation_completed = True |
There was a problem hiding this comment.
This flips a row that Agentic IF reads.
- Agentic IF uses this server as its
tb21task backend (agentic_if.yaml). - It masks any backend reply with
evaluation_completed: falseasverifier_error(outcome.py). - So for a
set -eterminal task whose failing pytest ends test.sh, main masks the Agentic IF row, and this PR scores it as an unmasked 0.
That direction looks right to us: a model failure was slipping out of the score. But it does change Agentic IF's measured set and mean reward, so "No change to rewards, reward profiles, or the training signal on main" doesn't hold there. Its public example rows are pinned TB2.1 tasks. The full set's terminal tests come from the private terminal-bench-tests.jsonl artifact (prepare.py), which is the kind of generated task set this PR targets.
Could you name Agentic IF under "Benchmark-result impact" and add one of these?
- A static count over
terminal-bench-tests.jsonl2.2.1: how manytest.shrun pytest underset -ewithout a guard (noset +e, no|| X=$?, no reward written first). Zero is proof enough. - If the count isn't zero, base vs head numbers for those tasks through Agentic IF. A fresh run works, or reclassify an existing run's saved episodes. The numbers we'd like:
- total rows;
- rows masked as
verifier_error; - rows with
reward_from_pytest_summary=true; - mean reward over measured rows.
A TB2.1 reward profile isn't needed for this: reward and mask_sample don't change on this path.
There was a problem hiding this comment.
Settled from our side.
We read the pinned agentic_if 2.2.1 terminal tests artifact and classified all 242 test.sh. None can reach this branch:
- 162 guard pytest;
- 75 don't use
set -e; - 2 write reward 0 from an EXIT trap;
- 3 don't run pytest at the top level.
So Agentic IF's pinned distribution is unchanged too. 72e4c902a2 records the Agentic IF interaction next to the switch (L113-L116).
One thing is left for you: "Benchmark-result impact" still says there is no change to the training signal on main. Could you add a line saying that Agentic IF turns these rows from masked into scored zeros on set -e task sets, and that none of its pinned 2.2.1 tasks reach the branch?
| task_name: str | ||
| test_output: str | ||
| # True when the reward came from pytest's summary because test.sh exited before writing reward.txt. | ||
| reward_from_pytest_summary: bool = False |
There was a problem hiding this comment.
A few corrections to the "Why" and "Benchmark-result impact" sections, so readers can repeat the scope check:
- Task count. The TB2.1 checkout has 89 tasks, not 91 (
NUM_TASKS), andprepare.pyclones upstream unpinned (L22-L25). We checked all 89test.shat7131e437: none of them sets-e. - TBLite. OpenThoughts-TBLite is also graded by this server (manifest). At
f075e463, 10 of its 100test.shuseset -e. All 10 guard pytest or write reward.txt first, so none reaches this path. Worth saying in the body. - Profile columns. The profiler turns every top-level bool into a metric (reward_profile.py). So every TB2.1 and TBLite profile gains
*/reward_from_pytest_summarycolumns, andmean/evaluation_completedrises onset -etask sets. Reward and masking are unchanged. - Recovery. On main these rows are
MASKED. That makesgym eval resubmit --recoverstop with "the run is not complete" (recovery.py), and it counts them as trial failures (L5526-L5534). Naming this is the clearest statement of what the PR fixes on main. - Wording. "its output ends in a pytest summary": the parser takes the last summary anywhere in the output (L171). "the last pytest summary in the output" would match the code.
|
|
||
| task_name: str | ||
| test_output: str | ||
| # True when the reward came from pytest's summary because test.sh exited before writing reward.txt. |
There was a problem hiding this comment.
This comment, the config comment (L113-L115) and the PR body all say the summary is used when test.sh exits without writing reward.txt. The branch also fires when reward.txt exists but float() fails on it (L740), for example an empty or garbage file. With a non-zero exit and a failing summary, that row is now graded 0 instead of left ungraded.
Grading it looks right to us: the failing pytest is still the verdict. Could you say "no readable reward.txt" here, at L113-L115 and in the body? The test asks are on the test file.
| # True when the reward came from pytest's summary because test.sh exited before writing reward.txt. | |
| # True when the reward came from pytest's summary because test.sh exited without a readable reward.txt. |
| script.write_text( | ||
| "set -euo pipefail\n" | ||
| f"bash -c {quote(failing_step)}\n" | ||
| "_EXIT_CODE=$?\n" |
There was a problem hiding this comment.
Under set -euo pipefail the _EXIT_CODE=$? line and the echo ... > reward.txt line never run. A non-zero step ends the script, and a zero step hits || exit 0. So assert not reward.txt.exists() passes in every case, and the one test that runs a real script has no passing control.
Could you add these cases?
- A passing step that reaches the reward line, for example
echo '=== 3 passed in 0.10s ==='; truefollowed byecho 1 > .../reward.txt. It should be graded 1 from reward.txt withreward_from_pytest_summaryFalse. - A failing summary and a non-zero exit when reward.txt exists.
- A valid
0or1keeps the file's grade, and the flag stays False. This is the TBLite shape: write the reward, thenexit $code. - Empty or invalid text is graded 0 from the summary (see the comment on
app.py:186).
- A valid
We ran versions of both at this head on Linux and they pass.
| except Exception: | ||
| if self.config.debug: | ||
| print(f"Hit an exception downloading and converting reward: {format_exc()}", file=stderr) | ||
| # test.sh exited without a readable reward.txt, typically because a failing pytest ended it under |
There was a problem hiding this comment.
This one isn't introduced here, but the PR's task population is where it matters. Nothing clears /logs/verifier before test.sh: there is only the mkdir -p at L695. Verification also runs in the agent's own sandbox.
So on a set -e task whose pytest fails before the script writes reward.txt, a /logs/verifier/reward.txt holding 1 that the agent wrote is downloaded as the grade. We reproduced it through verify with a real bash test.sh: reward 1.0, completed, not masked. The Harbor Environment Server empties that directory before running test.sh (verifier.py).
A follow-up issue is fine for this, rather than this PR. Running rm -f /logs/verifier/reward.txt in the same exec as the mkdir would close it.
…ng-reward pytest failures Agentic IF uses this server as its tb21 task backend and masks any result whose evaluation is not completed. With score_pytest_failures_without_reward on, a set -e task whose failing pytest ends test.sh is therefore scored 0 there instead of masked. Say so next to the switch, and say "no readable reward.txt": the branch also grades a reward.txt that exists but cannot be parsed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 72e4c90 |
yaoyu-33
left a comment
There was a problem hiding this comment.
Approving at 72e4c902a2.
The Agentic IF risk from the earlier review is settled.
-
Evidence. We read the pinned
agentic_if2.2.1terminal-bench-tests.jsonlartifact (SHA-256 matchesprepare.py) and classified all 242 terminaltest.sh. None can reach the new branch:- 75 run pytest without
set -e; - 162 guard pytest with
if,||orset +e; - 2 install an EXIT trap that writes reward 0 when
set -eaborts; - 3 run pytest only inside an
if, or not at all.
Every script the classifier flagged was then read by hand. So the Agentic IF distribution on its pinned data does not move either, just as for TB2.1 (89 tasks) and OpenThoughts-TBLite (100 tasks). No reward profile is needed.
- 75 run pytest without
-
What
72e4c902a2changes. It touches comments only. The switch's comment (L113-L116) now says that Agentic IF masks a tb21 result that is not completed, so on aset -etask set such a row becomes a scored 0 there. It and the field comment (L187) now also say "no readable reward.txt", since the branch also grades a reward.txt that exists but cannot be parsed. -
Validation. Pre-commit passes on the changed file, and CI is restarted at the new head. Earlier, at
2fec54b1ef: CI was green, and on Linux the server tests passed (88 passed, 13 skipped) and each guard's test failed once its guard was removed.
The remaining inline notes don't block merging:
- the PR-body corrections;
- the test that has no passing control;
- the pre-existing
/logs/verifiercleanup, which suits a follow-up.
Not run: real-model rollouts at the new head (the change is comments only), and a live Agentic IF run.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43569628145 |
What changed
Terminal Bench 2.1 now records a completed evaluation with reward 0 when
tests/test.shexits non-zero before writing/logs/verifier/reward.txtand its output ends in a pytest summary that counts failed tests or errors.pytest_reported_failure()reads the last pytest summary line and reports whether it counts failures or errors. It accepts:==== 2 failed, 1 passed in 0.10s ====);pytest -qprints (1 failed, 2 passed in 0.10s);A borderless line must start with pytest's counts, so tool output such as
Prepared 2 packages in 1.20sis not read as a summary.In that case the verify response has
reward=0,evaluation_completed=true,mask_sample=false, and a newreward_from_pytest_summary=truefield that marks the grade as coming from the summary instead of reward.txt.A new config key,
score_pytest_failures_without_reward(defaulttrue), turns this off.Unchanged:
uvorcurldownload, a setup crash) stays ungraded, as before.Why
Many task
test.shscripts run pytest underset -euo pipefailand write reward.txt only on the following lines. A failing pytest ends the script first, so the rollout has no reward.txt. The server returned reward 0 withevaluation_completed=false, which labels the model's own test failure as an evaluation that did not finish.A failing pytest is a verdict on the model, so recovery and observability should record it as a completed 0, not as an incomplete or unmeasured evaluation. The
set -euo pipefailpattern is common in large generated Terminal Bench-style task sets: in one such set, about a fifth of the task scripts use it. None of the 91 pinned public Terminal Bench 2.1 tasks (harbor-framework/terminal-bench-2-1 at7131e437) use it: eachtest.shchecks pytest's exit code and writes reward.txt itself. Public Terminal Bench 2.1 runs therefore never reach the new path.No issue is linked: this ports a fix from a downstream training fork, where rows with
evaluation_completed=falsewere masked, so failed rollouts on these tasks were dropped from training and only successes trained. That masking is not in Gym or NeMo RL main.Benchmark-result impact
No change to rewards, reward profiles, or the training signal on main. These rows already had
mask_sample=falseand reward 0, and both reward profiling and NeMo RL masking readmask_sample.What changes is how these rows are classified:
Public Terminal Bench 2.1 results do not change at all, because none of its pinned tasks use
set -e(see Why).Set
score_pytest_failures_without_reward: falseto keep the previous classification.Validation
Tests cover:
A
set -euo pipefailscript whose pytest step fails, run throughverifywith a realbashsubprocess:None of these cases is masked.
A timed-out test run whose partial output holds a failing summary: still ungraded and not masked.
The pytest summary parser on:
-q, colored and CRLF forms;A failed download of a reward.txt that exists, after a failing pytest: still masked as a verifier error, and not graded from the summary.
Each new test fails when the behavior it covers is removed:
main;The parser was also checked against real output from
pytest,pytest -q,pytest --color=yesandpytest -rAon a failing test file.Commands:
PYTHONPATH=$PWD .venv/bin/python -m pytest resources_servers/terminal_bench_2_1/tests/test_app.py -q pre-commit run --files resources_servers/terminal_bench_2_1/app.py resources_servers/terminal_bench_2_1/tests/test_app.pyRollout evidence
Run on the local workstation. The Gym servers ran there, sandboxes ran in OpenSandbox, and the policy model was served by the NVIDIA inference API. Agent: Terminus 2 through
benchmarks/terminal_bench_2_1/terminus_2.yaml, so verification ran through this resources server. Settings:max_turns: 40,evaluation_timeout: 900, one repeat per task.The public tasks do not use
set -e, so the smoke tasks are copies of public tasks withset -euo pipefailinserted before the pytest step oftest.sh. That reproduces the pattern in the generated task sets.test.shnvidia/openai/eccn-gpt-oss-20b(Chat Completions)prove-plus-commset -ecopynvidia/openai/eccn-gpt-oss-20bfix-gitset -ecopynvidia/openai/eccn-gpt-oss-20bfeal-linear-cryptanalysisset -ecopynvidia/openai/eccn-gpt-oss-20bgpt2-codegolfset -ecopyopenai/openai/eccn-gpt-6-luna(Responses API)prove-plus-commset -ecopyopenai/openai/eccn-gpt-6-lunafix-gitset -ecopyopenai/openai/eccn-gpt-6-lunaprove-plus-commopenai/openai/eccn-gpt-6-lunafix-gitBefore this change, each failing
set -erow would have come back withevaluation_completed=false. Here each has reward 0,evaluation_completed=true,reward_from_pytest_summary=true,mask_sample=falseand no failure kind. Passing rollouts still write reward.txt and score 1, with or withoutset -e.For each rollout I checked the agent output, the verifier
test_output(the pytest summary above), the grading fields, the collector's coverage report (all completed and measured, none masked or failed), and that no sandbox was left behind after the run.