Grade a fix the agent committed: locate the repo by base ancestry, reset tests from base

#2
by Chrisyichuan - opened

Problem

Every tests/test.sh locates the repository with find_repo, which only accepts a .git whose HEAD equals the base commit, and otherwise writes reward 0 without running a test ("fail closed").

An agent that fixes the bug and then runs git commit therefore scores 0 regardless of whether the fix is right: HEAD has moved to its own commit, whose parent is the base commit. In one RL run (Qwen3.5-9B, terminus agent), 5 of 344 Rebench rollouts were zeroed this way without being graded (e.g. cs-si__eodag-634: edit eodag/utils/__init__.py, self-test, git add, git commit, submit -> no repository at base commit). For RL this rewards "never touch git", not "fix the bug".

(Rollouts that git checkout an unrelated or older commit and fix the bug there, e.g. 9 rollouts on maas__python-libmaas-227, are also zeroed. That is correct and stays unchanged: the graded code is not the task's code.)

Change

Only the repo lookup and the test-surface reset change; the test patch, the FAIL_TO_PASS / PASS_TO_PASS runs and the reward rule are untouched. All 1,317 tests/test.sh get the same edits:

  1. BASE=<sha> is set once, and find_repo "$BASE" accepts a repo when git merge-base --is-ancestor "$BASE" HEAD holds (HEAD is base, or descends from it).
  2. The graded test files are restored from "$BASE" instead of HEAD.
  3. The whole test surface is listed with git ls-tree ... "$BASE" and restored from "$BASE".
  4. Test-surface files that do not exist in $BASE are removed whether untracked or committed (git ls-files + --others, then git cat-file -e "$BASE:$f" || rm). Previously only untracked files were removed, which was safe only because HEAD had to equal base; with commits allowed, a committed new test would otherwise survive.
  5. touched (diagnostic only) diffs against "$BASE", so committed pyproject.toml / setup.cfg / tox.ini edits are still reported.

With nothing committed, HEAD == BASE and the new script behaves exactly as before.

Verification

  • The edits are exact-string replacements, each required to match exactly once per file; all 1,317 files matched, and every patched script passes bash -n.
  • Tested end to end on a fixture repo running the real script's lookup/reset section: an agent that fixes src.py, tampers a graded test, deletes another, edits conftest.py and adds a new test file gets: fix kept, all tampering undone, added test removed, both when it commits and when it doesn't. Unpatched, the committed case scores 0 ungraded; an orphan/unrelated checkout still finds no repo and scores 0.
  • data/tasks-00000.tar is otherwise unchanged: same 10,536 members in the same order with the same mode/mtime/owner; only the 1,317 tests/test.sh contents differ.

The same rewrite is applied at build time in https://github.com/yichuan-w/torchtitan (branch yichuan/qwen35-port-cotrain, torchtitan/experiments/rl/examples/tmax/evolution/pack_to_dataset.py, patch_rebench_test_sh), which becomes a no-op once this is merged.

The Files tab only shows the LFS pointer of data/tasks-00000.tar (oid 8768da2b… -> fa393aff…, size 55,173,120 -> 55,326,720), so here is what changed inside it.

All 1,317 tests/test.sh receive the identical edit below (only the base commit differs per task; checked: 1 distinct diff once the sha is masked). No other member of the tar changed. Example, tasks/cs-si__eodag-634/tests/test.sh:

--- a/tasks/cs-si__eodag-634/tests/test.sh
+++ b/tasks/cs-si__eodag-634/tests/test.sh
@@ -14,3 +14,3 @@
     r="$(dirname "$d")"
-    if [ "$(git -C "$r" rev-parse HEAD 2>/dev/null)" = "$want" ]; then
+    if git -C "$r" merge-base --is-ancestor "$want" HEAD 2>/dev/null; then
       echo "$r"; return 0
@@ -30,3 +30,4 @@
 # broken box gets recorded as a wrong fix.
-R="$(find_repo 69d24e856d04abbf44a81786b67cc26e98d43ee5)" || {
+BASE=69d24e856d04abbf44a81786b67cc26e98d43ee5
+R="$(find_repo "$BASE")" || {
   echo "error=no_repo_at_base_commit" > /logs/verifier/pytest_rc.txt
@@ -41,3 +42,3 @@
   [ -z "$f" ] && continue
-  git checkout -q HEAD -- "$f" 2>/dev/null || rm -f -- "$f"
+  git checkout -q "$BASE" -- "$f" 2>/dev/null || rm -f -- "$f"
 done <<'TPFILES'
@@ -61,5 +62,5 @@
 # listing would have missed.
-git ls-tree -r -z --name-only HEAD \
+git ls-tree -r -z --name-only "$BASE" \
   | grep -zE '(^|/)(tests?|testing)/|(^|/)conftest\.py$|(^|/)pytest\.ini$' \
-  | xargs -0 -r git checkout -q HEAD -- 2>/dev/null
+  | xargs -0 -r git checkout -q "$BASE" -- 2>/dev/null
 # and anything the agent ADDED in there that HEAD never had. --exclude-standard
@@ -67,6 +68,6 @@
 # stay: removing those leaves a repository that cannot import itself.
-git ls-files -z --others --exclude-standard \
+{ git ls-files -z; git ls-files -z --others --exclude-standard; } \
   | grep -zE '(^|/)(tests?|testing)/|(^|/)conftest\.py$|(^|/)pytest\.ini$' \
-  | xargs -0 -r rm -f -- 2>/dev/null
-touched="$(git diff --name-only HEAD -- ':(glob)**/pyproject.toml' ':(glob)**/setup.cfg' ':(glob)**/tox.ini' 2>/dev/null)"
+  | while IFS= read -r -d '' f; do git cat-file -e "$BASE:$f" 2>/dev/null || rm -f -- "$f"; done
+touched="$(git diff --name-only "$BASE" -- ':(glob)**/pyproject.toml' ':(glob)**/setup.cfg' ':(glob)**/tox.ini' 2>/dev/null)"
 if ! git apply --whitespace=nowarn "$HERE/test.patch"; then
Fzz1 changed pull request status to merged

Sign up or log in to comment