Skip to content
farming-labsPublic

About

RL grade linter

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

gradelint

Test that RL task graders can't be fooled.

Warning

Early exploration. This version grades the reference solution, an answer that does nothing, three cheats (a fake pytest, a pytest plugin, and a fake uv), and any wrong answers the task ships in wrong/. The CLI, report format, and checks may change before 1.0.

An RL task is a folder: an instruction, a container, a reference solution, and a grader script that writes a reward. During training, the model does more of whatever earns reward. If the grader can be fooled, the model learns to fool it.

gradelint plays the cheater before the model does. It runs answers whose correct reward is already known through the task's own grader, and reports every grader that gives the wrong score.

answer fed to the grader     should get   if the grader disagrees
───────────────────────────  ──────────   ───────────────────────────
reference solution           1            the task can't be solved
do nothing                   0            the grader rewards nothing
known cheat                  0            the model will learn the cheat

On Terminal-Bench

We ran gradelint over every task in Terminal-Bench 2.0 and 2.1, 178 in all, one task per GitHub Actions job:

Terminal-Bench 2.1, 89 tasks Tasks flagged
Oracle + nop (reference solution earns 1, doing nothing earns 0) 5
gradelint (the same two checks, plus three cheats) 89

Every 2.1 grader paid full reward to a cheat that did none of the task: 83 to a fake uv, 6 to a planted pytest plugin. The same scripts ran unchanged against every task. Each payout was confirmed from the grader's own output. The method, every failure's cause, and the limits are in bench/README.md.

Try a small model

Train a BERT-tiny policy to choose among four arithmetic functions. Change one input pair and compare the reward a grader gives with the chance the model actually chooses the right function. The pilot runs on CPU with Python and uv. Run the small-model example.

Install

cargo install gradelint

Prebuilt binaries for macOS, Linux, and Windows are on the releases page, with SHA256SUMS and build provenance.

gradelint runs each task in Docker, so it needs a running Docker daemon. Set GRADELINT_DOCKER to use another Docker-compatible CLI.

Usage

Point it at a Harbor task folder, or at a folder whose subfolders are tasks:

$ gradelint check fixtures/good-task
good-task
  ✓ layout
  ✓ reference solution  expected 1, got 1
  ✓ do nothing          expected 0, got 0
  ✓ fake pytest         expected 0, got 0
  ✓ pytest plugin       expected 0, got 0
  ✓ fake uv             expected 0, got 0

1 task checked, no problems

A grader that throws away its own result is caught by the answer that does nothing:

$ gradelint check fixtures/rewards-anything
rewards-anything
  ✓ layout
  ✓ reference solution  expected 1, got 1
  ✗ do nothing          expected 0, got 1; the grader rewards an untouched environment; grade the agent's work, not the starting state
  ✗ fake pytest         expected 0, got 1; doing nothing earns reward too, so fix that first
  ✗ pytest plugin       expected 0, got 1; doing nothing earns reward too, so fix that first
  ✗ fake uv             expected 0, got 1; doing nothing earns reward too, so fix that first

1 of 1 task with problems

A grader that runs the image's own pytest passes the honest answers and still pays out to both cheats:

$ gradelint check fixtures/pytest-on-path
pytest-on-path
  ✓ layout
  ✓ reference solution  expected 1, got 1
  ✓ do nothing          expected 0, got 0
  ✗ fake pytest         expected 0, got 1; the grader runs a pytest the agent can replace; install the grader's tools in test.sh, or verify in a separate environment
  ✗ pytest plugin       expected 0, got 1; pytest loads plugins the agent installs; set PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 in test.sh, or verify in a separate environment
  ✓ fake uv             expected 0, got 0

1 of 1 task with problems

Installing the test tools while grading doesn't help when the agent controls the tools that do the install. This grader downloads uv with curl and runs pytest through uvx, as Terminal-Bench 2 graders do. Both pytest cheats miss, and a fake curl still gets paid:

$ gradelint check fixtures/uv-at-grading-time
uv-at-grading-time
  ✓ layout
  ✓ reference solution  expected 1, got 1
  ✓ do nothing          expected 0, got 0
  ✓ fake pytest         expected 0, got 0
  ✓ pytest plugin       expected 0, got 0
  ✗ fake uv             expected 0, got 1; the grader runs uv, or downloads it with curl, inside the container the agent used; verify in a separate environment

1 of 1 task with problems

Grading in a separate verifier container stops all three cheats. This is the same grader as pytest-on-path, but it runs in a fresh copy of the image that receives only the declared artifact, /app/calc.py, and Harbor's /logs/artifacts/ folder:

$ gradelint check fixtures/separate-verifier
separate-verifier
  ✓ layout
  ✓ reference solution  expected 1, got 1
  ✓ do nothing          expected 0, got 0
  ✓ fake pytest         expected 0, got 0
  ✓ pytest plugin       expected 0, got 0
  ✓ fake uv             expected 0, got 0

1 task checked, no problems

A separate verifier only sees what artifacts carries over, plus /logs/artifacts/. When a task declares the wrong path, the reference solution fails, and the report says which artifact was missing:

