A skill to stop your coding agent from burying the answer. ADHD-friendly output.
evals: harden blind judge isolation
Ayoub G.76b66165ad75
diff --git a/scripts/judge.py b/scripts/judge.pyindex d08e963..01022a6 100644--- a/scripts/judge.py+++ b/scripts/judge.py@@ -171,7 +171,7 @@ def assign_labels(group_key: tuple, conditions: list[str]) -> dict[str, str]:return dict(zip(ordered, labels))-def _neutral_cwd() -> str:+def _neutral_cwd():"""Run the judge in the same neutral context generation uses."""return run_evals._neutral_cwd()@@ -188,14 +188,15 @@ def invoke_judge("""completed = Nonefor attempt in range(retries + 1):- completed = subprocess.run(- list(command),- check=False,- capture_output=True,- text=True,- input=prompt,- cwd=_neutral_cwd(),- )+ with _neutral_cwd() as cwd:+ completed = subprocess.run(+ list(command),+ check=False,+ capture_output=True,+ text=True,+ input=prompt,+ cwd=cwd,+ )if completed.returncode == 0:breakif attempt < retries:@@ -244,6 +245,13 @@ def _build_parser() -> argparse.ArgumentParser:"--runner-config", type=Path, default=ROOT / "evals" / "runners.example.json")parser.add_argument("--runner", required=True)+ parser.add_argument(+ "--conditions",+ nargs="+",+ choices=sorted(run_evals.CONDITIONS),+ default=["baseline", "candidate"],+ help="Conditions that every response group must contain (default: baseline candidate).",+ )parser.add_argument("--retries", type=int, default=2)parser.add_argument("--output", type=Path, required=True)return parser@@ -258,7 +266,17 @@ def main(argv: list[str] | None = None) -> int:raise ValueError(f"{args.responses}: no responses to judge")groups = group_responses(rows)- required = {row["condition"] for row in rows}+ required = set(args.conditions)+ observed = {row["condition"] for row in rows}+ missing = sorted(required - observed)+ unexpected = sorted(observed - required)+ if missing or unexpected:+ details = []+ if missing:+ details.append(f"missing required condition(s): {', '.join(missing)}")+ if unexpected:+ details.append(f"unexpected condition(s): {', '.join(unexpected)}")+ raise ValueError("Response conditions do not match --conditions: " + "; ".join(details))complete, incomplete = partition_groups(groups, required)for case_id, trial in sorted(incomplete):print(@@ -293,7 +311,7 @@ def main(argv: list[str] | None = None) -> int:scored, cost = _judge_group(command, response_format, prompt, key, labels, args.retries)- except ValueError as exc:+ except (ValueError, RuntimeError) as exc:# One unusable verdict must not discard the groups already# written or the ones still queued behind it.print(f"skip {case_id}/trial {trial}: {exc}", file=sys.stderr)diff --git a/scripts/run_evals.py b/scripts/run_evals.pyindex 9a35462..1f6f629 100644--- a/scripts/run_evals.py+++ b/scripts/run_evals.py@@ -4,6 +4,7 @@from __future__ import annotationsimport argparse+from contextlib import contextmanagerimport jsonimport shleximport subprocess@@ -11,6 +12,7 @@ import sysimport tempfileimport timefrom collections import Counter, defaultdict+from collections.abc import Iteratorfrom pathlib import Pathfrom typing import Any@@ -27,11 +29,9 @@ WEIGHTS = {CONDITIONS = {"baseline", "candidate", "comparator"}-_NEUTRAL_CWD: str | None = None---def _neutral_cwd() -> str:- """An empty scratch directory to run a runner in.+@contextmanager+def _neutral_cwd() -> Iterator[str]:+ """Yield an empty scratch directory for one runner invocation.Agent CLIs adopt their working directory as project context: run one insidethis checkout and it answers prompts by inspecting the harness instead of@@ -42,10 +42,8 @@ def _neutral_cwd() -> str:working directory is simply another channel the operator's world leaks inthrough."""- global _NEUTRAL_CWD- if _NEUTRAL_CWD is None:- _NEUTRAL_CWD = tempfile.mkdtemp(prefix="eval-neutral-cwd-")- return _NEUTRAL_CWD+ with tempfile.TemporaryDirectory(prefix="eval-neutral-cwd-") as cwd:+ yield cwddef read_jsonl(path: Path) -> list[dict[str, Any]]:@@ -294,13 +292,14 @@ def run_evaluations(args: argparse.Namespace) -> int:invocation.append(prompt)completed = Nonefor attempt in range(args.retries + 1):- completed = subprocess.run(- invocation,- check=False,- capture_output=True,- text=True,- cwd=_neutral_cwd(),- )+ with _neutral_cwd() as cwd:+ completed = subprocess.run(+ invocation,+ check=False,+ capture_output=True,+ text=True,+ cwd=cwd,+ )if completed.returncode == 0:breakif attempt < args.retries:diff --git a/tests/test_judge.py b/tests/test_judge.pyindex 99812b8..ddf844f 100644--- a/tests/test_judge.py+++ b/tests/test_judge.py@@ -159,15 +159,21 @@ class PromptTest(unittest.TestCase):class NeutralWorkingDirectoryTest(unittest.TestCase):- def test_runner_cwd_is_an_empty_directory_outside_the_repository(self):+ def test_runner_cwd_is_fresh_and_outside_the_repository(self):# An agent CLI adopts its working directory as project context. Run it# in the repo and it starts inspecting the eval harness instead of# answering the prompt, which contaminates the responses being graded.- cwd = Path(judge._neutral_cwd()).resolve()+ with judge._neutral_cwd() as first:+ cwd = Path(first).resolve()+ self.assertNotEqual(judge.ROOT.resolve(), cwd)+ self.assertFalse(str(cwd).startswith(str(judge.ROOT.resolve())))+ self.assertEqual([], list(cwd.iterdir()))+ (cwd / "state-from-prior-run").write_text("not reusable")- self.assertNotEqual(judge.ROOT.resolve(), cwd)- self.assertFalse(str(cwd).startswith(str(judge.ROOT.resolve())))- self.assertEqual([], list(cwd.iterdir()))+ with judge._neutral_cwd() as second:+ next_cwd = Path(second).resolve()+ self.assertNotEqual(cwd, next_cwd)+ self.assertEqual([], list(next_cwd.iterdir()))class EndToEndTest(unittest.TestCase):@@ -311,6 +317,93 @@ class EndToEndTest(unittest.TestCase):self.assertEqual(2, len(rows))self.assertNotEqual(0, exit_code, "skipped groups must not report success")+ def test_missing_entire_condition_fails_before_judging(self):+ with tempfile.TemporaryDirectory() as tmp:+ tmp_path = Path(tmp)+ responses = tmp_path / "responses.jsonl"+ responses.write_text(+ json.dumps(+ {+ "case_id": "direct-answer",+ "trial": 1,+ "condition": "baseline",+ "runner": "stub",+ "response": "102",+ }+ )+ + "\n"+ )+ output = tmp_path / "scores.jsonl"+ runner_config = tmp_path / "runners.json"+ runner_config.write_text(+ json.dumps({"stub": {"command": ["sh", "-c", "exit 99"], "response_format": "text"}})+ )++ with self.assertRaisesRegex(ValueError, "missing required condition"):+ judge.main(+ [+ "--responses", str(responses),+ "--runner-config", str(runner_config),+ "--runner", "stub",+ "--output", str(output),+ ]+ )+ self.assertFalse(output.exists())++ def test_runner_failure_skips_its_group_and_continues(self):+ with tempfile.TemporaryDirectory() as tmp:+ tmp_path = Path(tmp)+ responses = tmp_path / "responses.jsonl"+ responses.write_text(+ "".join(+ json.dumps(+ {+ "case_id": case_id,+ "trial": 1,+ "condition": condition,+ "runner": "stub",+ "response": f"{case_id} {condition} text",+ }+ )+ + "\n"+ for case_id in ("direct-answer", "casual-message")+ for condition in ("baseline", "candidate")+ )+ )+ verdict = tmp_path / "verdict.json"+ verdict.write_text(json.dumps({"A": self.VERDICT, "B": self.VERDICT}))+ runner_config = tmp_path / "runners.json"+ runner_config.write_text(+ json.dumps(+ {+ "stub": {+ "command": [+ "sh",+ "-c",+ f'p=$(cat); case "$p" in *direct-answer*) exit 7;; *) cat {verdict};; esac',+ ],+ "response_format": "text",+ }+ }+ )+ )+ output = tmp_path / "scores.jsonl"++ exit_code = judge.main(+ [+ "--responses", str(responses),+ "--runner-config", str(runner_config),+ "--runner", "stub",+ "--retries", "0",+ "--output", str(output),+ ]+ )++ rows = run_evals.read_jsonl(output)+ self.assertEqual({"casual-message"}, {row["case_id"] for row in rows})+ self.assertEqual(2, len(rows))+ self.assertNotEqual(0, exit_code, "skipped groups must not report success")+if __name__ == "__main__":unittest.main()