Repository navigation
Description
What happens
In the coding example environment, if the hidden test command finishes without writing a JUnit report, the grade is marked isError=True. Job.reward leaves isError runs out of the mean. The agent's own code runs inside that test command, so the agent can make the report go missing. A task it failed is then dropped from the job's mean reward instead of counting as 0.
The chain at e95373f:
grade_testsreturnserror: "test command did not write JUnit XML"when the report file doesn't exist. This check runs before the exit-code and timeout checks. The repository testtest_missing_junit_report_is_grading_errorexplicitly expectsisError=Truewhen a command writes no report; this issue concerns the case where agent-edited code causes that outcome._gradeturns anyerrorfrom the test run intoEvaluationResult(isError=True).Job.rewardincludes runs withnot run.grade.is_errorand either a raw grade or a non-error trace. The docstring says this is meant to keep infrastructure failures out of the mean. Here the "infrastructure failure" comes from the agent's edit.
The test command imports the agent's package (src/flask). Two lines at the top of src/flask/__init__.py are enough:
import os as _o, sys as _s
if "pytest" in _s.modules: _o._exit(0)pytest exits with code 0 when the tests import flask, before it writes the report. Both shipped tasks (flask-4992, flask-5063) are affected.
The run's own reward stays 0.0, so this does not raise the per-run reward used for training. It affects the job-level number: Job.reward, the "Mean reward" line of hud eval and its mean_reward JSON field (hud/cli/eval.py, L559). hud eval does print a separate Errors: N count. The types reference describes job.reward as the "mean reward across runs" / "mean across every run".
Reproduce
The script uses the real coding-task template through TaskRunner.start / TaskRunner.grade: it clones the shipped flask.bundle, restores tests/, applies the hidden test patch, runs grader.grade_tests, then parses each grade frame with Grade.from_dict and aggregates with Job. Only the sandbox is stubbed: workspace.run runs the task's own test command with the same cwd and env vars, but without bwrap. The exploit doesn't depend on that, because the tests import the agent's code inside the sandbox too. No network, no model calls.
golden: the bundle's own*_goldenreference fixhonest: the agent leaves the repo unchanged (a failed attempt)cheat: same ashonest, plus the two lines above
repro.py
# Save as repro.py in the repo root and run it with the coding env's dependencies installed:
# python repro.py
# Uses the real coding-task template (TaskRunner.start -> agent edit -> TaskRunner.grade),
# the shipped flask.bundle and hidden test patches, grader.grade_tests, Grade.from_dict and Job.
# Only the sandbox is stubbed: workspace.run runs the task's own test command with local bash
# instead of inside bwrap. No network, no model calls.
import asyncio
import os
import subprocess
import sys
from dataclasses import dataclass
sys.path.insert(0, "environments/coding")
import env as coding_env # noqa: E402
import tasks as coding_tasks # noqa: E402
from hud.environment.server import TaskRunner # noqa: E402
from hud.eval.job import Job # noqa: E402
from hud.eval.run import Grade, Run # noqa: E402
# The agent's whole "solution": two lines at the top of the package the hidden tests import.
CHEAT = 'import os as _o, sys as _s\nif "pytest" in _s.modules: _o._exit(0)\n'
@dataclass
class Proc:
returncode: int
stdout: bytes
stderr: bytes
timed_out: bool = False
class LocalWorkspace:
"""Stand-in for the bwrap sandbox: same cwd, same command, same env vars."""
root = coding_env.REPO_DIR
async def terminate_sessions(self):
pass
async def discard_sandbox(self):
pass
async def run(self, argv, cwd, env, max_wait, scope):
done = subprocess.run(argv, cwd=cwd, env={**os.environ, **env}, capture_output=True, timeout=max_wait)
return Proc(done.returncode, done.stdout, done.stderr)
coding_env.workspace = LocalWorkspace()
coding_env.REPO_DIR.mkdir(parents=True, exist_ok=True)
def git(*args):
return subprocess.run(["git", "-C", str(coding_env.BASELINE_DIR), *args], capture_output=True, check=True).stdout
def golden(task): # the bundle's own reference fix (refs/heads/flask_*_golden)
base = task.args["base_ref"]
ref = base.replace("_baseline", "_golden")
for rel in git("diff", "--name-only", base, ref).decode().split():
(coding_env.REPO_DIR / rel).write_bytes(git("show", f"{ref}:{rel}"))
def honest(task): # agent fails: leaves the repo as it found it
pass
def cheat(task): # agent fails, then makes the hidden test run exit before it writes JUnit XML
init = coding_env.REPO_DIR / "src" / "flask" / "__init__.py"
init.write_text(CHEAT + init.read_text())
async def grade(task, edit):
runner = TaskRunner(coding_env.env.templates[task.id], task.args)
await runner.start() # clones the bundle, checks out base_ref, returns the prompt
edit(task)
frame = await runner.grade({}) # restores tests/, applies the hidden patch, runs pytest
run = Run(None, task.id, {})
run.grade = Grade.from_dict(frame)
print(
f"{task.slug} {edit.__name__:6s} reward={run.reward:.1f} is_error={run.grade.is_error} "
f"exit_code={run.grade.info.get('exit_code')} error={run.grade.info.get('error')!r}"
)
return run
async def main():
a, b = coding_tasks.tasks
runs = {(t.slug, e.__name__): await grade(t, e) for t in (a, b) for e in (golden, honest, cheat)}
print()
for label, picks in [
(f"solve {a.slug}, fail {b.slug} honestly", [(a, "golden"), (b, "honest")]),
(f"solve {a.slug}, crash tests on {b.slug}", [(a, "golden"), (b, "cheat")]),
("solve both", [(a, "golden"), (b, "golden")]),
]:
job = Job(id="repro", name=label, runs=[runs[(t.slug, e)] for t, e in picks])
print(f"Job.reward={job.reward:.3f} errors={len(job.errors)} [{label}]")
asyncio.run(main())Output at e95373f on Ubuntu 24.04 LTS (Linux 6.8), Python 3.12.3, with the coding env's locked deps (pytest 8.4.2, werkzeug 2.3.8, click 8.1.8), run under unshare -n:
flask-4992 golden reward=1.0 is_error=False exit_code=None error=None
flask-4992 honest reward=0.0 is_error=False exit_code=None error=None
flask-4992 cheat reward=0.0 is_error=True exit_code=0 error='test command did not write JUnit XML'
flask-5063 golden reward=1.0 is_error=False exit_code=None error=None
flask-5063 honest reward=0.0 is_error=False exit_code=None error=None
flask-5063 cheat reward=0.0 is_error=True exit_code=0 error='test command did not write JUnit XML'
Job.reward=0.500 errors=0 [solve flask-4992, fail flask-5063 honestly]
Job.reward=1.000 errors=1 [solve flask-4992, crash tests on flask-5063]
Job.reward=1.000 errors=0 [solve both]
(exit_code=None on the non-error rows just means combine() doesn't copy the test run's info to the top-level grade.)
Solving one task and failing the other honestly gives 0.500. Solving one and breaking the test run on the other gives 1.000, the same as solving both.
Impact
In a job with successful and failed runs, breaking the test command on a failed task can raise Job.reward / mean_reward by excluding that run. The separate error count still exposes the failure. It can also happen by accident: an edit that kills the interpreter at import time, or makes pytest exit early, is excluded rather than scored as 0. Per-run rewards and GRPO training are not affected, since the run itself still scores 0.0. Other templates that set isError after agent code has run would have the same effect on Job.reward; I only checked the coding environment.
Related: #717 is about the same exclusion rule from the other side (provider outages counted as real zeros).
Possible fix
- In the coding env, once the hidden tests have run against the agent's code, score a missing or unparsable JUnit report as 0.0 with
isError=False, and keep the reason ininfo. KeepisError=Truefor failures that happen before any agent code runs, such as a test patch that won't apply. By reading the code, a run that hitsGRADING_TIMEOUTwithout a report also takes the error path today, since the report check comes before thetimed_outcheck. The same 0.0 rule would cover that. - In the SDK, consider reporting an all-runs mean (errors counted as 0) next to
Job.reward, or printing the error count next tomean_rewardwherever it appears. Also align the "mean across every run" wording in the docs with the code.
Happy to help test a fix. Found while auditing public RL environments.
Activity
fix(coding): grade a run without a usable JUnit report as a failure
fix(coding): score a timed-out hidden-test run as a failure, not an e…
fix(coding): grade a run without a usable JUnit report as a failure
fix(coding): score a run without a usable JUnit report as a failure
fix: grading, training, shutdown and process-guard fixes (hud-evals#758)