$ gradelint check fixtures/missing-artifact
missing-artifact
  ✓ layout
  ✗ reference solution  expected 1, got 0; solution/solve.sh does not earn full reward in the separate verifier; check that artifacts lists every file the grader reads, then fix the solution or the grader
      artifact: /app/output/calc.py: not found in the agent's container
  ✓ do nothing          expected 0, got 0
  ✓ fake pytest         expected 0, got 0
  ✓ pytest plugin       expected 0, got 0
  ✓ fake uv             expected 0, got 0

1 of 1 task with problems

Your own wrong answers

The built-in cheats work on any task, but some mistakes only make sense for one task. Put a known-wrong answer in wrong/<name>/solve.sh, and gradelint runs it the way it runs the reference solution: the folder is copied to /solution and solve.sh runs. The grader must give it less than full reward. Partial credit is fine, and full marks for wrong work is reported.

my-task/
  solution/solve.sh          the right answer: must earn 1
  wrong/multiply/solve.sh    a wrong answer: must earn less than 1

This grader only checks add(2, 2) == 4, and 2 × 2 is 4 too:

$ gradelint check fixtures/weak-test
weak-test
  ✓ layout
  ✓ reference solution  expected 1, got 1
  ✓ do nothing          expected 0, got 0
  ✓ fake pytest         expected 0, got 0
  ✓ pytest plugin       expected 0, got 0
  ✓ fake uv             expected 0, got 0
  ✗ wrong: multiply     expected less than 1, got 1; the grader gives full reward to wrong/multiply; add a test case that this answer fails

1 of 1 task with problems

Harbor builds from environment/ and uploads only tests/ and solution/, so wrong/ never reaches the agent or the grader.

Layout problems are reported all at once, before anything runs:

$ gradelint check ./tasks/broken-task
broken-task
  ✗ missing tests/test.sh; Harbor runs this script to grade the task
  ✗ missing solution/solve.sh; add a reference solution so gradelint can prove the task is solvable

1 of 1 task with problems

JSON report

--json prints one JSON document instead of text, with the same exit codes. schema_version changes only when an existing key changes meaning or disappears; new keys can appear in any release.

$ gradelint check ./tasks/broken-task --json
{
  "gradelint_version": "0.1.0",
  "schema_version": 1,
  "summary": {
    "exit_code": 3,
    "tasks": 1,
    "unchecked": 0,
    "with_problems": 1
  },
  "tasks": [
    {
      "checks": [],
      "layout_ok": false,
      "name": "broken-task",
      "path": "broken-task",
      "problems": [
        {
          "code": "missing_grader",
          "message": "missing tests/test.sh; Harbor runs this script to grade the task"
        },
        {
          "code": "missing_solution",
          "message": "missing solution/solve.sh; add a reference solution so gradelint can prove the task is solvable"
        }
      ],
      "reasons": [],
      "status": "invalid"
    }
  ]
}
Key Values
tasks[].status passed, failed (a check failed), invalid (layout problems), unchecked
tasks[].verifier_mode shared or separate when the task loaded, else null
tasks[].checks[] id, label, expected_reward, outcome, reward, passed, message
tasks[].checks[].answer_output, grader_output The last 200 lines the answer and test.sh printed, stdout and stderr together. Empty when the step did not run or printed nothing.
tasks[].checks[].id reference, nothing, pytest-shim, pytest-plugin, uv-shim, or wrong:<name> for a task's own wrong answer
tasks[].checks[].expect full, nothing, or below_full; expected_reward is null for below_full
tasks[].checks[].outcome reward, no_reward, bad_reward, answer_timed_out, grader_timed_out
tasks[].checks[].rewards Every key of reward.json when the grader wrote an object, else null
tasks[].checks[].runs With --runs above 1: each run's outcome and reward. reward and outcome describe the first run that failed, or the last run
tasks[].checks[].steps For a multi-step task: each step that ran, as name, outcome, and reward
tasks[].checks[].flaky true when some runs passed and others failed
tasks[].checks[].artifact_notes With a separate verifier: each declared artifact that was missing, and each member left out because it was unsafe
tasks[].problems[].code missing_instruction, missing_task_toml, invalid_task_toml, missing_environment, missing_grader, missing_solution, invalid_verifier_mode, invalid_artifact, invalid_wrong_answer, invalid_steps
tasks[].reasons[] Why an unchecked task could not be checked
Exit code Meaning
0 Every task passed.
1 gradelint could not check every task.
2 Usage error, such as a path that doesn't exist.
3 At least one task has a problem.

How it works

Each answer gets a fresh container and follows Harbor's verification order:

  1. Start a container from environment/Dockerfile, or from [environment] docker_image, which is pulled first when it isn't local. Builds and pulls each get 30 minutes.
  2. Let the answer act. The reference solution copies solution/ to /solution and runs solve.sh, and so does each wrong/<name>/ answer with its own folder. Doing nothing runs nothing. A cheat runs its shell script, the way an agent with a shell would.
  3. Run the grader:
    • Shared verification (the default): copy tests/ to /tests in the same container and run test.sh.
    • Separate verification ([verifier] environment_mode = "separate", or a [verifier.environment] table): start a fresh verifier container and copy in /logs/artifacts/ and every path in artifacts, each at its original path. Then copy tests/ to /tests, unless the verifier image brings its own, and run test.sh there.
  4. Read /logs/verifier/reward.json, or reward.txt when there is no JSON, and compare the reward with the one the answer should earn.
  5. Remove the containers.

The verifier image follows Harbor's order: [verifier.environment] docker_image, then tests/Dockerfile (both bring their own /tests), then the agent's image or environment/Dockerfile. Artifacts are rebuilt the way Harbor's tarfile data filter rebuilds them: setuid and setgid bits and group or other write bits are cleared, and devices, FIFOs, and links that point outside the artifact are left out. A folder artifact with exclude patterns is archived with tar --exclude inside the agent's container, as Harbor does.

Answer Should earn When the grader disagrees
Reference solution 1 The solution is wrong, or the grader rejects correct work.
Do nothing 0 The grader rewards the starting state.
Fake pytest 0 Every pytest on PATH is replaced with one that always passes, and the grader runs it.
Pytest plugin 0 A plugin installed into the image's Python marks every test passed, and the grader's pytest loads it.
Fake uv 0 Every uv and uvx on PATH is replaced with one that always passes, and a curl in /usr/local/bin serves an installer for them to any astral.sh/uv URL. The grader runs uv, or downloads it while grading.
wrong/<name>/solve.sh less than 1 The grader gives full reward to an answer the task's author knows is wrong.

Cheats that don't apply to an image, such as the pytest cheats in an image without Python, leave the environment as it was, so a sound grader still pays 0.

The grader's reward comes from /logs/verifier/reward.json when it writes one, as in Harbor, and from reward.txt otherwise. reward.json must hold a number or an object of numbers. gradelint compares its reward key, else its only key, else the mean of every key, and reports every key under rewards. A missing or non-numeric reward fails the check. [agent] timeout_sec and [verifier] timeout_sec bound each step (600 seconds when unset).

A folder with docker-compose.yaml is started the way Harbor starts it: a main service built from the folder's Dockerfile, or running [environment] docker_image, kept alive with sleep infinity, with the task's compose file layered on top so it can add services or override main. Answers act and graders run in main. Every answer gets its own compose project, removed with docker compose down afterwards.

A multi-step task runs its [[steps]] in order in one environment, as Harbor runs it. With shared verification, the last step's /tests and /logs/verifier are cleared before each step after the first; a separate verifier starts fresh for each step. The step's workdir/ is copied into the working folder and its setup.sh runs. The answer acts, and the step is graded with the task's tests/ and the step's own tests laid over them. A step that misses its min_reward ends the task. The step rewards become the task's reward by multi_step_reward_strategy: each key's mean over the graded steps, with a missing key counting as 0 (the default), or the final step's. The reference solution runs each step's solution/solve.sh. Cheats and wrong answers act once, before the first step is graded, like an agent that then stops working. JSON checks list every step that ran under steps, including the one that stopped the task.

Containers get the task's [environment] cpus and memory_mb as docker run --cpus and --memory (a separate verifier takes them from [verifier.environment] when it has that table). A CPU request above what the Docker host has is lowered to the host's count, because Docker refuses to start the container otherwise. storage_mb and gpus are not applied.

--runs N grades every answer N times, each in fresh containers. A check passes only when every run does, and a check whose verdict changes between runs is marked flaky.

gradelint labels the images it builds with gradelint. Remove them with docker image prune --all --filter label=gradelint. Compose projects are named gradelint-<pid>-<n> and removed after each answer. If a run is interrupted, list leftovers with docker compose ls --all --filter name=gradelint- and remove each with docker compose -p <name> down --volumes.

Supported tasks

Task feature Status
environment/Dockerfile or [environment] docker_image Supported
Shared verification (the default when [verifier] environment_mode is unset) Supported
Separate verification, with artifacts, [verifier.environment] docker_image, or tests/Dockerfile Supported
environment/docker-compose.yaml and tests/docker-compose.yaml Supported
Artifacts collected from a compose service other than main Not yet; reported as unchecked (exit 1)
Multi-step tasks ([[steps]] and steps/) Supported
Per-step verifier environments ([steps.verifier] environment_mode or environment) Not yet; reported as unchecked (exit 1)
Rewards in /logs/verifier/reward.json Supported
[environment] cpus and memory_mb Applied to each container

A task without solution/solve.sh is reported as a problem: without a reference solution, gradelint can't show that the task is solvable.

What it does not do

gradelint does not train models, host tasks, or judge whether a task is worth training on. A clean report means none of its known cheats fooled the grader. It does not prove the grader is safe.

A failed cheat check shows that the grader trusts something the agent could change. It does not show that any model has found that path.

By default gradelint grades each answer once. A grader that pays out by chance, such as a timing test, can pass a check on one run and fail it on the next. --runs 5 catches more of these, but no number of runs proves a grader is deterministic.

License

MIT

About

RL grade linter

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages