Datasets:
Add 10000 GitHub Trending pr_diff environments (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/AeneasVerif__aeneas-1386/tests/test.sh +25 -0
- tasks/AeneasVerif__aeneas-1386/tests/verifier.py +737 -0
- tasks/AeneasVerif__aeneas-1388/environment/Dockerfile +37 -0
- tasks/AeneasVerif__aeneas-1388/instruction.md +11 -0
- tasks/AeneasVerif__aeneas-1388/solution/patch.diff +262 -0
- tasks/AeneasVerif__aeneas-1388/solution/solve.sh +6 -0
- tasks/AeneasVerif__aeneas-1388/task.toml +71 -0
- tasks/AeneasVerif__aeneas-1388/tests/capture.py +96 -0
- tasks/AeneasVerif__aeneas-1388/tests/instruction.md +11 -0
- tasks/AeneasVerif__aeneas-1388/tests/oracle.patch +262 -0
- tasks/AeneasVerif__aeneas-1388/tests/test.sh +25 -0
- tasks/AeneasVerif__aeneas-1388/tests/verifier.py +737 -0
- tasks/AeneasVerif__aeneas-1391/environment/Dockerfile +37 -0
- tasks/AeneasVerif__aeneas-1391/instruction.md +11 -0
- tasks/AeneasVerif__aeneas-1391/solution/patch.diff +113 -0
- tasks/AeneasVerif__aeneas-1391/solution/solve.sh +6 -0
- tasks/AeneasVerif__aeneas-1391/task.toml +71 -0
- tasks/AeneasVerif__aeneas-1391/tests/capture.py +96 -0
- tasks/AeneasVerif__aeneas-1391/tests/instruction.md +11 -0
- tasks/AeneasVerif__aeneas-1391/tests/oracle.patch +113 -0
- tasks/AeneasVerif__aeneas-1391/tests/test.sh +25 -0
- tasks/AeneasVerif__aeneas-1391/tests/verifier.py +737 -0
- tasks/AeneasVerif__aeneas-1400/environment/Dockerfile +37 -0
- tasks/AeneasVerif__aeneas-1400/instruction.md +11 -0
- tasks/AeneasVerif__aeneas-1400/solution/patch.diff +19 -0
- tasks/AeneasVerif__aeneas-1400/solution/solve.sh +6 -0
- tasks/AeneasVerif__aeneas-1400/task.toml +68 -0
- tasks/AeneasVerif__aeneas-1400/tests/capture.py +96 -0
- tasks/AeneasVerif__aeneas-1400/tests/instruction.md +11 -0
- tasks/AeneasVerif__aeneas-1400/tests/oracle.patch +19 -0
- tasks/AeneasVerif__aeneas-1400/tests/test.sh +25 -0
- tasks/AeneasVerif__aeneas-1400/tests/verifier.py +737 -0
- tasks/AeneasVerif__aeneas-1401/environment/Dockerfile +37 -0
- tasks/AeneasVerif__aeneas-1401/instruction.md +19 -0
- tasks/AeneasVerif__aeneas-1401/solution/patch.diff +61 -0
- tasks/AeneasVerif__aeneas-1401/solution/solve.sh +6 -0
- tasks/AeneasVerif__aeneas-1401/task.toml +69 -0
- tasks/AeneasVerif__aeneas-1401/tests/capture.py +96 -0
- tasks/AeneasVerif__aeneas-1401/tests/instruction.md +19 -0
- tasks/AeneasVerif__aeneas-1401/tests/oracle.patch +61 -0
- tasks/AeneasVerif__aeneas-1401/tests/test.sh +25 -0
- tasks/AeneasVerif__aeneas-1401/tests/verifier.py +737 -0
- tasks/AeneasVerif__aeneas-1414/environment/Dockerfile +37 -0
- tasks/AeneasVerif__aeneas-1414/instruction.md +13 -0
- tasks/AeneasVerif__aeneas-1414/solution/patch.diff +108 -0
- tasks/AeneasVerif__aeneas-1414/solution/solve.sh +6 -0
- tasks/AeneasVerif__aeneas-1414/task.toml +71 -0
- tasks/AeneasVerif__aeneas-1414/tests/capture.py +96 -0
- tasks/AeneasVerif__aeneas-1414/tests/instruction.md +13 -0
- tasks/AeneasVerif__aeneas-1414/tests/oracle.patch +108 -0
tasks/AeneasVerif__aeneas-1386/tests/test.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -uxo pipefail
|
| 3 |
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
| 4 |
+
cd /workspace
|
| 5 |
+
mkdir -p /logs/verifier
|
| 6 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json /logs/verifier/reward-details.json
|
| 7 |
+
CAPTURE_DIR="$(mktemp -d)" || exit 1
|
| 8 |
+
trap 'rm -rf -- "$CAPTURE_DIR"' EXIT
|
| 9 |
+
if ! python3 -I "$SCRIPT_DIR/capture.py" /workspace 399081f237935f9aa805f2d4a51fd3784aea11a9 > "$CAPTURE_DIR/predicted.patch"; then
|
| 10 |
+
echo "0.0" > /logs/verifier/reward.txt
|
| 11 |
+
printf '%s' '{"final_reward": 0.0, "evaluation_status": "graded", "eval_trustworthy": false, "capture_status": "error"}' > /logs/verifier/reward-details.json
|
| 12 |
+
exit 0
|
| 13 |
+
fi
|
| 14 |
+
rm -f /logs/verifier/predicted.patch
|
| 15 |
+
cp -- "$CAPTURE_DIR/predicted.patch" /logs/verifier/predicted.patch
|
| 16 |
+
: 'START_VERIFY_OUTPUT'
|
| 17 |
+
if ! python3 -I "$SCRIPT_DIR/verifier.py" \
|
| 18 |
+
"$SCRIPT_DIR/oracle.patch" \
|
| 19 |
+
"$CAPTURE_DIR/predicted.patch" \
|
| 20 |
+
"$SCRIPT_DIR/instruction.md"; then
|
| 21 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json
|
| 22 |
+
printf '%s' '{"final_reward": null, "reward": null, "evaluation_status": "ungraded", "eval_trustworthy": false, "verifier_status": "error"}' > /logs/verifier/reward-details.json
|
| 23 |
+
fi
|
| 24 |
+
: 'END_VERIFY_OUTPUT'
|
| 25 |
+
exit 0
|
tasks/AeneasVerif__aeneas-1386/tests/verifier.py
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""In-container verifier for pr_diff tasks (6-component reward).
|
| 2 |
+
|
| 3 |
+
This module is the **standalone verifier** that runs inside the task's
|
| 4 |
+
Docker container, NOT a helper used at generation time. Generation emits
|
| 5 |
+
its source as ``tests/verifier.py``. Harbor delivers it at verify time,
|
| 6 |
+
and ``tests/test.sh`` invokes it with the oracle, predicted patch and instruction.
|
| 7 |
+
|
| 8 |
+
Reward = weighted sum of 6 components (5 deterministic + 1 required LLM):
|
| 9 |
+
|
| 10 |
+
format_valid (0 or 1) — predicted parses as a unified diff (guard)
|
| 11 |
+
size_sanity ([0, 1]) — min(oracle_loc, pred_loc) / max(...)
|
| 12 |
+
catches "rampage through the codebase"
|
| 13 |
+
file_targeting ([0, 1]) — F1 over changed-file sets (NOT Jaccard —
|
| 14 |
+
symmetric penalty over-punishes extras)
|
| 15 |
+
region_overlap ([0, 1]) — predicted hunks overlap oracle hunks
|
| 16 |
+
(strongest spatial-localization signal)
|
| 17 |
+
similarity ([0, 1]) — SequenceMatcher ratio over +/- lines only
|
| 18 |
+
(no free credit for context lines)
|
| 19 |
+
llm_judge ([0, 1] or null) — an LLM rates "does this address the issue?"
|
| 20 |
+
Anthropic Haiku by default; any OpenAI-
|
| 21 |
+
compatible server via ``R2E_JUDGE_ENDPOINT``.
|
| 22 |
+
null when the judge is unavailable
|
| 23 |
+
(no key or model, network, unreadable
|
| 24 |
+
reply) → ungraded, no reward file; a
|
| 25 |
+
reply without a valid score (refusal,
|
| 26 |
+
content filter, empty, no "score") → a
|
| 27 |
+
graded 0
|
| 28 |
+
|
| 29 |
+
Default weights: 0.00 / 0.08 / 0.12 / 0.20 / 0.10 / 0.50 (retuned from
|
| 30 |
+
the original 0.05 / 0.05 / 0.10 / 0.20 / 0.20 / 0.40 after a 23-task
|
| 31 |
+
pilot — see the comment block above ``_DEFAULT_WEIGHTS`` below).
|
| 32 |
+
Override per-task via ``task.toml.metadata`` or per-run via env vars
|
| 33 |
+
``R2E_W_FORMAT`` / ``R2E_W_SIZE`` / ``R2E_W_FILE`` / ``R2E_W_REGION`` /
|
| 34 |
+
``R2E_W_SIM`` / ``R2E_W_JUDGE`` (pass via harbor ``--ve`` so they
|
| 35 |
+
reach the verifier container).
|
| 36 |
+
|
| 37 |
+
Judge routing, also via ``--ve``: ``R2E_JUDGE_MODEL`` picks the model
|
| 38 |
+
(default Haiku); ``R2E_JUDGE_ENDPOINT`` points at an OpenAI-compatible
|
| 39 |
+
server (vLLM, Ollama, a gateway) and switches the request to
|
| 40 |
+
``<endpoint>/chat/completions`` with a bearer token from
|
| 41 |
+
``R2E_JUDGE_API_KEY`` — or a placeholder when unset, since self-hosted
|
| 42 |
+
servers ignore it. ``ANTHROPIC_API_KEY`` is only read on the default
|
| 43 |
+
route and is never sent to a custom endpoint.
|
| 44 |
+
|
| 45 |
+
Final reward is clipped to [0, 1] and additionally clamped to ≤ 0.40
|
| 46 |
+
when ``size_sanity < 0.10`` (catastrophic-size hard cap — stops a
|
| 47 |
+
charitable judge from inflating scores on wildly wrong-sized patches).
|
| 48 |
+
|
| 49 |
+
Outputs (mirrors `_pr_runtime_verifier.py` after #75):
|
| 50 |
+
/logs/verifier/reward.txt — single float (Harbor reads this);
|
| 51 |
+
graded runs only
|
| 52 |
+
/logs/verifier/reward-details.json — full component breakdown + status
|
| 53 |
+
(structured diagnostics; Harbor's `reward.json` schema is flat-numeric-
|
| 54 |
+
only, so the breakdown goes to the `reward-details.json` sidecar which
|
| 55 |
+
Harbor renders under Verifier Logs → Rewards)
|
| 56 |
+
|
| 57 |
+
Pure stdlib — uses only ``difflib``, ``json``, ``os``, ``re``,
|
| 58 |
+
``urllib``, ``sys``. The same module is imported by the unit tests
|
| 59 |
+
under ``tests/test_pr_diff_verifier.py`` so the in-container behavior
|
| 60 |
+
stays in lockstep with what we test.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
from __future__ import annotations
|
| 64 |
+
|
| 65 |
+
import argparse
|
| 66 |
+
import difflib
|
| 67 |
+
import json
|
| 68 |
+
import math
|
| 69 |
+
import os
|
| 70 |
+
import re
|
| 71 |
+
import sys
|
| 72 |
+
import urllib.error
|
| 73 |
+
import urllib.request
|
| 74 |
+
|
| 75 |
+
# ---------------------------------------------------------------------------
|
| 76 |
+
# Parsing helpers (shared by multiple components)
|
| 77 |
+
# ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
_DIFF_HEADER_RE = re.compile(r"^diff --git a/(\S+) b/(\S+)$")
|
| 80 |
+
_HUNK_HEADER_RE = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
| 81 |
+
_FILE_MARKER_RE = re.compile(r"^(?:---|\+\+\+) ")
|
| 82 |
+
_INDEX_RE = re.compile(r"^index ")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def file_paths(diff: str) -> set[str]:
|
| 86 |
+
"""Return the set of ``b/<path>`` paths touched by a unified diff."""
|
| 87 |
+
paths: set[str] = set()
|
| 88 |
+
for line in diff.splitlines():
|
| 89 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 90 |
+
if m:
|
| 91 |
+
paths.add(m.group(2))
|
| 92 |
+
return paths
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def hunk_ranges(diff: str) -> dict[str, list[tuple[int, int]]]:
|
| 96 |
+
"""For each touched file, return list of (start_line, end_line) ranges
|
| 97 |
+
on the **post-change** side (the ``+`` numbers in ``@@ -X +Y @@``).
|
| 98 |
+
"""
|
| 99 |
+
out: dict[str, list[tuple[int, int]]] = {}
|
| 100 |
+
current_file: str | None = None
|
| 101 |
+
for line in diff.splitlines():
|
| 102 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 103 |
+
if m:
|
| 104 |
+
current_file = m.group(2)
|
| 105 |
+
out.setdefault(current_file, [])
|
| 106 |
+
continue
|
| 107 |
+
m = _HUNK_HEADER_RE.match(line)
|
| 108 |
+
if m and current_file is not None:
|
| 109 |
+
new_start = int(m.group(3))
|
| 110 |
+
new_count = int(m.group(4) or "1")
|
| 111 |
+
end = new_start + max(new_count - 1, 0)
|
| 112 |
+
out[current_file].append((new_start, end))
|
| 113 |
+
return out
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _normalize_changes_only(diff: str) -> list[str]:
|
| 117 |
+
"""Return the +/- lines (the actual changes) for similarity scoring.
|
| 118 |
+
|
| 119 |
+
Drops:
|
| 120 |
+
- ``diff --git`` / ``index abc..def`` metadata
|
| 121 |
+
- ``@@ ... @@`` hunk markers (volatile line numbers)
|
| 122 |
+
- context lines (no +/- prefix) — these are unchanged code, scoring
|
| 123 |
+
them inflates similarity for trivial patches
|
| 124 |
+
Keeps file-marker lines (``--- a/foo`` / ``+++ b/foo``) so file identity
|
| 125 |
+
stays in the comparison; normalizes off the tab+timestamp suffix git
|
| 126 |
+
sometimes appends.
|
| 127 |
+
"""
|
| 128 |
+
out: list[str] = []
|
| 129 |
+
for line in diff.splitlines():
|
| 130 |
+
if _DIFF_HEADER_RE.match(line) or _INDEX_RE.match(line):
|
| 131 |
+
continue
|
| 132 |
+
if _HUNK_HEADER_RE.match(line):
|
| 133 |
+
continue
|
| 134 |
+
if _FILE_MARKER_RE.match(line):
|
| 135 |
+
out.append(line.split("\t")[0].strip())
|
| 136 |
+
continue
|
| 137 |
+
# +/- lines (actual changes)
|
| 138 |
+
if line.startswith("+") or line.startswith("-"):
|
| 139 |
+
out.append(line)
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------------------------
|
| 144 |
+
# Reward components
|
| 145 |
+
# ---------------------------------------------------------------------------
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def format_valid(predicted: str) -> float:
|
| 149 |
+
"""1.0 if the predicted text looks like a unified diff; else 0.0.
|
| 150 |
+
|
| 151 |
+
Requires both a ``diff --git`` header and at least one real +/- line
|
| 152 |
+
(not the ``---`` / ``+++`` file-marker lines).
|
| 153 |
+
"""
|
| 154 |
+
if not predicted.strip():
|
| 155 |
+
return 0.0
|
| 156 |
+
has_header = False
|
| 157 |
+
has_change = False
|
| 158 |
+
for line in predicted.splitlines():
|
| 159 |
+
if _DIFF_HEADER_RE.match(line):
|
| 160 |
+
has_header = True
|
| 161 |
+
elif (line.startswith("+") or line.startswith("-")) and not line.startswith(
|
| 162 |
+
("+++ ", "--- ")
|
| 163 |
+
):
|
| 164 |
+
has_change = True
|
| 165 |
+
if has_header and has_change:
|
| 166 |
+
return 1.0
|
| 167 |
+
return 0.0
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def file_targeting(oracle: str, predicted: str) -> float:
|
| 171 |
+
"""F1 over the changed-file sets.
|
| 172 |
+
|
| 173 |
+
Why F1 instead of Jaccard:
|
| 174 |
+
- Missing an oracle file (FN) is a *big* failure.
|
| 175 |
+
- Touching one unrelated extra file (FP) is a small one.
|
| 176 |
+
- Jaccard punishes both equally, which over-penalizes the agent
|
| 177 |
+
for any extra exploration.
|
| 178 |
+
- F1 weights TP twice, giving partial credit when the agent finds
|
| 179 |
+
most-but-not-all of the oracle files even with some noise.
|
| 180 |
+
|
| 181 |
+
Returns 1.0 if both sides touch zero files (degenerate).
|
| 182 |
+
"""
|
| 183 |
+
o = file_paths(oracle)
|
| 184 |
+
p = file_paths(predicted)
|
| 185 |
+
if not o and not p:
|
| 186 |
+
return 1.0
|
| 187 |
+
tp = len(o & p)
|
| 188 |
+
fn = len(o - p)
|
| 189 |
+
fp = len(p - o)
|
| 190 |
+
if tp == 0:
|
| 191 |
+
return 0.0
|
| 192 |
+
# F1 = 2·TP / (2·TP + FN + FP)
|
| 193 |
+
return (2 * tp) / (2 * tp + fn + fp)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _count_loc_changes(diff: str) -> int:
|
| 197 |
+
"""Number of real +/- lines (excluding file-marker lines)."""
|
| 198 |
+
n = 0
|
| 199 |
+
for line in diff.splitlines():
|
| 200 |
+
if (line.startswith("+") or line.startswith("-")) and not line.startswith(("+++ ", "--- ")):
|
| 201 |
+
n += 1
|
| 202 |
+
return n
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def size_sanity(oracle: str, predicted: str) -> float:
|
| 206 |
+
"""Penalize predicted patches that are wildly larger / smaller than the oracle.
|
| 207 |
+
|
| 208 |
+
Returns ``min(oracle_loc, predicted_loc) / max(oracle_loc, predicted_loc)``.
|
| 209 |
+
Both empty → 1.0 (degenerate but well-defined). One empty → 0.0.
|
| 210 |
+
|
| 211 |
+
This is the "don't rampage through the codebase" guard — a 200-line
|
| 212 |
+
diff for a 3-line oracle scores ~0.015 here even if every other
|
| 213 |
+
component looks OK.
|
| 214 |
+
"""
|
| 215 |
+
o_loc = _count_loc_changes(oracle)
|
| 216 |
+
p_loc = _count_loc_changes(predicted)
|
| 217 |
+
if o_loc == 0 and p_loc == 0:
|
| 218 |
+
return 1.0
|
| 219 |
+
if o_loc == 0 or p_loc == 0:
|
| 220 |
+
return 0.0
|
| 221 |
+
return min(o_loc, p_loc) / max(o_loc, p_loc)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def region_overlap(oracle: str, predicted: str, *, slack_lines: int = 5) -> float:
|
| 225 |
+
"""For each oracle hunk, did the predicted diff edit a line within
|
| 226 |
+
``slack_lines`` of that hunk in the same file?
|
| 227 |
+
|
| 228 |
+
Returns the fraction of oracle hunks that have at least one matching
|
| 229 |
+
predicted hunk. ``slack_lines`` tolerates slight line-number drift
|
| 230 |
+
when git diff renders the predicted hunk at a different offset.
|
| 231 |
+
"""
|
| 232 |
+
o_ranges = hunk_ranges(oracle)
|
| 233 |
+
p_ranges = hunk_ranges(predicted)
|
| 234 |
+
total = sum(len(v) for v in o_ranges.values())
|
| 235 |
+
if total == 0:
|
| 236 |
+
return 1.0 # oracle has no hunks (degenerate)
|
| 237 |
+
matched = 0
|
| 238 |
+
for fname, ranges in o_ranges.items():
|
| 239 |
+
p_in_file = p_ranges.get(fname, [])
|
| 240 |
+
for o_start, o_end in ranges:
|
| 241 |
+
for p_start, p_end in p_in_file:
|
| 242 |
+
# Interval overlap with slack — max(starts) <= min(ends) + slack
|
| 243 |
+
if max(o_start, p_start) <= min(o_end, p_end) + slack_lines:
|
| 244 |
+
matched += 1
|
| 245 |
+
break
|
| 246 |
+
return matched / total
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def similarity(oracle: str, predicted: str) -> float:
|
| 250 |
+
"""SequenceMatcher ratio over +/- lines only.
|
| 251 |
+
|
| 252 |
+
No free credit for context lines — fixes the v0.8.1 inflation where a
|
| 253 |
+
one-line fix scored ~0.7 just because the 3 context lines on either
|
| 254 |
+
side were "matched".
|
| 255 |
+
"""
|
| 256 |
+
if not predicted.strip():
|
| 257 |
+
return 0.0
|
| 258 |
+
o = _normalize_changes_only(oracle)
|
| 259 |
+
p = _normalize_changes_only(predicted)
|
| 260 |
+
if not o:
|
| 261 |
+
return 0.0
|
| 262 |
+
# Exact matching is quadratic-or-worse on repeated lines: 200 x 2,000
|
| 263 |
+
# identical changed lines take ~2 s, 500 x 5,000 take ~35 s, which can
|
| 264 |
+
# run the verifier past Harbor's timeout. Above this many line pairs,
|
| 265 |
+
# fall back to difflib's popular-element heuristic, which stays fast.
|
| 266 |
+
exact = len(o) * len(p) <= _SIMILARITY_EXACT_PAIRS
|
| 267 |
+
return difflib.SequenceMatcher(a=o, b=p, autojunk=not exact).ratio()
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
_SIMILARITY_EXACT_PAIRS = 400_000
|
| 271 |
+
|
| 272 |
+
# A predicted patch over 10x the oracle's changed lines is already a
|
| 273 |
+
# catastrophic size mismatch (size_sanity < 0.10). Past this floor such a
|
| 274 |
+
# patch is a graded 0 instead of being scored, so one huge file can't slow
|
| 275 |
+
# the verifier past its timeout and turn a failing episode into a dropped,
|
| 276 |
+
# ungraded one. The byte cap stops it from being read at all.
|
| 277 |
+
_MAX_PREDICTED_FACTOR = 10
|
| 278 |
+
_MAX_PREDICTED_FLOOR_LOC = 1_000
|
| 279 |
+
_MAX_PREDICTED_BYTES = 16 * 1024 * 1024
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def predicted_too_large(oracle: str, predicted: str) -> bool:
|
| 283 |
+
"""Whether the predicted patch is too large to score (a graded 0)."""
|
| 284 |
+
limit = max(_MAX_PREDICTED_FACTOR * _count_loc_changes(oracle), _MAX_PREDICTED_FLOOR_LOC)
|
| 285 |
+
return _count_loc_changes(predicted) > limit
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# ---------------------------------------------------------------------------
|
| 289 |
+
# LLM-as-judge (Anthropic Messages API, stdlib urllib)
|
| 290 |
+
# ---------------------------------------------------------------------------
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
_JUDGE_PROMPT = (
|
| 294 |
+
"You are scoring a code-fix patch on whether it logically addresses the "
|
| 295 |
+
"described issue. Output a single JSON object: "
|
| 296 |
+
'{{"score": <float in [0,1]>, "reasoning": "<<=30 words"}}.\n\n'
|
| 297 |
+
"DO NOT use the oracle to grade. Score on:\n"
|
| 298 |
+
" - Does the predicted diff touch code regions that could plausibly fix the issue?\n"
|
| 299 |
+
" - Is the change direction consistent with what the issue describes?\n"
|
| 300 |
+
" - Is it a real attempt (not boilerplate, not no-op)?\n\n"
|
| 301 |
+
"Issue:\n{instruction}\n\n"
|
| 302 |
+
"Oracle (reference fix for comparison only — don't grade on similarity to it):\n"
|
| 303 |
+
"{oracle}\n\n"
|
| 304 |
+
"Predicted:\n{predicted}\n\n"
|
| 305 |
+
"Return ONLY the JSON object."
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
_DEFAULT_JUDGE_MODEL = "claude-haiku-4-5-20251001"
|
| 310 |
+
_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages"
|
| 311 |
+
# Bearer token for a self-hosted judge when R2E_JUDGE_API_KEY is unset. vLLM /
|
| 312 |
+
# Ollama ignore it; the OpenAI wire format still wants one. Same value llm.py uses.
|
| 313 |
+
_PLACEHOLDER_API_KEY = "EMPTY"
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def llm_judge(
|
| 317 |
+
*,
|
| 318 |
+
instruction: str,
|
| 319 |
+
oracle: str,
|
| 320 |
+
predicted: str,
|
| 321 |
+
api_key: str,
|
| 322 |
+
model: str = _DEFAULT_JUDGE_MODEL,
|
| 323 |
+
timeout: int = 60,
|
| 324 |
+
endpoint: str | None = None,
|
| 325 |
+
) -> tuple[float | None, str]:
|
| 326 |
+
"""Return ``(score, status)``.
|
| 327 |
+
|
| 328 |
+
``score`` is a float in [0, 1] on success, ``None`` on failure.
|
| 329 |
+
``status`` is a short string: ``"ok"`` / ``"no_api_key"`` /
|
| 330 |
+
``"no_judge_model"`` / ``"empty_predicted"`` / ``"network"`` /
|
| 331 |
+
``"parse"`` / ``"output_limit"`` / ``"missing_score"`` / ``"invalid_score"``.
|
| 332 |
+
``output_limit`` means the judge exhausted its configured token budget
|
| 333 |
+
(ungraded, even if a partial answer contains a score). ``parse`` means
|
| 334 |
+
the provider's body isn't JSON or has the wrong shape (ungraded); a reply
|
| 335 |
+
with no usable text (refusal, content filter, empty) or no valid score is
|
| 336 |
+
``missing_score`` / ``invalid_score`` (a graded 0). A missing score never
|
| 337 |
+
increases the other weights.
|
| 338 |
+
|
| 339 |
+
``endpoint`` — base URL of an OpenAI-compatible server. When set, the
|
| 340 |
+
request goes to ``<endpoint>/chat/completions`` with ``api_key`` as a
|
| 341 |
+
bearer token, at temperature 0, and ``model`` must be given explicitly;
|
| 342 |
+
otherwise it goes to Anthropic's Messages API unchanged.
|
| 343 |
+
"""
|
| 344 |
+
if not api_key:
|
| 345 |
+
return None, "no_api_key"
|
| 346 |
+
if endpoint and not model:
|
| 347 |
+
return None, "no_judge_model"
|
| 348 |
+
if not predicted.strip():
|
| 349 |
+
return 0.0, "empty_predicted"
|
| 350 |
+
|
| 351 |
+
# Truncate hard so we don't blow up the prompt for big diffs
|
| 352 |
+
prompt = _JUDGE_PROMPT.format(
|
| 353 |
+
instruction=instruction[:4000],
|
| 354 |
+
oracle=oracle[:4000],
|
| 355 |
+
predicted=predicted[:4000],
|
| 356 |
+
)
|
| 357 |
+
payload: dict = {
|
| 358 |
+
"model": model,
|
| 359 |
+
"max_tokens": 200,
|
| 360 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 361 |
+
}
|
| 362 |
+
if endpoint:
|
| 363 |
+
# Small self-hosted models are noisy judges at their default sampling
|
| 364 |
+
# temperature (same input scoring 0.0 one call and 1.0 the next); pin
|
| 365 |
+
# them to greedy. The Anthropic route keeps its defaults — the weights
|
| 366 |
+
# were calibrated against them.
|
| 367 |
+
payload["temperature"] = 0
|
| 368 |
+
url = endpoint.rstrip("/") + "/chat/completions"
|
| 369 |
+
headers = {
|
| 370 |
+
"authorization": f"Bearer {api_key}",
|
| 371 |
+
"content-type": "application/json",
|
| 372 |
+
}
|
| 373 |
+
else:
|
| 374 |
+
url = _ANTHROPIC_MESSAGES_URL
|
| 375 |
+
headers = {
|
| 376 |
+
"x-api-key": api_key,
|
| 377 |
+
"anthropic-version": "2023-06-01",
|
| 378 |
+
"content-type": "application/json",
|
| 379 |
+
}
|
| 380 |
+
body = json.dumps(payload).encode("utf-8")
|
| 381 |
+
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
|
| 382 |
+
try:
|
| 383 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 384 |
+
raw = resp.read().decode("utf-8")
|
| 385 |
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError):
|
| 386 |
+
return None, "network"
|
| 387 |
+
|
| 388 |
+
try:
|
| 389 |
+
response = json.loads(raw)
|
| 390 |
+
except json.JSONDecodeError:
|
| 391 |
+
return None, "parse"
|
| 392 |
+
# Provider-reported truncation is a grader capacity failure, not evidence
|
| 393 |
+
# that the submitted patch is wrong. Reasoning models can spend the entire
|
| 394 |
+
# output budget before producing visible text. Never grade a partial score.
|
| 395 |
+
if isinstance(response, dict):
|
| 396 |
+
choices = response.get("choices")
|
| 397 |
+
if endpoint:
|
| 398 |
+
if (
|
| 399 |
+
isinstance(choices, list)
|
| 400 |
+
and choices
|
| 401 |
+
and isinstance(choices[0], dict)
|
| 402 |
+
and choices[0].get("finish_reason") == "length"
|
| 403 |
+
):
|
| 404 |
+
return None, "output_limit"
|
| 405 |
+
elif response.get("stop_reason") in {"max_tokens", "model_context_window_exceeded"}:
|
| 406 |
+
return None, "output_limit"
|
| 407 |
+
text = _judge_text(response, openai_compatible=bool(endpoint))
|
| 408 |
+
if text is None:
|
| 409 |
+
return None, "parse"
|
| 410 |
+
|
| 411 |
+
# Pull the first JSON object out of the model's response
|
| 412 |
+
m = re.search(r"\{[^{}]*\"score\"[^{}]*\}", text, re.DOTALL)
|
| 413 |
+
if not m:
|
| 414 |
+
return None, "missing_score"
|
| 415 |
+
try:
|
| 416 |
+
obj = json.loads(m.group(0))
|
| 417 |
+
score = obj.get("score")
|
| 418 |
+
except (json.JSONDecodeError, ValueError, TypeError):
|
| 419 |
+
return None, "missing_score"
|
| 420 |
+
if type(score) not in (int, float) or not 0 <= score <= 1 or not math.isfinite(score):
|
| 421 |
+
return None, "invalid_score"
|
| 422 |
+
return float(score), "ok"
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _judge_text(payload: object, *, openai_compatible: bool) -> str | None:
|
| 426 |
+
"""The judge's answer text, ``""`` when it gave none, ``None`` for a wrong shape.
|
| 427 |
+
|
| 428 |
+
A refusal or a content filter is a well-formed reply with no usable text.
|
| 429 |
+
The agent's patch is in the prompt, so it can provoke one: that is ``""``,
|
| 430 |
+
which grades 0, not ``None``, which leaves the run ungraded.
|
| 431 |
+
|
| 432 |
+
Anthropic: a refusal is HTTP 200 with ``stop_reason: "refusal"`` and
|
| 433 |
+
``content`` empty or holding partial text to discard. OpenAI-compatible:
|
| 434 |
+
``message.content`` is null with a ``refusal`` string or
|
| 435 |
+
``finish_reason: "content_filter"``.
|
| 436 |
+
"""
|
| 437 |
+
if not isinstance(payload, dict):
|
| 438 |
+
return None
|
| 439 |
+
if openai_compatible:
|
| 440 |
+
choices = payload.get("choices")
|
| 441 |
+
if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
|
| 442 |
+
return None
|
| 443 |
+
message = choices[0].get("message")
|
| 444 |
+
if not isinstance(message, dict):
|
| 445 |
+
return None
|
| 446 |
+
if message.get("refusal") or choices[0].get("finish_reason") == "content_filter":
|
| 447 |
+
return ""
|
| 448 |
+
content = message.get("content")
|
| 449 |
+
if content is None:
|
| 450 |
+
return ""
|
| 451 |
+
if isinstance(content, str):
|
| 452 |
+
return content
|
| 453 |
+
if isinstance(content, list): # content parts
|
| 454 |
+
return "".join(
|
| 455 |
+
part.get("text", "")
|
| 456 |
+
for part in content
|
| 457 |
+
if isinstance(part, dict) and isinstance(part.get("text", ""), str)
|
| 458 |
+
)
|
| 459 |
+
return None
|
| 460 |
+
content = payload.get("content")
|
| 461 |
+
if not isinstance(content, list):
|
| 462 |
+
return None
|
| 463 |
+
if payload.get("stop_reason") == "refusal":
|
| 464 |
+
return ""
|
| 465 |
+
return "".join(
|
| 466 |
+
block["text"]
|
| 467 |
+
for block in content
|
| 468 |
+
if isinstance(block, dict)
|
| 469 |
+
and block.get("type", "text") == "text"
|
| 470 |
+
and isinstance(block.get("text"), str)
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# ---------------------------------------------------------------------------
|
| 475 |
+
# Combination
|
| 476 |
+
# ---------------------------------------------------------------------------
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
# Judge replies the agent can provoke: its patch text is part of the judge
|
| 480 |
+
# prompt, so it can steer the answer away from a valid score. These are a
|
| 481 |
+
# graded 0. An unreadable provider envelope (`parse`), missing configuration,
|
| 482 |
+
# a disabled judge, transport errors and an exhausted judge output budget leave
|
| 483 |
+
# the evaluation ungraded. Truncation alone cannot establish an incorrect patch.
|
| 484 |
+
_JUDGE_GRADED_ZERO = frozenset({"missing_score", "invalid_score"})
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def evaluation_status(judge_score: float | None, judge_status: str) -> str:
|
| 488 |
+
"""`graded` when the judge scored or the agent can have caused its failure."""
|
| 489 |
+
if judge_score is not None or judge_status in _JUDGE_GRADED_ZERO:
|
| 490 |
+
return "graded"
|
| 491 |
+
return "ungraded"
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def combine(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 495 |
+
"""Combine declared components, requiring a positively weighted judge.
|
| 496 |
+
|
| 497 |
+
Without a judge score the result is 0. ``main`` records it as a graded 0
|
| 498 |
+
when the agent can have caused the judge failure, and otherwise writes no
|
| 499 |
+
reward file, so Harbor reports the trial as VERIFIER_FAILED.
|
| 500 |
+
"""
|
| 501 |
+
if weights.get("llm_judge", 0) <= 0 or components.get("llm_judge") is None:
|
| 502 |
+
return 0.0
|
| 503 |
+
if any(w > 0 and components.get(k) is None for k, w in weights.items()):
|
| 504 |
+
return 0.0
|
| 505 |
+
return _weighted_mean(components, weights)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def _weighted_mean(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 509 |
+
available = [(k, w) for k, w in weights.items() if w > 0 and components.get(k) is not None]
|
| 510 |
+
if not available:
|
| 511 |
+
return 0.0
|
| 512 |
+
# Relative weights need not sum to one. Scale first so large finite
|
| 513 |
+
# overrides cannot overflow the numerator or denominator into NaN.
|
| 514 |
+
scale = max(w for _, w in available)
|
| 515 |
+
normalized = [(k, w / scale) for k, w in available]
|
| 516 |
+
return sum(w * components[k] for k, w in normalized) / sum(w for _, w in normalized)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
# ---------------------------------------------------------------------------
|
| 520 |
+
# Entry point (invoked by tests/test.sh inside the container)
|
| 521 |
+
# ---------------------------------------------------------------------------
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
# Weights retuned after a 23-task pilot. Rationale (LLM-as-reward-engineer
|
| 525 |
+
# analysis grounded in per-task component data):
|
| 526 |
+
#
|
| 527 |
+
# - format_valid → 0.00: was 1.0 across ALL 21 evaluated tasks. Zero
|
| 528 |
+
# discriminative signal — its 0.05 weight was pure dead weight.
|
| 529 |
+
# - similarity → 0.10: Pearson ~0.85 correlation with region_overlap.
|
| 530 |
+
# Carrying both at 0.20 double-counts positional accuracy and
|
| 531 |
+
# additionally penalizes legitimate alternative implementations.
|
| 532 |
+
# - llm_judge → 0.50: only component capturing semantic correctness
|
| 533 |
+
# independent of textual form; diverges informatively from
|
| 534 |
+
# similarity on cases like tokenizers (judge=0.72, sim=0.08).
|
| 535 |
+
# - region_overlap stays 0.20: strongest spatial-localization signal.
|
| 536 |
+
# - file_targeting → 0.12: leading indicator, less correlated with the
|
| 537 |
+
# rest than region/similarity are with each other.
|
| 538 |
+
# - size_sanity → 0.08: useful outlier detector for catastrophic
|
| 539 |
+
# over/under-generation (prettier=0.01, serde=0.08).
|
| 540 |
+
#
|
| 541 |
+
# Total: 0.00 + 0.08 + 0.12 + 0.20 + 0.10 + 0.50 = 1.00.
|
| 542 |
+
_DEFAULT_WEIGHTS = {
|
| 543 |
+
"format_valid": 0.00,
|
| 544 |
+
"size_sanity": 0.08,
|
| 545 |
+
"file_targeting": 0.12,
|
| 546 |
+
"region_overlap": 0.20,
|
| 547 |
+
"similarity": 0.10,
|
| 548 |
+
"llm_judge": 0.50,
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
# Hard cap: when size_sanity < this threshold, clamp final reward to
|
| 552 |
+
# ≤ CATASTROPHIC_SIZE_CAP. Prevents a charitable judge from inflating
|
| 553 |
+
# the score on patches that are wildly the wrong size (catastrophic
|
| 554 |
+
# over- or under-generation).
|
| 555 |
+
_CATASTROPHIC_SIZE_THRESHOLD = 0.10
|
| 556 |
+
_CATASTROPHIC_SIZE_CAP = 0.40
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _read_weights_from_env() -> dict[str, float]:
|
| 560 |
+
"""Override defaults via R2E_W_* env vars (set in container by harbor)."""
|
| 561 |
+
overrides = {
|
| 562 |
+
"format_valid": os.environ.get("R2E_W_FORMAT"),
|
| 563 |
+
"size_sanity": os.environ.get("R2E_W_SIZE"),
|
| 564 |
+
"file_targeting": os.environ.get("R2E_W_FILE"),
|
| 565 |
+
"region_overlap": os.environ.get("R2E_W_REGION"),
|
| 566 |
+
"similarity": os.environ.get("R2E_W_SIM"),
|
| 567 |
+
"llm_judge": os.environ.get("R2E_W_JUDGE"),
|
| 568 |
+
}
|
| 569 |
+
out = dict(_DEFAULT_WEIGHTS)
|
| 570 |
+
for k, v in overrides.items():
|
| 571 |
+
if v is None:
|
| 572 |
+
continue
|
| 573 |
+
try:
|
| 574 |
+
value = float(v)
|
| 575 |
+
if math.isfinite(value) and value >= 0:
|
| 576 |
+
out[k] = value
|
| 577 |
+
except (TypeError, ValueError):
|
| 578 |
+
continue
|
| 579 |
+
return out
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def _judge_config_from_env() -> tuple[str, str, str | None]:
|
| 583 |
+
"""``(api_key, model, endpoint)`` for the judge, from the verifier env.
|
| 584 |
+
|
| 585 |
+
With ``R2E_JUDGE_ENDPOINT`` set, the key comes from ``R2E_JUDGE_API_KEY``
|
| 586 |
+
(placeholder when unset) and ``ANTHROPIC_API_KEY`` is never forwarded to
|
| 587 |
+
the custom server. ``R2E_JUDGE_MODEL`` has no default on that route (a
|
| 588 |
+
self-hosted server won't have Haiku): when unset, ``model`` comes back
|
| 589 |
+
as ``""`` and ``llm_judge`` reports ``no_judge_model`` instead of
|
| 590 |
+
calling out. Without an endpoint the default Anthropic route is
|
| 591 |
+
unchanged.
|
| 592 |
+
"""
|
| 593 |
+
endpoint = os.environ.get("R2E_JUDGE_ENDPOINT", "").strip() or None
|
| 594 |
+
model = os.environ.get("R2E_JUDGE_MODEL", "").strip()
|
| 595 |
+
if endpoint:
|
| 596 |
+
api_key = os.environ.get("R2E_JUDGE_API_KEY", "").strip() or _PLACEHOLDER_API_KEY
|
| 597 |
+
return api_key, model, endpoint
|
| 598 |
+
return os.environ.get("ANTHROPIC_API_KEY", "").strip(), model or _DEFAULT_JUDGE_MODEL, None
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def main(argv: list[str] | None = None) -> int:
|
| 602 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 603 |
+
parser.add_argument("oracle")
|
| 604 |
+
parser.add_argument("predicted")
|
| 605 |
+
parser.add_argument("instruction")
|
| 606 |
+
parser.add_argument("--out-dir", default="/logs/verifier")
|
| 607 |
+
args = parser.parse_args(argv)
|
| 608 |
+
os.makedirs(args.out_dir, exist_ok=True)
|
| 609 |
+
# This run is the only authority on the reward: an earlier or planted
|
| 610 |
+
# reward file must not stand if this evaluation ends up ungraded.
|
| 611 |
+
for name in ("reward.txt", "reward.json"):
|
| 612 |
+
try:
|
| 613 |
+
os.unlink(os.path.join(args.out_dir, name))
|
| 614 |
+
except FileNotFoundError:
|
| 615 |
+
pass
|
| 616 |
+
oracle = _read_or_empty(args.oracle)
|
| 617 |
+
try:
|
| 618 |
+
oversized = os.path.getsize(args.predicted) > _MAX_PREDICTED_BYTES
|
| 619 |
+
except OSError:
|
| 620 |
+
oversized = False
|
| 621 |
+
predicted = "" if oversized else _read_or_empty(args.predicted)
|
| 622 |
+
if oversized or predicted_too_large(oracle, predicted):
|
| 623 |
+
breakdown = {
|
| 624 |
+
"final_reward": 0.0,
|
| 625 |
+
"evaluation_status": "graded",
|
| 626 |
+
"eval_trustworthy": False,
|
| 627 |
+
"predicted_status": "predicted_too_large",
|
| 628 |
+
}
|
| 629 |
+
_write_outputs(args.out_dir, 0.0, breakdown)
|
| 630 |
+
return 0
|
| 631 |
+
instruction = _read_or_empty(args.instruction)
|
| 632 |
+
api_key, judge_model, judge_endpoint = _judge_config_from_env()
|
| 633 |
+
|
| 634 |
+
fv = format_valid(predicted)
|
| 635 |
+
ss = size_sanity(oracle, predicted)
|
| 636 |
+
ft = file_targeting(oracle, predicted)
|
| 637 |
+
ro = region_overlap(oracle, predicted)
|
| 638 |
+
sim = similarity(oracle, predicted)
|
| 639 |
+
weights = _read_weights_from_env()
|
| 640 |
+
if weights["llm_judge"] <= 0:
|
| 641 |
+
judge_score, judge_status = None, "disabled"
|
| 642 |
+
else:
|
| 643 |
+
judge_score, judge_status = llm_judge(
|
| 644 |
+
instruction=instruction,
|
| 645 |
+
oracle=oracle,
|
| 646 |
+
predicted=predicted,
|
| 647 |
+
api_key=api_key,
|
| 648 |
+
model=judge_model,
|
| 649 |
+
endpoint=judge_endpoint,
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
components: dict[str, float | None] = {
|
| 653 |
+
"format_valid": fv,
|
| 654 |
+
"size_sanity": ss,
|
| 655 |
+
"file_targeting": ft,
|
| 656 |
+
"region_overlap": ro,
|
| 657 |
+
"similarity": sim,
|
| 658 |
+
"llm_judge": judge_score,
|
| 659 |
+
}
|
| 660 |
+
final = combine(components, weights)
|
| 661 |
+
final = max(0.0, min(1.0, final))
|
| 662 |
+
|
| 663 |
+
# Hard cap on catastrophic size mismatches. Without this, a charitable
|
| 664 |
+
# judge can inflate the reward on patches that are dramatically the
|
| 665 |
+
# wrong size (prettier scored 0.23 with size_sanity=0.011 — the judge
|
| 666 |
+
# was lenient at 0.25 despite the patch being a near-no-op vs a
|
| 667 |
+
# 500-line oracle). The cap kicks in only at the extremes.
|
| 668 |
+
if ss < _CATASTROPHIC_SIZE_THRESHOLD:
|
| 669 |
+
final = min(final, _CATASTROPHIC_SIZE_CAP)
|
| 670 |
+
|
| 671 |
+
status = evaluation_status(judge_score, judge_status)
|
| 672 |
+
breakdown = {
|
| 673 |
+
# No reward exists for an ungraded evaluation: null, not a placeholder 0.
|
| 674 |
+
"final_reward": round(final, 6) if status == "graded" else None,
|
| 675 |
+
"evaluation_status": status,
|
| 676 |
+
"eval_trustworthy": judge_score is not None,
|
| 677 |
+
"diagnostic_similarity": round(
|
| 678 |
+
_weighted_mean(components, {k: w for k, w in weights.items() if k != "llm_judge"}),
|
| 679 |
+
6,
|
| 680 |
+
),
|
| 681 |
+
"components": {k: (None if v is None else round(v, 6)) for k, v in components.items()},
|
| 682 |
+
"weights": {k: round(v, 6) for k, v in weights.items()},
|
| 683 |
+
"judge_model": judge_model if judge_status == "ok" else None,
|
| 684 |
+
"judge_endpoint": judge_endpoint,
|
| 685 |
+
"judge_status": judge_status,
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
_write_outputs(args.out_dir, final, breakdown)
|
| 689 |
+
return 0
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def _write_outputs(out_dir: str, final: float, breakdown: dict) -> None:
|
| 693 |
+
# An ungraded evaluation writes no reward file. Harbor then raises
|
| 694 |
+
# RewardFileNotFoundError: the trial is VERIFIER_FAILED, reward_valid is
|
| 695 |
+
# false, and RL consumers (OpenEnv harbor_env -> TRL) drop the rollout
|
| 696 |
+
# instead of training on a 0. Harbor's job mean and pass@k still count the
|
| 697 |
+
# trial as 0, so evaluation stays fail-closed.
|
| 698 |
+
if breakdown["evaluation_status"] == "graded":
|
| 699 |
+
with open(os.path.join(out_dir, "reward.txt"), "w", encoding="utf-8") as f:
|
| 700 |
+
f.write(f"{final:.6f}\n")
|
| 701 |
+
# Harbor's `reward.json` must be a flat map of floats/ints (spec, see
|
| 702 |
+
# <https://harborframework.com/docs/tasks>); our breakdown carries nested
|
| 703 |
+
# dicts, judge strings, and status strings, so it goes to the sidecar the
|
| 704 |
+
# Harbor UI renders under Verifier Logs → Rewards. Mirrors #75 (Neubig)
|
| 705 |
+
# for `_pr_runtime_verifier.py`.
|
| 706 |
+
with open(os.path.join(out_dir, "reward-details.json"), "w", encoding="utf-8") as f:
|
| 707 |
+
json.dump(breakdown, f, indent=2)
|
| 708 |
+
|
| 709 |
+
# Also print to stdout so harbor's log captures the breakdown
|
| 710 |
+
print(json.dumps(breakdown, indent=2))
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def _read_or_empty(path: str) -> str:
|
| 714 |
+
try:
|
| 715 |
+
with open(path, encoding="utf-8") as f:
|
| 716 |
+
return f.read()
|
| 717 |
+
except (OSError, UnicodeDecodeError):
|
| 718 |
+
return ""
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
if __name__ == "__main__":
|
| 722 |
+
sys.exit(main())
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
__all__ = [
|
| 726 |
+
"combine",
|
| 727 |
+
"file_paths",
|
| 728 |
+
"file_targeting",
|
| 729 |
+
"format_valid",
|
| 730 |
+
"hunk_ranges",
|
| 731 |
+
"llm_judge",
|
| 732 |
+
"main",
|
| 733 |
+
"predicted_too_large",
|
| 734 |
+
"region_overlap",
|
| 735 |
+
"similarity",
|
| 736 |
+
"size_sanity",
|
| 737 |
+
]
|
tasks/AeneasVerif__aeneas-1388/environment/Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto-generated by Repo2RLEnv pr_diff — 6-component reward env.
|
| 2 |
+
# Agent-agnostic: the agent (claude-code / openhands / codex / etc.)
|
| 3 |
+
# installs itself at run time via its harbor adapter. We only ship
|
| 4 |
+
# the source repo — the oracle + verifier arrive at verify time via
|
| 5 |
+
# tests/, never baked into the agent's image.
|
| 6 |
+
FROM python:3.12-slim
|
| 7 |
+
ARG GITHUB_TOKEN=
|
| 8 |
+
RUN apt-get update \
|
| 9 |
+
&& apt-get install -y --no-install-recommends git ca-certificates curl \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
RUN git config --global --add safe.directory /workspace \
|
| 12 |
+
&& git config --global init.defaultBranch main \
|
| 13 |
+
&& git config --global advice.detachedHead false
|
| 14 |
+
RUN if [ -n "$GITHUB_TOKEN" ]; then \
|
| 15 |
+
git clone --filter=blob:none https://x-access-token:"${GITHUB_TOKEN}"@github.com/AeneasVerif/aeneas.git /workspace; \
|
| 16 |
+
else \
|
| 17 |
+
git clone --filter=blob:none https://github.com/AeneasVerif/aeneas.git /workspace; \
|
| 18 |
+
fi \
|
| 19 |
+
&& git -C /workspace remote set-url origin https://github.com/AeneasVerif/aeneas.git
|
| 20 |
+
WORKDIR /workspace
|
| 21 |
+
RUN git fetch --depth 1 origin ca282ec2312a96f6a985a4d23a663690816d3f3e 2>/dev/null \
|
| 22 |
+
|| git fetch --unshallow origin 2>/dev/null || true
|
| 23 |
+
RUN git reset --hard ca282ec2312a96f6a985a4d23a663690816d3f3e \
|
| 24 |
+
&& git clean -fdx -e .venv -e venv -e __pycache__
|
| 25 |
+
RUN git checkout -q -B base ca282ec2312a96f6a985a4d23a663690816d3f3e \
|
| 26 |
+
&& git remote remove origin 2>/dev/null || true
|
| 27 |
+
RUN for ref in $(git branch --format='%(refname:short)' | grep -vx base); do git branch -D "$ref" 2>/dev/null || true; done \
|
| 28 |
+
&& git tag -l | xargs -r git tag -d >/dev/null 2>&1 || true \
|
| 29 |
+
&& git for-each-ref --format='%(refname)' refs/remotes 2>/dev/null | xargs -r -n1 git update-ref -d 2>/dev/null || true \
|
| 30 |
+
&& git reflog expire --expire=now --all 2>/dev/null || true \
|
| 31 |
+
&& git gc --prune=now 2>/dev/null || true
|
| 32 |
+
RUN P="$(git rev-parse --git-dir)/objects/pack"; if ls "$P"/*.promisor >/dev/null 2>&1; then \
|
| 33 |
+
git rev-list --objects --all --missing=allow-promisor > "$P/../scrub.list" \
|
| 34 |
+
&& K=$(git pack-objects -q --missing=allow-promisor "$P/scrub" < "$P/../scrub.list") \
|
| 35 |
+
&& rm -f "$P/../scrub.list" "$P"/pack-* "$P"/multi-pack-index* \
|
| 36 |
+
&& touch "$P/scrub-$K.promisor" && git prune --expire=now; \
|
| 37 |
+
fi
|
tasks/AeneasVerif__aeneas-1388/instruction.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Improve `intro_massert_visitor` following regressions
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
introduced regressions in the generated output
|
| 8 |
+
|
| 9 |
+
## Task
|
| 10 |
+
|
| 11 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `ca282ec2312a`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1388/solution/patch.diff
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/src/pure/PureMicroPassesGeneral.ml b/src/pure/PureMicroPassesGeneral.ml
|
| 2 |
+
index 6dcf0f5887..588f931f81 100644
|
| 3 |
+
--- a/src/pure/PureMicroPassesGeneral.ml
|
| 4 |
+
+++ b/src/pure/PureMicroPassesGeneral.ml
|
| 5 |
+
@@ -23,7 +23,7 @@ let remove_meta (ctx : ctx) (def : fun_decl) : fun_decl =
|
| 6 |
+
~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 7 |
+
|
| 8 |
+
if e0 then e_then else (massert e1; cont)
|
| 9 |
+
- ~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 10 |
+
+ ~~> massert (e0 || e1); if e0 then e_then else cont
|
| 11 |
+
]}
|
| 12 |
+
This eventually allows properly reconstructing the or patterns in
|
| 13 |
+
assertions. *)
|
| 14 |
+
@@ -38,6 +38,50 @@ let intro_massert_visitor (_ctx : ctx) (def : fun_decl) =
|
| 15 |
+
-> Some scrut_arg
|
| 16 |
+
| _ -> None
|
| 17 |
+
in
|
| 18 |
+
+ (* Look for a [massert] call, possibly hidden behind a chain of leading
|
| 19 |
+
+ non-monadic let-bindings of the shape:
|
| 20 |
+
+ {[
|
| 21 |
+
+ let x0 = v0 in
|
| 22 |
+
+ ...
|
| 23 |
+
+ let xn = vn in
|
| 24 |
+
+ let _ = massert e1 in
|
| 25 |
+
+ cont
|
| 26 |
+
+ ]}
|
| 27 |
+
+ A non-monadic let-binding ([monadic = false]) can never fail: by
|
| 28 |
+
+ construction of the translation, its right-hand side is a pure
|
| 29 |
+
+ computation (e.g. a plain variable, as introduced by [IntroSymbolic]
|
| 30 |
+
+ when the symbolic execution copies a value, but also, more generally,
|
| 31 |
+
+ any pure operation such as [buf.len ()]). Such bindings can therefore
|
| 32 |
+
+ always be hoisted out of a branch without changing the semantics of the
|
| 33 |
+
+ program, which is what lets us peel them off to expose the (monadic)
|
| 34 |
+
+ [massert] call beneath, so that the merging below can fire.
|
| 35 |
+
+
|
| 36 |
+
+ If we find a match, we return the pattern of the [massert] call, its
|
| 37 |
+
+ argument [e1], the expression which follows it, and a function that
|
| 38 |
+
+ rebuilds the (possibly peeled) wrapping let-bindings around a
|
| 39 |
+
+ replacement expression. If there is no leading non-monadic let, the
|
| 40 |
+
+ rebuilding function is the identity. *)
|
| 41 |
+
+ let rec find_massert_let (branch_ty : ty) (e : texpr) :
|
| 42 |
+
+ (tpat * texpr * texpr * (expr -> expr)) option =
|
| 43 |
+
+ match e.e with
|
| 44 |
+
+ | Let (true, pat, rhs, cont) -> (
|
| 45 |
+
+ (* Monadic binding: we're allowed to dive into the rhs to extract an assertion *)
|
| 46 |
+
+ match get_massert_arg rhs with
|
| 47 |
+
+ | Some e1 -> Some (pat, e1, cont, fun inner -> inner)
|
| 48 |
+
+ | None -> None)
|
| 49 |
+
+ | Let (false, ({ pat = POpen _; _ } as lv), rhs, cont) -> (
|
| 50 |
+
+ (* Pure binding: we're allowed to dive into the continuation to extract an assertion *)
|
| 51 |
+
+ match find_massert_let branch_ty cont with
|
| 52 |
+
+ | Some (pat, e1, inner_cont, rebuild) ->
|
| 53 |
+
+ Some
|
| 54 |
+
+ ( pat,
|
| 55 |
+
+ e1,
|
| 56 |
+
+ inner_cont,
|
| 57 |
+
+ fun inner ->
|
| 58 |
+
+ Let (false, lv, rhs, { e = rebuild inner; ty = branch_ty }) )
|
| 59 |
+
+ | None -> None)
|
| 60 |
+
+ | _ -> None
|
| 61 |
+
+ in
|
| 62 |
+
object
|
| 63 |
+
inherit [_] map_expr as super
|
| 64 |
+
|
| 65 |
+
@@ -72,42 +116,46 @@ let intro_massert_visitor (_ctx : ctx) (def : fun_decl) =
|
| 66 |
+
~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 67 |
+
|
| 68 |
+
if e0 then e_then else (massert e1; cont)
|
| 69 |
+
- ~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 70 |
+
+ ~~> massert (e0 || e1); if e0 then e_then else cont
|
| 71 |
+
]}
|
| 72 |
+
- This is valid because when [e0 = false], [¬e0 || e1 = true]
|
| 73 |
+
- so the massert trivially succeeds, preserving the semantics. *)
|
| 74 |
+
- let check_else_branch () =
|
| 75 |
+
- match e_false.e with
|
| 76 |
+
- | Let (true, pat, rhs, cont_else) -> (
|
| 77 |
+
- match get_massert_arg rhs with
|
| 78 |
+
- | Some e1 ->
|
| 79 |
+
- let new_scrut = mk_bool_or scrut e1 in
|
| 80 |
+
- let massert = mk_massert new_scrut in
|
| 81 |
+
- let remaining_switch =
|
| 82 |
+
- {
|
| 83 |
+
- e = Switch (scrut, If (e_true, cont_else));
|
| 84 |
+
- ty = e_false.ty;
|
| 85 |
+
- }
|
| 86 |
+
- in
|
| 87 |
+
- Let (true, pat, massert, remaining_switch)
|
| 88 |
+
- | None -> Switch (scrut, If (e_true, e_false)))
|
| 89 |
+
- | _ -> Switch (scrut, If (e_true, e_false))
|
| 90 |
+
+ This is valid because in the first case, when [e0 = false],
|
| 91 |
+
+ [¬e0 || e1 = true] so the massert trivially succeeds (and
|
| 92 |
+
+ similarly for the second case when [e0 = true]), preserving
|
| 93 |
+
+ the semantics.
|
| 94 |
+
+
|
| 95 |
+
+ [negate] tells us whether [scrut] must be negated before being
|
| 96 |
+
+ combined with [e1] (this is the case when we are looking at
|
| 97 |
+
+ the "then" branch, as illustrated above). [mk_if] rebuilds the
|
| 98 |
+
+ [If] switch, plugging the transformed branch ([cont]) and the
|
| 99 |
+
+ untouched branch ([other]) back in the right slots. *)
|
| 100 |
+
+ let try_hoist_massert ~(negate : bool) (branch : texpr)
|
| 101 |
+
+ (other : texpr) (mk_if : texpr -> texpr -> switch_body) :
|
| 102 |
+
+ expr option =
|
| 103 |
+
+ match find_massert_let branch.ty branch with
|
| 104 |
+
+ | Some (pat, e1, cont, rebuild) ->
|
| 105 |
+
+ let massert_scrut =
|
| 106 |
+
+ if negate then mk_bool_not scrut else scrut
|
| 107 |
+
+ in
|
| 108 |
+
+ let new_scrut = mk_bool_or massert_scrut e1 in
|
| 109 |
+
+ let massert = mk_massert new_scrut in
|
| 110 |
+
+ let remaining_switch =
|
| 111 |
+
+ { e = Switch (scrut, mk_if cont other); ty = branch.ty }
|
| 112 |
+
+ in
|
| 113 |
+
+ Some (rebuild (Let (true, pat, massert, remaining_switch)))
|
| 114 |
+
+ | None -> None
|
| 115 |
+
in
|
| 116 |
+
- match e_true.e with
|
| 117 |
+
- | Let (true, pat, rhs, cont_then) -> (
|
| 118 |
+
- match get_massert_arg rhs with
|
| 119 |
+
- | Some e1 ->
|
| 120 |
+
- let new_scrut = mk_bool_or (mk_bool_not scrut) e1 in
|
| 121 |
+
- let massert = mk_massert new_scrut in
|
| 122 |
+
- let remaining_switch =
|
| 123 |
+
- {
|
| 124 |
+
- e = Switch (scrut, If (cont_then, e_false));
|
| 125 |
+
- ty = e_true.ty;
|
| 126 |
+
- }
|
| 127 |
+
- in
|
| 128 |
+
- Let (true, pat, massert, remaining_switch)
|
| 129 |
+
- | None -> check_else_branch ())
|
| 130 |
+
- | _ -> check_else_branch ()
|
| 131 |
+
+ match
|
| 132 |
+
+ try_hoist_massert ~negate:true e_true e_false (fun cont other ->
|
| 133 |
+
+ If (cont, other))
|
| 134 |
+
+ with
|
| 135 |
+
+ | Some e -> e
|
| 136 |
+
+ | None -> (
|
| 137 |
+
+ match
|
| 138 |
+
+ try_hoist_massert ~negate:false e_false e_true
|
| 139 |
+
+ (fun cont other -> If (other, cont))
|
| 140 |
+
+ with
|
| 141 |
+
+ | Some e -> e
|
| 142 |
+
+ | None -> Switch (scrut, If (e_true, e_false)))
|
| 143 |
+
end
|
| 144 |
+
| _ -> super#visit_Switch env scrut switch
|
| 145 |
+
end
|
| 146 |
+
diff --git a/tests/lean/AssertCfg.lean b/tests/lean/AssertCfg.lean
|
| 147 |
+
index 2b651fde40..373703b433 100644
|
| 148 |
+
--- a/tests/lean/AssertCfg.lean
|
| 149 |
+
+++ b/tests/lean/AssertCfg.lean
|
| 150 |
+
@@ -38,9 +38,7 @@ def f : Result Unit := do
|
| 151 |
+
Source: 'tests/src/assert-cfg.rs', lines 15:0-18:1
|
| 152 |
+
Visibility: public -/
|
| 153 |
+
def assert_or (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 154 |
+
- if b0
|
| 155 |
+
- then ok ()
|
| 156 |
+
- else massert b1
|
| 157 |
+
+ massert (b0 || b1)
|
| 158 |
+
f
|
| 159 |
+
|
| 160 |
+
/-- [assert_cfg::assert_and]:
|
| 161 |
+
@@ -63,36 +61,28 @@ def assert_not_or (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 162 |
+
Source: 'tests/src/assert-cfg.rs', lines 30:0-33:1
|
| 163 |
+
Visibility: public -/
|
| 164 |
+
def assert_not_and (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 165 |
+
- if b0
|
| 166 |
+
- then massert (¬ b1)
|
| 167 |
+
- else ok ()
|
| 168 |
+
+ massert ((¬ b0) || (¬ b1))
|
| 169 |
+
f
|
| 170 |
+
|
| 171 |
+
/-- [assert_cfg::assert_not_b0_or_b1]:
|
| 172 |
+
Source: 'tests/src/assert-cfg.rs', lines 35:0-38:1
|
| 173 |
+
Visibility: public -/
|
| 174 |
+
def assert_not_b0_or_b1 (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 175 |
+
- if b0
|
| 176 |
+
- then massert b1
|
| 177 |
+
- else ok ()
|
| 178 |
+
+ massert ((¬ b0) || b1)
|
| 179 |
+
f
|
| 180 |
+
|
| 181 |
+
/-- [assert_cfg::assert_b0_or_not_b1]:
|
| 182 |
+
Source: 'tests/src/assert-cfg.rs', lines 40:0-43:1
|
| 183 |
+
Visibility: public -/
|
| 184 |
+
def assert_b0_or_not_b1 (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 185 |
+
- if b0
|
| 186 |
+
- then ok ()
|
| 187 |
+
- else massert (¬ b1)
|
| 188 |
+
+ massert (b0 || (¬ b1))
|
| 189 |
+
f
|
| 190 |
+
|
| 191 |
+
/-- [assert_cfg::assert_not_b0_or_not_b1]:
|
| 192 |
+
Source: 'tests/src/assert-cfg.rs', lines 45:0-48:1
|
| 193 |
+
Visibility: public -/
|
| 194 |
+
def assert_not_b0_or_not_b1 (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 195 |
+
- if b0
|
| 196 |
+
- then massert (¬ b1)
|
| 197 |
+
- else ok ()
|
| 198 |
+
+ massert ((¬ b0) || (¬ b1))
|
| 199 |
+
f
|
| 200 |
+
|
| 201 |
+
/-- [assert_cfg::assert_not_b0_and_b1]:
|
| 202 |
+
@@ -329,19 +319,15 @@ def assert_or_in_loop_loop.body
|
| 203 |
+
massert (c < 100#u32)
|
| 204 |
+
let c1 ← lift (core.num.U32.wrapping_sub c 200#u32)
|
| 205 |
+
let i1 ← lift (IScalar.hcast .U32 (-200)#i32)
|
| 206 |
+
- let iter2 ←
|
| 207 |
+
- do
|
| 208 |
+
- massert ((c1 >= i1) || (c1 < 100#u32))
|
| 209 |
+
- if c1 >= i1
|
| 210 |
+
- then ok iter1
|
| 211 |
+
- else ok iter1
|
| 212 |
+
+ massert ((c1 >= i1) || (c1 < 100#u32))
|
| 213 |
+
+ let iter2 ← if c1 >= i1
|
| 214 |
+
+ then ok iter1
|
| 215 |
+
+ else ok iter1
|
| 216 |
+
let i2 ← c1 >>> 16#i32
|
| 217 |
+
let i3 ← lift (100#u32 &&& i2)
|
| 218 |
+
let c2 ← lift (core.num.U32.wrapping_add c1 i3)
|
| 219 |
+
let i4 ← lift (IScalar.hcast .U32 (-100)#i32)
|
| 220 |
+
- if c2 >= i4
|
| 221 |
+
- then ok ()
|
| 222 |
+
- else massert (c2 < 100#u32)
|
| 223 |
+
+ massert ((c2 >= i4) || (c2 < 100#u32))
|
| 224 |
+
let i5 ← c2 >>> 16#i32
|
| 225 |
+
let i6 ← lift (100#u32 &&& i5)
|
| 226 |
+
let c3 ← lift (core.num.U32.wrapping_add c2 i6)
|
| 227 |
+
diff --git a/tests/lean/JoinDuplicate.lean b/tests/lean/JoinDuplicate.lean
|
| 228 |
+
index f8bcb0179b..349880889f 100644
|
| 229 |
+
--- a/tests/lean/JoinDuplicate.lean
|
| 230 |
+
+++ b/tests/lean/JoinDuplicate.lean
|
| 231 |
+
@@ -22,8 +22,9 @@ namespace join_duplicate
|
| 232 |
+
/-- [join_duplicate::join_nested_shared]:
|
| 233 |
+
Source: 'tests/src/join-duplicate.rs', lines 3:0-10:1 -/
|
| 234 |
+
def join_nested_shared (b : Bool) : Result Unit := do
|
| 235 |
+
+ massert ((¬ b) || (1#i32 > 0#i32))
|
| 236 |
+
if b
|
| 237 |
+
- then massert (1#i32 > 0#i32)
|
| 238 |
+
+ then ok ()
|
| 239 |
+
else massert (2#i32 > 0#i32)
|
| 240 |
+
|
| 241 |
+
/-- [join_duplicate::join_nested_shared_in_loop]: loop body 0:
|
| 242 |
+
diff --git a/tests/lean/LoopsIssues.lean b/tests/lean/LoopsIssues.lean
|
| 243 |
+
index 14afb16e1e..30aadb3969 100644
|
| 244 |
+
--- a/tests/lean/LoopsIssues.lean
|
| 245 |
+
+++ b/tests/lean/LoopsIssues.lean
|
| 246 |
+
@@ -148,12 +148,11 @@ def mut_loop_len_loop.body
|
| 247 |
+
(b : Bool) (buf : Array Std.U8 4#usize) :
|
| 248 |
+
Result (ControlFlow Unit Unit)
|
| 249 |
+
:= do
|
| 250 |
+
+ let s ← lift (Array.to_slice buf)
|
| 251 |
+
+ let i := Slice.len s
|
| 252 |
+
+ massert ((¬ b) || (0#usize <= i))
|
| 253 |
+
if b
|
| 254 |
+
- then
|
| 255 |
+
- let s ← lift (Array.to_slice buf)
|
| 256 |
+
- let i := Slice.len s
|
| 257 |
+
- massert (0#usize <= i)
|
| 258 |
+
- ok (cont ())
|
| 259 |
+
+ then ok (cont ())
|
| 260 |
+
else ok (done ())
|
| 261 |
+
|
| 262 |
+
/-- [loops_issues::mut_loop_len]: loop 0:
|
tasks/AeneasVerif__aeneas-1388/solution/solve.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euxo pipefail
|
| 3 |
+
cd /workspace
|
| 4 |
+
git config --global --add safe.directory /workspace
|
| 5 |
+
PATCH="$(dirname "$0")/patch.diff"
|
| 6 |
+
git apply --verbose --reject "$PATCH"
|
tasks/AeneasVerif__aeneas-1388/task.toml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "trending/AeneasVerif__aeneas-1388"
|
| 5 |
+
description = "Improve `intro_massert_visitor` following regressions"
|
| 6 |
+
|
| 7 |
+
[metadata]
|
| 8 |
+
difficulty = "large"
|
| 9 |
+
category = "bugfix"
|
| 10 |
+
keywords = [
|
| 11 |
+
"aeneas",
|
| 12 |
+
"pr_diff",
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
[metadata.repo2env]
|
| 16 |
+
pipeline = "pr_diff"
|
| 17 |
+
pipeline_version = "0.3.0"
|
| 18 |
+
repo = "AeneasVerif/aeneas"
|
| 19 |
+
ref = "ca282ec2312a96f6a985a4d23a663690816d3f3e"
|
| 20 |
+
reference = "https://github.com/AeneasVerif/aeneas/pull/1388"
|
| 21 |
+
source_access = "auto"
|
| 22 |
+
built_at = "2026-11-16T16:10:00.169485+00:00"
|
| 23 |
+
reward_kinds = [
|
| 24 |
+
"diff_similarity",
|
| 25 |
+
]
|
| 26 |
+
spec_version = "0.2.0"
|
| 27 |
+
content_hash = "sha256:d7594f8e7cbcb4cd7880d01743f34506e28742459a0b6c3bb5284060752019a9"
|
| 28 |
+
|
| 29 |
+
[metadata.repo2env.pr_diff]
|
| 30 |
+
pr_merged_at = "2026-10-01T11:01:05Z"
|
| 31 |
+
diff_format = "unified"
|
| 32 |
+
context_files = [
|
| 33 |
+
"src/pure/PureMicroPassesGeneral.ml",
|
| 34 |
+
"tests/lean/AssertCfg.lean",
|
| 35 |
+
"tests/lean/JoinDuplicate.lean",
|
| 36 |
+
"tests/lean/LoopsIssues.lean",
|
| 37 |
+
]
|
| 38 |
+
bootstrap_image = "python:3.12-slim"
|
| 39 |
+
|
| 40 |
+
[metadata.repo2env.reward_calibration]
|
| 41 |
+
baseline_reward = 0.0
|
| 42 |
+
loc_changed = 164
|
| 43 |
+
difficulty = "large"
|
| 44 |
+
|
| 45 |
+
[metadata.repo2env.evaluation]
|
| 46 |
+
schema_version = "1"
|
| 47 |
+
status = "unverified"
|
| 48 |
+
stage = "generation"
|
| 49 |
+
reason_codes = [
|
| 50 |
+
"validation_not_run",
|
| 51 |
+
]
|
| 52 |
+
detail = "Generated task; validation has not been established."
|
| 53 |
+
provenance = "unknown"
|
| 54 |
+
evidence = []
|
| 55 |
+
|
| 56 |
+
[metadata.repo2env.reproducibility]
|
| 57 |
+
mode = "inline_dockerfile"
|
| 58 |
+
image_ref = "python:3.12-slim"
|
| 59 |
+
image_tag = "python:3.12-slim"
|
| 60 |
+
image_visibility = "public"
|
| 61 |
+
pushed_at = "2026-11-16T16:19:57.823022+00:00"
|
| 62 |
+
pushed_by = "scalingX"
|
| 63 |
+
inline_recipe_sha256 = "sha256:c13f74ce022cc7f1779ce038782783b0d36378eaf4b2ee28674264bf7ad8403b"
|
| 64 |
+
inline_recipe_lines = 37
|
| 65 |
+
inline_recipe_source = "user_dockerfile"
|
| 66 |
+
|
| 67 |
+
[agent]
|
| 68 |
+
timeout_sec = 1800.0
|
| 69 |
+
|
| 70 |
+
[verifier]
|
| 71 |
+
timeout_sec = 300.0
|
tasks/AeneasVerif__aeneas-1388/tests/capture.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standalone PR-diff capture without executing workspace Git configuration.
|
| 2 |
+
|
| 3 |
+
The emitted task uses a regular clone with a pinned base commit. Only its
|
| 4 |
+
object store is read: refs, index, config, hooks and replacement refs are not
|
| 5 |
+
used. This is a configuration boundary, not a sandbox for a malicious process
|
| 6 |
+
that can modify the verifier, binaries or object store while capture runs.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import tempfile
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def capture(workspace: Path, base_commit: str) -> bytes:
|
| 23 |
+
"""Capture tracked and new files through a fresh private Git index."""
|
| 24 |
+
if not re.fullmatch(r"[a-fA-F0-9]{40}", base_commit):
|
| 25 |
+
raise ValueError("Expected the task's pinned SHA-1 base commit")
|
| 26 |
+
objects = workspace.resolve() / ".git" / "objects"
|
| 27 |
+
if not objects.is_dir():
|
| 28 |
+
raise ValueError("The task's cloned Git object store is missing")
|
| 29 |
+
git = shutil.which("git", path=os.defpath)
|
| 30 |
+
if git is None:
|
| 31 |
+
raise FileNotFoundError("System git is unavailable")
|
| 32 |
+
with tempfile.TemporaryDirectory(prefix="r2e-diff-") as temporary:
|
| 33 |
+
private = Path(temporary)
|
| 34 |
+
# Do not forward GIT_CONFIG_PARAMETERS/COUNT, external diff programs,
|
| 35 |
+
# system/global includes, user attributes, templates or credential env.
|
| 36 |
+
env = {
|
| 37 |
+
"PATH": os.defpath,
|
| 38 |
+
"HOME": temporary,
|
| 39 |
+
"XDG_CONFIG_HOME": temporary,
|
| 40 |
+
"GIT_CONFIG_NOSYSTEM": "1",
|
| 41 |
+
"GIT_CONFIG_GLOBAL": os.devnull,
|
| 42 |
+
"GIT_ATTR_NOSYSTEM": "1",
|
| 43 |
+
"GIT_NO_REPLACE_OBJECTS": "1",
|
| 44 |
+
"GIT_NO_LAZY_FETCH": "1",
|
| 45 |
+
"GIT_TERMINAL_PROMPT": "0",
|
| 46 |
+
"LC_ALL": "C",
|
| 47 |
+
}
|
| 48 |
+
subprocess.run(
|
| 49 |
+
[git, "init", "--quiet", "--template=", str(private / "repository")],
|
| 50 |
+
env=env,
|
| 51 |
+
cwd=private,
|
| 52 |
+
check=True,
|
| 53 |
+
capture_output=True,
|
| 54 |
+
timeout=60,
|
| 55 |
+
)
|
| 56 |
+
env["GIT_ALTERNATE_OBJECT_DIRECTORIES"] = json.dumps(str(objects), ensure_ascii=False)
|
| 57 |
+
command = [
|
| 58 |
+
git,
|
| 59 |
+
f"--git-dir={private / 'repository/.git'}",
|
| 60 |
+
f"--work-tree={workspace.resolve()}",
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def run(*args: str) -> bytes:
|
| 64 |
+
return subprocess.run(
|
| 65 |
+
[*command, *args],
|
| 66 |
+
env=env,
|
| 67 |
+
cwd=workspace,
|
| 68 |
+
check=True,
|
| 69 |
+
capture_output=True,
|
| 70 |
+
timeout=60,
|
| 71 |
+
).stdout
|
| 72 |
+
|
| 73 |
+
run("read-tree", f"{base_commit}^{{tree}}")
|
| 74 |
+
# All filter drivers are undefined in the private configuration. The
|
| 75 |
+
# workspace's clean filters, fsmonitor and hooks cannot be invoked.
|
| 76 |
+
run("add", "--all", "--", ".")
|
| 77 |
+
return run("diff", "--cached", "--no-ext-diff", "--no-textconv", base_commit, "--")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def main(argv: list[str] | None = None) -> int:
|
| 81 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 82 |
+
parser.add_argument("workspace", type=Path)
|
| 83 |
+
parser.add_argument("base_commit")
|
| 84 |
+
args = parser.parse_args(argv)
|
| 85 |
+
try:
|
| 86 |
+
patch = capture(args.workspace, args.base_commit)
|
| 87 |
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
| 88 |
+
# Do not echo child stderr: it may contain workspace-controlled data.
|
| 89 |
+
sys.stderr.write(f"PR-diff capture failed ({type(exc).__name__})\n")
|
| 90 |
+
return 1
|
| 91 |
+
sys.stdout.buffer.write(patch)
|
| 92 |
+
return 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
sys.exit(main())
|
tasks/AeneasVerif__aeneas-1388/tests/instruction.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Improve `intro_massert_visitor` following regressions
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
introduced regressions in the generated output
|
| 8 |
+
|
| 9 |
+
## Task
|
| 10 |
+
|
| 11 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `ca282ec2312a`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1388/tests/oracle.patch
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/src/pure/PureMicroPassesGeneral.ml b/src/pure/PureMicroPassesGeneral.ml
|
| 2 |
+
index 6dcf0f5887..588f931f81 100644
|
| 3 |
+
--- a/src/pure/PureMicroPassesGeneral.ml
|
| 4 |
+
+++ b/src/pure/PureMicroPassesGeneral.ml
|
| 5 |
+
@@ -23,7 +23,7 @@ let remove_meta (ctx : ctx) (def : fun_decl) : fun_decl =
|
| 6 |
+
~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 7 |
+
|
| 8 |
+
if e0 then e_then else (massert e1; cont)
|
| 9 |
+
- ~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 10 |
+
+ ~~> massert (e0 || e1); if e0 then e_then else cont
|
| 11 |
+
]}
|
| 12 |
+
This eventually allows properly reconstructing the or patterns in
|
| 13 |
+
assertions. *)
|
| 14 |
+
@@ -38,6 +38,50 @@ let intro_massert_visitor (_ctx : ctx) (def : fun_decl) =
|
| 15 |
+
-> Some scrut_arg
|
| 16 |
+
| _ -> None
|
| 17 |
+
in
|
| 18 |
+
+ (* Look for a [massert] call, possibly hidden behind a chain of leading
|
| 19 |
+
+ non-monadic let-bindings of the shape:
|
| 20 |
+
+ {[
|
| 21 |
+
+ let x0 = v0 in
|
| 22 |
+
+ ...
|
| 23 |
+
+ let xn = vn in
|
| 24 |
+
+ let _ = massert e1 in
|
| 25 |
+
+ cont
|
| 26 |
+
+ ]}
|
| 27 |
+
+ A non-monadic let-binding ([monadic = false]) can never fail: by
|
| 28 |
+
+ construction of the translation, its right-hand side is a pure
|
| 29 |
+
+ computation (e.g. a plain variable, as introduced by [IntroSymbolic]
|
| 30 |
+
+ when the symbolic execution copies a value, but also, more generally,
|
| 31 |
+
+ any pure operation such as [buf.len ()]). Such bindings can therefore
|
| 32 |
+
+ always be hoisted out of a branch without changing the semantics of the
|
| 33 |
+
+ program, which is what lets us peel them off to expose the (monadic)
|
| 34 |
+
+ [massert] call beneath, so that the merging below can fire.
|
| 35 |
+
+
|
| 36 |
+
+ If we find a match, we return the pattern of the [massert] call, its
|
| 37 |
+
+ argument [e1], the expression which follows it, and a function that
|
| 38 |
+
+ rebuilds the (possibly peeled) wrapping let-bindings around a
|
| 39 |
+
+ replacement expression. If there is no leading non-monadic let, the
|
| 40 |
+
+ rebuilding function is the identity. *)
|
| 41 |
+
+ let rec find_massert_let (branch_ty : ty) (e : texpr) :
|
| 42 |
+
+ (tpat * texpr * texpr * (expr -> expr)) option =
|
| 43 |
+
+ match e.e with
|
| 44 |
+
+ | Let (true, pat, rhs, cont) -> (
|
| 45 |
+
+ (* Monadic binding: we're allowed to dive into the rhs to extract an assertion *)
|
| 46 |
+
+ match get_massert_arg rhs with
|
| 47 |
+
+ | Some e1 -> Some (pat, e1, cont, fun inner -> inner)
|
| 48 |
+
+ | None -> None)
|
| 49 |
+
+ | Let (false, ({ pat = POpen _; _ } as lv), rhs, cont) -> (
|
| 50 |
+
+ (* Pure binding: we're allowed to dive into the continuation to extract an assertion *)
|
| 51 |
+
+ match find_massert_let branch_ty cont with
|
| 52 |
+
+ | Some (pat, e1, inner_cont, rebuild) ->
|
| 53 |
+
+ Some
|
| 54 |
+
+ ( pat,
|
| 55 |
+
+ e1,
|
| 56 |
+
+ inner_cont,
|
| 57 |
+
+ fun inner ->
|
| 58 |
+
+ Let (false, lv, rhs, { e = rebuild inner; ty = branch_ty }) )
|
| 59 |
+
+ | None -> None)
|
| 60 |
+
+ | _ -> None
|
| 61 |
+
+ in
|
| 62 |
+
object
|
| 63 |
+
inherit [_] map_expr as super
|
| 64 |
+
|
| 65 |
+
@@ -72,42 +116,46 @@ let intro_massert_visitor (_ctx : ctx) (def : fun_decl) =
|
| 66 |
+
~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 67 |
+
|
| 68 |
+
if e0 then e_then else (massert e1; cont)
|
| 69 |
+
- ~~> massert (¬e0 || e1); if e0 then cont else e_else
|
| 70 |
+
+ ~~> massert (e0 || e1); if e0 then e_then else cont
|
| 71 |
+
]}
|
| 72 |
+
- This is valid because when [e0 = false], [¬e0 || e1 = true]
|
| 73 |
+
- so the massert trivially succeeds, preserving the semantics. *)
|
| 74 |
+
- let check_else_branch () =
|
| 75 |
+
- match e_false.e with
|
| 76 |
+
- | Let (true, pat, rhs, cont_else) -> (
|
| 77 |
+
- match get_massert_arg rhs with
|
| 78 |
+
- | Some e1 ->
|
| 79 |
+
- let new_scrut = mk_bool_or scrut e1 in
|
| 80 |
+
- let massert = mk_massert new_scrut in
|
| 81 |
+
- let remaining_switch =
|
| 82 |
+
- {
|
| 83 |
+
- e = Switch (scrut, If (e_true, cont_else));
|
| 84 |
+
- ty = e_false.ty;
|
| 85 |
+
- }
|
| 86 |
+
- in
|
| 87 |
+
- Let (true, pat, massert, remaining_switch)
|
| 88 |
+
- | None -> Switch (scrut, If (e_true, e_false)))
|
| 89 |
+
- | _ -> Switch (scrut, If (e_true, e_false))
|
| 90 |
+
+ This is valid because in the first case, when [e0 = false],
|
| 91 |
+
+ [¬e0 || e1 = true] so the massert trivially succeeds (and
|
| 92 |
+
+ similarly for the second case when [e0 = true]), preserving
|
| 93 |
+
+ the semantics.
|
| 94 |
+
+
|
| 95 |
+
+ [negate] tells us whether [scrut] must be negated before being
|
| 96 |
+
+ combined with [e1] (this is the case when we are looking at
|
| 97 |
+
+ the "then" branch, as illustrated above). [mk_if] rebuilds the
|
| 98 |
+
+ [If] switch, plugging the transformed branch ([cont]) and the
|
| 99 |
+
+ untouched branch ([other]) back in the right slots. *)
|
| 100 |
+
+ let try_hoist_massert ~(negate : bool) (branch : texpr)
|
| 101 |
+
+ (other : texpr) (mk_if : texpr -> texpr -> switch_body) :
|
| 102 |
+
+ expr option =
|
| 103 |
+
+ match find_massert_let branch.ty branch with
|
| 104 |
+
+ | Some (pat, e1, cont, rebuild) ->
|
| 105 |
+
+ let massert_scrut =
|
| 106 |
+
+ if negate then mk_bool_not scrut else scrut
|
| 107 |
+
+ in
|
| 108 |
+
+ let new_scrut = mk_bool_or massert_scrut e1 in
|
| 109 |
+
+ let massert = mk_massert new_scrut in
|
| 110 |
+
+ let remaining_switch =
|
| 111 |
+
+ { e = Switch (scrut, mk_if cont other); ty = branch.ty }
|
| 112 |
+
+ in
|
| 113 |
+
+ Some (rebuild (Let (true, pat, massert, remaining_switch)))
|
| 114 |
+
+ | None -> None
|
| 115 |
+
in
|
| 116 |
+
- match e_true.e with
|
| 117 |
+
- | Let (true, pat, rhs, cont_then) -> (
|
| 118 |
+
- match get_massert_arg rhs with
|
| 119 |
+
- | Some e1 ->
|
| 120 |
+
- let new_scrut = mk_bool_or (mk_bool_not scrut) e1 in
|
| 121 |
+
- let massert = mk_massert new_scrut in
|
| 122 |
+
- let remaining_switch =
|
| 123 |
+
- {
|
| 124 |
+
- e = Switch (scrut, If (cont_then, e_false));
|
| 125 |
+
- ty = e_true.ty;
|
| 126 |
+
- }
|
| 127 |
+
- in
|
| 128 |
+
- Let (true, pat, massert, remaining_switch)
|
| 129 |
+
- | None -> check_else_branch ())
|
| 130 |
+
- | _ -> check_else_branch ()
|
| 131 |
+
+ match
|
| 132 |
+
+ try_hoist_massert ~negate:true e_true e_false (fun cont other ->
|
| 133 |
+
+ If (cont, other))
|
| 134 |
+
+ with
|
| 135 |
+
+ | Some e -> e
|
| 136 |
+
+ | None -> (
|
| 137 |
+
+ match
|
| 138 |
+
+ try_hoist_massert ~negate:false e_false e_true
|
| 139 |
+
+ (fun cont other -> If (other, cont))
|
| 140 |
+
+ with
|
| 141 |
+
+ | Some e -> e
|
| 142 |
+
+ | None -> Switch (scrut, If (e_true, e_false)))
|
| 143 |
+
end
|
| 144 |
+
| _ -> super#visit_Switch env scrut switch
|
| 145 |
+
end
|
| 146 |
+
diff --git a/tests/lean/AssertCfg.lean b/tests/lean/AssertCfg.lean
|
| 147 |
+
index 2b651fde40..373703b433 100644
|
| 148 |
+
--- a/tests/lean/AssertCfg.lean
|
| 149 |
+
+++ b/tests/lean/AssertCfg.lean
|
| 150 |
+
@@ -38,9 +38,7 @@ def f : Result Unit := do
|
| 151 |
+
Source: 'tests/src/assert-cfg.rs', lines 15:0-18:1
|
| 152 |
+
Visibility: public -/
|
| 153 |
+
def assert_or (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 154 |
+
- if b0
|
| 155 |
+
- then ok ()
|
| 156 |
+
- else massert b1
|
| 157 |
+
+ massert (b0 || b1)
|
| 158 |
+
f
|
| 159 |
+
|
| 160 |
+
/-- [assert_cfg::assert_and]:
|
| 161 |
+
@@ -63,36 +61,28 @@ def assert_not_or (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 162 |
+
Source: 'tests/src/assert-cfg.rs', lines 30:0-33:1
|
| 163 |
+
Visibility: public -/
|
| 164 |
+
def assert_not_and (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 165 |
+
- if b0
|
| 166 |
+
- then massert (¬ b1)
|
| 167 |
+
- else ok ()
|
| 168 |
+
+ massert ((¬ b0) || (¬ b1))
|
| 169 |
+
f
|
| 170 |
+
|
| 171 |
+
/-- [assert_cfg::assert_not_b0_or_b1]:
|
| 172 |
+
Source: 'tests/src/assert-cfg.rs', lines 35:0-38:1
|
| 173 |
+
Visibility: public -/
|
| 174 |
+
def assert_not_b0_or_b1 (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 175 |
+
- if b0
|
| 176 |
+
- then massert b1
|
| 177 |
+
- else ok ()
|
| 178 |
+
+ massert ((¬ b0) || b1)
|
| 179 |
+
f
|
| 180 |
+
|
| 181 |
+
/-- [assert_cfg::assert_b0_or_not_b1]:
|
| 182 |
+
Source: 'tests/src/assert-cfg.rs', lines 40:0-43:1
|
| 183 |
+
Visibility: public -/
|
| 184 |
+
def assert_b0_or_not_b1 (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 185 |
+
- if b0
|
| 186 |
+
- then ok ()
|
| 187 |
+
- else massert (¬ b1)
|
| 188 |
+
+ massert (b0 || (¬ b1))
|
| 189 |
+
f
|
| 190 |
+
|
| 191 |
+
/-- [assert_cfg::assert_not_b0_or_not_b1]:
|
| 192 |
+
Source: 'tests/src/assert-cfg.rs', lines 45:0-48:1
|
| 193 |
+
Visibility: public -/
|
| 194 |
+
def assert_not_b0_or_not_b1 (b0 : Bool) (b1 : Bool) : Result Unit := do
|
| 195 |
+
- if b0
|
| 196 |
+
- then massert (¬ b1)
|
| 197 |
+
- else ok ()
|
| 198 |
+
+ massert ((¬ b0) || (¬ b1))
|
| 199 |
+
f
|
| 200 |
+
|
| 201 |
+
/-- [assert_cfg::assert_not_b0_and_b1]:
|
| 202 |
+
@@ -329,19 +319,15 @@ def assert_or_in_loop_loop.body
|
| 203 |
+
massert (c < 100#u32)
|
| 204 |
+
let c1 ← lift (core.num.U32.wrapping_sub c 200#u32)
|
| 205 |
+
let i1 ← lift (IScalar.hcast .U32 (-200)#i32)
|
| 206 |
+
- let iter2 ←
|
| 207 |
+
- do
|
| 208 |
+
- massert ((c1 >= i1) || (c1 < 100#u32))
|
| 209 |
+
- if c1 >= i1
|
| 210 |
+
- then ok iter1
|
| 211 |
+
- else ok iter1
|
| 212 |
+
+ massert ((c1 >= i1) || (c1 < 100#u32))
|
| 213 |
+
+ let iter2 ← if c1 >= i1
|
| 214 |
+
+ then ok iter1
|
| 215 |
+
+ else ok iter1
|
| 216 |
+
let i2 ← c1 >>> 16#i32
|
| 217 |
+
let i3 ← lift (100#u32 &&& i2)
|
| 218 |
+
let c2 ← lift (core.num.U32.wrapping_add c1 i3)
|
| 219 |
+
let i4 ← lift (IScalar.hcast .U32 (-100)#i32)
|
| 220 |
+
- if c2 >= i4
|
| 221 |
+
- then ok ()
|
| 222 |
+
- else massert (c2 < 100#u32)
|
| 223 |
+
+ massert ((c2 >= i4) || (c2 < 100#u32))
|
| 224 |
+
let i5 ← c2 >>> 16#i32
|
| 225 |
+
let i6 ← lift (100#u32 &&& i5)
|
| 226 |
+
let c3 ← lift (core.num.U32.wrapping_add c2 i6)
|
| 227 |
+
diff --git a/tests/lean/JoinDuplicate.lean b/tests/lean/JoinDuplicate.lean
|
| 228 |
+
index f8bcb0179b..349880889f 100644
|
| 229 |
+
--- a/tests/lean/JoinDuplicate.lean
|
| 230 |
+
+++ b/tests/lean/JoinDuplicate.lean
|
| 231 |
+
@@ -22,8 +22,9 @@ namespace join_duplicate
|
| 232 |
+
/-- [join_duplicate::join_nested_shared]:
|
| 233 |
+
Source: 'tests/src/join-duplicate.rs', lines 3:0-10:1 -/
|
| 234 |
+
def join_nested_shared (b : Bool) : Result Unit := do
|
| 235 |
+
+ massert ((¬ b) || (1#i32 > 0#i32))
|
| 236 |
+
if b
|
| 237 |
+
- then massert (1#i32 > 0#i32)
|
| 238 |
+
+ then ok ()
|
| 239 |
+
else massert (2#i32 > 0#i32)
|
| 240 |
+
|
| 241 |
+
/-- [join_duplicate::join_nested_shared_in_loop]: loop body 0:
|
| 242 |
+
diff --git a/tests/lean/LoopsIssues.lean b/tests/lean/LoopsIssues.lean
|
| 243 |
+
index 14afb16e1e..30aadb3969 100644
|
| 244 |
+
--- a/tests/lean/LoopsIssues.lean
|
| 245 |
+
+++ b/tests/lean/LoopsIssues.lean
|
| 246 |
+
@@ -148,12 +148,11 @@ def mut_loop_len_loop.body
|
| 247 |
+
(b : Bool) (buf : Array Std.U8 4#usize) :
|
| 248 |
+
Result (ControlFlow Unit Unit)
|
| 249 |
+
:= do
|
| 250 |
+
+ let s ← lift (Array.to_slice buf)
|
| 251 |
+
+ let i := Slice.len s
|
| 252 |
+
+ massert ((¬ b) || (0#usize <= i))
|
| 253 |
+
if b
|
| 254 |
+
- then
|
| 255 |
+
- let s ← lift (Array.to_slice buf)
|
| 256 |
+
- let i := Slice.len s
|
| 257 |
+
- massert (0#usize <= i)
|
| 258 |
+
- ok (cont ())
|
| 259 |
+
+ then ok (cont ())
|
| 260 |
+
else ok (done ())
|
| 261 |
+
|
| 262 |
+
/-- [loops_issues::mut_loop_len]: loop 0:
|
tasks/AeneasVerif__aeneas-1388/tests/test.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -uxo pipefail
|
| 3 |
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
| 4 |
+
cd /workspace
|
| 5 |
+
mkdir -p /logs/verifier
|
| 6 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json /logs/verifier/reward-details.json
|
| 7 |
+
CAPTURE_DIR="$(mktemp -d)" || exit 1
|
| 8 |
+
trap 'rm -rf -- "$CAPTURE_DIR"' EXIT
|
| 9 |
+
if ! python3 -I "$SCRIPT_DIR/capture.py" /workspace ca282ec2312a96f6a985a4d23a663690816d3f3e > "$CAPTURE_DIR/predicted.patch"; then
|
| 10 |
+
echo "0.0" > /logs/verifier/reward.txt
|
| 11 |
+
printf '%s' '{"final_reward": 0.0, "evaluation_status": "graded", "eval_trustworthy": false, "capture_status": "error"}' > /logs/verifier/reward-details.json
|
| 12 |
+
exit 0
|
| 13 |
+
fi
|
| 14 |
+
rm -f /logs/verifier/predicted.patch
|
| 15 |
+
cp -- "$CAPTURE_DIR/predicted.patch" /logs/verifier/predicted.patch
|
| 16 |
+
: 'START_VERIFY_OUTPUT'
|
| 17 |
+
if ! python3 -I "$SCRIPT_DIR/verifier.py" \
|
| 18 |
+
"$SCRIPT_DIR/oracle.patch" \
|
| 19 |
+
"$CAPTURE_DIR/predicted.patch" \
|
| 20 |
+
"$SCRIPT_DIR/instruction.md"; then
|
| 21 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json
|
| 22 |
+
printf '%s' '{"final_reward": null, "reward": null, "evaluation_status": "ungraded", "eval_trustworthy": false, "verifier_status": "error"}' > /logs/verifier/reward-details.json
|
| 23 |
+
fi
|
| 24 |
+
: 'END_VERIFY_OUTPUT'
|
| 25 |
+
exit 0
|
tasks/AeneasVerif__aeneas-1388/tests/verifier.py
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""In-container verifier for pr_diff tasks (6-component reward).
|
| 2 |
+
|
| 3 |
+
This module is the **standalone verifier** that runs inside the task's
|
| 4 |
+
Docker container, NOT a helper used at generation time. Generation emits
|
| 5 |
+
its source as ``tests/verifier.py``. Harbor delivers it at verify time,
|
| 6 |
+
and ``tests/test.sh`` invokes it with the oracle, predicted patch and instruction.
|
| 7 |
+
|
| 8 |
+
Reward = weighted sum of 6 components (5 deterministic + 1 required LLM):
|
| 9 |
+
|
| 10 |
+
format_valid (0 or 1) — predicted parses as a unified diff (guard)
|
| 11 |
+
size_sanity ([0, 1]) — min(oracle_loc, pred_loc) / max(...)
|
| 12 |
+
catches "rampage through the codebase"
|
| 13 |
+
file_targeting ([0, 1]) — F1 over changed-file sets (NOT Jaccard —
|
| 14 |
+
symmetric penalty over-punishes extras)
|
| 15 |
+
region_overlap ([0, 1]) — predicted hunks overlap oracle hunks
|
| 16 |
+
(strongest spatial-localization signal)
|
| 17 |
+
similarity ([0, 1]) — SequenceMatcher ratio over +/- lines only
|
| 18 |
+
(no free credit for context lines)
|
| 19 |
+
llm_judge ([0, 1] or null) — an LLM rates "does this address the issue?"
|
| 20 |
+
Anthropic Haiku by default; any OpenAI-
|
| 21 |
+
compatible server via ``R2E_JUDGE_ENDPOINT``.
|
| 22 |
+
null when the judge is unavailable
|
| 23 |
+
(no key or model, network, unreadable
|
| 24 |
+
reply) → ungraded, no reward file; a
|
| 25 |
+
reply without a valid score (refusal,
|
| 26 |
+
content filter, empty, no "score") → a
|
| 27 |
+
graded 0
|
| 28 |
+
|
| 29 |
+
Default weights: 0.00 / 0.08 / 0.12 / 0.20 / 0.10 / 0.50 (retuned from
|
| 30 |
+
the original 0.05 / 0.05 / 0.10 / 0.20 / 0.20 / 0.40 after a 23-task
|
| 31 |
+
pilot — see the comment block above ``_DEFAULT_WEIGHTS`` below).
|
| 32 |
+
Override per-task via ``task.toml.metadata`` or per-run via env vars
|
| 33 |
+
``R2E_W_FORMAT`` / ``R2E_W_SIZE`` / ``R2E_W_FILE`` / ``R2E_W_REGION`` /
|
| 34 |
+
``R2E_W_SIM`` / ``R2E_W_JUDGE`` (pass via harbor ``--ve`` so they
|
| 35 |
+
reach the verifier container).
|
| 36 |
+
|
| 37 |
+
Judge routing, also via ``--ve``: ``R2E_JUDGE_MODEL`` picks the model
|
| 38 |
+
(default Haiku); ``R2E_JUDGE_ENDPOINT`` points at an OpenAI-compatible
|
| 39 |
+
server (vLLM, Ollama, a gateway) and switches the request to
|
| 40 |
+
``<endpoint>/chat/completions`` with a bearer token from
|
| 41 |
+
``R2E_JUDGE_API_KEY`` — or a placeholder when unset, since self-hosted
|
| 42 |
+
servers ignore it. ``ANTHROPIC_API_KEY`` is only read on the default
|
| 43 |
+
route and is never sent to a custom endpoint.
|
| 44 |
+
|
| 45 |
+
Final reward is clipped to [0, 1] and additionally clamped to ≤ 0.40
|
| 46 |
+
when ``size_sanity < 0.10`` (catastrophic-size hard cap — stops a
|
| 47 |
+
charitable judge from inflating scores on wildly wrong-sized patches).
|
| 48 |
+
|
| 49 |
+
Outputs (mirrors `_pr_runtime_verifier.py` after #75):
|
| 50 |
+
/logs/verifier/reward.txt — single float (Harbor reads this);
|
| 51 |
+
graded runs only
|
| 52 |
+
/logs/verifier/reward-details.json — full component breakdown + status
|
| 53 |
+
(structured diagnostics; Harbor's `reward.json` schema is flat-numeric-
|
| 54 |
+
only, so the breakdown goes to the `reward-details.json` sidecar which
|
| 55 |
+
Harbor renders under Verifier Logs → Rewards)
|
| 56 |
+
|
| 57 |
+
Pure stdlib — uses only ``difflib``, ``json``, ``os``, ``re``,
|
| 58 |
+
``urllib``, ``sys``. The same module is imported by the unit tests
|
| 59 |
+
under ``tests/test_pr_diff_verifier.py`` so the in-container behavior
|
| 60 |
+
stays in lockstep with what we test.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
from __future__ import annotations
|
| 64 |
+
|
| 65 |
+
import argparse
|
| 66 |
+
import difflib
|
| 67 |
+
import json
|
| 68 |
+
import math
|
| 69 |
+
import os
|
| 70 |
+
import re
|
| 71 |
+
import sys
|
| 72 |
+
import urllib.error
|
| 73 |
+
import urllib.request
|
| 74 |
+
|
| 75 |
+
# ---------------------------------------------------------------------------
|
| 76 |
+
# Parsing helpers (shared by multiple components)
|
| 77 |
+
# ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
_DIFF_HEADER_RE = re.compile(r"^diff --git a/(\S+) b/(\S+)$")
|
| 80 |
+
_HUNK_HEADER_RE = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
| 81 |
+
_FILE_MARKER_RE = re.compile(r"^(?:---|\+\+\+) ")
|
| 82 |
+
_INDEX_RE = re.compile(r"^index ")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def file_paths(diff: str) -> set[str]:
|
| 86 |
+
"""Return the set of ``b/<path>`` paths touched by a unified diff."""
|
| 87 |
+
paths: set[str] = set()
|
| 88 |
+
for line in diff.splitlines():
|
| 89 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 90 |
+
if m:
|
| 91 |
+
paths.add(m.group(2))
|
| 92 |
+
return paths
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def hunk_ranges(diff: str) -> dict[str, list[tuple[int, int]]]:
|
| 96 |
+
"""For each touched file, return list of (start_line, end_line) ranges
|
| 97 |
+
on the **post-change** side (the ``+`` numbers in ``@@ -X +Y @@``).
|
| 98 |
+
"""
|
| 99 |
+
out: dict[str, list[tuple[int, int]]] = {}
|
| 100 |
+
current_file: str | None = None
|
| 101 |
+
for line in diff.splitlines():
|
| 102 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 103 |
+
if m:
|
| 104 |
+
current_file = m.group(2)
|
| 105 |
+
out.setdefault(current_file, [])
|
| 106 |
+
continue
|
| 107 |
+
m = _HUNK_HEADER_RE.match(line)
|
| 108 |
+
if m and current_file is not None:
|
| 109 |
+
new_start = int(m.group(3))
|
| 110 |
+
new_count = int(m.group(4) or "1")
|
| 111 |
+
end = new_start + max(new_count - 1, 0)
|
| 112 |
+
out[current_file].append((new_start, end))
|
| 113 |
+
return out
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _normalize_changes_only(diff: str) -> list[str]:
|
| 117 |
+
"""Return the +/- lines (the actual changes) for similarity scoring.
|
| 118 |
+
|
| 119 |
+
Drops:
|
| 120 |
+
- ``diff --git`` / ``index abc..def`` metadata
|
| 121 |
+
- ``@@ ... @@`` hunk markers (volatile line numbers)
|
| 122 |
+
- context lines (no +/- prefix) — these are unchanged code, scoring
|
| 123 |
+
them inflates similarity for trivial patches
|
| 124 |
+
Keeps file-marker lines (``--- a/foo`` / ``+++ b/foo``) so file identity
|
| 125 |
+
stays in the comparison; normalizes off the tab+timestamp suffix git
|
| 126 |
+
sometimes appends.
|
| 127 |
+
"""
|
| 128 |
+
out: list[str] = []
|
| 129 |
+
for line in diff.splitlines():
|
| 130 |
+
if _DIFF_HEADER_RE.match(line) or _INDEX_RE.match(line):
|
| 131 |
+
continue
|
| 132 |
+
if _HUNK_HEADER_RE.match(line):
|
| 133 |
+
continue
|
| 134 |
+
if _FILE_MARKER_RE.match(line):
|
| 135 |
+
out.append(line.split("\t")[0].strip())
|
| 136 |
+
continue
|
| 137 |
+
# +/- lines (actual changes)
|
| 138 |
+
if line.startswith("+") or line.startswith("-"):
|
| 139 |
+
out.append(line)
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------------------------
|
| 144 |
+
# Reward components
|
| 145 |
+
# ---------------------------------------------------------------------------
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def format_valid(predicted: str) -> float:
|
| 149 |
+
"""1.0 if the predicted text looks like a unified diff; else 0.0.
|
| 150 |
+
|
| 151 |
+
Requires both a ``diff --git`` header and at least one real +/- line
|
| 152 |
+
(not the ``---`` / ``+++`` file-marker lines).
|
| 153 |
+
"""
|
| 154 |
+
if not predicted.strip():
|
| 155 |
+
return 0.0
|
| 156 |
+
has_header = False
|
| 157 |
+
has_change = False
|
| 158 |
+
for line in predicted.splitlines():
|
| 159 |
+
if _DIFF_HEADER_RE.match(line):
|
| 160 |
+
has_header = True
|
| 161 |
+
elif (line.startswith("+") or line.startswith("-")) and not line.startswith(
|
| 162 |
+
("+++ ", "--- ")
|
| 163 |
+
):
|
| 164 |
+
has_change = True
|
| 165 |
+
if has_header and has_change:
|
| 166 |
+
return 1.0
|
| 167 |
+
return 0.0
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def file_targeting(oracle: str, predicted: str) -> float:
|
| 171 |
+
"""F1 over the changed-file sets.
|
| 172 |
+
|
| 173 |
+
Why F1 instead of Jaccard:
|
| 174 |
+
- Missing an oracle file (FN) is a *big* failure.
|
| 175 |
+
- Touching one unrelated extra file (FP) is a small one.
|
| 176 |
+
- Jaccard punishes both equally, which over-penalizes the agent
|
| 177 |
+
for any extra exploration.
|
| 178 |
+
- F1 weights TP twice, giving partial credit when the agent finds
|
| 179 |
+
most-but-not-all of the oracle files even with some noise.
|
| 180 |
+
|
| 181 |
+
Returns 1.0 if both sides touch zero files (degenerate).
|
| 182 |
+
"""
|
| 183 |
+
o = file_paths(oracle)
|
| 184 |
+
p = file_paths(predicted)
|
| 185 |
+
if not o and not p:
|
| 186 |
+
return 1.0
|
| 187 |
+
tp = len(o & p)
|
| 188 |
+
fn = len(o - p)
|
| 189 |
+
fp = len(p - o)
|
| 190 |
+
if tp == 0:
|
| 191 |
+
return 0.0
|
| 192 |
+
# F1 = 2·TP / (2·TP + FN + FP)
|
| 193 |
+
return (2 * tp) / (2 * tp + fn + fp)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _count_loc_changes(diff: str) -> int:
|
| 197 |
+
"""Number of real +/- lines (excluding file-marker lines)."""
|
| 198 |
+
n = 0
|
| 199 |
+
for line in diff.splitlines():
|
| 200 |
+
if (line.startswith("+") or line.startswith("-")) and not line.startswith(("+++ ", "--- ")):
|
| 201 |
+
n += 1
|
| 202 |
+
return n
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def size_sanity(oracle: str, predicted: str) -> float:
|
| 206 |
+
"""Penalize predicted patches that are wildly larger / smaller than the oracle.
|
| 207 |
+
|
| 208 |
+
Returns ``min(oracle_loc, predicted_loc) / max(oracle_loc, predicted_loc)``.
|
| 209 |
+
Both empty → 1.0 (degenerate but well-defined). One empty → 0.0.
|
| 210 |
+
|
| 211 |
+
This is the "don't rampage through the codebase" guard — a 200-line
|
| 212 |
+
diff for a 3-line oracle scores ~0.015 here even if every other
|
| 213 |
+
component looks OK.
|
| 214 |
+
"""
|
| 215 |
+
o_loc = _count_loc_changes(oracle)
|
| 216 |
+
p_loc = _count_loc_changes(predicted)
|
| 217 |
+
if o_loc == 0 and p_loc == 0:
|
| 218 |
+
return 1.0
|
| 219 |
+
if o_loc == 0 or p_loc == 0:
|
| 220 |
+
return 0.0
|
| 221 |
+
return min(o_loc, p_loc) / max(o_loc, p_loc)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def region_overlap(oracle: str, predicted: str, *, slack_lines: int = 5) -> float:
|
| 225 |
+
"""For each oracle hunk, did the predicted diff edit a line within
|
| 226 |
+
``slack_lines`` of that hunk in the same file?
|
| 227 |
+
|
| 228 |
+
Returns the fraction of oracle hunks that have at least one matching
|
| 229 |
+
predicted hunk. ``slack_lines`` tolerates slight line-number drift
|
| 230 |
+
when git diff renders the predicted hunk at a different offset.
|
| 231 |
+
"""
|
| 232 |
+
o_ranges = hunk_ranges(oracle)
|
| 233 |
+
p_ranges = hunk_ranges(predicted)
|
| 234 |
+
total = sum(len(v) for v in o_ranges.values())
|
| 235 |
+
if total == 0:
|
| 236 |
+
return 1.0 # oracle has no hunks (degenerate)
|
| 237 |
+
matched = 0
|
| 238 |
+
for fname, ranges in o_ranges.items():
|
| 239 |
+
p_in_file = p_ranges.get(fname, [])
|
| 240 |
+
for o_start, o_end in ranges:
|
| 241 |
+
for p_start, p_end in p_in_file:
|
| 242 |
+
# Interval overlap with slack — max(starts) <= min(ends) + slack
|
| 243 |
+
if max(o_start, p_start) <= min(o_end, p_end) + slack_lines:
|
| 244 |
+
matched += 1
|
| 245 |
+
break
|
| 246 |
+
return matched / total
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def similarity(oracle: str, predicted: str) -> float:
|
| 250 |
+
"""SequenceMatcher ratio over +/- lines only.
|
| 251 |
+
|
| 252 |
+
No free credit for context lines — fixes the v0.8.1 inflation where a
|
| 253 |
+
one-line fix scored ~0.7 just because the 3 context lines on either
|
| 254 |
+
side were "matched".
|
| 255 |
+
"""
|
| 256 |
+
if not predicted.strip():
|
| 257 |
+
return 0.0
|
| 258 |
+
o = _normalize_changes_only(oracle)
|
| 259 |
+
p = _normalize_changes_only(predicted)
|
| 260 |
+
if not o:
|
| 261 |
+
return 0.0
|
| 262 |
+
# Exact matching is quadratic-or-worse on repeated lines: 200 x 2,000
|
| 263 |
+
# identical changed lines take ~2 s, 500 x 5,000 take ~35 s, which can
|
| 264 |
+
# run the verifier past Harbor's timeout. Above this many line pairs,
|
| 265 |
+
# fall back to difflib's popular-element heuristic, which stays fast.
|
| 266 |
+
exact = len(o) * len(p) <= _SIMILARITY_EXACT_PAIRS
|
| 267 |
+
return difflib.SequenceMatcher(a=o, b=p, autojunk=not exact).ratio()
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
_SIMILARITY_EXACT_PAIRS = 400_000
|
| 271 |
+
|
| 272 |
+
# A predicted patch over 10x the oracle's changed lines is already a
|
| 273 |
+
# catastrophic size mismatch (size_sanity < 0.10). Past this floor such a
|
| 274 |
+
# patch is a graded 0 instead of being scored, so one huge file can't slow
|
| 275 |
+
# the verifier past its timeout and turn a failing episode into a dropped,
|
| 276 |
+
# ungraded one. The byte cap stops it from being read at all.
|
| 277 |
+
_MAX_PREDICTED_FACTOR = 10
|
| 278 |
+
_MAX_PREDICTED_FLOOR_LOC = 1_000
|
| 279 |
+
_MAX_PREDICTED_BYTES = 16 * 1024 * 1024
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def predicted_too_large(oracle: str, predicted: str) -> bool:
|
| 283 |
+
"""Whether the predicted patch is too large to score (a graded 0)."""
|
| 284 |
+
limit = max(_MAX_PREDICTED_FACTOR * _count_loc_changes(oracle), _MAX_PREDICTED_FLOOR_LOC)
|
| 285 |
+
return _count_loc_changes(predicted) > limit
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# ---------------------------------------------------------------------------
|
| 289 |
+
# LLM-as-judge (Anthropic Messages API, stdlib urllib)
|
| 290 |
+
# ---------------------------------------------------------------------------
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
_JUDGE_PROMPT = (
|
| 294 |
+
"You are scoring a code-fix patch on whether it logically addresses the "
|
| 295 |
+
"described issue. Output a single JSON object: "
|
| 296 |
+
'{{"score": <float in [0,1]>, "reasoning": "<<=30 words"}}.\n\n'
|
| 297 |
+
"DO NOT use the oracle to grade. Score on:\n"
|
| 298 |
+
" - Does the predicted diff touch code regions that could plausibly fix the issue?\n"
|
| 299 |
+
" - Is the change direction consistent with what the issue describes?\n"
|
| 300 |
+
" - Is it a real attempt (not boilerplate, not no-op)?\n\n"
|
| 301 |
+
"Issue:\n{instruction}\n\n"
|
| 302 |
+
"Oracle (reference fix for comparison only — don't grade on similarity to it):\n"
|
| 303 |
+
"{oracle}\n\n"
|
| 304 |
+
"Predicted:\n{predicted}\n\n"
|
| 305 |
+
"Return ONLY the JSON object."
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
_DEFAULT_JUDGE_MODEL = "claude-haiku-4-5-20251001"
|
| 310 |
+
_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages"
|
| 311 |
+
# Bearer token for a self-hosted judge when R2E_JUDGE_API_KEY is unset. vLLM /
|
| 312 |
+
# Ollama ignore it; the OpenAI wire format still wants one. Same value llm.py uses.
|
| 313 |
+
_PLACEHOLDER_API_KEY = "EMPTY"
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def llm_judge(
|
| 317 |
+
*,
|
| 318 |
+
instruction: str,
|
| 319 |
+
oracle: str,
|
| 320 |
+
predicted: str,
|
| 321 |
+
api_key: str,
|
| 322 |
+
model: str = _DEFAULT_JUDGE_MODEL,
|
| 323 |
+
timeout: int = 60,
|
| 324 |
+
endpoint: str | None = None,
|
| 325 |
+
) -> tuple[float | None, str]:
|
| 326 |
+
"""Return ``(score, status)``.
|
| 327 |
+
|
| 328 |
+
``score`` is a float in [0, 1] on success, ``None`` on failure.
|
| 329 |
+
``status`` is a short string: ``"ok"`` / ``"no_api_key"`` /
|
| 330 |
+
``"no_judge_model"`` / ``"empty_predicted"`` / ``"network"`` /
|
| 331 |
+
``"parse"`` / ``"output_limit"`` / ``"missing_score"`` / ``"invalid_score"``.
|
| 332 |
+
``output_limit`` means the judge exhausted its configured token budget
|
| 333 |
+
(ungraded, even if a partial answer contains a score). ``parse`` means
|
| 334 |
+
the provider's body isn't JSON or has the wrong shape (ungraded); a reply
|
| 335 |
+
with no usable text (refusal, content filter, empty) or no valid score is
|
| 336 |
+
``missing_score`` / ``invalid_score`` (a graded 0). A missing score never
|
| 337 |
+
increases the other weights.
|
| 338 |
+
|
| 339 |
+
``endpoint`` — base URL of an OpenAI-compatible server. When set, the
|
| 340 |
+
request goes to ``<endpoint>/chat/completions`` with ``api_key`` as a
|
| 341 |
+
bearer token, at temperature 0, and ``model`` must be given explicitly;
|
| 342 |
+
otherwise it goes to Anthropic's Messages API unchanged.
|
| 343 |
+
"""
|
| 344 |
+
if not api_key:
|
| 345 |
+
return None, "no_api_key"
|
| 346 |
+
if endpoint and not model:
|
| 347 |
+
return None, "no_judge_model"
|
| 348 |
+
if not predicted.strip():
|
| 349 |
+
return 0.0, "empty_predicted"
|
| 350 |
+
|
| 351 |
+
# Truncate hard so we don't blow up the prompt for big diffs
|
| 352 |
+
prompt = _JUDGE_PROMPT.format(
|
| 353 |
+
instruction=instruction[:4000],
|
| 354 |
+
oracle=oracle[:4000],
|
| 355 |
+
predicted=predicted[:4000],
|
| 356 |
+
)
|
| 357 |
+
payload: dict = {
|
| 358 |
+
"model": model,
|
| 359 |
+
"max_tokens": 200,
|
| 360 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 361 |
+
}
|
| 362 |
+
if endpoint:
|
| 363 |
+
# Small self-hosted models are noisy judges at their default sampling
|
| 364 |
+
# temperature (same input scoring 0.0 one call and 1.0 the next); pin
|
| 365 |
+
# them to greedy. The Anthropic route keeps its defaults — the weights
|
| 366 |
+
# were calibrated against them.
|
| 367 |
+
payload["temperature"] = 0
|
| 368 |
+
url = endpoint.rstrip("/") + "/chat/completions"
|
| 369 |
+
headers = {
|
| 370 |
+
"authorization": f"Bearer {api_key}",
|
| 371 |
+
"content-type": "application/json",
|
| 372 |
+
}
|
| 373 |
+
else:
|
| 374 |
+
url = _ANTHROPIC_MESSAGES_URL
|
| 375 |
+
headers = {
|
| 376 |
+
"x-api-key": api_key,
|
| 377 |
+
"anthropic-version": "2023-06-01",
|
| 378 |
+
"content-type": "application/json",
|
| 379 |
+
}
|
| 380 |
+
body = json.dumps(payload).encode("utf-8")
|
| 381 |
+
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
|
| 382 |
+
try:
|
| 383 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 384 |
+
raw = resp.read().decode("utf-8")
|
| 385 |
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError):
|
| 386 |
+
return None, "network"
|
| 387 |
+
|
| 388 |
+
try:
|
| 389 |
+
response = json.loads(raw)
|
| 390 |
+
except json.JSONDecodeError:
|
| 391 |
+
return None, "parse"
|
| 392 |
+
# Provider-reported truncation is a grader capacity failure, not evidence
|
| 393 |
+
# that the submitted patch is wrong. Reasoning models can spend the entire
|
| 394 |
+
# output budget before producing visible text. Never grade a partial score.
|
| 395 |
+
if isinstance(response, dict):
|
| 396 |
+
choices = response.get("choices")
|
| 397 |
+
if endpoint:
|
| 398 |
+
if (
|
| 399 |
+
isinstance(choices, list)
|
| 400 |
+
and choices
|
| 401 |
+
and isinstance(choices[0], dict)
|
| 402 |
+
and choices[0].get("finish_reason") == "length"
|
| 403 |
+
):
|
| 404 |
+
return None, "output_limit"
|
| 405 |
+
elif response.get("stop_reason") in {"max_tokens", "model_context_window_exceeded"}:
|
| 406 |
+
return None, "output_limit"
|
| 407 |
+
text = _judge_text(response, openai_compatible=bool(endpoint))
|
| 408 |
+
if text is None:
|
| 409 |
+
return None, "parse"
|
| 410 |
+
|
| 411 |
+
# Pull the first JSON object out of the model's response
|
| 412 |
+
m = re.search(r"\{[^{}]*\"score\"[^{}]*\}", text, re.DOTALL)
|
| 413 |
+
if not m:
|
| 414 |
+
return None, "missing_score"
|
| 415 |
+
try:
|
| 416 |
+
obj = json.loads(m.group(0))
|
| 417 |
+
score = obj.get("score")
|
| 418 |
+
except (json.JSONDecodeError, ValueError, TypeError):
|
| 419 |
+
return None, "missing_score"
|
| 420 |
+
if type(score) not in (int, float) or not 0 <= score <= 1 or not math.isfinite(score):
|
| 421 |
+
return None, "invalid_score"
|
| 422 |
+
return float(score), "ok"
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _judge_text(payload: object, *, openai_compatible: bool) -> str | None:
|
| 426 |
+
"""The judge's answer text, ``""`` when it gave none, ``None`` for a wrong shape.
|
| 427 |
+
|
| 428 |
+
A refusal or a content filter is a well-formed reply with no usable text.
|
| 429 |
+
The agent's patch is in the prompt, so it can provoke one: that is ``""``,
|
| 430 |
+
which grades 0, not ``None``, which leaves the run ungraded.
|
| 431 |
+
|
| 432 |
+
Anthropic: a refusal is HTTP 200 with ``stop_reason: "refusal"`` and
|
| 433 |
+
``content`` empty or holding partial text to discard. OpenAI-compatible:
|
| 434 |
+
``message.content`` is null with a ``refusal`` string or
|
| 435 |
+
``finish_reason: "content_filter"``.
|
| 436 |
+
"""
|
| 437 |
+
if not isinstance(payload, dict):
|
| 438 |
+
return None
|
| 439 |
+
if openai_compatible:
|
| 440 |
+
choices = payload.get("choices")
|
| 441 |
+
if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
|
| 442 |
+
return None
|
| 443 |
+
message = choices[0].get("message")
|
| 444 |
+
if not isinstance(message, dict):
|
| 445 |
+
return None
|
| 446 |
+
if message.get("refusal") or choices[0].get("finish_reason") == "content_filter":
|
| 447 |
+
return ""
|
| 448 |
+
content = message.get("content")
|
| 449 |
+
if content is None:
|
| 450 |
+
return ""
|
| 451 |
+
if isinstance(content, str):
|
| 452 |
+
return content
|
| 453 |
+
if isinstance(content, list): # content parts
|
| 454 |
+
return "".join(
|
| 455 |
+
part.get("text", "")
|
| 456 |
+
for part in content
|
| 457 |
+
if isinstance(part, dict) and isinstance(part.get("text", ""), str)
|
| 458 |
+
)
|
| 459 |
+
return None
|
| 460 |
+
content = payload.get("content")
|
| 461 |
+
if not isinstance(content, list):
|
| 462 |
+
return None
|
| 463 |
+
if payload.get("stop_reason") == "refusal":
|
| 464 |
+
return ""
|
| 465 |
+
return "".join(
|
| 466 |
+
block["text"]
|
| 467 |
+
for block in content
|
| 468 |
+
if isinstance(block, dict)
|
| 469 |
+
and block.get("type", "text") == "text"
|
| 470 |
+
and isinstance(block.get("text"), str)
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# ---------------------------------------------------------------------------
|
| 475 |
+
# Combination
|
| 476 |
+
# ---------------------------------------------------------------------------
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
# Judge replies the agent can provoke: its patch text is part of the judge
|
| 480 |
+
# prompt, so it can steer the answer away from a valid score. These are a
|
| 481 |
+
# graded 0. An unreadable provider envelope (`parse`), missing configuration,
|
| 482 |
+
# a disabled judge, transport errors and an exhausted judge output budget leave
|
| 483 |
+
# the evaluation ungraded. Truncation alone cannot establish an incorrect patch.
|
| 484 |
+
_JUDGE_GRADED_ZERO = frozenset({"missing_score", "invalid_score"})
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def evaluation_status(judge_score: float | None, judge_status: str) -> str:
|
| 488 |
+
"""`graded` when the judge scored or the agent can have caused its failure."""
|
| 489 |
+
if judge_score is not None or judge_status in _JUDGE_GRADED_ZERO:
|
| 490 |
+
return "graded"
|
| 491 |
+
return "ungraded"
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def combine(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 495 |
+
"""Combine declared components, requiring a positively weighted judge.
|
| 496 |
+
|
| 497 |
+
Without a judge score the result is 0. ``main`` records it as a graded 0
|
| 498 |
+
when the agent can have caused the judge failure, and otherwise writes no
|
| 499 |
+
reward file, so Harbor reports the trial as VERIFIER_FAILED.
|
| 500 |
+
"""
|
| 501 |
+
if weights.get("llm_judge", 0) <= 0 or components.get("llm_judge") is None:
|
| 502 |
+
return 0.0
|
| 503 |
+
if any(w > 0 and components.get(k) is None for k, w in weights.items()):
|
| 504 |
+
return 0.0
|
| 505 |
+
return _weighted_mean(components, weights)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def _weighted_mean(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 509 |
+
available = [(k, w) for k, w in weights.items() if w > 0 and components.get(k) is not None]
|
| 510 |
+
if not available:
|
| 511 |
+
return 0.0
|
| 512 |
+
# Relative weights need not sum to one. Scale first so large finite
|
| 513 |
+
# overrides cannot overflow the numerator or denominator into NaN.
|
| 514 |
+
scale = max(w for _, w in available)
|
| 515 |
+
normalized = [(k, w / scale) for k, w in available]
|
| 516 |
+
return sum(w * components[k] for k, w in normalized) / sum(w for _, w in normalized)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
# ---------------------------------------------------------------------------
|
| 520 |
+
# Entry point (invoked by tests/test.sh inside the container)
|
| 521 |
+
# ---------------------------------------------------------------------------
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
# Weights retuned after a 23-task pilot. Rationale (LLM-as-reward-engineer
|
| 525 |
+
# analysis grounded in per-task component data):
|
| 526 |
+
#
|
| 527 |
+
# - format_valid → 0.00: was 1.0 across ALL 21 evaluated tasks. Zero
|
| 528 |
+
# discriminative signal — its 0.05 weight was pure dead weight.
|
| 529 |
+
# - similarity → 0.10: Pearson ~0.85 correlation with region_overlap.
|
| 530 |
+
# Carrying both at 0.20 double-counts positional accuracy and
|
| 531 |
+
# additionally penalizes legitimate alternative implementations.
|
| 532 |
+
# - llm_judge → 0.50: only component capturing semantic correctness
|
| 533 |
+
# independent of textual form; diverges informatively from
|
| 534 |
+
# similarity on cases like tokenizers (judge=0.72, sim=0.08).
|
| 535 |
+
# - region_overlap stays 0.20: strongest spatial-localization signal.
|
| 536 |
+
# - file_targeting → 0.12: leading indicator, less correlated with the
|
| 537 |
+
# rest than region/similarity are with each other.
|
| 538 |
+
# - size_sanity → 0.08: useful outlier detector for catastrophic
|
| 539 |
+
# over/under-generation (prettier=0.01, serde=0.08).
|
| 540 |
+
#
|
| 541 |
+
# Total: 0.00 + 0.08 + 0.12 + 0.20 + 0.10 + 0.50 = 1.00.
|
| 542 |
+
_DEFAULT_WEIGHTS = {
|
| 543 |
+
"format_valid": 0.00,
|
| 544 |
+
"size_sanity": 0.08,
|
| 545 |
+
"file_targeting": 0.12,
|
| 546 |
+
"region_overlap": 0.20,
|
| 547 |
+
"similarity": 0.10,
|
| 548 |
+
"llm_judge": 0.50,
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
# Hard cap: when size_sanity < this threshold, clamp final reward to
|
| 552 |
+
# ≤ CATASTROPHIC_SIZE_CAP. Prevents a charitable judge from inflating
|
| 553 |
+
# the score on patches that are wildly the wrong size (catastrophic
|
| 554 |
+
# over- or under-generation).
|
| 555 |
+
_CATASTROPHIC_SIZE_THRESHOLD = 0.10
|
| 556 |
+
_CATASTROPHIC_SIZE_CAP = 0.40
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _read_weights_from_env() -> dict[str, float]:
|
| 560 |
+
"""Override defaults via R2E_W_* env vars (set in container by harbor)."""
|
| 561 |
+
overrides = {
|
| 562 |
+
"format_valid": os.environ.get("R2E_W_FORMAT"),
|
| 563 |
+
"size_sanity": os.environ.get("R2E_W_SIZE"),
|
| 564 |
+
"file_targeting": os.environ.get("R2E_W_FILE"),
|
| 565 |
+
"region_overlap": os.environ.get("R2E_W_REGION"),
|
| 566 |
+
"similarity": os.environ.get("R2E_W_SIM"),
|
| 567 |
+
"llm_judge": os.environ.get("R2E_W_JUDGE"),
|
| 568 |
+
}
|
| 569 |
+
out = dict(_DEFAULT_WEIGHTS)
|
| 570 |
+
for k, v in overrides.items():
|
| 571 |
+
if v is None:
|
| 572 |
+
continue
|
| 573 |
+
try:
|
| 574 |
+
value = float(v)
|
| 575 |
+
if math.isfinite(value) and value >= 0:
|
| 576 |
+
out[k] = value
|
| 577 |
+
except (TypeError, ValueError):
|
| 578 |
+
continue
|
| 579 |
+
return out
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def _judge_config_from_env() -> tuple[str, str, str | None]:
|
| 583 |
+
"""``(api_key, model, endpoint)`` for the judge, from the verifier env.
|
| 584 |
+
|
| 585 |
+
With ``R2E_JUDGE_ENDPOINT`` set, the key comes from ``R2E_JUDGE_API_KEY``
|
| 586 |
+
(placeholder when unset) and ``ANTHROPIC_API_KEY`` is never forwarded to
|
| 587 |
+
the custom server. ``R2E_JUDGE_MODEL`` has no default on that route (a
|
| 588 |
+
self-hosted server won't have Haiku): when unset, ``model`` comes back
|
| 589 |
+
as ``""`` and ``llm_judge`` reports ``no_judge_model`` instead of
|
| 590 |
+
calling out. Without an endpoint the default Anthropic route is
|
| 591 |
+
unchanged.
|
| 592 |
+
"""
|
| 593 |
+
endpoint = os.environ.get("R2E_JUDGE_ENDPOINT", "").strip() or None
|
| 594 |
+
model = os.environ.get("R2E_JUDGE_MODEL", "").strip()
|
| 595 |
+
if endpoint:
|
| 596 |
+
api_key = os.environ.get("R2E_JUDGE_API_KEY", "").strip() or _PLACEHOLDER_API_KEY
|
| 597 |
+
return api_key, model, endpoint
|
| 598 |
+
return os.environ.get("ANTHROPIC_API_KEY", "").strip(), model or _DEFAULT_JUDGE_MODEL, None
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def main(argv: list[str] | None = None) -> int:
|
| 602 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 603 |
+
parser.add_argument("oracle")
|
| 604 |
+
parser.add_argument("predicted")
|
| 605 |
+
parser.add_argument("instruction")
|
| 606 |
+
parser.add_argument("--out-dir", default="/logs/verifier")
|
| 607 |
+
args = parser.parse_args(argv)
|
| 608 |
+
os.makedirs(args.out_dir, exist_ok=True)
|
| 609 |
+
# This run is the only authority on the reward: an earlier or planted
|
| 610 |
+
# reward file must not stand if this evaluation ends up ungraded.
|
| 611 |
+
for name in ("reward.txt", "reward.json"):
|
| 612 |
+
try:
|
| 613 |
+
os.unlink(os.path.join(args.out_dir, name))
|
| 614 |
+
except FileNotFoundError:
|
| 615 |
+
pass
|
| 616 |
+
oracle = _read_or_empty(args.oracle)
|
| 617 |
+
try:
|
| 618 |
+
oversized = os.path.getsize(args.predicted) > _MAX_PREDICTED_BYTES
|
| 619 |
+
except OSError:
|
| 620 |
+
oversized = False
|
| 621 |
+
predicted = "" if oversized else _read_or_empty(args.predicted)
|
| 622 |
+
if oversized or predicted_too_large(oracle, predicted):
|
| 623 |
+
breakdown = {
|
| 624 |
+
"final_reward": 0.0,
|
| 625 |
+
"evaluation_status": "graded",
|
| 626 |
+
"eval_trustworthy": False,
|
| 627 |
+
"predicted_status": "predicted_too_large",
|
| 628 |
+
}
|
| 629 |
+
_write_outputs(args.out_dir, 0.0, breakdown)
|
| 630 |
+
return 0
|
| 631 |
+
instruction = _read_or_empty(args.instruction)
|
| 632 |
+
api_key, judge_model, judge_endpoint = _judge_config_from_env()
|
| 633 |
+
|
| 634 |
+
fv = format_valid(predicted)
|
| 635 |
+
ss = size_sanity(oracle, predicted)
|
| 636 |
+
ft = file_targeting(oracle, predicted)
|
| 637 |
+
ro = region_overlap(oracle, predicted)
|
| 638 |
+
sim = similarity(oracle, predicted)
|
| 639 |
+
weights = _read_weights_from_env()
|
| 640 |
+
if weights["llm_judge"] <= 0:
|
| 641 |
+
judge_score, judge_status = None, "disabled"
|
| 642 |
+
else:
|
| 643 |
+
judge_score, judge_status = llm_judge(
|
| 644 |
+
instruction=instruction,
|
| 645 |
+
oracle=oracle,
|
| 646 |
+
predicted=predicted,
|
| 647 |
+
api_key=api_key,
|
| 648 |
+
model=judge_model,
|
| 649 |
+
endpoint=judge_endpoint,
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
components: dict[str, float | None] = {
|
| 653 |
+
"format_valid": fv,
|
| 654 |
+
"size_sanity": ss,
|
| 655 |
+
"file_targeting": ft,
|
| 656 |
+
"region_overlap": ro,
|
| 657 |
+
"similarity": sim,
|
| 658 |
+
"llm_judge": judge_score,
|
| 659 |
+
}
|
| 660 |
+
final = combine(components, weights)
|
| 661 |
+
final = max(0.0, min(1.0, final))
|
| 662 |
+
|
| 663 |
+
# Hard cap on catastrophic size mismatches. Without this, a charitable
|
| 664 |
+
# judge can inflate the reward on patches that are dramatically the
|
| 665 |
+
# wrong size (prettier scored 0.23 with size_sanity=0.011 — the judge
|
| 666 |
+
# was lenient at 0.25 despite the patch being a near-no-op vs a
|
| 667 |
+
# 500-line oracle). The cap kicks in only at the extremes.
|
| 668 |
+
if ss < _CATASTROPHIC_SIZE_THRESHOLD:
|
| 669 |
+
final = min(final, _CATASTROPHIC_SIZE_CAP)
|
| 670 |
+
|
| 671 |
+
status = evaluation_status(judge_score, judge_status)
|
| 672 |
+
breakdown = {
|
| 673 |
+
# No reward exists for an ungraded evaluation: null, not a placeholder 0.
|
| 674 |
+
"final_reward": round(final, 6) if status == "graded" else None,
|
| 675 |
+
"evaluation_status": status,
|
| 676 |
+
"eval_trustworthy": judge_score is not None,
|
| 677 |
+
"diagnostic_similarity": round(
|
| 678 |
+
_weighted_mean(components, {k: w for k, w in weights.items() if k != "llm_judge"}),
|
| 679 |
+
6,
|
| 680 |
+
),
|
| 681 |
+
"components": {k: (None if v is None else round(v, 6)) for k, v in components.items()},
|
| 682 |
+
"weights": {k: round(v, 6) for k, v in weights.items()},
|
| 683 |
+
"judge_model": judge_model if judge_status == "ok" else None,
|
| 684 |
+
"judge_endpoint": judge_endpoint,
|
| 685 |
+
"judge_status": judge_status,
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
_write_outputs(args.out_dir, final, breakdown)
|
| 689 |
+
return 0
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def _write_outputs(out_dir: str, final: float, breakdown: dict) -> None:
|
| 693 |
+
# An ungraded evaluation writes no reward file. Harbor then raises
|
| 694 |
+
# RewardFileNotFoundError: the trial is VERIFIER_FAILED, reward_valid is
|
| 695 |
+
# false, and RL consumers (OpenEnv harbor_env -> TRL) drop the rollout
|
| 696 |
+
# instead of training on a 0. Harbor's job mean and pass@k still count the
|
| 697 |
+
# trial as 0, so evaluation stays fail-closed.
|
| 698 |
+
if breakdown["evaluation_status"] == "graded":
|
| 699 |
+
with open(os.path.join(out_dir, "reward.txt"), "w", encoding="utf-8") as f:
|
| 700 |
+
f.write(f"{final:.6f}\n")
|
| 701 |
+
# Harbor's `reward.json` must be a flat map of floats/ints (spec, see
|
| 702 |
+
# <https://harborframework.com/docs/tasks>); our breakdown carries nested
|
| 703 |
+
# dicts, judge strings, and status strings, so it goes to the sidecar the
|
| 704 |
+
# Harbor UI renders under Verifier Logs → Rewards. Mirrors #75 (Neubig)
|
| 705 |
+
# for `_pr_runtime_verifier.py`.
|
| 706 |
+
with open(os.path.join(out_dir, "reward-details.json"), "w", encoding="utf-8") as f:
|
| 707 |
+
json.dump(breakdown, f, indent=2)
|
| 708 |
+
|
| 709 |
+
# Also print to stdout so harbor's log captures the breakdown
|
| 710 |
+
print(json.dumps(breakdown, indent=2))
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def _read_or_empty(path: str) -> str:
|
| 714 |
+
try:
|
| 715 |
+
with open(path, encoding="utf-8") as f:
|
| 716 |
+
return f.read()
|
| 717 |
+
except (OSError, UnicodeDecodeError):
|
| 718 |
+
return ""
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
if __name__ == "__main__":
|
| 722 |
+
sys.exit(main())
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
__all__ = [
|
| 726 |
+
"combine",
|
| 727 |
+
"file_paths",
|
| 728 |
+
"file_targeting",
|
| 729 |
+
"format_valid",
|
| 730 |
+
"hunk_ranges",
|
| 731 |
+
"llm_judge",
|
| 732 |
+
"main",
|
| 733 |
+
"predicted_too_large",
|
| 734 |
+
"region_overlap",
|
| 735 |
+
"similarity",
|
| 736 |
+
"size_sanity",
|
| 737 |
+
]
|
tasks/AeneasVerif__aeneas-1391/environment/Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto-generated by Repo2RLEnv pr_diff — 6-component reward env.
|
| 2 |
+
# Agent-agnostic: the agent (claude-code / openhands / codex / etc.)
|
| 3 |
+
# installs itself at run time via its harbor adapter. We only ship
|
| 4 |
+
# the source repo — the oracle + verifier arrive at verify time via
|
| 5 |
+
# tests/, never baked into the agent's image.
|
| 6 |
+
FROM python:3.12-slim
|
| 7 |
+
ARG GITHUB_TOKEN=
|
| 8 |
+
RUN apt-get update \
|
| 9 |
+
&& apt-get install -y --no-install-recommends git ca-certificates curl \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
RUN git config --global --add safe.directory /workspace \
|
| 12 |
+
&& git config --global init.defaultBranch main \
|
| 13 |
+
&& git config --global advice.detachedHead false
|
| 14 |
+
RUN if [ -n "$GITHUB_TOKEN" ]; then \
|
| 15 |
+
git clone --filter=blob:none https://x-access-token:"${GITHUB_TOKEN}"@github.com/AeneasVerif/aeneas.git /workspace; \
|
| 16 |
+
else \
|
| 17 |
+
git clone --filter=blob:none https://github.com/AeneasVerif/aeneas.git /workspace; \
|
| 18 |
+
fi \
|
| 19 |
+
&& git -C /workspace remote set-url origin https://github.com/AeneasVerif/aeneas.git
|
| 20 |
+
WORKDIR /workspace
|
| 21 |
+
RUN git fetch --depth 1 origin a7f240d7360b5a34cde5305a8d773ed8324f6d42 2>/dev/null \
|
| 22 |
+
|| git fetch --unshallow origin 2>/dev/null || true
|
| 23 |
+
RUN git reset --hard a7f240d7360b5a34cde5305a8d773ed8324f6d42 \
|
| 24 |
+
&& git clean -fdx -e .venv -e venv -e __pycache__
|
| 25 |
+
RUN git checkout -q -B base a7f240d7360b5a34cde5305a8d773ed8324f6d42 \
|
| 26 |
+
&& git remote remove origin 2>/dev/null || true
|
| 27 |
+
RUN for ref in $(git branch --format='%(refname:short)' | grep -vx base); do git branch -D "$ref" 2>/dev/null || true; done \
|
| 28 |
+
&& git tag -l | xargs -r git tag -d >/dev/null 2>&1 || true \
|
| 29 |
+
&& git for-each-ref --format='%(refname)' refs/remotes 2>/dev/null | xargs -r -n1 git update-ref -d 2>/dev/null || true \
|
| 30 |
+
&& git reflog expire --expire=now --all 2>/dev/null || true \
|
| 31 |
+
&& git gc --prune=now 2>/dev/null || true
|
| 32 |
+
RUN P="$(git rev-parse --git-dir)/objects/pack"; if ls "$P"/*.promisor >/dev/null 2>&1; then \
|
| 33 |
+
git rev-list --objects --all --missing=allow-promisor > "$P/../scrub.list" \
|
| 34 |
+
&& K=$(git pack-objects -q --missing=allow-promisor "$P/scrub" < "$P/../scrub.list") \
|
| 35 |
+
&& rm -f "$P/../scrub.list" "$P"/pack-* "$P"/multi-pack-index* \
|
| 36 |
+
&& touch "$P/scrub-$K.promisor" && git prune --expire=now; \
|
| 37 |
+
fi
|
tasks/AeneasVerif__aeneas-1391/instruction.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Update charon
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
Companion PR to
|
| 8 |
+
|
| 9 |
+
## Task
|
| 10 |
+
|
| 11 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `a7f240d7360b`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1391/solution/patch.diff
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/charon-pin b/charon-pin
|
| 2 |
+
index dd8c667a76..7ed0692fa5 100644
|
| 3 |
+
--- a/charon-pin
|
| 4 |
+
+++ b/charon-pin
|
| 5 |
+
@@ -1,2 +1,2 @@
|
| 6 |
+
# This is the commit from https://github.com/AeneasVerif/charon that should be used with this version of aeneas.
|
| 7 |
+
-4f01ad7b82e309b94745416fdaee1a159f27d572
|
| 8 |
+
+c8f15d7d658c86a95658f71ad99cddd4be002e04
|
| 9 |
+
diff --git a/flake.lock b/flake.lock
|
| 10 |
+
index 95c4dd0f13..83ebea2669 100644
|
| 11 |
+
--- a/flake.lock
|
| 12 |
+
+++ b/flake.lock
|
| 13 |
+
@@ -10,11 +10,11 @@
|
| 14 |
+
"rust-overlay": "rust-overlay"
|
| 15 |
+
},
|
| 16 |
+
"locked": {
|
| 17 |
+
- "lastModified": 1790849996,
|
| 18 |
+
- "narHash": "sha256-4E5gan937tr+7hI0jjPyorZoPmmn0CcZ4ujjSxRgzFw=",
|
| 19 |
+
+ "lastModified": 1790894892,
|
| 20 |
+
+ "narHash": "sha256-oy45Qfbeya3cJjlrUclpUiY5tdj2861MDvTyZHLMoEY=",
|
| 21 |
+
"owner": "aeneasverif",
|
| 22 |
+
"repo": "charon",
|
| 23 |
+
- "rev": "4f01ad7b82e309b94745416fdaee1a159f27d572",
|
| 24 |
+
+ "rev": "c8f15d7d658c86a95658f71ad99cddd4be002e04",
|
| 25 |
+
"type": "github"
|
| 26 |
+
},
|
| 27 |
+
"original": {
|
| 28 |
+
diff --git a/src/PrePasses.ml b/src/PrePasses.ml
|
| 29 |
+
index 7eb98606d2..9ff513092e 100644
|
| 30 |
+
--- a/src/PrePasses.ml
|
| 31 |
+
+++ b/src/PrePasses.ml
|
| 32 |
+
@@ -88,10 +88,10 @@ let erase_body_regions (crate : crate) (f : fun_decl) : fun_decl =
|
| 33 |
+
f
|
| 34 |
+
|
| 35 |
+
(** Replace the occurrences of [core::intrinsics::unreachable] with
|
| 36 |
+
- [Abort UndefinedBehavior]. This helps with the analyzes and the symbolic
|
| 37 |
+
+ [UndefinedBehavior]. This helps with the analyzes and the symbolic
|
| 38 |
+
evaluation (in particular, we stop the evaluation when encountering an
|
| 39 |
+
- [Abort] - this can help us avoid merging control-flow after a match for
|
| 40 |
+
- instance *)
|
| 41 |
+
+ [UndefinedBehavior] - this can help us avoid merging control-flow after a
|
| 42 |
+
+ match for instance *)
|
| 43 |
+
let remove_unreachable (crate : crate) (f : fun_decl) : fun_decl =
|
| 44 |
+
let impl_pat = NameMatcher.parse_pattern "core::intrinsics::unreachable" in
|
| 45 |
+
let match_name = ExtractName.match_name crate in
|
| 46 |
+
@@ -116,7 +116,7 @@ let remove_unreachable (crate : crate) (f : fun_decl) : fun_decl =
|
| 47 |
+
match stl with
|
| 48 |
+
| [] -> []
|
| 49 |
+
| st :: stl ->
|
| 50 |
+
- if is_unreachable st then [ { st with kind = Abort UndefinedBehavior } ]
|
| 51 |
+
+ if is_unreachable st then [ { st with kind = UndefinedBehavior } ]
|
| 52 |
+
else st :: update stl
|
| 53 |
+
in
|
| 54 |
+
let visitor =
|
| 55 |
+
@@ -578,7 +578,7 @@ let update_loops (crate : crate) (f : fun_decl) : fun_decl =
|
| 56 |
+
| st :: after -> (
|
| 57 |
+
match st.kind with
|
| 58 |
+
| Return -> [ { st with kind = Break 0 } ]
|
| 59 |
+
- | Abort _ -> [ st ]
|
| 60 |
+
+ | Panic _ | UnwindTerminate | UndefinedBehavior -> [ st ]
|
| 61 |
+
| _ -> st :: decompose_after after)
|
| 62 |
+
in
|
| 63 |
+
let after = decompose_after after in
|
| 64 |
+
@@ -702,8 +702,13 @@ let remove_useless_joins (crate : crate) (f : fun_decl) : fun_decl =
|
| 65 |
+
match st.kind with
|
| 66 |
+
| Nop | StorageLive _ | StorageDead _ | PlaceMention _ | Borrowck _
|
| 67 |
+
| Drop (_, _, _, _) -> (can_inline, st :: ls)
|
| 68 |
+
- | Abort _ | Return | UnwindResume | Break _ | Continue _ ->
|
| 69 |
+
- (true, [ st ])
|
| 70 |
+
+ | Panic _
|
| 71 |
+
+ | UnwindTerminate
|
| 72 |
+
+ | UndefinedBehavior
|
| 73 |
+
+ | Return
|
| 74 |
+
+ | UnwindResume
|
| 75 |
+
+ | Break _
|
| 76 |
+
+ | Continue _ -> (true, [ st ])
|
| 77 |
+
| Switch (data, branches) ->
|
| 78 |
+
[%ldebug "Switch: can_inline: " ^ Print.bool_to_string can_inline];
|
| 79 |
+
(* Attempt to inline inside the body *)
|
| 80 |
+
@@ -1466,8 +1471,7 @@ let simplify_panics (crate : crate) (f : fun_decl) : fun_decl =
|
| 81 |
+
match skip_storage_dead stl with
|
| 82 |
+
| st1 :: stl1 -> (
|
| 83 |
+
match st1.kind with
|
| 84 |
+
- | Abort (Panic _) ->
|
| 85 |
+
- self#visit_statement env st1 :: update stl1
|
| 86 |
+
+ | Panic _ -> self#visit_statement env st1 :: update stl1
|
| 87 |
+
| _ -> self#visit_statement env st0 :: update stl)
|
| 88 |
+
| [] -> self#visit_statement env st0 :: update stl)
|
| 89 |
+
| st0 :: stl -> self#visit_statement env st0 :: update stl
|
| 90 |
+
@@ -1581,7 +1585,9 @@ let decompose_global_accesses (crate : crate) (f : fun_decl) : fun_decl =
|
| 91 |
+
Call ({ call with func; args }, on_unwind)
|
| 92 |
+
| SetDiscriminant _ | StorageLive _ | StorageDead _ | PlaceMention _
|
| 93 |
+
| Drop (_, _, _, _)
|
| 94 |
+
- | Abort _
|
| 95 |
+
+ | Panic _
|
| 96 |
+
+ | UnwindTerminate
|
| 97 |
+
+ | UndefinedBehavior
|
| 98 |
+
| Return
|
| 99 |
+
| UnwindResume
|
| 100 |
+
| Break _
|
| 101 |
+
diff --git a/src/interp/InterpStatements.ml b/src/interp/InterpStatements.ml
|
| 102 |
+
index e921d3e141..8cc6f8d583 100644
|
| 103 |
+
--- a/src/interp/InterpStatements.ml
|
| 104 |
+
+++ b/src/interp/InterpStatements.ml
|
| 105 |
+
@@ -794,7 +794,7 @@ and eval_statement_raw (config : config) (st : statement) : stl_cm_fun =
|
| 106 |
+
let (ctx, res), cc = eval_assertion config st.span assertion ctx in
|
| 107 |
+
([ (ctx, res) ], cc_singleton __FILE__ __LINE__ st.span cc)
|
| 108 |
+
| Call (call, _) -> eval_function_call config st.span call ctx
|
| 109 |
+
- | Abort _ ->
|
| 110 |
+
+ | Panic _ | UnwindTerminate | UndefinedBehavior ->
|
| 111 |
+
(* Evaluate to a panic only if the execution is concrete, otherwise we stop
|
| 112 |
+
evaluating there and synthesize a [panic] node in the symbolic AST. *)
|
| 113 |
+
if config.mode = ConcreteMode then
|
tasks/AeneasVerif__aeneas-1391/solution/solve.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euxo pipefail
|
| 3 |
+
cd /workspace
|
| 4 |
+
git config --global --add safe.directory /workspace
|
| 5 |
+
PATCH="$(dirname "$0")/patch.diff"
|
| 6 |
+
git apply --verbose --reject "$PATCH"
|
tasks/AeneasVerif__aeneas-1391/task.toml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "trending/AeneasVerif__aeneas-1391"
|
| 5 |
+
description = "Update charon"
|
| 6 |
+
|
| 7 |
+
[metadata]
|
| 8 |
+
difficulty = "medium"
|
| 9 |
+
category = "bugfix"
|
| 10 |
+
keywords = [
|
| 11 |
+
"aeneas",
|
| 12 |
+
"pr_diff",
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
[metadata.repo2env]
|
| 16 |
+
pipeline = "pr_diff"
|
| 17 |
+
pipeline_version = "0.3.0"
|
| 18 |
+
repo = "AeneasVerif/aeneas"
|
| 19 |
+
ref = "a7f240d7360b5a34cde5305a8d773ed8324f6d42"
|
| 20 |
+
reference = "https://github.com/AeneasVerif/aeneas/pull/1391"
|
| 21 |
+
source_access = "auto"
|
| 22 |
+
built_at = "2026-11-16T16:10:00.166298+00:00"
|
| 23 |
+
reward_kinds = [
|
| 24 |
+
"diff_similarity",
|
| 25 |
+
]
|
| 26 |
+
spec_version = "0.2.0"
|
| 27 |
+
content_hash = "sha256:b2d2a12d2cf3a1f95f9597db16d25576c9cf23e438d581efd399fbe9d8adea06"
|
| 28 |
+
|
| 29 |
+
[metadata.repo2env.pr_diff]
|
| 30 |
+
pr_merged_at = "2026-10-01T23:27:12Z"
|
| 31 |
+
diff_format = "unified"
|
| 32 |
+
context_files = [
|
| 33 |
+
"charon-pin",
|
| 34 |
+
"flake.lock",
|
| 35 |
+
"src/PrePasses.ml",
|
| 36 |
+
"src/interp/InterpStatements.ml",
|
| 37 |
+
]
|
| 38 |
+
bootstrap_image = "python:3.12-slim"
|
| 39 |
+
|
| 40 |
+
[metadata.repo2env.reward_calibration]
|
| 41 |
+
baseline_reward = 0.0
|
| 42 |
+
loc_changed = 36
|
| 43 |
+
difficulty = "medium"
|
| 44 |
+
|
| 45 |
+
[metadata.repo2env.evaluation]
|
| 46 |
+
schema_version = "1"
|
| 47 |
+
status = "unverified"
|
| 48 |
+
stage = "generation"
|
| 49 |
+
reason_codes = [
|
| 50 |
+
"validation_not_run",
|
| 51 |
+
]
|
| 52 |
+
detail = "Generated task; validation has not been established."
|
| 53 |
+
provenance = "unknown"
|
| 54 |
+
evidence = []
|
| 55 |
+
|
| 56 |
+
[metadata.repo2env.reproducibility]
|
| 57 |
+
mode = "inline_dockerfile"
|
| 58 |
+
image_ref = "python:3.12-slim"
|
| 59 |
+
image_tag = "python:3.12-slim"
|
| 60 |
+
image_visibility = "public"
|
| 61 |
+
pushed_at = "2026-11-16T16:19:57.823571+00:00"
|
| 62 |
+
pushed_by = "scalingX"
|
| 63 |
+
inline_recipe_sha256 = "sha256:0b032735c9c2eb818b412c776ba7942cd13a84ee2d0e695f4d1f152871b036b5"
|
| 64 |
+
inline_recipe_lines = 37
|
| 65 |
+
inline_recipe_source = "user_dockerfile"
|
| 66 |
+
|
| 67 |
+
[agent]
|
| 68 |
+
timeout_sec = 1800.0
|
| 69 |
+
|
| 70 |
+
[verifier]
|
| 71 |
+
timeout_sec = 300.0
|
tasks/AeneasVerif__aeneas-1391/tests/capture.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standalone PR-diff capture without executing workspace Git configuration.
|
| 2 |
+
|
| 3 |
+
The emitted task uses a regular clone with a pinned base commit. Only its
|
| 4 |
+
object store is read: refs, index, config, hooks and replacement refs are not
|
| 5 |
+
used. This is a configuration boundary, not a sandbox for a malicious process
|
| 6 |
+
that can modify the verifier, binaries or object store while capture runs.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import tempfile
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def capture(workspace: Path, base_commit: str) -> bytes:
|
| 23 |
+
"""Capture tracked and new files through a fresh private Git index."""
|
| 24 |
+
if not re.fullmatch(r"[a-fA-F0-9]{40}", base_commit):
|
| 25 |
+
raise ValueError("Expected the task's pinned SHA-1 base commit")
|
| 26 |
+
objects = workspace.resolve() / ".git" / "objects"
|
| 27 |
+
if not objects.is_dir():
|
| 28 |
+
raise ValueError("The task's cloned Git object store is missing")
|
| 29 |
+
git = shutil.which("git", path=os.defpath)
|
| 30 |
+
if git is None:
|
| 31 |
+
raise FileNotFoundError("System git is unavailable")
|
| 32 |
+
with tempfile.TemporaryDirectory(prefix="r2e-diff-") as temporary:
|
| 33 |
+
private = Path(temporary)
|
| 34 |
+
# Do not forward GIT_CONFIG_PARAMETERS/COUNT, external diff programs,
|
| 35 |
+
# system/global includes, user attributes, templates or credential env.
|
| 36 |
+
env = {
|
| 37 |
+
"PATH": os.defpath,
|
| 38 |
+
"HOME": temporary,
|
| 39 |
+
"XDG_CONFIG_HOME": temporary,
|
| 40 |
+
"GIT_CONFIG_NOSYSTEM": "1",
|
| 41 |
+
"GIT_CONFIG_GLOBAL": os.devnull,
|
| 42 |
+
"GIT_ATTR_NOSYSTEM": "1",
|
| 43 |
+
"GIT_NO_REPLACE_OBJECTS": "1",
|
| 44 |
+
"GIT_NO_LAZY_FETCH": "1",
|
| 45 |
+
"GIT_TERMINAL_PROMPT": "0",
|
| 46 |
+
"LC_ALL": "C",
|
| 47 |
+
}
|
| 48 |
+
subprocess.run(
|
| 49 |
+
[git, "init", "--quiet", "--template=", str(private / "repository")],
|
| 50 |
+
env=env,
|
| 51 |
+
cwd=private,
|
| 52 |
+
check=True,
|
| 53 |
+
capture_output=True,
|
| 54 |
+
timeout=60,
|
| 55 |
+
)
|
| 56 |
+
env["GIT_ALTERNATE_OBJECT_DIRECTORIES"] = json.dumps(str(objects), ensure_ascii=False)
|
| 57 |
+
command = [
|
| 58 |
+
git,
|
| 59 |
+
f"--git-dir={private / 'repository/.git'}",
|
| 60 |
+
f"--work-tree={workspace.resolve()}",
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def run(*args: str) -> bytes:
|
| 64 |
+
return subprocess.run(
|
| 65 |
+
[*command, *args],
|
| 66 |
+
env=env,
|
| 67 |
+
cwd=workspace,
|
| 68 |
+
check=True,
|
| 69 |
+
capture_output=True,
|
| 70 |
+
timeout=60,
|
| 71 |
+
).stdout
|
| 72 |
+
|
| 73 |
+
run("read-tree", f"{base_commit}^{{tree}}")
|
| 74 |
+
# All filter drivers are undefined in the private configuration. The
|
| 75 |
+
# workspace's clean filters, fsmonitor and hooks cannot be invoked.
|
| 76 |
+
run("add", "--all", "--", ".")
|
| 77 |
+
return run("diff", "--cached", "--no-ext-diff", "--no-textconv", base_commit, "--")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def main(argv: list[str] | None = None) -> int:
|
| 81 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 82 |
+
parser.add_argument("workspace", type=Path)
|
| 83 |
+
parser.add_argument("base_commit")
|
| 84 |
+
args = parser.parse_args(argv)
|
| 85 |
+
try:
|
| 86 |
+
patch = capture(args.workspace, args.base_commit)
|
| 87 |
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
| 88 |
+
# Do not echo child stderr: it may contain workspace-controlled data.
|
| 89 |
+
sys.stderr.write(f"PR-diff capture failed ({type(exc).__name__})\n")
|
| 90 |
+
return 1
|
| 91 |
+
sys.stdout.buffer.write(patch)
|
| 92 |
+
return 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
sys.exit(main())
|
tasks/AeneasVerif__aeneas-1391/tests/instruction.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Update charon
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
Companion PR to
|
| 8 |
+
|
| 9 |
+
## Task
|
| 10 |
+
|
| 11 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `a7f240d7360b`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1391/tests/oracle.patch
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/charon-pin b/charon-pin
|
| 2 |
+
index dd8c667a76..7ed0692fa5 100644
|
| 3 |
+
--- a/charon-pin
|
| 4 |
+
+++ b/charon-pin
|
| 5 |
+
@@ -1,2 +1,2 @@
|
| 6 |
+
# This is the commit from https://github.com/AeneasVerif/charon that should be used with this version of aeneas.
|
| 7 |
+
-4f01ad7b82e309b94745416fdaee1a159f27d572
|
| 8 |
+
+c8f15d7d658c86a95658f71ad99cddd4be002e04
|
| 9 |
+
diff --git a/flake.lock b/flake.lock
|
| 10 |
+
index 95c4dd0f13..83ebea2669 100644
|
| 11 |
+
--- a/flake.lock
|
| 12 |
+
+++ b/flake.lock
|
| 13 |
+
@@ -10,11 +10,11 @@
|
| 14 |
+
"rust-overlay": "rust-overlay"
|
| 15 |
+
},
|
| 16 |
+
"locked": {
|
| 17 |
+
- "lastModified": 1790849996,
|
| 18 |
+
- "narHash": "sha256-4E5gan937tr+7hI0jjPyorZoPmmn0CcZ4ujjSxRgzFw=",
|
| 19 |
+
+ "lastModified": 1790894892,
|
| 20 |
+
+ "narHash": "sha256-oy45Qfbeya3cJjlrUclpUiY5tdj2861MDvTyZHLMoEY=",
|
| 21 |
+
"owner": "aeneasverif",
|
| 22 |
+
"repo": "charon",
|
| 23 |
+
- "rev": "4f01ad7b82e309b94745416fdaee1a159f27d572",
|
| 24 |
+
+ "rev": "c8f15d7d658c86a95658f71ad99cddd4be002e04",
|
| 25 |
+
"type": "github"
|
| 26 |
+
},
|
| 27 |
+
"original": {
|
| 28 |
+
diff --git a/src/PrePasses.ml b/src/PrePasses.ml
|
| 29 |
+
index 7eb98606d2..9ff513092e 100644
|
| 30 |
+
--- a/src/PrePasses.ml
|
| 31 |
+
+++ b/src/PrePasses.ml
|
| 32 |
+
@@ -88,10 +88,10 @@ let erase_body_regions (crate : crate) (f : fun_decl) : fun_decl =
|
| 33 |
+
f
|
| 34 |
+
|
| 35 |
+
(** Replace the occurrences of [core::intrinsics::unreachable] with
|
| 36 |
+
- [Abort UndefinedBehavior]. This helps with the analyzes and the symbolic
|
| 37 |
+
+ [UndefinedBehavior]. This helps with the analyzes and the symbolic
|
| 38 |
+
evaluation (in particular, we stop the evaluation when encountering an
|
| 39 |
+
- [Abort] - this can help us avoid merging control-flow after a match for
|
| 40 |
+
- instance *)
|
| 41 |
+
+ [UndefinedBehavior] - this can help us avoid merging control-flow after a
|
| 42 |
+
+ match for instance *)
|
| 43 |
+
let remove_unreachable (crate : crate) (f : fun_decl) : fun_decl =
|
| 44 |
+
let impl_pat = NameMatcher.parse_pattern "core::intrinsics::unreachable" in
|
| 45 |
+
let match_name = ExtractName.match_name crate in
|
| 46 |
+
@@ -116,7 +116,7 @@ let remove_unreachable (crate : crate) (f : fun_decl) : fun_decl =
|
| 47 |
+
match stl with
|
| 48 |
+
| [] -> []
|
| 49 |
+
| st :: stl ->
|
| 50 |
+
- if is_unreachable st then [ { st with kind = Abort UndefinedBehavior } ]
|
| 51 |
+
+ if is_unreachable st then [ { st with kind = UndefinedBehavior } ]
|
| 52 |
+
else st :: update stl
|
| 53 |
+
in
|
| 54 |
+
let visitor =
|
| 55 |
+
@@ -578,7 +578,7 @@ let update_loops (crate : crate) (f : fun_decl) : fun_decl =
|
| 56 |
+
| st :: after -> (
|
| 57 |
+
match st.kind with
|
| 58 |
+
| Return -> [ { st with kind = Break 0 } ]
|
| 59 |
+
- | Abort _ -> [ st ]
|
| 60 |
+
+ | Panic _ | UnwindTerminate | UndefinedBehavior -> [ st ]
|
| 61 |
+
| _ -> st :: decompose_after after)
|
| 62 |
+
in
|
| 63 |
+
let after = decompose_after after in
|
| 64 |
+
@@ -702,8 +702,13 @@ let remove_useless_joins (crate : crate) (f : fun_decl) : fun_decl =
|
| 65 |
+
match st.kind with
|
| 66 |
+
| Nop | StorageLive _ | StorageDead _ | PlaceMention _ | Borrowck _
|
| 67 |
+
| Drop (_, _, _, _) -> (can_inline, st :: ls)
|
| 68 |
+
- | Abort _ | Return | UnwindResume | Break _ | Continue _ ->
|
| 69 |
+
- (true, [ st ])
|
| 70 |
+
+ | Panic _
|
| 71 |
+
+ | UnwindTerminate
|
| 72 |
+
+ | UndefinedBehavior
|
| 73 |
+
+ | Return
|
| 74 |
+
+ | UnwindResume
|
| 75 |
+
+ | Break _
|
| 76 |
+
+ | Continue _ -> (true, [ st ])
|
| 77 |
+
| Switch (data, branches) ->
|
| 78 |
+
[%ldebug "Switch: can_inline: " ^ Print.bool_to_string can_inline];
|
| 79 |
+
(* Attempt to inline inside the body *)
|
| 80 |
+
@@ -1466,8 +1471,7 @@ let simplify_panics (crate : crate) (f : fun_decl) : fun_decl =
|
| 81 |
+
match skip_storage_dead stl with
|
| 82 |
+
| st1 :: stl1 -> (
|
| 83 |
+
match st1.kind with
|
| 84 |
+
- | Abort (Panic _) ->
|
| 85 |
+
- self#visit_statement env st1 :: update stl1
|
| 86 |
+
+ | Panic _ -> self#visit_statement env st1 :: update stl1
|
| 87 |
+
| _ -> self#visit_statement env st0 :: update stl)
|
| 88 |
+
| [] -> self#visit_statement env st0 :: update stl)
|
| 89 |
+
| st0 :: stl -> self#visit_statement env st0 :: update stl
|
| 90 |
+
@@ -1581,7 +1585,9 @@ let decompose_global_accesses (crate : crate) (f : fun_decl) : fun_decl =
|
| 91 |
+
Call ({ call with func; args }, on_unwind)
|
| 92 |
+
| SetDiscriminant _ | StorageLive _ | StorageDead _ | PlaceMention _
|
| 93 |
+
| Drop (_, _, _, _)
|
| 94 |
+
- | Abort _
|
| 95 |
+
+ | Panic _
|
| 96 |
+
+ | UnwindTerminate
|
| 97 |
+
+ | UndefinedBehavior
|
| 98 |
+
| Return
|
| 99 |
+
| UnwindResume
|
| 100 |
+
| Break _
|
| 101 |
+
diff --git a/src/interp/InterpStatements.ml b/src/interp/InterpStatements.ml
|
| 102 |
+
index e921d3e141..8cc6f8d583 100644
|
| 103 |
+
--- a/src/interp/InterpStatements.ml
|
| 104 |
+
+++ b/src/interp/InterpStatements.ml
|
| 105 |
+
@@ -794,7 +794,7 @@ and eval_statement_raw (config : config) (st : statement) : stl_cm_fun =
|
| 106 |
+
let (ctx, res), cc = eval_assertion config st.span assertion ctx in
|
| 107 |
+
([ (ctx, res) ], cc_singleton __FILE__ __LINE__ st.span cc)
|
| 108 |
+
| Call (call, _) -> eval_function_call config st.span call ctx
|
| 109 |
+
- | Abort _ ->
|
| 110 |
+
+ | Panic _ | UnwindTerminate | UndefinedBehavior ->
|
| 111 |
+
(* Evaluate to a panic only if the execution is concrete, otherwise we stop
|
| 112 |
+
evaluating there and synthesize a [panic] node in the symbolic AST. *)
|
| 113 |
+
if config.mode = ConcreteMode then
|
tasks/AeneasVerif__aeneas-1391/tests/test.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -uxo pipefail
|
| 3 |
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
| 4 |
+
cd /workspace
|
| 5 |
+
mkdir -p /logs/verifier
|
| 6 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json /logs/verifier/reward-details.json
|
| 7 |
+
CAPTURE_DIR="$(mktemp -d)" || exit 1
|
| 8 |
+
trap 'rm -rf -- "$CAPTURE_DIR"' EXIT
|
| 9 |
+
if ! python3 -I "$SCRIPT_DIR/capture.py" /workspace a7f240d7360b5a34cde5305a8d773ed8324f6d42 > "$CAPTURE_DIR/predicted.patch"; then
|
| 10 |
+
echo "0.0" > /logs/verifier/reward.txt
|
| 11 |
+
printf '%s' '{"final_reward": 0.0, "evaluation_status": "graded", "eval_trustworthy": false, "capture_status": "error"}' > /logs/verifier/reward-details.json
|
| 12 |
+
exit 0
|
| 13 |
+
fi
|
| 14 |
+
rm -f /logs/verifier/predicted.patch
|
| 15 |
+
cp -- "$CAPTURE_DIR/predicted.patch" /logs/verifier/predicted.patch
|
| 16 |
+
: 'START_VERIFY_OUTPUT'
|
| 17 |
+
if ! python3 -I "$SCRIPT_DIR/verifier.py" \
|
| 18 |
+
"$SCRIPT_DIR/oracle.patch" \
|
| 19 |
+
"$CAPTURE_DIR/predicted.patch" \
|
| 20 |
+
"$SCRIPT_DIR/instruction.md"; then
|
| 21 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json
|
| 22 |
+
printf '%s' '{"final_reward": null, "reward": null, "evaluation_status": "ungraded", "eval_trustworthy": false, "verifier_status": "error"}' > /logs/verifier/reward-details.json
|
| 23 |
+
fi
|
| 24 |
+
: 'END_VERIFY_OUTPUT'
|
| 25 |
+
exit 0
|
tasks/AeneasVerif__aeneas-1391/tests/verifier.py
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""In-container verifier for pr_diff tasks (6-component reward).
|
| 2 |
+
|
| 3 |
+
This module is the **standalone verifier** that runs inside the task's
|
| 4 |
+
Docker container, NOT a helper used at generation time. Generation emits
|
| 5 |
+
its source as ``tests/verifier.py``. Harbor delivers it at verify time,
|
| 6 |
+
and ``tests/test.sh`` invokes it with the oracle, predicted patch and instruction.
|
| 7 |
+
|
| 8 |
+
Reward = weighted sum of 6 components (5 deterministic + 1 required LLM):
|
| 9 |
+
|
| 10 |
+
format_valid (0 or 1) — predicted parses as a unified diff (guard)
|
| 11 |
+
size_sanity ([0, 1]) — min(oracle_loc, pred_loc) / max(...)
|
| 12 |
+
catches "rampage through the codebase"
|
| 13 |
+
file_targeting ([0, 1]) — F1 over changed-file sets (NOT Jaccard —
|
| 14 |
+
symmetric penalty over-punishes extras)
|
| 15 |
+
region_overlap ([0, 1]) — predicted hunks overlap oracle hunks
|
| 16 |
+
(strongest spatial-localization signal)
|
| 17 |
+
similarity ([0, 1]) — SequenceMatcher ratio over +/- lines only
|
| 18 |
+
(no free credit for context lines)
|
| 19 |
+
llm_judge ([0, 1] or null) — an LLM rates "does this address the issue?"
|
| 20 |
+
Anthropic Haiku by default; any OpenAI-
|
| 21 |
+
compatible server via ``R2E_JUDGE_ENDPOINT``.
|
| 22 |
+
null when the judge is unavailable
|
| 23 |
+
(no key or model, network, unreadable
|
| 24 |
+
reply) → ungraded, no reward file; a
|
| 25 |
+
reply without a valid score (refusal,
|
| 26 |
+
content filter, empty, no "score") → a
|
| 27 |
+
graded 0
|
| 28 |
+
|
| 29 |
+
Default weights: 0.00 / 0.08 / 0.12 / 0.20 / 0.10 / 0.50 (retuned from
|
| 30 |
+
the original 0.05 / 0.05 / 0.10 / 0.20 / 0.20 / 0.40 after a 23-task
|
| 31 |
+
pilot — see the comment block above ``_DEFAULT_WEIGHTS`` below).
|
| 32 |
+
Override per-task via ``task.toml.metadata`` or per-run via env vars
|
| 33 |
+
``R2E_W_FORMAT`` / ``R2E_W_SIZE`` / ``R2E_W_FILE`` / ``R2E_W_REGION`` /
|
| 34 |
+
``R2E_W_SIM`` / ``R2E_W_JUDGE`` (pass via harbor ``--ve`` so they
|
| 35 |
+
reach the verifier container).
|
| 36 |
+
|
| 37 |
+
Judge routing, also via ``--ve``: ``R2E_JUDGE_MODEL`` picks the model
|
| 38 |
+
(default Haiku); ``R2E_JUDGE_ENDPOINT`` points at an OpenAI-compatible
|
| 39 |
+
server (vLLM, Ollama, a gateway) and switches the request to
|
| 40 |
+
``<endpoint>/chat/completions`` with a bearer token from
|
| 41 |
+
``R2E_JUDGE_API_KEY`` — or a placeholder when unset, since self-hosted
|
| 42 |
+
servers ignore it. ``ANTHROPIC_API_KEY`` is only read on the default
|
| 43 |
+
route and is never sent to a custom endpoint.
|
| 44 |
+
|
| 45 |
+
Final reward is clipped to [0, 1] and additionally clamped to ≤ 0.40
|
| 46 |
+
when ``size_sanity < 0.10`` (catastrophic-size hard cap — stops a
|
| 47 |
+
charitable judge from inflating scores on wildly wrong-sized patches).
|
| 48 |
+
|
| 49 |
+
Outputs (mirrors `_pr_runtime_verifier.py` after #75):
|
| 50 |
+
/logs/verifier/reward.txt — single float (Harbor reads this);
|
| 51 |
+
graded runs only
|
| 52 |
+
/logs/verifier/reward-details.json — full component breakdown + status
|
| 53 |
+
(structured diagnostics; Harbor's `reward.json` schema is flat-numeric-
|
| 54 |
+
only, so the breakdown goes to the `reward-details.json` sidecar which
|
| 55 |
+
Harbor renders under Verifier Logs → Rewards)
|
| 56 |
+
|
| 57 |
+
Pure stdlib — uses only ``difflib``, ``json``, ``os``, ``re``,
|
| 58 |
+
``urllib``, ``sys``. The same module is imported by the unit tests
|
| 59 |
+
under ``tests/test_pr_diff_verifier.py`` so the in-container behavior
|
| 60 |
+
stays in lockstep with what we test.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
from __future__ import annotations
|
| 64 |
+
|
| 65 |
+
import argparse
|
| 66 |
+
import difflib
|
| 67 |
+
import json
|
| 68 |
+
import math
|
| 69 |
+
import os
|
| 70 |
+
import re
|
| 71 |
+
import sys
|
| 72 |
+
import urllib.error
|
| 73 |
+
import urllib.request
|
| 74 |
+
|
| 75 |
+
# ---------------------------------------------------------------------------
|
| 76 |
+
# Parsing helpers (shared by multiple components)
|
| 77 |
+
# ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
_DIFF_HEADER_RE = re.compile(r"^diff --git a/(\S+) b/(\S+)$")
|
| 80 |
+
_HUNK_HEADER_RE = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
| 81 |
+
_FILE_MARKER_RE = re.compile(r"^(?:---|\+\+\+) ")
|
| 82 |
+
_INDEX_RE = re.compile(r"^index ")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def file_paths(diff: str) -> set[str]:
|
| 86 |
+
"""Return the set of ``b/<path>`` paths touched by a unified diff."""
|
| 87 |
+
paths: set[str] = set()
|
| 88 |
+
for line in diff.splitlines():
|
| 89 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 90 |
+
if m:
|
| 91 |
+
paths.add(m.group(2))
|
| 92 |
+
return paths
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def hunk_ranges(diff: str) -> dict[str, list[tuple[int, int]]]:
|
| 96 |
+
"""For each touched file, return list of (start_line, end_line) ranges
|
| 97 |
+
on the **post-change** side (the ``+`` numbers in ``@@ -X +Y @@``).
|
| 98 |
+
"""
|
| 99 |
+
out: dict[str, list[tuple[int, int]]] = {}
|
| 100 |
+
current_file: str | None = None
|
| 101 |
+
for line in diff.splitlines():
|
| 102 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 103 |
+
if m:
|
| 104 |
+
current_file = m.group(2)
|
| 105 |
+
out.setdefault(current_file, [])
|
| 106 |
+
continue
|
| 107 |
+
m = _HUNK_HEADER_RE.match(line)
|
| 108 |
+
if m and current_file is not None:
|
| 109 |
+
new_start = int(m.group(3))
|
| 110 |
+
new_count = int(m.group(4) or "1")
|
| 111 |
+
end = new_start + max(new_count - 1, 0)
|
| 112 |
+
out[current_file].append((new_start, end))
|
| 113 |
+
return out
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _normalize_changes_only(diff: str) -> list[str]:
|
| 117 |
+
"""Return the +/- lines (the actual changes) for similarity scoring.
|
| 118 |
+
|
| 119 |
+
Drops:
|
| 120 |
+
- ``diff --git`` / ``index abc..def`` metadata
|
| 121 |
+
- ``@@ ... @@`` hunk markers (volatile line numbers)
|
| 122 |
+
- context lines (no +/- prefix) — these are unchanged code, scoring
|
| 123 |
+
them inflates similarity for trivial patches
|
| 124 |
+
Keeps file-marker lines (``--- a/foo`` / ``+++ b/foo``) so file identity
|
| 125 |
+
stays in the comparison; normalizes off the tab+timestamp suffix git
|
| 126 |
+
sometimes appends.
|
| 127 |
+
"""
|
| 128 |
+
out: list[str] = []
|
| 129 |
+
for line in diff.splitlines():
|
| 130 |
+
if _DIFF_HEADER_RE.match(line) or _INDEX_RE.match(line):
|
| 131 |
+
continue
|
| 132 |
+
if _HUNK_HEADER_RE.match(line):
|
| 133 |
+
continue
|
| 134 |
+
if _FILE_MARKER_RE.match(line):
|
| 135 |
+
out.append(line.split("\t")[0].strip())
|
| 136 |
+
continue
|
| 137 |
+
# +/- lines (actual changes)
|
| 138 |
+
if line.startswith("+") or line.startswith("-"):
|
| 139 |
+
out.append(line)
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------------------------
|
| 144 |
+
# Reward components
|
| 145 |
+
# ---------------------------------------------------------------------------
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def format_valid(predicted: str) -> float:
|
| 149 |
+
"""1.0 if the predicted text looks like a unified diff; else 0.0.
|
| 150 |
+
|
| 151 |
+
Requires both a ``diff --git`` header and at least one real +/- line
|
| 152 |
+
(not the ``---`` / ``+++`` file-marker lines).
|
| 153 |
+
"""
|
| 154 |
+
if not predicted.strip():
|
| 155 |
+
return 0.0
|
| 156 |
+
has_header = False
|
| 157 |
+
has_change = False
|
| 158 |
+
for line in predicted.splitlines():
|
| 159 |
+
if _DIFF_HEADER_RE.match(line):
|
| 160 |
+
has_header = True
|
| 161 |
+
elif (line.startswith("+") or line.startswith("-")) and not line.startswith(
|
| 162 |
+
("+++ ", "--- ")
|
| 163 |
+
):
|
| 164 |
+
has_change = True
|
| 165 |
+
if has_header and has_change:
|
| 166 |
+
return 1.0
|
| 167 |
+
return 0.0
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def file_targeting(oracle: str, predicted: str) -> float:
|
| 171 |
+
"""F1 over the changed-file sets.
|
| 172 |
+
|
| 173 |
+
Why F1 instead of Jaccard:
|
| 174 |
+
- Missing an oracle file (FN) is a *big* failure.
|
| 175 |
+
- Touching one unrelated extra file (FP) is a small one.
|
| 176 |
+
- Jaccard punishes both equally, which over-penalizes the agent
|
| 177 |
+
for any extra exploration.
|
| 178 |
+
- F1 weights TP twice, giving partial credit when the agent finds
|
| 179 |
+
most-but-not-all of the oracle files even with some noise.
|
| 180 |
+
|
| 181 |
+
Returns 1.0 if both sides touch zero files (degenerate).
|
| 182 |
+
"""
|
| 183 |
+
o = file_paths(oracle)
|
| 184 |
+
p = file_paths(predicted)
|
| 185 |
+
if not o and not p:
|
| 186 |
+
return 1.0
|
| 187 |
+
tp = len(o & p)
|
| 188 |
+
fn = len(o - p)
|
| 189 |
+
fp = len(p - o)
|
| 190 |
+
if tp == 0:
|
| 191 |
+
return 0.0
|
| 192 |
+
# F1 = 2·TP / (2·TP + FN + FP)
|
| 193 |
+
return (2 * tp) / (2 * tp + fn + fp)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _count_loc_changes(diff: str) -> int:
|
| 197 |
+
"""Number of real +/- lines (excluding file-marker lines)."""
|
| 198 |
+
n = 0
|
| 199 |
+
for line in diff.splitlines():
|
| 200 |
+
if (line.startswith("+") or line.startswith("-")) and not line.startswith(("+++ ", "--- ")):
|
| 201 |
+
n += 1
|
| 202 |
+
return n
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def size_sanity(oracle: str, predicted: str) -> float:
|
| 206 |
+
"""Penalize predicted patches that are wildly larger / smaller than the oracle.
|
| 207 |
+
|
| 208 |
+
Returns ``min(oracle_loc, predicted_loc) / max(oracle_loc, predicted_loc)``.
|
| 209 |
+
Both empty → 1.0 (degenerate but well-defined). One empty → 0.0.
|
| 210 |
+
|
| 211 |
+
This is the "don't rampage through the codebase" guard — a 200-line
|
| 212 |
+
diff for a 3-line oracle scores ~0.015 here even if every other
|
| 213 |
+
component looks OK.
|
| 214 |
+
"""
|
| 215 |
+
o_loc = _count_loc_changes(oracle)
|
| 216 |
+
p_loc = _count_loc_changes(predicted)
|
| 217 |
+
if o_loc == 0 and p_loc == 0:
|
| 218 |
+
return 1.0
|
| 219 |
+
if o_loc == 0 or p_loc == 0:
|
| 220 |
+
return 0.0
|
| 221 |
+
return min(o_loc, p_loc) / max(o_loc, p_loc)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def region_overlap(oracle: str, predicted: str, *, slack_lines: int = 5) -> float:
|
| 225 |
+
"""For each oracle hunk, did the predicted diff edit a line within
|
| 226 |
+
``slack_lines`` of that hunk in the same file?
|
| 227 |
+
|
| 228 |
+
Returns the fraction of oracle hunks that have at least one matching
|
| 229 |
+
predicted hunk. ``slack_lines`` tolerates slight line-number drift
|
| 230 |
+
when git diff renders the predicted hunk at a different offset.
|
| 231 |
+
"""
|
| 232 |
+
o_ranges = hunk_ranges(oracle)
|
| 233 |
+
p_ranges = hunk_ranges(predicted)
|
| 234 |
+
total = sum(len(v) for v in o_ranges.values())
|
| 235 |
+
if total == 0:
|
| 236 |
+
return 1.0 # oracle has no hunks (degenerate)
|
| 237 |
+
matched = 0
|
| 238 |
+
for fname, ranges in o_ranges.items():
|
| 239 |
+
p_in_file = p_ranges.get(fname, [])
|
| 240 |
+
for o_start, o_end in ranges:
|
| 241 |
+
for p_start, p_end in p_in_file:
|
| 242 |
+
# Interval overlap with slack — max(starts) <= min(ends) + slack
|
| 243 |
+
if max(o_start, p_start) <= min(o_end, p_end) + slack_lines:
|
| 244 |
+
matched += 1
|
| 245 |
+
break
|
| 246 |
+
return matched / total
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def similarity(oracle: str, predicted: str) -> float:
|
| 250 |
+
"""SequenceMatcher ratio over +/- lines only.
|
| 251 |
+
|
| 252 |
+
No free credit for context lines — fixes the v0.8.1 inflation where a
|
| 253 |
+
one-line fix scored ~0.7 just because the 3 context lines on either
|
| 254 |
+
side were "matched".
|
| 255 |
+
"""
|
| 256 |
+
if not predicted.strip():
|
| 257 |
+
return 0.0
|
| 258 |
+
o = _normalize_changes_only(oracle)
|
| 259 |
+
p = _normalize_changes_only(predicted)
|
| 260 |
+
if not o:
|
| 261 |
+
return 0.0
|
| 262 |
+
# Exact matching is quadratic-or-worse on repeated lines: 200 x 2,000
|
| 263 |
+
# identical changed lines take ~2 s, 500 x 5,000 take ~35 s, which can
|
| 264 |
+
# run the verifier past Harbor's timeout. Above this many line pairs,
|
| 265 |
+
# fall back to difflib's popular-element heuristic, which stays fast.
|
| 266 |
+
exact = len(o) * len(p) <= _SIMILARITY_EXACT_PAIRS
|
| 267 |
+
return difflib.SequenceMatcher(a=o, b=p, autojunk=not exact).ratio()
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
_SIMILARITY_EXACT_PAIRS = 400_000
|
| 271 |
+
|
| 272 |
+
# A predicted patch over 10x the oracle's changed lines is already a
|
| 273 |
+
# catastrophic size mismatch (size_sanity < 0.10). Past this floor such a
|
| 274 |
+
# patch is a graded 0 instead of being scored, so one huge file can't slow
|
| 275 |
+
# the verifier past its timeout and turn a failing episode into a dropped,
|
| 276 |
+
# ungraded one. The byte cap stops it from being read at all.
|
| 277 |
+
_MAX_PREDICTED_FACTOR = 10
|
| 278 |
+
_MAX_PREDICTED_FLOOR_LOC = 1_000
|
| 279 |
+
_MAX_PREDICTED_BYTES = 16 * 1024 * 1024
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def predicted_too_large(oracle: str, predicted: str) -> bool:
|
| 283 |
+
"""Whether the predicted patch is too large to score (a graded 0)."""
|
| 284 |
+
limit = max(_MAX_PREDICTED_FACTOR * _count_loc_changes(oracle), _MAX_PREDICTED_FLOOR_LOC)
|
| 285 |
+
return _count_loc_changes(predicted) > limit
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# ---------------------------------------------------------------------------
|
| 289 |
+
# LLM-as-judge (Anthropic Messages API, stdlib urllib)
|
| 290 |
+
# ---------------------------------------------------------------------------
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
_JUDGE_PROMPT = (
|
| 294 |
+
"You are scoring a code-fix patch on whether it logically addresses the "
|
| 295 |
+
"described issue. Output a single JSON object: "
|
| 296 |
+
'{{"score": <float in [0,1]>, "reasoning": "<<=30 words"}}.\n\n'
|
| 297 |
+
"DO NOT use the oracle to grade. Score on:\n"
|
| 298 |
+
" - Does the predicted diff touch code regions that could plausibly fix the issue?\n"
|
| 299 |
+
" - Is the change direction consistent with what the issue describes?\n"
|
| 300 |
+
" - Is it a real attempt (not boilerplate, not no-op)?\n\n"
|
| 301 |
+
"Issue:\n{instruction}\n\n"
|
| 302 |
+
"Oracle (reference fix for comparison only — don't grade on similarity to it):\n"
|
| 303 |
+
"{oracle}\n\n"
|
| 304 |
+
"Predicted:\n{predicted}\n\n"
|
| 305 |
+
"Return ONLY the JSON object."
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
_DEFAULT_JUDGE_MODEL = "claude-haiku-4-5-20251001"
|
| 310 |
+
_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages"
|
| 311 |
+
# Bearer token for a self-hosted judge when R2E_JUDGE_API_KEY is unset. vLLM /
|
| 312 |
+
# Ollama ignore it; the OpenAI wire format still wants one. Same value llm.py uses.
|
| 313 |
+
_PLACEHOLDER_API_KEY = "EMPTY"
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def llm_judge(
|
| 317 |
+
*,
|
| 318 |
+
instruction: str,
|
| 319 |
+
oracle: str,
|
| 320 |
+
predicted: str,
|
| 321 |
+
api_key: str,
|
| 322 |
+
model: str = _DEFAULT_JUDGE_MODEL,
|
| 323 |
+
timeout: int = 60,
|
| 324 |
+
endpoint: str | None = None,
|
| 325 |
+
) -> tuple[float | None, str]:
|
| 326 |
+
"""Return ``(score, status)``.
|
| 327 |
+
|
| 328 |
+
``score`` is a float in [0, 1] on success, ``None`` on failure.
|
| 329 |
+
``status`` is a short string: ``"ok"`` / ``"no_api_key"`` /
|
| 330 |
+
``"no_judge_model"`` / ``"empty_predicted"`` / ``"network"`` /
|
| 331 |
+
``"parse"`` / ``"output_limit"`` / ``"missing_score"`` / ``"invalid_score"``.
|
| 332 |
+
``output_limit`` means the judge exhausted its configured token budget
|
| 333 |
+
(ungraded, even if a partial answer contains a score). ``parse`` means
|
| 334 |
+
the provider's body isn't JSON or has the wrong shape (ungraded); a reply
|
| 335 |
+
with no usable text (refusal, content filter, empty) or no valid score is
|
| 336 |
+
``missing_score`` / ``invalid_score`` (a graded 0). A missing score never
|
| 337 |
+
increases the other weights.
|
| 338 |
+
|
| 339 |
+
``endpoint`` — base URL of an OpenAI-compatible server. When set, the
|
| 340 |
+
request goes to ``<endpoint>/chat/completions`` with ``api_key`` as a
|
| 341 |
+
bearer token, at temperature 0, and ``model`` must be given explicitly;
|
| 342 |
+
otherwise it goes to Anthropic's Messages API unchanged.
|
| 343 |
+
"""
|
| 344 |
+
if not api_key:
|
| 345 |
+
return None, "no_api_key"
|
| 346 |
+
if endpoint and not model:
|
| 347 |
+
return None, "no_judge_model"
|
| 348 |
+
if not predicted.strip():
|
| 349 |
+
return 0.0, "empty_predicted"
|
| 350 |
+
|
| 351 |
+
# Truncate hard so we don't blow up the prompt for big diffs
|
| 352 |
+
prompt = _JUDGE_PROMPT.format(
|
| 353 |
+
instruction=instruction[:4000],
|
| 354 |
+
oracle=oracle[:4000],
|
| 355 |
+
predicted=predicted[:4000],
|
| 356 |
+
)
|
| 357 |
+
payload: dict = {
|
| 358 |
+
"model": model,
|
| 359 |
+
"max_tokens": 200,
|
| 360 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 361 |
+
}
|
| 362 |
+
if endpoint:
|
| 363 |
+
# Small self-hosted models are noisy judges at their default sampling
|
| 364 |
+
# temperature (same input scoring 0.0 one call and 1.0 the next); pin
|
| 365 |
+
# them to greedy. The Anthropic route keeps its defaults — the weights
|
| 366 |
+
# were calibrated against them.
|
| 367 |
+
payload["temperature"] = 0
|
| 368 |
+
url = endpoint.rstrip("/") + "/chat/completions"
|
| 369 |
+
headers = {
|
| 370 |
+
"authorization": f"Bearer {api_key}",
|
| 371 |
+
"content-type": "application/json",
|
| 372 |
+
}
|
| 373 |
+
else:
|
| 374 |
+
url = _ANTHROPIC_MESSAGES_URL
|
| 375 |
+
headers = {
|
| 376 |
+
"x-api-key": api_key,
|
| 377 |
+
"anthropic-version": "2023-06-01",
|
| 378 |
+
"content-type": "application/json",
|
| 379 |
+
}
|
| 380 |
+
body = json.dumps(payload).encode("utf-8")
|
| 381 |
+
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
|
| 382 |
+
try:
|
| 383 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 384 |
+
raw = resp.read().decode("utf-8")
|
| 385 |
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError):
|
| 386 |
+
return None, "network"
|
| 387 |
+
|
| 388 |
+
try:
|
| 389 |
+
response = json.loads(raw)
|
| 390 |
+
except json.JSONDecodeError:
|
| 391 |
+
return None, "parse"
|
| 392 |
+
# Provider-reported truncation is a grader capacity failure, not evidence
|
| 393 |
+
# that the submitted patch is wrong. Reasoning models can spend the entire
|
| 394 |
+
# output budget before producing visible text. Never grade a partial score.
|
| 395 |
+
if isinstance(response, dict):
|
| 396 |
+
choices = response.get("choices")
|
| 397 |
+
if endpoint:
|
| 398 |
+
if (
|
| 399 |
+
isinstance(choices, list)
|
| 400 |
+
and choices
|
| 401 |
+
and isinstance(choices[0], dict)
|
| 402 |
+
and choices[0].get("finish_reason") == "length"
|
| 403 |
+
):
|
| 404 |
+
return None, "output_limit"
|
| 405 |
+
elif response.get("stop_reason") in {"max_tokens", "model_context_window_exceeded"}:
|
| 406 |
+
return None, "output_limit"
|
| 407 |
+
text = _judge_text(response, openai_compatible=bool(endpoint))
|
| 408 |
+
if text is None:
|
| 409 |
+
return None, "parse"
|
| 410 |
+
|
| 411 |
+
# Pull the first JSON object out of the model's response
|
| 412 |
+
m = re.search(r"\{[^{}]*\"score\"[^{}]*\}", text, re.DOTALL)
|
| 413 |
+
if not m:
|
| 414 |
+
return None, "missing_score"
|
| 415 |
+
try:
|
| 416 |
+
obj = json.loads(m.group(0))
|
| 417 |
+
score = obj.get("score")
|
| 418 |
+
except (json.JSONDecodeError, ValueError, TypeError):
|
| 419 |
+
return None, "missing_score"
|
| 420 |
+
if type(score) not in (int, float) or not 0 <= score <= 1 or not math.isfinite(score):
|
| 421 |
+
return None, "invalid_score"
|
| 422 |
+
return float(score), "ok"
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _judge_text(payload: object, *, openai_compatible: bool) -> str | None:
|
| 426 |
+
"""The judge's answer text, ``""`` when it gave none, ``None`` for a wrong shape.
|
| 427 |
+
|
| 428 |
+
A refusal or a content filter is a well-formed reply with no usable text.
|
| 429 |
+
The agent's patch is in the prompt, so it can provoke one: that is ``""``,
|
| 430 |
+
which grades 0, not ``None``, which leaves the run ungraded.
|
| 431 |
+
|
| 432 |
+
Anthropic: a refusal is HTTP 200 with ``stop_reason: "refusal"`` and
|
| 433 |
+
``content`` empty or holding partial text to discard. OpenAI-compatible:
|
| 434 |
+
``message.content`` is null with a ``refusal`` string or
|
| 435 |
+
``finish_reason: "content_filter"``.
|
| 436 |
+
"""
|
| 437 |
+
if not isinstance(payload, dict):
|
| 438 |
+
return None
|
| 439 |
+
if openai_compatible:
|
| 440 |
+
choices = payload.get("choices")
|
| 441 |
+
if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
|
| 442 |
+
return None
|
| 443 |
+
message = choices[0].get("message")
|
| 444 |
+
if not isinstance(message, dict):
|
| 445 |
+
return None
|
| 446 |
+
if message.get("refusal") or choices[0].get("finish_reason") == "content_filter":
|
| 447 |
+
return ""
|
| 448 |
+
content = message.get("content")
|
| 449 |
+
if content is None:
|
| 450 |
+
return ""
|
| 451 |
+
if isinstance(content, str):
|
| 452 |
+
return content
|
| 453 |
+
if isinstance(content, list): # content parts
|
| 454 |
+
return "".join(
|
| 455 |
+
part.get("text", "")
|
| 456 |
+
for part in content
|
| 457 |
+
if isinstance(part, dict) and isinstance(part.get("text", ""), str)
|
| 458 |
+
)
|
| 459 |
+
return None
|
| 460 |
+
content = payload.get("content")
|
| 461 |
+
if not isinstance(content, list):
|
| 462 |
+
return None
|
| 463 |
+
if payload.get("stop_reason") == "refusal":
|
| 464 |
+
return ""
|
| 465 |
+
return "".join(
|
| 466 |
+
block["text"]
|
| 467 |
+
for block in content
|
| 468 |
+
if isinstance(block, dict)
|
| 469 |
+
and block.get("type", "text") == "text"
|
| 470 |
+
and isinstance(block.get("text"), str)
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# ---------------------------------------------------------------------------
|
| 475 |
+
# Combination
|
| 476 |
+
# ---------------------------------------------------------------------------
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
# Judge replies the agent can provoke: its patch text is part of the judge
|
| 480 |
+
# prompt, so it can steer the answer away from a valid score. These are a
|
| 481 |
+
# graded 0. An unreadable provider envelope (`parse`), missing configuration,
|
| 482 |
+
# a disabled judge, transport errors and an exhausted judge output budget leave
|
| 483 |
+
# the evaluation ungraded. Truncation alone cannot establish an incorrect patch.
|
| 484 |
+
_JUDGE_GRADED_ZERO = frozenset({"missing_score", "invalid_score"})
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def evaluation_status(judge_score: float | None, judge_status: str) -> str:
|
| 488 |
+
"""`graded` when the judge scored or the agent can have caused its failure."""
|
| 489 |
+
if judge_score is not None or judge_status in _JUDGE_GRADED_ZERO:
|
| 490 |
+
return "graded"
|
| 491 |
+
return "ungraded"
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def combine(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 495 |
+
"""Combine declared components, requiring a positively weighted judge.
|
| 496 |
+
|
| 497 |
+
Without a judge score the result is 0. ``main`` records it as a graded 0
|
| 498 |
+
when the agent can have caused the judge failure, and otherwise writes no
|
| 499 |
+
reward file, so Harbor reports the trial as VERIFIER_FAILED.
|
| 500 |
+
"""
|
| 501 |
+
if weights.get("llm_judge", 0) <= 0 or components.get("llm_judge") is None:
|
| 502 |
+
return 0.0
|
| 503 |
+
if any(w > 0 and components.get(k) is None for k, w in weights.items()):
|
| 504 |
+
return 0.0
|
| 505 |
+
return _weighted_mean(components, weights)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def _weighted_mean(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 509 |
+
available = [(k, w) for k, w in weights.items() if w > 0 and components.get(k) is not None]
|
| 510 |
+
if not available:
|
| 511 |
+
return 0.0
|
| 512 |
+
# Relative weights need not sum to one. Scale first so large finite
|
| 513 |
+
# overrides cannot overflow the numerator or denominator into NaN.
|
| 514 |
+
scale = max(w for _, w in available)
|
| 515 |
+
normalized = [(k, w / scale) for k, w in available]
|
| 516 |
+
return sum(w * components[k] for k, w in normalized) / sum(w for _, w in normalized)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
# ---------------------------------------------------------------------------
|
| 520 |
+
# Entry point (invoked by tests/test.sh inside the container)
|
| 521 |
+
# ---------------------------------------------------------------------------
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
# Weights retuned after a 23-task pilot. Rationale (LLM-as-reward-engineer
|
| 525 |
+
# analysis grounded in per-task component data):
|
| 526 |
+
#
|
| 527 |
+
# - format_valid → 0.00: was 1.0 across ALL 21 evaluated tasks. Zero
|
| 528 |
+
# discriminative signal — its 0.05 weight was pure dead weight.
|
| 529 |
+
# - similarity → 0.10: Pearson ~0.85 correlation with region_overlap.
|
| 530 |
+
# Carrying both at 0.20 double-counts positional accuracy and
|
| 531 |
+
# additionally penalizes legitimate alternative implementations.
|
| 532 |
+
# - llm_judge → 0.50: only component capturing semantic correctness
|
| 533 |
+
# independent of textual form; diverges informatively from
|
| 534 |
+
# similarity on cases like tokenizers (judge=0.72, sim=0.08).
|
| 535 |
+
# - region_overlap stays 0.20: strongest spatial-localization signal.
|
| 536 |
+
# - file_targeting → 0.12: leading indicator, less correlated with the
|
| 537 |
+
# rest than region/similarity are with each other.
|
| 538 |
+
# - size_sanity → 0.08: useful outlier detector for catastrophic
|
| 539 |
+
# over/under-generation (prettier=0.01, serde=0.08).
|
| 540 |
+
#
|
| 541 |
+
# Total: 0.00 + 0.08 + 0.12 + 0.20 + 0.10 + 0.50 = 1.00.
|
| 542 |
+
_DEFAULT_WEIGHTS = {
|
| 543 |
+
"format_valid": 0.00,
|
| 544 |
+
"size_sanity": 0.08,
|
| 545 |
+
"file_targeting": 0.12,
|
| 546 |
+
"region_overlap": 0.20,
|
| 547 |
+
"similarity": 0.10,
|
| 548 |
+
"llm_judge": 0.50,
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
# Hard cap: when size_sanity < this threshold, clamp final reward to
|
| 552 |
+
# ≤ CATASTROPHIC_SIZE_CAP. Prevents a charitable judge from inflating
|
| 553 |
+
# the score on patches that are wildly the wrong size (catastrophic
|
| 554 |
+
# over- or under-generation).
|
| 555 |
+
_CATASTROPHIC_SIZE_THRESHOLD = 0.10
|
| 556 |
+
_CATASTROPHIC_SIZE_CAP = 0.40
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _read_weights_from_env() -> dict[str, float]:
|
| 560 |
+
"""Override defaults via R2E_W_* env vars (set in container by harbor)."""
|
| 561 |
+
overrides = {
|
| 562 |
+
"format_valid": os.environ.get("R2E_W_FORMAT"),
|
| 563 |
+
"size_sanity": os.environ.get("R2E_W_SIZE"),
|
| 564 |
+
"file_targeting": os.environ.get("R2E_W_FILE"),
|
| 565 |
+
"region_overlap": os.environ.get("R2E_W_REGION"),
|
| 566 |
+
"similarity": os.environ.get("R2E_W_SIM"),
|
| 567 |
+
"llm_judge": os.environ.get("R2E_W_JUDGE"),
|
| 568 |
+
}
|
| 569 |
+
out = dict(_DEFAULT_WEIGHTS)
|
| 570 |
+
for k, v in overrides.items():
|
| 571 |
+
if v is None:
|
| 572 |
+
continue
|
| 573 |
+
try:
|
| 574 |
+
value = float(v)
|
| 575 |
+
if math.isfinite(value) and value >= 0:
|
| 576 |
+
out[k] = value
|
| 577 |
+
except (TypeError, ValueError):
|
| 578 |
+
continue
|
| 579 |
+
return out
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def _judge_config_from_env() -> tuple[str, str, str | None]:
|
| 583 |
+
"""``(api_key, model, endpoint)`` for the judge, from the verifier env.
|
| 584 |
+
|
| 585 |
+
With ``R2E_JUDGE_ENDPOINT`` set, the key comes from ``R2E_JUDGE_API_KEY``
|
| 586 |
+
(placeholder when unset) and ``ANTHROPIC_API_KEY`` is never forwarded to
|
| 587 |
+
the custom server. ``R2E_JUDGE_MODEL`` has no default on that route (a
|
| 588 |
+
self-hosted server won't have Haiku): when unset, ``model`` comes back
|
| 589 |
+
as ``""`` and ``llm_judge`` reports ``no_judge_model`` instead of
|
| 590 |
+
calling out. Without an endpoint the default Anthropic route is
|
| 591 |
+
unchanged.
|
| 592 |
+
"""
|
| 593 |
+
endpoint = os.environ.get("R2E_JUDGE_ENDPOINT", "").strip() or None
|
| 594 |
+
model = os.environ.get("R2E_JUDGE_MODEL", "").strip()
|
| 595 |
+
if endpoint:
|
| 596 |
+
api_key = os.environ.get("R2E_JUDGE_API_KEY", "").strip() or _PLACEHOLDER_API_KEY
|
| 597 |
+
return api_key, model, endpoint
|
| 598 |
+
return os.environ.get("ANTHROPIC_API_KEY", "").strip(), model or _DEFAULT_JUDGE_MODEL, None
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def main(argv: list[str] | None = None) -> int:
|
| 602 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 603 |
+
parser.add_argument("oracle")
|
| 604 |
+
parser.add_argument("predicted")
|
| 605 |
+
parser.add_argument("instruction")
|
| 606 |
+
parser.add_argument("--out-dir", default="/logs/verifier")
|
| 607 |
+
args = parser.parse_args(argv)
|
| 608 |
+
os.makedirs(args.out_dir, exist_ok=True)
|
| 609 |
+
# This run is the only authority on the reward: an earlier or planted
|
| 610 |
+
# reward file must not stand if this evaluation ends up ungraded.
|
| 611 |
+
for name in ("reward.txt", "reward.json"):
|
| 612 |
+
try:
|
| 613 |
+
os.unlink(os.path.join(args.out_dir, name))
|
| 614 |
+
except FileNotFoundError:
|
| 615 |
+
pass
|
| 616 |
+
oracle = _read_or_empty(args.oracle)
|
| 617 |
+
try:
|
| 618 |
+
oversized = os.path.getsize(args.predicted) > _MAX_PREDICTED_BYTES
|
| 619 |
+
except OSError:
|
| 620 |
+
oversized = False
|
| 621 |
+
predicted = "" if oversized else _read_or_empty(args.predicted)
|
| 622 |
+
if oversized or predicted_too_large(oracle, predicted):
|
| 623 |
+
breakdown = {
|
| 624 |
+
"final_reward": 0.0,
|
| 625 |
+
"evaluation_status": "graded",
|
| 626 |
+
"eval_trustworthy": False,
|
| 627 |
+
"predicted_status": "predicted_too_large",
|
| 628 |
+
}
|
| 629 |
+
_write_outputs(args.out_dir, 0.0, breakdown)
|
| 630 |
+
return 0
|
| 631 |
+
instruction = _read_or_empty(args.instruction)
|
| 632 |
+
api_key, judge_model, judge_endpoint = _judge_config_from_env()
|
| 633 |
+
|
| 634 |
+
fv = format_valid(predicted)
|
| 635 |
+
ss = size_sanity(oracle, predicted)
|
| 636 |
+
ft = file_targeting(oracle, predicted)
|
| 637 |
+
ro = region_overlap(oracle, predicted)
|
| 638 |
+
sim = similarity(oracle, predicted)
|
| 639 |
+
weights = _read_weights_from_env()
|
| 640 |
+
if weights["llm_judge"] <= 0:
|
| 641 |
+
judge_score, judge_status = None, "disabled"
|
| 642 |
+
else:
|
| 643 |
+
judge_score, judge_status = llm_judge(
|
| 644 |
+
instruction=instruction,
|
| 645 |
+
oracle=oracle,
|
| 646 |
+
predicted=predicted,
|
| 647 |
+
api_key=api_key,
|
| 648 |
+
model=judge_model,
|
| 649 |
+
endpoint=judge_endpoint,
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
components: dict[str, float | None] = {
|
| 653 |
+
"format_valid": fv,
|
| 654 |
+
"size_sanity": ss,
|
| 655 |
+
"file_targeting": ft,
|
| 656 |
+
"region_overlap": ro,
|
| 657 |
+
"similarity": sim,
|
| 658 |
+
"llm_judge": judge_score,
|
| 659 |
+
}
|
| 660 |
+
final = combine(components, weights)
|
| 661 |
+
final = max(0.0, min(1.0, final))
|
| 662 |
+
|
| 663 |
+
# Hard cap on catastrophic size mismatches. Without this, a charitable
|
| 664 |
+
# judge can inflate the reward on patches that are dramatically the
|
| 665 |
+
# wrong size (prettier scored 0.23 with size_sanity=0.011 — the judge
|
| 666 |
+
# was lenient at 0.25 despite the patch being a near-no-op vs a
|
| 667 |
+
# 500-line oracle). The cap kicks in only at the extremes.
|
| 668 |
+
if ss < _CATASTROPHIC_SIZE_THRESHOLD:
|
| 669 |
+
final = min(final, _CATASTROPHIC_SIZE_CAP)
|
| 670 |
+
|
| 671 |
+
status = evaluation_status(judge_score, judge_status)
|
| 672 |
+
breakdown = {
|
| 673 |
+
# No reward exists for an ungraded evaluation: null, not a placeholder 0.
|
| 674 |
+
"final_reward": round(final, 6) if status == "graded" else None,
|
| 675 |
+
"evaluation_status": status,
|
| 676 |
+
"eval_trustworthy": judge_score is not None,
|
| 677 |
+
"diagnostic_similarity": round(
|
| 678 |
+
_weighted_mean(components, {k: w for k, w in weights.items() if k != "llm_judge"}),
|
| 679 |
+
6,
|
| 680 |
+
),
|
| 681 |
+
"components": {k: (None if v is None else round(v, 6)) for k, v in components.items()},
|
| 682 |
+
"weights": {k: round(v, 6) for k, v in weights.items()},
|
| 683 |
+
"judge_model": judge_model if judge_status == "ok" else None,
|
| 684 |
+
"judge_endpoint": judge_endpoint,
|
| 685 |
+
"judge_status": judge_status,
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
_write_outputs(args.out_dir, final, breakdown)
|
| 689 |
+
return 0
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def _write_outputs(out_dir: str, final: float, breakdown: dict) -> None:
|
| 693 |
+
# An ungraded evaluation writes no reward file. Harbor then raises
|
| 694 |
+
# RewardFileNotFoundError: the trial is VERIFIER_FAILED, reward_valid is
|
| 695 |
+
# false, and RL consumers (OpenEnv harbor_env -> TRL) drop the rollout
|
| 696 |
+
# instead of training on a 0. Harbor's job mean and pass@k still count the
|
| 697 |
+
# trial as 0, so evaluation stays fail-closed.
|
| 698 |
+
if breakdown["evaluation_status"] == "graded":
|
| 699 |
+
with open(os.path.join(out_dir, "reward.txt"), "w", encoding="utf-8") as f:
|
| 700 |
+
f.write(f"{final:.6f}\n")
|
| 701 |
+
# Harbor's `reward.json` must be a flat map of floats/ints (spec, see
|
| 702 |
+
# <https://harborframework.com/docs/tasks>); our breakdown carries nested
|
| 703 |
+
# dicts, judge strings, and status strings, so it goes to the sidecar the
|
| 704 |
+
# Harbor UI renders under Verifier Logs → Rewards. Mirrors #75 (Neubig)
|
| 705 |
+
# for `_pr_runtime_verifier.py`.
|
| 706 |
+
with open(os.path.join(out_dir, "reward-details.json"), "w", encoding="utf-8") as f:
|
| 707 |
+
json.dump(breakdown, f, indent=2)
|
| 708 |
+
|
| 709 |
+
# Also print to stdout so harbor's log captures the breakdown
|
| 710 |
+
print(json.dumps(breakdown, indent=2))
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def _read_or_empty(path: str) -> str:
|
| 714 |
+
try:
|
| 715 |
+
with open(path, encoding="utf-8") as f:
|
| 716 |
+
return f.read()
|
| 717 |
+
except (OSError, UnicodeDecodeError):
|
| 718 |
+
return ""
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
if __name__ == "__main__":
|
| 722 |
+
sys.exit(main())
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
__all__ = [
|
| 726 |
+
"combine",
|
| 727 |
+
"file_paths",
|
| 728 |
+
"file_targeting",
|
| 729 |
+
"format_valid",
|
| 730 |
+
"hunk_ranges",
|
| 731 |
+
"llm_judge",
|
| 732 |
+
"main",
|
| 733 |
+
"predicted_too_large",
|
| 734 |
+
"region_overlap",
|
| 735 |
+
"similarity",
|
| 736 |
+
"size_sanity",
|
| 737 |
+
]
|
tasks/AeneasVerif__aeneas-1400/environment/Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto-generated by Repo2RLEnv pr_diff — 6-component reward env.
|
| 2 |
+
# Agent-agnostic: the agent (claude-code / openhands / codex / etc.)
|
| 3 |
+
# installs itself at run time via its harbor adapter. We only ship
|
| 4 |
+
# the source repo — the oracle + verifier arrive at verify time via
|
| 5 |
+
# tests/, never baked into the agent's image.
|
| 6 |
+
FROM python:3.12-slim
|
| 7 |
+
ARG GITHUB_TOKEN=
|
| 8 |
+
RUN apt-get update \
|
| 9 |
+
&& apt-get install -y --no-install-recommends git ca-certificates curl \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
RUN git config --global --add safe.directory /workspace \
|
| 12 |
+
&& git config --global init.defaultBranch main \
|
| 13 |
+
&& git config --global advice.detachedHead false
|
| 14 |
+
RUN if [ -n "$GITHUB_TOKEN" ]; then \
|
| 15 |
+
git clone --filter=blob:none https://x-access-token:"${GITHUB_TOKEN}"@github.com/AeneasVerif/aeneas.git /workspace; \
|
| 16 |
+
else \
|
| 17 |
+
git clone --filter=blob:none https://github.com/AeneasVerif/aeneas.git /workspace; \
|
| 18 |
+
fi \
|
| 19 |
+
&& git -C /workspace remote set-url origin https://github.com/AeneasVerif/aeneas.git
|
| 20 |
+
WORKDIR /workspace
|
| 21 |
+
RUN git fetch --depth 1 origin 557eff83ecef5083b98a52a94ca7fae63d6c1dab 2>/dev/null \
|
| 22 |
+
|| git fetch --unshallow origin 2>/dev/null || true
|
| 23 |
+
RUN git reset --hard 557eff83ecef5083b98a52a94ca7fae63d6c1dab \
|
| 24 |
+
&& git clean -fdx -e .venv -e venv -e __pycache__
|
| 25 |
+
RUN git checkout -q -B base 557eff83ecef5083b98a52a94ca7fae63d6c1dab \
|
| 26 |
+
&& git remote remove origin 2>/dev/null || true
|
| 27 |
+
RUN for ref in $(git branch --format='%(refname:short)' | grep -vx base); do git branch -D "$ref" 2>/dev/null || true; done \
|
| 28 |
+
&& git tag -l | xargs -r git tag -d >/dev/null 2>&1 || true \
|
| 29 |
+
&& git for-each-ref --format='%(refname)' refs/remotes 2>/dev/null | xargs -r -n1 git update-ref -d 2>/dev/null || true \
|
| 30 |
+
&& git reflog expire --expire=now --all 2>/dev/null || true \
|
| 31 |
+
&& git gc --prune=now 2>/dev/null || true
|
| 32 |
+
RUN P="$(git rev-parse --git-dir)/objects/pack"; if ls "$P"/*.promisor >/dev/null 2>&1; then \
|
| 33 |
+
git rev-list --objects --all --missing=allow-promisor > "$P/../scrub.list" \
|
| 34 |
+
&& K=$(git pack-objects -q --missing=allow-promisor "$P/scrub" < "$P/../scrub.list") \
|
| 35 |
+
&& rm -f "$P/../scrub.list" "$P"/pack-* "$P"/multi-pack-index* \
|
| 36 |
+
&& touch "$P/scrub-$K.promisor" && git prune --expire=now; \
|
| 37 |
+
fi
|
tasks/AeneasVerif__aeneas-1400/instruction.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Add Repr instance for Result
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
`Result` is now a `@[irreducible]` alias for ITree, so it no longer inherits a Repr instance (the old inductive definition had a "deriving Repr"). Add one manually, mirroring the old deriving Repr output, so that `#eval` on `Result` prints `Aeneas.Std.Result.ok` again.
|
| 8 |
+
|
| 9 |
+
## Task
|
| 10 |
+
|
| 11 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `557eff83ecef`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1400/solution/patch.diff
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/backends/lean/Aeneas/Std/Primitives.lean b/backends/lean/Aeneas/Std/Primitives.lean
|
| 2 |
+
index b5cb07e5f1..be9c30b698 100644
|
| 3 |
+
--- a/backends/lean/Aeneas/Std/Primitives.lean
|
| 4 |
+
+++ b/backends/lean/Aeneas/Std/Primitives.lean
|
| 5 |
+
@@ -147,6 +147,14 @@ theorem Result.match.fail {α : Type u} {e} :
|
| 6 |
+
(Result.fail e : Result α).match = .vis (.fail e) PEmpty.elim := by
|
| 7 |
+
simp [Result.fail_eq_vis]
|
| 8 |
+
|
| 9 |
+
+/-- The `Repr` instance for `Result`, so that `#eval` on `Result`-producing expressions prints `Aeneas.Std.Result.ok`/`fail`/`div`. -/
|
| 10 |
+
+instance Result.reprInst {α : Type u} [Repr α] : Repr (Result α) where
|
| 11 |
+
+ reprPrec r _ :=
|
| 12 |
+
+ match Result.match r with
|
| 13 |
+
+ | .ok a => "Aeneas.Std.Result.ok " ++ repr a
|
| 14 |
+
+ | .div => "Aeneas.Std.Result.div"
|
| 15 |
+
+ | .vis (.fail e) _ => "Aeneas.Std.Result.fail " ++ repr e
|
| 16 |
+
+
|
| 17 |
+
/-!
|
| 18 |
+
`Result` not being an inductive type it has no built-in constructor facts that grind
|
| 19 |
+
can leverage. As we do not want to abuse e-matching, because it risks saturating
|
tasks/AeneasVerif__aeneas-1400/solution/solve.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euxo pipefail
|
| 3 |
+
cd /workspace
|
| 4 |
+
git config --global --add safe.directory /workspace
|
| 5 |
+
PATCH="$(dirname "$0")/patch.diff"
|
| 6 |
+
git apply --verbose --reject "$PATCH"
|
tasks/AeneasVerif__aeneas-1400/task.toml
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "trending/AeneasVerif__aeneas-1400"
|
| 5 |
+
description = "Add Repr instance for Result"
|
| 6 |
+
|
| 7 |
+
[metadata]
|
| 8 |
+
difficulty = "small"
|
| 9 |
+
category = "bugfix"
|
| 10 |
+
keywords = [
|
| 11 |
+
"aeneas",
|
| 12 |
+
"pr_diff",
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
[metadata.repo2env]
|
| 16 |
+
pipeline = "pr_diff"
|
| 17 |
+
pipeline_version = "0.3.0"
|
| 18 |
+
repo = "AeneasVerif/aeneas"
|
| 19 |
+
ref = "557eff83ecef5083b98a52a94ca7fae63d6c1dab"
|
| 20 |
+
reference = "https://github.com/AeneasVerif/aeneas/pull/1400"
|
| 21 |
+
source_access = "auto"
|
| 22 |
+
built_at = "2026-11-16T16:10:00.165041+00:00"
|
| 23 |
+
reward_kinds = [
|
| 24 |
+
"diff_similarity",
|
| 25 |
+
]
|
| 26 |
+
spec_version = "0.2.0"
|
| 27 |
+
content_hash = "sha256:b921d615d07ed57f420a431ed1b5572d65f86ec2f408e9c591e5ed13ce8512e6"
|
| 28 |
+
|
| 29 |
+
[metadata.repo2env.pr_diff]
|
| 30 |
+
pr_merged_at = "2026-10-06T08:14:43Z"
|
| 31 |
+
diff_format = "unified"
|
| 32 |
+
context_files = [
|
| 33 |
+
"backends/lean/Aeneas/Std/Primitives.lean",
|
| 34 |
+
]
|
| 35 |
+
bootstrap_image = "python:3.12-slim"
|
| 36 |
+
|
| 37 |
+
[metadata.repo2env.reward_calibration]
|
| 38 |
+
baseline_reward = 0.0
|
| 39 |
+
loc_changed = 8
|
| 40 |
+
difficulty = "small"
|
| 41 |
+
|
| 42 |
+
[metadata.repo2env.evaluation]
|
| 43 |
+
schema_version = "1"
|
| 44 |
+
status = "unverified"
|
| 45 |
+
stage = "generation"
|
| 46 |
+
reason_codes = [
|
| 47 |
+
"validation_not_run",
|
| 48 |
+
]
|
| 49 |
+
detail = "Generated task; validation has not been established."
|
| 50 |
+
provenance = "unknown"
|
| 51 |
+
evidence = []
|
| 52 |
+
|
| 53 |
+
[metadata.repo2env.reproducibility]
|
| 54 |
+
mode = "inline_dockerfile"
|
| 55 |
+
image_ref = "python:3.12-slim"
|
| 56 |
+
image_tag = "python:3.12-slim"
|
| 57 |
+
image_visibility = "public"
|
| 58 |
+
pushed_at = "2026-11-16T16:19:57.824122+00:00"
|
| 59 |
+
pushed_by = "scalingX"
|
| 60 |
+
inline_recipe_sha256 = "sha256:25330152cb3d9b7dea3375eeca525a85288ed17917a51f8bcf91f77ee8f39a70"
|
| 61 |
+
inline_recipe_lines = 37
|
| 62 |
+
inline_recipe_source = "user_dockerfile"
|
| 63 |
+
|
| 64 |
+
[agent]
|
| 65 |
+
timeout_sec = 1800.0
|
| 66 |
+
|
| 67 |
+
[verifier]
|
| 68 |
+
timeout_sec = 300.0
|
tasks/AeneasVerif__aeneas-1400/tests/capture.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standalone PR-diff capture without executing workspace Git configuration.
|
| 2 |
+
|
| 3 |
+
The emitted task uses a regular clone with a pinned base commit. Only its
|
| 4 |
+
object store is read: refs, index, config, hooks and replacement refs are not
|
| 5 |
+
used. This is a configuration boundary, not a sandbox for a malicious process
|
| 6 |
+
that can modify the verifier, binaries or object store while capture runs.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import tempfile
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def capture(workspace: Path, base_commit: str) -> bytes:
|
| 23 |
+
"""Capture tracked and new files through a fresh private Git index."""
|
| 24 |
+
if not re.fullmatch(r"[a-fA-F0-9]{40}", base_commit):
|
| 25 |
+
raise ValueError("Expected the task's pinned SHA-1 base commit")
|
| 26 |
+
objects = workspace.resolve() / ".git" / "objects"
|
| 27 |
+
if not objects.is_dir():
|
| 28 |
+
raise ValueError("The task's cloned Git object store is missing")
|
| 29 |
+
git = shutil.which("git", path=os.defpath)
|
| 30 |
+
if git is None:
|
| 31 |
+
raise FileNotFoundError("System git is unavailable")
|
| 32 |
+
with tempfile.TemporaryDirectory(prefix="r2e-diff-") as temporary:
|
| 33 |
+
private = Path(temporary)
|
| 34 |
+
# Do not forward GIT_CONFIG_PARAMETERS/COUNT, external diff programs,
|
| 35 |
+
# system/global includes, user attributes, templates or credential env.
|
| 36 |
+
env = {
|
| 37 |
+
"PATH": os.defpath,
|
| 38 |
+
"HOME": temporary,
|
| 39 |
+
"XDG_CONFIG_HOME": temporary,
|
| 40 |
+
"GIT_CONFIG_NOSYSTEM": "1",
|
| 41 |
+
"GIT_CONFIG_GLOBAL": os.devnull,
|
| 42 |
+
"GIT_ATTR_NOSYSTEM": "1",
|
| 43 |
+
"GIT_NO_REPLACE_OBJECTS": "1",
|
| 44 |
+
"GIT_NO_LAZY_FETCH": "1",
|
| 45 |
+
"GIT_TERMINAL_PROMPT": "0",
|
| 46 |
+
"LC_ALL": "C",
|
| 47 |
+
}
|
| 48 |
+
subprocess.run(
|
| 49 |
+
[git, "init", "--quiet", "--template=", str(private / "repository")],
|
| 50 |
+
env=env,
|
| 51 |
+
cwd=private,
|
| 52 |
+
check=True,
|
| 53 |
+
capture_output=True,
|
| 54 |
+
timeout=60,
|
| 55 |
+
)
|
| 56 |
+
env["GIT_ALTERNATE_OBJECT_DIRECTORIES"] = json.dumps(str(objects), ensure_ascii=False)
|
| 57 |
+
command = [
|
| 58 |
+
git,
|
| 59 |
+
f"--git-dir={private / 'repository/.git'}",
|
| 60 |
+
f"--work-tree={workspace.resolve()}",
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def run(*args: str) -> bytes:
|
| 64 |
+
return subprocess.run(
|
| 65 |
+
[*command, *args],
|
| 66 |
+
env=env,
|
| 67 |
+
cwd=workspace,
|
| 68 |
+
check=True,
|
| 69 |
+
capture_output=True,
|
| 70 |
+
timeout=60,
|
| 71 |
+
).stdout
|
| 72 |
+
|
| 73 |
+
run("read-tree", f"{base_commit}^{{tree}}")
|
| 74 |
+
# All filter drivers are undefined in the private configuration. The
|
| 75 |
+
# workspace's clean filters, fsmonitor and hooks cannot be invoked.
|
| 76 |
+
run("add", "--all", "--", ".")
|
| 77 |
+
return run("diff", "--cached", "--no-ext-diff", "--no-textconv", base_commit, "--")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def main(argv: list[str] | None = None) -> int:
|
| 81 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 82 |
+
parser.add_argument("workspace", type=Path)
|
| 83 |
+
parser.add_argument("base_commit")
|
| 84 |
+
args = parser.parse_args(argv)
|
| 85 |
+
try:
|
| 86 |
+
patch = capture(args.workspace, args.base_commit)
|
| 87 |
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
| 88 |
+
# Do not echo child stderr: it may contain workspace-controlled data.
|
| 89 |
+
sys.stderr.write(f"PR-diff capture failed ({type(exc).__name__})\n")
|
| 90 |
+
return 1
|
| 91 |
+
sys.stdout.buffer.write(patch)
|
| 92 |
+
return 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
sys.exit(main())
|
tasks/AeneasVerif__aeneas-1400/tests/instruction.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Add Repr instance for Result
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
`Result` is now a `@[irreducible]` alias for ITree, so it no longer inherits a Repr instance (the old inductive definition had a "deriving Repr"). Add one manually, mirroring the old deriving Repr output, so that `#eval` on `Result` prints `Aeneas.Std.Result.ok` again.
|
| 8 |
+
|
| 9 |
+
## Task
|
| 10 |
+
|
| 11 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `557eff83ecef`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1400/tests/oracle.patch
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/backends/lean/Aeneas/Std/Primitives.lean b/backends/lean/Aeneas/Std/Primitives.lean
|
| 2 |
+
index b5cb07e5f1..be9c30b698 100644
|
| 3 |
+
--- a/backends/lean/Aeneas/Std/Primitives.lean
|
| 4 |
+
+++ b/backends/lean/Aeneas/Std/Primitives.lean
|
| 5 |
+
@@ -147,6 +147,14 @@ theorem Result.match.fail {α : Type u} {e} :
|
| 6 |
+
(Result.fail e : Result α).match = .vis (.fail e) PEmpty.elim := by
|
| 7 |
+
simp [Result.fail_eq_vis]
|
| 8 |
+
|
| 9 |
+
+/-- The `Repr` instance for `Result`, so that `#eval` on `Result`-producing expressions prints `Aeneas.Std.Result.ok`/`fail`/`div`. -/
|
| 10 |
+
+instance Result.reprInst {α : Type u} [Repr α] : Repr (Result α) where
|
| 11 |
+
+ reprPrec r _ :=
|
| 12 |
+
+ match Result.match r with
|
| 13 |
+
+ | .ok a => "Aeneas.Std.Result.ok " ++ repr a
|
| 14 |
+
+ | .div => "Aeneas.Std.Result.div"
|
| 15 |
+
+ | .vis (.fail e) _ => "Aeneas.Std.Result.fail " ++ repr e
|
| 16 |
+
+
|
| 17 |
+
/-!
|
| 18 |
+
`Result` not being an inductive type it has no built-in constructor facts that grind
|
| 19 |
+
can leverage. As we do not want to abuse e-matching, because it risks saturating
|
tasks/AeneasVerif__aeneas-1400/tests/test.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -uxo pipefail
|
| 3 |
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
| 4 |
+
cd /workspace
|
| 5 |
+
mkdir -p /logs/verifier
|
| 6 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json /logs/verifier/reward-details.json
|
| 7 |
+
CAPTURE_DIR="$(mktemp -d)" || exit 1
|
| 8 |
+
trap 'rm -rf -- "$CAPTURE_DIR"' EXIT
|
| 9 |
+
if ! python3 -I "$SCRIPT_DIR/capture.py" /workspace 557eff83ecef5083b98a52a94ca7fae63d6c1dab > "$CAPTURE_DIR/predicted.patch"; then
|
| 10 |
+
echo "0.0" > /logs/verifier/reward.txt
|
| 11 |
+
printf '%s' '{"final_reward": 0.0, "evaluation_status": "graded", "eval_trustworthy": false, "capture_status": "error"}' > /logs/verifier/reward-details.json
|
| 12 |
+
exit 0
|
| 13 |
+
fi
|
| 14 |
+
rm -f /logs/verifier/predicted.patch
|
| 15 |
+
cp -- "$CAPTURE_DIR/predicted.patch" /logs/verifier/predicted.patch
|
| 16 |
+
: 'START_VERIFY_OUTPUT'
|
| 17 |
+
if ! python3 -I "$SCRIPT_DIR/verifier.py" \
|
| 18 |
+
"$SCRIPT_DIR/oracle.patch" \
|
| 19 |
+
"$CAPTURE_DIR/predicted.patch" \
|
| 20 |
+
"$SCRIPT_DIR/instruction.md"; then
|
| 21 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json
|
| 22 |
+
printf '%s' '{"final_reward": null, "reward": null, "evaluation_status": "ungraded", "eval_trustworthy": false, "verifier_status": "error"}' > /logs/verifier/reward-details.json
|
| 23 |
+
fi
|
| 24 |
+
: 'END_VERIFY_OUTPUT'
|
| 25 |
+
exit 0
|
tasks/AeneasVerif__aeneas-1400/tests/verifier.py
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
This module is the **standalone verifier** that runs inside the task's
|
| 4 |
+
Docker container, NOT a helper used at generation time. Generation emits
|
| 5 |
+
its source as ``tests/verifier.py``. Harbor delivers it at verify time,
|
| 6 |
+
and ``tests/test.sh`` invokes it with the oracle, predicted patch and instruction.
|
| 7 |
+
|
| 8 |
+
Reward = weighted sum of 6 components (5 deterministic + 1 required LLM):
|
| 9 |
+
|
| 10 |
+
format_valid (0 or 1) — predicted parses as a unified diff (guard)
|
| 11 |
+
size_sanity ([0, 1]) — min(oracle_loc, pred_loc) / max(...)
|
| 12 |
+
catches "rampage through the codebase"
|
| 13 |
+
file_targeting ([0, 1]) — F1 over changed-file sets (NOT Jaccard —
|
| 14 |
+
symmetric penalty over-punishes extras)
|
| 15 |
+
region_overlap ([0, 1]) — predicted hunks overlap oracle hunks
|
| 16 |
+
(strongest spatial-localization signal)
|
| 17 |
+
similarity ([0, 1]) — SequenceMatcher ratio over +/- lines only
|
| 18 |
+
(no free credit for context lines)
|
| 19 |
+
llm_judge ([0, 1] or null) — an LLM rates "does this address the issue?"
|
| 20 |
+
Anthropic Haiku by default; any OpenAI-
|
| 21 |
+
compatible server via ``R2E_JUDGE_ENDPOINT``.
|
| 22 |
+
null when the judge is unavailable
|
| 23 |
+
(no key or model, network, unreadable
|
| 24 |
+
reply) → ungraded, no reward file; a
|
| 25 |
+
reply without a valid score (refusal,
|
| 26 |
+
content filter, empty, no "score") → a
|
| 27 |
+
graded 0
|
| 28 |
+
|
| 29 |
+
Default weights: 0.00 / 0.08 / 0.12 / 0.20 / 0.10 / 0.50 (retuned from
|
| 30 |
+
the original 0.05 / 0.05 / 0.10 / 0.20 / 0.20 / 0.40 after a 23-task
|
| 31 |
+
pilot — see the comment block above ``_DEFAULT_WEIGHTS`` below).
|
| 32 |
+
Override per-task via ``task.toml.metadata`` or per-run via env vars
|
| 33 |
+
``R2E_W_FORMAT`` / ``R2E_W_SIZE`` / ``R2E_W_FILE`` / ``R2E_W_REGION`` /
|
| 34 |
+
``R2E_W_SIM`` / ``R2E_W_JUDGE`` (pass via harbor ``--ve`` so they
|
| 35 |
+
reach the verifier container).
|
| 36 |
+
|
| 37 |
+
Judge routing, also via ``--ve``: ``R2E_JUDGE_MODEL`` picks the model
|
| 38 |
+
(default Haiku); ``R2E_JUDGE_ENDPOINT`` points at an OpenAI-compatible
|
| 39 |
+
server (vLLM, Ollama, a gateway) and switches the request to
|
| 40 |
+
``<endpoint>/chat/completions`` with a bearer token from
|
| 41 |
+
``R2E_JUDGE_API_KEY`` — or a placeholder when unset, since self-hosted
|
| 42 |
+
servers ignore it. ``ANTHROPIC_API_KEY`` is only read on the default
|
| 43 |
+
route and is never sent to a custom endpoint.
|
| 44 |
+
|
| 45 |
+
Final reward is clipped to [0, 1] and additionally clamped to ≤ 0.40
|
| 46 |
+
when ``size_sanity < 0.10`` (catastrophic-size hard cap — stops a
|
| 47 |
+
charitable judge from inflating scores on wildly wrong-sized patches).
|
| 48 |
+
|
| 49 |
+
Outputs (mirrors `_pr_runtime_verifier.py` after #75):
|
| 50 |
+
/logs/verifier/reward.txt — single float (Harbor reads this);
|
| 51 |
+
graded runs only
|
| 52 |
+
/logs/verifier/reward-details.json — full component breakdown + status
|
| 53 |
+
(structured diagnostics; Harbor's `reward.json` schema is flat-numeric-
|
| 54 |
+
only, so the breakdown goes to the `reward-details.json` sidecar which
|
| 55 |
+
Harbor renders under Verifier Logs → Rewards)
|
| 56 |
+
|
| 57 |
+
Pure stdlib — uses only ``difflib``, ``json``, ``os``, ``re``,
|
| 58 |
+
``urllib``, ``sys``. The same module is imported by the unit tests
|
| 59 |
+
under ``tests/test_pr_diff_verifier.py`` so the in-container behavior
|
| 60 |
+
stays in lockstep with what we test.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
from __future__ import annotations
|
| 64 |
+
|
| 65 |
+
import argparse
|
| 66 |
+
import difflib
|
| 67 |
+
import json
|
| 68 |
+
import math
|
| 69 |
+
import os
|
| 70 |
+
import re
|
| 71 |
+
import sys
|
| 72 |
+
import urllib.error
|
| 73 |
+
import urllib.request
|
| 74 |
+
|
| 75 |
+
# ---------------------------------------------------------------------------
|
| 76 |
+
# Parsing helpers (shared by multiple components)
|
| 77 |
+
# ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
_DIFF_HEADER_RE = re.compile(r"^diff --git a/(\S+) b/(\S+)$")
|
| 80 |
+
_HUNK_HEADER_RE = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
| 81 |
+
_FILE_MARKER_RE = re.compile(r"^(?:---|\+\+\+) ")
|
| 82 |
+
_INDEX_RE = re.compile(r"^index ")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def file_paths(diff: str) -> set[str]:
|
| 86 |
+
"""Return the set of ``b/<path>`` paths touched by a unified diff."""
|
| 87 |
+
paths: set[str] = set()
|
| 88 |
+
for line in diff.splitlines():
|
| 89 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 90 |
+
if m:
|
| 91 |
+
paths.add(m.group(2))
|
| 92 |
+
return paths
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def hunk_ranges(diff: str) -> dict[str, list[tuple[int, int]]]:
|
| 96 |
+
"""For each touched file, return list of (start_line, end_line) ranges
|
| 97 |
+
on the **post-change** side (the ``+`` numbers in ``@@ -X +Y @@``).
|
| 98 |
+
"""
|
| 99 |
+
out: dict[str, list[tuple[int, int]]] = {}
|
| 100 |
+
current_file: str | None = None
|
| 101 |
+
for line in diff.splitlines():
|
| 102 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 103 |
+
if m:
|
| 104 |
+
current_file = m.group(2)
|
| 105 |
+
out.setdefault(current_file, [])
|
| 106 |
+
continue
|
| 107 |
+
m = _HUNK_HEADER_RE.match(line)
|
| 108 |
+
if m and current_file is not None:
|
| 109 |
+
new_start = int(m.group(3))
|
| 110 |
+
new_count = int(m.group(4) or "1")
|
| 111 |
+
end = new_start + max(new_count - 1, 0)
|
| 112 |
+
out[current_file].append((new_start, end))
|
| 113 |
+
return out
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _normalize_changes_only(diff: str) -> list[str]:
|
| 117 |
+
"""Return the +/- lines (the actual changes) for similarity scoring.
|
| 118 |
+
|
| 119 |
+
Drops:
|
| 120 |
+
- ``diff --git`` / ``index abc..def`` metadata
|
| 121 |
+
- ``@@ ... @@`` hunk markers (volatile line numbers)
|
| 122 |
+
- context lines (no +/- prefix) — these are unchanged code, scoring
|
| 123 |
+
them inflates similarity for trivial patches
|
| 124 |
+
Keeps file-marker lines (``--- a/foo`` / ``+++ b/foo``) so file identity
|
| 125 |
+
stays in the comparison; normalizes off the tab+timestamp suffix git
|
| 126 |
+
sometimes appends.
|
| 127 |
+
"""
|
| 128 |
+
out: list[str] = []
|
| 129 |
+
for line in diff.splitlines():
|
| 130 |
+
if _DIFF_HEADER_RE.match(line) or _INDEX_RE.match(line):
|
| 131 |
+
continue
|
| 132 |
+
if _HUNK_HEADER_RE.match(line):
|
| 133 |
+
continue
|
| 134 |
+
if _FILE_MARKER_RE.match(line):
|
| 135 |
+
out.append(line.split("\t")[0].strip())
|
| 136 |
+
continue
|
| 137 |
+
# +/- lines (actual changes)
|
| 138 |
+
if line.startswith("+") or line.startswith("-"):
|
| 139 |
+
out.append(line)
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------------------------
|
| 144 |
+
# Reward components
|
| 145 |
+
# ---------------------------------------------------------------------------
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def format_valid(predicted: str) -> float:
|
| 149 |
+
"""1.0 if the predicted text looks like a unified diff; else 0.0.
|
| 150 |
+
|
| 151 |
+
Requires both a ``diff --git`` header and at least one real +/- line
|
| 152 |
+
(not the ``---`` / ``+++`` file-marker lines).
|
| 153 |
+
"""
|
| 154 |
+
if not predicted.strip():
|
| 155 |
+
return 0.0
|
| 156 |
+
has_header = False
|
| 157 |
+
has_change = False
|
| 158 |
+
for line in predicted.splitlines():
|
| 159 |
+
if _DIFF_HEADER_RE.match(line):
|
| 160 |
+
has_header = True
|
| 161 |
+
elif (line.startswith("+") or line.startswith("-")) and not line.startswith(
|
| 162 |
+
("+++ ", "--- ")
|
| 163 |
+
):
|
| 164 |
+
has_change = True
|
| 165 |
+
if has_header and has_change:
|
| 166 |
+
return 1.0
|
| 167 |
+
return 0.0
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def file_targeting(oracle: str, predicted: str) -> float:
|
| 171 |
+
"""F1 over the changed-file sets.
|
| 172 |
+
|
| 173 |
+
Why F1 instead of Jaccard:
|
| 174 |
+
- Missing an oracle file (FN) is a *big* failure.
|
| 175 |
+
- Touching one unrelated extra file (FP) is a small one.
|
| 176 |
+
- Jaccard punishes both equally, which over-penalizes the agent
|
| 177 |
+
for any extra exploration.
|
| 178 |
+
- F1 weights TP twice, giving partial credit when the agent finds
|
| 179 |
+
most-but-not-all of the oracle files even with some noise.
|
| 180 |
+
|
| 181 |
+
Returns 1.0 if both sides touch zero files (degenerate).
|
| 182 |
+
"""
|
| 183 |
+
o = file_paths(oracle)
|
| 184 |
+
p = file_paths(predicted)
|
| 185 |
+
if not o and not p:
|
| 186 |
+
return 1.0
|
| 187 |
+
tp = len(o & p)
|
| 188 |
+
fn = len(o - p)
|
| 189 |
+
fp = len(p - o)
|
| 190 |
+
if tp == 0:
|
| 191 |
+
return 0.0
|
| 192 |
+
# F1 = 2·TP / (2·TP + FN + FP)
|
| 193 |
+
return (2 * tp) / (2 * tp + fn + fp)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _count_loc_changes(diff: str) -> int:
|
| 197 |
+
"""Number of real +/- lines (excluding file-marker lines)."""
|
| 198 |
+
n = 0
|
| 199 |
+
for line in diff.splitlines():
|
| 200 |
+
if (line.startswith("+") or line.startswith("-")) and not line.startswith(("+++ ", "--- ")):
|
| 201 |
+
n += 1
|
| 202 |
+
return n
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def size_sanity(oracle: str, predicted: str) -> float:
|
| 206 |
+
"""Penalize predicted patches that are wildly larger / smaller than the oracle.
|
| 207 |
+
|
| 208 |
+
Returns ``min(oracle_loc, predicted_loc) / max(oracle_loc, predicted_loc)``.
|
| 209 |
+
Both empty → 1.0 (degenerate but well-defined). One empty → 0.0.
|
| 210 |
+
|
| 211 |
+
This is the "don't rampage through the codebase" guard — a 200-line
|
| 212 |
+
diff for a 3-line oracle scores ~0.015 here even if every other
|
| 213 |
+
component looks OK.
|
| 214 |
+
"""
|
| 215 |
+
o_loc = _count_loc_changes(oracle)
|
| 216 |
+
p_loc = _count_loc_changes(predicted)
|
| 217 |
+
if o_loc == 0 and p_loc == 0:
|
| 218 |
+
return 1.0
|
| 219 |
+
if o_loc == 0 or p_loc == 0:
|
| 220 |
+
return 0.0
|
| 221 |
+
return min(o_loc, p_loc) / max(o_loc, p_loc)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def region_overlap(oracle: str, predicted: str, *, slack_lines: int = 5) -> float:
|
| 225 |
+
"""For each oracle hunk, did the predicted diff edit a line within
|
| 226 |
+
``slack_lines`` of that hunk in the same file?
|
| 227 |
+
|
| 228 |
+
Returns the fraction of oracle hunks that have at least one matching
|
| 229 |
+
predicted hunk. ``slack_lines`` tolerates slight line-number drift
|
| 230 |
+
when git diff renders the predicted hunk at a different offset.
|
| 231 |
+
"""
|
| 232 |
+
o_ranges = hunk_ranges(oracle)
|
| 233 |
+
p_ranges = hunk_ranges(predicted)
|
| 234 |
+
total = sum(len(v) for v in o_ranges.values())
|
| 235 |
+
if total == 0:
|
| 236 |
+
return 1.0 # oracle has no hunks (degenerate)
|
| 237 |
+
matched = 0
|
| 238 |
+
for fname, ranges in o_ranges.items():
|
| 239 |
+
p_in_file = p_ranges.get(fname, [])
|
| 240 |
+
for o_start, o_end in ranges:
|
| 241 |
+
for p_start, p_end in p_in_file:
|
| 242 |
+
# Interval overlap with slack — max(starts) <= min(ends) + slack
|
| 243 |
+
if max(o_start, p_start) <= min(o_end, p_end) + slack_lines:
|
| 244 |
+
matched += 1
|
| 245 |
+
break
|
| 246 |
+
return matched / total
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def similarity(oracle: str, predicted: str) -> float:
|
| 250 |
+
"""SequenceMatcher ratio over +/- lines only.
|
| 251 |
+
|
| 252 |
+
No free credit for context lines — fixes the v0.8.1 inflation where a
|
| 253 |
+
one-line fix scored ~0.7 just because the 3 context lines on either
|
| 254 |
+
side were "matched".
|
| 255 |
+
"""
|
| 256 |
+
if not predicted.strip():
|
| 257 |
+
return 0.0
|
| 258 |
+
o = _normalize_changes_only(oracle)
|
| 259 |
+
p = _normalize_changes_only(predicted)
|
| 260 |
+
if not o:
|
| 261 |
+
return 0.0
|
| 262 |
+
# Exact matching is quadratic-or-worse on repeated lines: 200 x 2,000
|
| 263 |
+
# identical changed lines take ~2 s, 500 x 5,000 take ~35 s, which can
|
| 264 |
+
# run the verifier past Harbor's timeout. Above this many line pairs,
|
| 265 |
+
# fall back to difflib's popular-element heuristic, which stays fast.
|
| 266 |
+
exact = len(o) * len(p) <= _SIMILARITY_EXACT_PAIRS
|
| 267 |
+
return difflib.SequenceMatcher(a=o, b=p, autojunk=not exact).ratio()
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
_SIMILARITY_EXACT_PAIRS = 400_000
|
| 271 |
+
|
| 272 |
+
# A predicted patch over 10x the oracle's changed lines is already a
|
| 273 |
+
# catastrophic size mismatch (size_sanity < 0.10). Past this floor such a
|
| 274 |
+
# patch is a graded 0 instead of being scored, so one huge file can't slow
|
| 275 |
+
# the verifier past its timeout and turn a failing episode into a dropped,
|
| 276 |
+
# ungraded one. The byte cap stops it from being read at all.
|
| 277 |
+
_MAX_PREDICTED_FACTOR = 10
|
| 278 |
+
_MAX_PREDICTED_FLOOR_LOC = 1_000
|
| 279 |
+
_MAX_PREDICTED_BYTES = 16 * 1024 * 1024
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def predicted_too_large(oracle: str, predicted: str) -> bool:
|
| 283 |
+
"""Whether the predicted patch is too large to score (a graded 0)."""
|
| 284 |
+
limit = max(_MAX_PREDICTED_FACTOR * _count_loc_changes(oracle), _MAX_PREDICTED_FLOOR_LOC)
|
| 285 |
+
return _count_loc_changes(predicted) > limit
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# ---------------------------------------------------------------------------
|
| 289 |
+
# LLM-as-judge (Anthropic Messages API, stdlib urllib)
|
| 290 |
+
# ---------------------------------------------------------------------------
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
_JUDGE_PROMPT = (
|
| 294 |
+
"You are scoring a code-fix patch on whether it logically addresses the "
|
| 295 |
+
"described issue. Output a single JSON object: "
|
| 296 |
+
'{{"score": <float in [0,1]>, "reasoning": "<<=30 words"}}.\n\n'
|
| 297 |
+
"DO NOT use the oracle to grade. Score on:\n"
|
| 298 |
+
" - Does the predicted diff touch code regions that could plausibly fix the issue?\n"
|
| 299 |
+
" - Is the change direction consistent with what the issue describes?\n"
|
| 300 |
+
" - Is it a real attempt (not boilerplate, not no-op)?\n\n"
|
| 301 |
+
"Issue:\n{instruction}\n\n"
|
| 302 |
+
"Oracle (reference fix for comparison only — don't grade on similarity to it):\n"
|
| 303 |
+
"{oracle}\n\n"
|
| 304 |
+
"Predicted:\n{predicted}\n\n"
|
| 305 |
+
"Return ONLY the JSON object."
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
_DEFAULT_JUDGE_MODEL = "claude-haiku-4-5-20251001"
|
| 310 |
+
_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages"
|
| 311 |
+
# Bearer token for a self-hosted judge when R2E_JUDGE_API_KEY is unset. vLLM /
|
| 312 |
+
# Ollama ignore it; the OpenAI wire format still wants one. Same value llm.py uses.
|
| 313 |
+
_PLACEHOLDER_API_KEY = "EMPTY"
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def llm_judge(
|
| 317 |
+
*,
|
| 318 |
+
instruction: str,
|
| 319 |
+
oracle: str,
|
| 320 |
+
predicted: str,
|
| 321 |
+
api_key: str,
|
| 322 |
+
model: str = _DEFAULT_JUDGE_MODEL,
|
| 323 |
+
timeout: int = 60,
|
| 324 |
+
endpoint: str | None = None,
|
| 325 |
+
) -> tuple[float | None, str]:
|
| 326 |
+
"""Return ``(score, status)``.
|
| 327 |
+
|
| 328 |
+
``score`` is a float in [0, 1] on success, ``None`` on failure.
|
| 329 |
+
``status`` is a short string: ``"ok"`` / ``"no_api_key"`` /
|
| 330 |
+
``"no_judge_model"`` / ``"empty_predicted"`` / ``"network"`` /
|
| 331 |
+
``"parse"`` / ``"output_limit"`` / ``"missing_score"`` / ``"invalid_score"``.
|
| 332 |
+
``output_limit`` means the judge exhausted its configured token budget
|
| 333 |
+
(ungraded, even if a partial answer contains a score). ``parse`` means
|
| 334 |
+
the provider's body isn't JSON or has the wrong shape (ungraded); a reply
|
| 335 |
+
with no usable text (refusal, content filter, empty) or no valid score is
|
| 336 |
+
``missing_score`` / ``invalid_score`` (a graded 0). A missing score never
|
| 337 |
+
increases the other weights.
|
| 338 |
+
|
| 339 |
+
``endpoint`` — base URL of an OpenAI-compatible server. When set, the
|
| 340 |
+
request goes to ``<endpoint>/chat/completions`` with ``api_key`` as a
|
| 341 |
+
bearer token, at temperature 0, and ``model`` must be given explicitly;
|
| 342 |
+
otherwise it goes to Anthropic's Messages API unchanged.
|
| 343 |
+
"""
|
| 344 |
+
if not api_key:
|
| 345 |
+
return None, "no_api_key"
|
| 346 |
+
if endpoint and not model:
|
| 347 |
+
return None, "no_judge_model"
|
| 348 |
+
if not predicted.strip():
|
| 349 |
+
return 0.0, "empty_predicted"
|
| 350 |
+
|
| 351 |
+
# Truncate hard so we don't blow up the prompt for big diffs
|
| 352 |
+
prompt = _JUDGE_PROMPT.format(
|
| 353 |
+
instruction=instruction[:4000],
|
| 354 |
+
oracle=oracle[:4000],
|
| 355 |
+
predicted=predicted[:4000],
|
| 356 |
+
)
|
| 357 |
+
payload: dict = {
|
| 358 |
+
"model": model,
|
| 359 |
+
"max_tokens": 200,
|
| 360 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 361 |
+
}
|
| 362 |
+
if endpoint:
|
| 363 |
+
# Small self-hosted models are noisy judges at their default sampling
|
| 364 |
+
# temperature (same input scoring 0.0 one call and 1.0 the next); pin
|
| 365 |
+
# them to greedy. The Anthropic route keeps its defaults — the weights
|
| 366 |
+
# were calibrated against them.
|
| 367 |
+
payload["temperature"] = 0
|
| 368 |
+
url = endpoint.rstrip("/") + "/chat/completions"
|
| 369 |
+
headers = {
|
| 370 |
+
"authorization": f"Bearer {api_key}",
|
| 371 |
+
"content-type": "application/json",
|
| 372 |
+
}
|
| 373 |
+
else:
|
| 374 |
+
url = _ANTHROPIC_MESSAGES_URL
|
| 375 |
+
headers = {
|
| 376 |
+
"x-api-key": api_key,
|
| 377 |
+
"anthropic-version": "2023-06-01",
|
| 378 |
+
"content-type": "application/json",
|
| 379 |
+
}
|
| 380 |
+
body = json.dumps(payload).encode("utf-8")
|
| 381 |
+
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
|
| 382 |
+
try:
|
| 383 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 384 |
+
raw = resp.read().decode("utf-8")
|
| 385 |
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError):
|
| 386 |
+
return None, "network"
|
| 387 |
+
|
| 388 |
+
try:
|
| 389 |
+
response = json.loads(raw)
|
| 390 |
+
except json.JSONDecodeError:
|
| 391 |
+
return None, "parse"
|
| 392 |
+
# Provider-reported truncation is a grader capacity failure, not evidence
|
| 393 |
+
# that the submitted patch is wrong. Reasoning models can spend the entire
|
| 394 |
+
# output budget before producing visible text. Never grade a partial score.
|
| 395 |
+
if isinstance(response, dict):
|
| 396 |
+
choices = response.get("choices")
|
| 397 |
+
if endpoint:
|
| 398 |
+
if (
|
| 399 |
+
isinstance(choices, list)
|
| 400 |
+
and choices
|
| 401 |
+
and isinstance(choices[0], dict)
|
| 402 |
+
and choices[0].get("finish_reason") == "length"
|
| 403 |
+
):
|
| 404 |
+
return None, "output_limit"
|
| 405 |
+
elif response.get("stop_reason") in {"max_tokens", "model_context_window_exceeded"}:
|
| 406 |
+
return None, "output_limit"
|
| 407 |
+
text = _judge_text(response, openai_compatible=bool(endpoint))
|
| 408 |
+
if text is None:
|
| 409 |
+
return None, "parse"
|
| 410 |
+
|
| 411 |
+
# Pull the first JSON object out of the model's response
|
| 412 |
+
m = re.search(r"\{[^{}]*\"score\"[^{}]*\}", text, re.DOTALL)
|
| 413 |
+
if not m:
|
| 414 |
+
return None, "missing_score"
|
| 415 |
+
try:
|
| 416 |
+
obj = json.loads(m.group(0))
|
| 417 |
+
score = obj.get("score")
|
| 418 |
+
except (json.JSONDecodeError, ValueError, TypeError):
|
| 419 |
+
return None, "missing_score"
|
| 420 |
+
if type(score) not in (int, float) or not 0 <= score <= 1 or not math.isfinite(score):
|
| 421 |
+
return None, "invalid_score"
|
| 422 |
+
return float(score), "ok"
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _judge_text(payload: object, *, openai_compatible: bool) -> str | None:
|
| 426 |
+
"""The judge's answer text, ``""`` when it gave none, ``None`` for a wrong shape.
|
| 427 |
+
|
| 428 |
+
A refusal or a content filter is a well-formed reply with no usable text.
|
| 429 |
+
The agent's patch is in the prompt, so it can provoke one: that is ``""``,
|
| 430 |
+
which grades 0, not ``None``, which leaves the run ungraded.
|
| 431 |
+
|
| 432 |
+
Anthropic: a refusal is HTTP 200 with ``stop_reason: "refusal"`` and
|
| 433 |
+
``content`` empty or holding partial text to discard. OpenAI-compatible:
|
| 434 |
+
``message.content`` is null with a ``refusal`` string or
|
| 435 |
+
``finish_reason: "content_filter"``.
|
| 436 |
+
"""
|
| 437 |
+
if not isinstance(payload, dict):
|
| 438 |
+
return None
|
| 439 |
+
if openai_compatible:
|
| 440 |
+
choices = payload.get("choices")
|
| 441 |
+
if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
|
| 442 |
+
return None
|
| 443 |
+
message = choices[0].get("message")
|
| 444 |
+
if not isinstance(message, dict):
|
| 445 |
+
return None
|
| 446 |
+
if message.get("refusal") or choices[0].get("finish_reason") == "content_filter":
|
| 447 |
+
return ""
|
| 448 |
+
content = message.get("content")
|
| 449 |
+
if content is None:
|
| 450 |
+
return ""
|
| 451 |
+
if isinstance(content, str):
|
| 452 |
+
return content
|
| 453 |
+
if isinstance(content, list): # content parts
|
| 454 |
+
return "".join(
|
| 455 |
+
part.get("text", "")
|
| 456 |
+
for part in content
|
| 457 |
+
if isinstance(part, dict) and isinstance(part.get("text", ""), str)
|
| 458 |
+
)
|
| 459 |
+
return None
|
| 460 |
+
content = payload.get("content")
|
| 461 |
+
if not isinstance(content, list):
|
| 462 |
+
return None
|
| 463 |
+
if payload.get("stop_reason") == "refusal":
|
| 464 |
+
return ""
|
| 465 |
+
return "".join(
|
| 466 |
+
block["text"]
|
| 467 |
+
for block in content
|
| 468 |
+
if isinstance(block, dict)
|
| 469 |
+
and block.get("type", "text") == "text"
|
| 470 |
+
and isinstance(block.get("text"), str)
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# ---------------------------------------------------------------------------
|
| 475 |
+
# Combination
|
| 476 |
+
# ---------------------------------------------------------------------------
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
# Judge replies the agent can provoke: its patch text is part of the judge
|
| 480 |
+
# prompt, so it can steer the answer away from a valid score. These are a
|
| 481 |
+
# graded 0. An unreadable provider envelope (`parse`), missing configuration,
|
| 482 |
+
# a disabled judge, transport errors and an exhausted judge output budget leave
|
| 483 |
+
# the evaluation ungraded. Truncation alone cannot establish an incorrect patch.
|
| 484 |
+
_JUDGE_GRADED_ZERO = frozenset({"missing_score", "invalid_score"})
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def evaluation_status(judge_score: float | None, judge_status: str) -> str:
|
| 488 |
+
"""`graded` when the judge scored or the agent can have caused its failure."""
|
| 489 |
+
if judge_score is not None or judge_status in _JUDGE_GRADED_ZERO:
|
| 490 |
+
return "graded"
|
| 491 |
+
return "ungraded"
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def combine(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 495 |
+
"""Combine declared components, requiring a positively weighted judge.
|
| 496 |
+
|
| 497 |
+
Without a judge score the result is 0. ``main`` records it as a graded 0
|
| 498 |
+
when the agent can have caused the judge failure, and otherwise writes no
|
| 499 |
+
reward file, so Harbor reports the trial as VERIFIER_FAILED.
|
| 500 |
+
"""
|
| 501 |
+
if weights.get("llm_judge", 0) <= 0 or components.get("llm_judge") is None:
|
| 502 |
+
return 0.0
|
| 503 |
+
if any(w > 0 and components.get(k) is None for k, w in weights.items()):
|
| 504 |
+
return 0.0
|
| 505 |
+
return _weighted_mean(components, weights)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def _weighted_mean(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 509 |
+
available = [(k, w) for k, w in weights.items() if w > 0 and components.get(k) is not None]
|
| 510 |
+
if not available:
|
| 511 |
+
return 0.0
|
| 512 |
+
# Relative weights need not sum to one. Scale first so large finite
|
| 513 |
+
# overrides cannot overflow the numerator or denominator into NaN.
|
| 514 |
+
scale = max(w for _, w in available)
|
| 515 |
+
normalized = [(k, w / scale) for k, w in available]
|
| 516 |
+
return sum(w * components[k] for k, w in normalized) / sum(w for _, w in normalized)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
# ---------------------------------------------------------------------------
|
| 520 |
+
# Entry point (invoked by tests/test.sh inside the container)
|
| 521 |
+
# ---------------------------------------------------------------------------
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
# Weights retuned after a 23-task pilot. Rationale (LLM-as-reward-engineer
|
| 525 |
+
# analysis grounded in per-task component data):
|
| 526 |
+
#
|
| 527 |
+
# - format_valid → 0.00: was 1.0 across ALL 21 evaluated tasks. Zero
|
| 528 |
+
# discriminative signal — its 0.05 weight was pure dead weight.
|
| 529 |
+
# - similarity → 0.10: Pearson ~0.85 correlation with region_overlap.
|
| 530 |
+
# Carrying both at 0.20 double-counts positional accuracy and
|
| 531 |
+
# additionally penalizes legitimate alternative implementations.
|
| 532 |
+
# - llm_judge → 0.50: only component capturing semantic correctness
|
| 533 |
+
# independent of textual form; diverges informatively from
|
| 534 |
+
# similarity on cases like tokenizers (judge=0.72, sim=0.08).
|
| 535 |
+
# - region_overlap stays 0.20: strongest spatial-localization signal.
|
| 536 |
+
# - file_targeting → 0.12: leading indicator, less correlated with the
|
| 537 |
+
# rest than region/similarity are with each other.
|
| 538 |
+
# - size_sanity → 0.08: useful outlier detector for catastrophic
|
| 539 |
+
# over/under-generation (prettier=0.01, serde=0.08).
|
| 540 |
+
#
|
| 541 |
+
# Total: 0.00 + 0.08 + 0.12 + 0.20 + 0.10 + 0.50 = 1.00.
|
| 542 |
+
_DEFAULT_WEIGHTS = {
|
| 543 |
+
"format_valid": 0.00,
|
| 544 |
+
"size_sanity": 0.08,
|
| 545 |
+
"file_targeting": 0.12,
|
| 546 |
+
"region_overlap": 0.20,
|
| 547 |
+
"similarity": 0.10,
|
| 548 |
+
"llm_judge": 0.50,
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
# Hard cap: when size_sanity < this threshold, clamp final reward to
|
| 552 |
+
# ≤ CATASTROPHIC_SIZE_CAP. Prevents a charitable judge from inflating
|
| 553 |
+
# the score on patches that are wildly the wrong size (catastrophic
|
| 554 |
+
# over- or under-generation).
|
| 555 |
+
_CATASTROPHIC_SIZE_THRESHOLD = 0.10
|
| 556 |
+
_CATASTROPHIC_SIZE_CAP = 0.40
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _read_weights_from_env() -> dict[str, float]:
|
| 560 |
+
"""Override defaults via R2E_W_* env vars (set in container by harbor)."""
|
| 561 |
+
overrides = {
|
| 562 |
+
"format_valid": os.environ.get("R2E_W_FORMAT"),
|
| 563 |
+
"size_sanity": os.environ.get("R2E_W_SIZE"),
|
| 564 |
+
"file_targeting": os.environ.get("R2E_W_FILE"),
|
| 565 |
+
"region_overlap": os.environ.get("R2E_W_REGION"),
|
| 566 |
+
"similarity": os.environ.get("R2E_W_SIM"),
|
| 567 |
+
"llm_judge": os.environ.get("R2E_W_JUDGE"),
|
| 568 |
+
}
|
| 569 |
+
out = dict(_DEFAULT_WEIGHTS)
|
| 570 |
+
for k, v in overrides.items():
|
| 571 |
+
if v is None:
|
| 572 |
+
continue
|
| 573 |
+
try:
|
| 574 |
+
value = float(v)
|
| 575 |
+
if math.isfinite(value) and value >= 0:
|
| 576 |
+
out[k] = value
|
| 577 |
+
except (TypeError, ValueError):
|
| 578 |
+
continue
|
| 579 |
+
return out
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def _judge_config_from_env() -> tuple[str, str, str | None]:
|
| 583 |
+
"""``(api_key, model, endpoint)`` for the judge, from the verifier env.
|
| 584 |
+
|
| 585 |
+
With ``R2E_JUDGE_ENDPOINT`` set, the key comes from ``R2E_JUDGE_API_KEY``
|
| 586 |
+
(placeholder when unset) and ``ANTHROPIC_API_KEY`` is never forwarded to
|
| 587 |
+
the custom server. ``R2E_JUDGE_MODEL`` has no default on that route (a
|
| 588 |
+
self-hosted server won't have Haiku): when unset, ``model`` comes back
|
| 589 |
+
as ``""`` and ``llm_judge`` reports ``no_judge_model`` instead of
|
| 590 |
+
calling out. Without an endpoint the default Anthropic route is
|
| 591 |
+
unchanged.
|
| 592 |
+
"""
|
| 593 |
+
endpoint = os.environ.get("R2E_JUDGE_ENDPOINT", "").strip() or None
|
| 594 |
+
model = os.environ.get("R2E_JUDGE_MODEL", "").strip()
|
| 595 |
+
if endpoint:
|
| 596 |
+
api_key = os.environ.get("R2E_JUDGE_API_KEY", "").strip() or _PLACEHOLDER_API_KEY
|
| 597 |
+
return api_key, model, endpoint
|
| 598 |
+
return os.environ.get("ANTHROPIC_API_KEY", "").strip(), model or _DEFAULT_JUDGE_MODEL, None
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def main(argv: list[str] | None = None) -> int:
|
| 602 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 603 |
+
parser.add_argument("oracle")
|
| 604 |
+
parser.add_argument("predicted")
|
| 605 |
+
parser.add_argument("instruction")
|
| 606 |
+
parser.add_argument("--out-dir", default="/logs/verifier")
|
| 607 |
+
args = parser.parse_args(argv)
|
| 608 |
+
os.makedirs(args.out_dir, exist_ok=True)
|
| 609 |
+
# This run is the only authority on the reward: an earlier or planted
|
| 610 |
+
# reward file must not stand if this evaluation ends up ungraded.
|
| 611 |
+
for name in ("reward.txt", "reward.json"):
|
| 612 |
+
try:
|
| 613 |
+
os.unlink(os.path.join(args.out_dir, name))
|
| 614 |
+
except FileNotFoundError:
|
| 615 |
+
pass
|
| 616 |
+
oracle = _read_or_empty(args.oracle)
|
| 617 |
+
try:
|
| 618 |
+
oversized = os.path.getsize(args.predicted) > _MAX_PREDICTED_BYTES
|
| 619 |
+
except OSError:
|
| 620 |
+
oversized = False
|
| 621 |
+
predicted = "" if oversized else _read_or_empty(args.predicted)
|
| 622 |
+
if oversized or predicted_too_large(oracle, predicted):
|
| 623 |
+
breakdown = {
|
| 624 |
+
"final_reward": 0.0,
|
| 625 |
+
"evaluation_status": "graded",
|
| 626 |
+
"eval_trustworthy": False,
|
| 627 |
+
"predicted_status": "predicted_too_large",
|
| 628 |
+
}
|
| 629 |
+
_write_outputs(args.out_dir, 0.0, breakdown)
|
| 630 |
+
return 0
|
| 631 |
+
instruction = _read_or_empty(args.instruction)
|
| 632 |
+
api_key, judge_model, judge_endpoint = _judge_config_from_env()
|
| 633 |
+
|
| 634 |
+
fv = format_valid(predicted)
|
| 635 |
+
ss = size_sanity(oracle, predicted)
|
| 636 |
+
ft = file_targeting(oracle, predicted)
|
| 637 |
+
ro = region_overlap(oracle, predicted)
|
| 638 |
+
sim = similarity(oracle, predicted)
|
| 639 |
+
weights = _read_weights_from_env()
|
| 640 |
+
if weights["llm_judge"] <= 0:
|
| 641 |
+
judge_score, judge_status = None, "disabled"
|
| 642 |
+
else:
|
| 643 |
+
judge_score, judge_status = llm_judge(
|
| 644 |
+
instruction=instruction,
|
| 645 |
+
oracle=oracle,
|
| 646 |
+
predicted=predicted,
|
| 647 |
+
api_key=api_key,
|
| 648 |
+
model=judge_model,
|
| 649 |
+
endpoint=judge_endpoint,
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
components: dict[str, float | None] = {
|
| 653 |
+
"format_valid": fv,
|
| 654 |
+
"size_sanity": ss,
|
| 655 |
+
"file_targeting": ft,
|
| 656 |
+
"region_overlap": ro,
|
| 657 |
+
"similarity": sim,
|
| 658 |
+
"llm_judge": judge_score,
|
| 659 |
+
}
|
| 660 |
+
final = combine(components, weights)
|
| 661 |
+
final = max(0.0, min(1.0, final))
|
| 662 |
+
|
| 663 |
+
# Hard cap on catastrophic size mismatches. Without this, a charitable
|
| 664 |
+
# judge can inflate the reward on patches that are dramatically the
|
| 665 |
+
# wrong size (prettier scored 0.23 with size_sanity=0.011 — the judge
|
| 666 |
+
# was lenient at 0.25 despite the patch being a near-no-op vs a
|
| 667 |
+
# 500-line oracle). The cap kicks in only at the extremes.
|
| 668 |
+
if ss < _CATASTROPHIC_SIZE_THRESHOLD:
|
| 669 |
+
final = min(final, _CATASTROPHIC_SIZE_CAP)
|
| 670 |
+
|
| 671 |
+
status = evaluation_status(judge_score, judge_status)
|
| 672 |
+
breakdown = {
|
| 673 |
+
# No reward exists for an ungraded evaluation: null, not a placeholder 0.
|
| 674 |
+
"final_reward": round(final, 6) if status == "graded" else None,
|
| 675 |
+
"evaluation_status": status,
|
| 676 |
+
"eval_trustworthy": judge_score is not None,
|
| 677 |
+
"diagnostic_similarity": round(
|
| 678 |
+
_weighted_mean(components, {k: w for k, w in weights.items() if k != "llm_judge"}),
|
| 679 |
+
6,
|
| 680 |
+
),
|
| 681 |
+
"components": {k: (None if v is None else round(v, 6)) for k, v in components.items()},
|
| 682 |
+
"weights": {k: round(v, 6) for k, v in weights.items()},
|
| 683 |
+
"judge_model": judge_model if judge_status == "ok" else None,
|
| 684 |
+
"judge_endpoint": judge_endpoint,
|
| 685 |
+
"judge_status": judge_status,
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
_write_outputs(args.out_dir, final, breakdown)
|
| 689 |
+
return 0
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def _write_outputs(out_dir: str, final: float, breakdown: dict) -> None:
|
| 693 |
+
# An ungraded evaluation writes no reward file. Harbor then raises
|
| 694 |
+
# RewardFileNotFoundError: the trial is VERIFIER_FAILED, reward_valid is
|
| 695 |
+
# false, and RL consumers (OpenEnv harbor_env -> TRL) drop the rollout
|
| 696 |
+
# instead of training on a 0. Harbor's job mean and pass@k still count the
|
| 697 |
+
# trial as 0, so evaluation stays fail-closed.
|
| 698 |
+
if breakdown["evaluation_status"] == "graded":
|
| 699 |
+
with open(os.path.join(out_dir, "reward.txt"), "w", encoding="utf-8") as f:
|
| 700 |
+
f.write(f"{final:.6f}\n")
|
| 701 |
+
# Harbor's `reward.json` must be a flat map of floats/ints (spec, see
|
| 702 |
+
# <https://harborframework.com/docs/tasks>); our breakdown carries nested
|
| 703 |
+
# dicts, judge strings, and status strings, so it goes to the sidecar the
|
| 704 |
+
# Harbor UI renders under Verifier Logs → Rewards. Mirrors #75 (Neubig)
|
| 705 |
+
# for `_pr_runtime_verifier.py`.
|
| 706 |
+
with open(os.path.join(out_dir, "reward-details.json"), "w", encoding="utf-8") as f:
|
| 707 |
+
json.dump(breakdown, f, indent=2)
|
| 708 |
+
|
| 709 |
+
# Also print to stdout so harbor's log captures the breakdown
|
| 710 |
+
print(json.dumps(breakdown, indent=2))
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def _read_or_empty(path: str) -> str:
|
| 714 |
+
try:
|
| 715 |
+
with open(path, encoding="utf-8") as f:
|
| 716 |
+
return f.read()
|
| 717 |
+
except (OSError, UnicodeDecodeError):
|
| 718 |
+
return ""
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
if __name__ == "__main__":
|
| 722 |
+
sys.exit(main())
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
__all__ = [
|
| 726 |
+
"combine",
|
| 727 |
+
"file_paths",
|
| 728 |
+
"file_targeting",
|
| 729 |
+
"format_valid",
|
| 730 |
+
"hunk_ranges",
|
| 731 |
+
"llm_judge",
|
| 732 |
+
"main",
|
| 733 |
+
"predicted_too_large",
|
| 734 |
+
"region_overlap",
|
| 735 |
+
"similarity",
|
| 736 |
+
"size_sanity",
|
| 737 |
+
]
|
tasks/AeneasVerif__aeneas-1401/environment/Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto-generated by Repo2RLEnv pr_diff — 6-component reward env.
|
| 2 |
+
# Agent-agnostic: the agent (claude-code / openhands / codex / etc.)
|
| 3 |
+
# installs itself at run time via its harbor adapter. We only ship
|
| 4 |
+
# the source repo — the oracle + verifier arrive at verify time via
|
| 5 |
+
# tests/, never baked into the agent's image.
|
| 6 |
+
FROM python:3.12-slim
|
| 7 |
+
ARG GITHUB_TOKEN=
|
| 8 |
+
RUN apt-get update \
|
| 9 |
+
&& apt-get install -y --no-install-recommends git ca-certificates curl \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
RUN git config --global --add safe.directory /workspace \
|
| 12 |
+
&& git config --global init.defaultBranch main \
|
| 13 |
+
&& git config --global advice.detachedHead false
|
| 14 |
+
RUN if [ -n "$GITHUB_TOKEN" ]; then \
|
| 15 |
+
git clone --filter=blob:none https://x-access-token:"${GITHUB_TOKEN}"@github.com/AeneasVerif/aeneas.git /workspace; \
|
| 16 |
+
else \
|
| 17 |
+
git clone --filter=blob:none https://github.com/AeneasVerif/aeneas.git /workspace; \
|
| 18 |
+
fi \
|
| 19 |
+
&& git -C /workspace remote set-url origin https://github.com/AeneasVerif/aeneas.git
|
| 20 |
+
WORKDIR /workspace
|
| 21 |
+
RUN git fetch --depth 1 origin a033718497e1ddd3e3a0e448723f1bc29ac3382a 2>/dev/null \
|
| 22 |
+
|| git fetch --unshallow origin 2>/dev/null || true
|
| 23 |
+
RUN git reset --hard a033718497e1ddd3e3a0e448723f1bc29ac3382a \
|
| 24 |
+
&& git clean -fdx -e .venv -e venv -e __pycache__
|
| 25 |
+
RUN git checkout -q -B base a033718497e1ddd3e3a0e448723f1bc29ac3382a \
|
| 26 |
+
&& git remote remove origin 2>/dev/null || true
|
| 27 |
+
RUN for ref in $(git branch --format='%(refname:short)' | grep -vx base); do git branch -D "$ref" 2>/dev/null || true; done \
|
| 28 |
+
&& git tag -l | xargs -r git tag -d >/dev/null 2>&1 || true \
|
| 29 |
+
&& git for-each-ref --format='%(refname)' refs/remotes 2>/dev/null | xargs -r -n1 git update-ref -d 2>/dev/null || true \
|
| 30 |
+
&& git reflog expire --expire=now --all 2>/dev/null || true \
|
| 31 |
+
&& git gc --prune=now 2>/dev/null || true
|
| 32 |
+
RUN P="$(git rev-parse --git-dir)/objects/pack"; if ls "$P"/*.promisor >/dev/null 2>&1; then \
|
| 33 |
+
git rev-list --objects --all --missing=allow-promisor > "$P/../scrub.list" \
|
| 34 |
+
&& K=$(git pack-objects -q --missing=allow-promisor "$P/scrub" < "$P/../scrub.list") \
|
| 35 |
+
&& rm -f "$P/../scrub.list" "$P"/pack-* "$P"/multi-pack-index* \
|
| 36 |
+
&& touch "$P/scrub-$K.promisor" && git prune --expire=now; \
|
| 37 |
+
fi
|
tasks/AeneasVerif__aeneas-1401/instruction.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Remove duplicate of `core` in 3 identifiers
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
Correct `Aeneas.Std.core.core.clone.CloneGlobal` to `Aeneas.Std.core.clone.CloneGlobal` and similar for two other definitions where the full identifier contains `core.core` (assuming that this was just a mistake with the naming).
|
| 8 |
+
|
| 9 |
+
The side effects of this were minimal but they did cause a Lean warning of duplicated namespace and so downstream projects get the clutter of the warnings.
|
| 10 |
+
|
| 11 |
+
If the double `core` is really wanted then the linter could be silenced for each definition.
|
| 12 |
+
|
| 13 |
+
> Please indicate whether the PR was AI assisted
|
| 14 |
+
|
| 15 |
+
No AI used in this PR
|
| 16 |
+
|
| 17 |
+
## Task
|
| 18 |
+
|
| 19 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `a033718497e1`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1401/solution/patch.diff
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/backends/lean/Aeneas/Std/Core/Core.lean b/backends/lean/Aeneas/Std/Core/Core.lean
|
| 2 |
+
index b93e6aa140..ab6541b002 100644
|
| 3 |
+
--- a/backends/lean/Aeneas/Std/Core/Core.lean
|
| 4 |
+
+++ b/backends/lean/Aeneas/Std/Core/Core.lean
|
| 5 |
+
@@ -35,7 +35,7 @@ def clone.Clone.clone_from.default {Self : Type} (CloneInst : core.clone.Clone S
|
| 6 |
+
CloneInst.clone source
|
| 7 |
+
|
| 8 |
+
@[expose, reducible, rust_trait_impl "core::clone::Clone<alloc::alloc::Global>"]
|
| 9 |
+
-def core.clone.CloneGlobal : core.clone.Clone Global := {
|
| 10 |
+
+def clone.CloneGlobal : core.clone.Clone Global := {
|
| 11 |
+
clone := alloc.alloc.CloneGlobal.clone
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
@@ -56,7 +56,7 @@ def alloc.boxed.CloneBox.clone {T : Type} (cloneInst : core.clone.Clone T) : T
|
| 15 |
+
|
| 16 |
+
@[expose, reducible, rust_trait_impl "core::clone::Clone<Box<@T>>"
|
| 17 |
+
(keepParams := [true, false]) (keepTraitClauses := [true, false])]
|
| 18 |
+
-def core.clone.CloneBox {T : Type} (cloneInst : core.clone.Clone T) : core.clone.Clone T := {
|
| 19 |
+
+def clone.CloneBox {T : Type} (cloneInst : core.clone.Clone T) : core.clone.Clone T := {
|
| 20 |
+
clone := alloc.boxed.CloneBox.clone cloneInst
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@@ -65,7 +65,7 @@ structure marker.Copy (Self : Type) where
|
| 24 |
+
cloneInst : core.clone.Clone Self
|
| 25 |
+
|
| 26 |
+
@[expose, reducible, rust_trait_impl "core::marker::Copy<bool>"]
|
| 27 |
+
-def core.marker.CopyBool : core.marker.Copy Bool := {
|
| 28 |
+
+def marker.CopyBool : core.marker.Copy Bool := {
|
| 29 |
+
cloneInst := core.clone.CloneBool
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
diff --git a/src/extract/ExtractBuiltinLean.ml b/src/extract/ExtractBuiltinLean.ml
|
| 33 |
+
index f8cf6b5312..93979df93d 100644
|
| 34 |
+
--- a/src/extract/ExtractBuiltinLean.ml
|
| 35 |
+
+++ b/src/extract/ExtractBuiltinLean.ml
|
| 36 |
+
@@ -1507,14 +1507,14 @@ let lean_builtin_trait_decls =
|
| 37 |
+
let lean_builtin_trait_impls =
|
| 38 |
+
[
|
| 39 |
+
(* file: "Aeneas/Std/Core/Core.lean", line: 57 *)
|
| 40 |
+
- mk_trait_impl "core::clone::Clone<Box<@T>>" "core.core.clone.CloneBox"
|
| 41 |
+
+ mk_trait_impl "core::clone::Clone<Box<@T>>" "core.clone.CloneBox"
|
| 42 |
+
~keep_params:(Some [ true; false ])
|
| 43 |
+
~keep_trait_clauses:(Some [ true; false ]);
|
| 44 |
+
(* file: "Aeneas/Std/Array/Array.lean", line: 379 *)
|
| 45 |
+
mk_trait_impl "core::clone::Clone<[@T; @N]>" "core.clone.CloneArray";
|
| 46 |
+
(* file: "Aeneas/Std/Core/Core.lean", line: 37 *)
|
| 47 |
+
mk_trait_impl "core::clone::Clone<alloc::alloc::Global>"
|
| 48 |
+
- "core.core.clone.CloneGlobal";
|
| 49 |
+
+ "core.clone.CloneGlobal";
|
| 50 |
+
(* file: "Aeneas/Std/Vec.lean", line: 618 *)
|
| 51 |
+
mk_trait_impl "core::clone::Clone<alloc::vec::Vec<@T>>"
|
| 52 |
+
"core.clone.CloneallocvecVec"
|
| 53 |
+
@@ -1713,7 +1713,7 @@ let lean_builtin_trait_impls =
|
| 54 |
+
(* file: "Aeneas/Std/Array/Array.lean", line: 477 *)
|
| 55 |
+
mk_trait_impl "core::marker::Copy<[@T; @N]>" "Array.Insts.CoreMarkerCopy";
|
| 56 |
+
(* file: "Aeneas/Std/Core/Core.lean", line: 67 *)
|
| 57 |
+
- mk_trait_impl "core::marker::Copy<bool>" "core.core.marker.CopyBool";
|
| 58 |
+
+ mk_trait_impl "core::marker::Copy<bool>" "core.marker.CopyBool";
|
| 59 |
+
(* file: "Aeneas/Std/Core/Ops.lean", line: 31 *)
|
| 60 |
+
mk_trait_impl "core::ops::deref::Deref<Box<@T>, @T>"
|
| 61 |
+
"core.ops.deref.DerefBoxInst"
|
tasks/AeneasVerif__aeneas-1401/solution/solve.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euxo pipefail
|
| 3 |
+
cd /workspace
|
| 4 |
+
git config --global --add safe.directory /workspace
|
| 5 |
+
PATCH="$(dirname "$0")/patch.diff"
|
| 6 |
+
git apply --verbose --reject "$PATCH"
|
tasks/AeneasVerif__aeneas-1401/task.toml
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "trending/AeneasVerif__aeneas-1401"
|
| 5 |
+
description = "Remove duplicate of `core` in 3 identifiers"
|
| 6 |
+
|
| 7 |
+
[metadata]
|
| 8 |
+
difficulty = "small"
|
| 9 |
+
category = "bugfix"
|
| 10 |
+
keywords = [
|
| 11 |
+
"aeneas",
|
| 12 |
+
"pr_diff",
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
[metadata.repo2env]
|
| 16 |
+
pipeline = "pr_diff"
|
| 17 |
+
pipeline_version = "0.3.0"
|
| 18 |
+
repo = "AeneasVerif/aeneas"
|
| 19 |
+
ref = "a033718497e1ddd3e3a0e448723f1bc29ac3382a"
|
| 20 |
+
reference = "https://github.com/AeneasVerif/aeneas/pull/1401"
|
| 21 |
+
source_access = "auto"
|
| 22 |
+
built_at = "2026-11-16T16:10:00.163763+00:00"
|
| 23 |
+
reward_kinds = [
|
| 24 |
+
"diff_similarity",
|
| 25 |
+
]
|
| 26 |
+
spec_version = "0.2.0"
|
| 27 |
+
content_hash = "sha256:24921d29397768320a759b61ebbf76016d67f19e18ea71a3178143cc24fce227"
|
| 28 |
+
|
| 29 |
+
[metadata.repo2env.pr_diff]
|
| 30 |
+
pr_merged_at = "2026-10-06T14:20:02Z"
|
| 31 |
+
diff_format = "unified"
|
| 32 |
+
context_files = [
|
| 33 |
+
"backends/lean/Aeneas/Std/Core/Core.lean",
|
| 34 |
+
"src/extract/ExtractBuiltinLean.ml",
|
| 35 |
+
]
|
| 36 |
+
bootstrap_image = "python:3.12-slim"
|
| 37 |
+
|
| 38 |
+
[metadata.repo2env.reward_calibration]
|
| 39 |
+
baseline_reward = 0.0
|
| 40 |
+
loc_changed = 12
|
| 41 |
+
difficulty = "small"
|
| 42 |
+
|
| 43 |
+
[metadata.repo2env.evaluation]
|
| 44 |
+
schema_version = "1"
|
| 45 |
+
status = "unverified"
|
| 46 |
+
stage = "generation"
|
| 47 |
+
reason_codes = [
|
| 48 |
+
"validation_not_run",
|
| 49 |
+
]
|
| 50 |
+
detail = "Generated task; validation has not been established."
|
| 51 |
+
provenance = "unknown"
|
| 52 |
+
evidence = []
|
| 53 |
+
|
| 54 |
+
[metadata.repo2env.reproducibility]
|
| 55 |
+
mode = "inline_dockerfile"
|
| 56 |
+
image_ref = "python:3.12-slim"
|
| 57 |
+
image_tag = "python:3.12-slim"
|
| 58 |
+
image_visibility = "public"
|
| 59 |
+
pushed_at = "2026-11-16T16:19:57.824610+00:00"
|
| 60 |
+
pushed_by = "scalingX"
|
| 61 |
+
inline_recipe_sha256 = "sha256:4b13fc5a8989370fa2841c67ec39754ae37e88a1f7f6ed77f89753b3e26160af"
|
| 62 |
+
inline_recipe_lines = 37
|
| 63 |
+
inline_recipe_source = "user_dockerfile"
|
| 64 |
+
|
| 65 |
+
[agent]
|
| 66 |
+
timeout_sec = 1800.0
|
| 67 |
+
|
| 68 |
+
[verifier]
|
| 69 |
+
timeout_sec = 300.0
|
tasks/AeneasVerif__aeneas-1401/tests/capture.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standalone PR-diff capture without executing workspace Git configuration.
|
| 2 |
+
|
| 3 |
+
The emitted task uses a regular clone with a pinned base commit. Only its
|
| 4 |
+
object store is read: refs, index, config, hooks and replacement refs are not
|
| 5 |
+
used. This is a configuration boundary, not a sandbox for a malicious process
|
| 6 |
+
that can modify the verifier, binaries or object store while capture runs.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import tempfile
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def capture(workspace: Path, base_commit: str) -> bytes:
|
| 23 |
+
"""Capture tracked and new files through a fresh private Git index."""
|
| 24 |
+
if not re.fullmatch(r"[a-fA-F0-9]{40}", base_commit):
|
| 25 |
+
raise ValueError("Expected the task's pinned SHA-1 base commit")
|
| 26 |
+
objects = workspace.resolve() / ".git" / "objects"
|
| 27 |
+
if not objects.is_dir():
|
| 28 |
+
raise ValueError("The task's cloned Git object store is missing")
|
| 29 |
+
git = shutil.which("git", path=os.defpath)
|
| 30 |
+
if git is None:
|
| 31 |
+
raise FileNotFoundError("System git is unavailable")
|
| 32 |
+
with tempfile.TemporaryDirectory(prefix="r2e-diff-") as temporary:
|
| 33 |
+
private = Path(temporary)
|
| 34 |
+
# Do not forward GIT_CONFIG_PARAMETERS/COUNT, external diff programs,
|
| 35 |
+
# system/global includes, user attributes, templates or credential env.
|
| 36 |
+
env = {
|
| 37 |
+
"PATH": os.defpath,
|
| 38 |
+
"HOME": temporary,
|
| 39 |
+
"XDG_CONFIG_HOME": temporary,
|
| 40 |
+
"GIT_CONFIG_NOSYSTEM": "1",
|
| 41 |
+
"GIT_CONFIG_GLOBAL": os.devnull,
|
| 42 |
+
"GIT_ATTR_NOSYSTEM": "1",
|
| 43 |
+
"GIT_NO_REPLACE_OBJECTS": "1",
|
| 44 |
+
"GIT_NO_LAZY_FETCH": "1",
|
| 45 |
+
"GIT_TERMINAL_PROMPT": "0",
|
| 46 |
+
"LC_ALL": "C",
|
| 47 |
+
}
|
| 48 |
+
subprocess.run(
|
| 49 |
+
[git, "init", "--quiet", "--template=", str(private / "repository")],
|
| 50 |
+
env=env,
|
| 51 |
+
cwd=private,
|
| 52 |
+
check=True,
|
| 53 |
+
capture_output=True,
|
| 54 |
+
timeout=60,
|
| 55 |
+
)
|
| 56 |
+
env["GIT_ALTERNATE_OBJECT_DIRECTORIES"] = json.dumps(str(objects), ensure_ascii=False)
|
| 57 |
+
command = [
|
| 58 |
+
git,
|
| 59 |
+
f"--git-dir={private / 'repository/.git'}",
|
| 60 |
+
f"--work-tree={workspace.resolve()}",
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def run(*args: str) -> bytes:
|
| 64 |
+
return subprocess.run(
|
| 65 |
+
[*command, *args],
|
| 66 |
+
env=env,
|
| 67 |
+
cwd=workspace,
|
| 68 |
+
check=True,
|
| 69 |
+
capture_output=True,
|
| 70 |
+
timeout=60,
|
| 71 |
+
).stdout
|
| 72 |
+
|
| 73 |
+
run("read-tree", f"{base_commit}^{{tree}}")
|
| 74 |
+
# All filter drivers are undefined in the private configuration. The
|
| 75 |
+
# workspace's clean filters, fsmonitor and hooks cannot be invoked.
|
| 76 |
+
run("add", "--all", "--", ".")
|
| 77 |
+
return run("diff", "--cached", "--no-ext-diff", "--no-textconv", base_commit, "--")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def main(argv: list[str] | None = None) -> int:
|
| 81 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 82 |
+
parser.add_argument("workspace", type=Path)
|
| 83 |
+
parser.add_argument("base_commit")
|
| 84 |
+
args = parser.parse_args(argv)
|
| 85 |
+
try:
|
| 86 |
+
patch = capture(args.workspace, args.base_commit)
|
| 87 |
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
| 88 |
+
# Do not echo child stderr: it may contain workspace-controlled data.
|
| 89 |
+
sys.stderr.write(f"PR-diff capture failed ({type(exc).__name__})\n")
|
| 90 |
+
return 1
|
| 91 |
+
sys.stdout.buffer.write(patch)
|
| 92 |
+
return 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
sys.exit(main())
|
tasks/AeneasVerif__aeneas-1401/tests/instruction.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Remove duplicate of `core` in 3 identifiers
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
Correct `Aeneas.Std.core.core.clone.CloneGlobal` to `Aeneas.Std.core.clone.CloneGlobal` and similar for two other definitions where the full identifier contains `core.core` (assuming that this was just a mistake with the naming).
|
| 8 |
+
|
| 9 |
+
The side effects of this were minimal but they did cause a Lean warning of duplicated namespace and so downstream projects get the clutter of the warnings.
|
| 10 |
+
|
| 11 |
+
If the double `core` is really wanted then the linter could be silenced for each definition.
|
| 12 |
+
|
| 13 |
+
> Please indicate whether the PR was AI assisted
|
| 14 |
+
|
| 15 |
+
No AI used in this PR
|
| 16 |
+
|
| 17 |
+
## Task
|
| 18 |
+
|
| 19 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `a033718497e1`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1401/tests/oracle.patch
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/backends/lean/Aeneas/Std/Core/Core.lean b/backends/lean/Aeneas/Std/Core/Core.lean
|
| 2 |
+
index b93e6aa140..ab6541b002 100644
|
| 3 |
+
--- a/backends/lean/Aeneas/Std/Core/Core.lean
|
| 4 |
+
+++ b/backends/lean/Aeneas/Std/Core/Core.lean
|
| 5 |
+
@@ -35,7 +35,7 @@ def clone.Clone.clone_from.default {Self : Type} (CloneInst : core.clone.Clone S
|
| 6 |
+
CloneInst.clone source
|
| 7 |
+
|
| 8 |
+
@[expose, reducible, rust_trait_impl "core::clone::Clone<alloc::alloc::Global>"]
|
| 9 |
+
-def core.clone.CloneGlobal : core.clone.Clone Global := {
|
| 10 |
+
+def clone.CloneGlobal : core.clone.Clone Global := {
|
| 11 |
+
clone := alloc.alloc.CloneGlobal.clone
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
@@ -56,7 +56,7 @@ def alloc.boxed.CloneBox.clone {T : Type} (cloneInst : core.clone.Clone T) : T
|
| 15 |
+
|
| 16 |
+
@[expose, reducible, rust_trait_impl "core::clone::Clone<Box<@T>>"
|
| 17 |
+
(keepParams := [true, false]) (keepTraitClauses := [true, false])]
|
| 18 |
+
-def core.clone.CloneBox {T : Type} (cloneInst : core.clone.Clone T) : core.clone.Clone T := {
|
| 19 |
+
+def clone.CloneBox {T : Type} (cloneInst : core.clone.Clone T) : core.clone.Clone T := {
|
| 20 |
+
clone := alloc.boxed.CloneBox.clone cloneInst
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@@ -65,7 +65,7 @@ structure marker.Copy (Self : Type) where
|
| 24 |
+
cloneInst : core.clone.Clone Self
|
| 25 |
+
|
| 26 |
+
@[expose, reducible, rust_trait_impl "core::marker::Copy<bool>"]
|
| 27 |
+
-def core.marker.CopyBool : core.marker.Copy Bool := {
|
| 28 |
+
+def marker.CopyBool : core.marker.Copy Bool := {
|
| 29 |
+
cloneInst := core.clone.CloneBool
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
diff --git a/src/extract/ExtractBuiltinLean.ml b/src/extract/ExtractBuiltinLean.ml
|
| 33 |
+
index f8cf6b5312..93979df93d 100644
|
| 34 |
+
--- a/src/extract/ExtractBuiltinLean.ml
|
| 35 |
+
+++ b/src/extract/ExtractBuiltinLean.ml
|
| 36 |
+
@@ -1507,14 +1507,14 @@ let lean_builtin_trait_decls =
|
| 37 |
+
let lean_builtin_trait_impls =
|
| 38 |
+
[
|
| 39 |
+
(* file: "Aeneas/Std/Core/Core.lean", line: 57 *)
|
| 40 |
+
- mk_trait_impl "core::clone::Clone<Box<@T>>" "core.core.clone.CloneBox"
|
| 41 |
+
+ mk_trait_impl "core::clone::Clone<Box<@T>>" "core.clone.CloneBox"
|
| 42 |
+
~keep_params:(Some [ true; false ])
|
| 43 |
+
~keep_trait_clauses:(Some [ true; false ]);
|
| 44 |
+
(* file: "Aeneas/Std/Array/Array.lean", line: 379 *)
|
| 45 |
+
mk_trait_impl "core::clone::Clone<[@T; @N]>" "core.clone.CloneArray";
|
| 46 |
+
(* file: "Aeneas/Std/Core/Core.lean", line: 37 *)
|
| 47 |
+
mk_trait_impl "core::clone::Clone<alloc::alloc::Global>"
|
| 48 |
+
- "core.core.clone.CloneGlobal";
|
| 49 |
+
+ "core.clone.CloneGlobal";
|
| 50 |
+
(* file: "Aeneas/Std/Vec.lean", line: 618 *)
|
| 51 |
+
mk_trait_impl "core::clone::Clone<alloc::vec::Vec<@T>>"
|
| 52 |
+
"core.clone.CloneallocvecVec"
|
| 53 |
+
@@ -1713,7 +1713,7 @@ let lean_builtin_trait_impls =
|
| 54 |
+
(* file: "Aeneas/Std/Array/Array.lean", line: 477 *)
|
| 55 |
+
mk_trait_impl "core::marker::Copy<[@T; @N]>" "Array.Insts.CoreMarkerCopy";
|
| 56 |
+
(* file: "Aeneas/Std/Core/Core.lean", line: 67 *)
|
| 57 |
+
- mk_trait_impl "core::marker::Copy<bool>" "core.core.marker.CopyBool";
|
| 58 |
+
+ mk_trait_impl "core::marker::Copy<bool>" "core.marker.CopyBool";
|
| 59 |
+
(* file: "Aeneas/Std/Core/Ops.lean", line: 31 *)
|
| 60 |
+
mk_trait_impl "core::ops::deref::Deref<Box<@T>, @T>"
|
| 61 |
+
"core.ops.deref.DerefBoxInst"
|
tasks/AeneasVerif__aeneas-1401/tests/test.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -uxo pipefail
|
| 3 |
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
| 4 |
+
cd /workspace
|
| 5 |
+
mkdir -p /logs/verifier
|
| 6 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json /logs/verifier/reward-details.json
|
| 7 |
+
CAPTURE_DIR="$(mktemp -d)" || exit 1
|
| 8 |
+
trap 'rm -rf -- "$CAPTURE_DIR"' EXIT
|
| 9 |
+
if ! python3 -I "$SCRIPT_DIR/capture.py" /workspace a033718497e1ddd3e3a0e448723f1bc29ac3382a > "$CAPTURE_DIR/predicted.patch"; then
|
| 10 |
+
echo "0.0" > /logs/verifier/reward.txt
|
| 11 |
+
printf '%s' '{"final_reward": 0.0, "evaluation_status": "graded", "eval_trustworthy": false, "capture_status": "error"}' > /logs/verifier/reward-details.json
|
| 12 |
+
exit 0
|
| 13 |
+
fi
|
| 14 |
+
rm -f /logs/verifier/predicted.patch
|
| 15 |
+
cp -- "$CAPTURE_DIR/predicted.patch" /logs/verifier/predicted.patch
|
| 16 |
+
: 'START_VERIFY_OUTPUT'
|
| 17 |
+
if ! python3 -I "$SCRIPT_DIR/verifier.py" \
|
| 18 |
+
"$SCRIPT_DIR/oracle.patch" \
|
| 19 |
+
"$CAPTURE_DIR/predicted.patch" \
|
| 20 |
+
"$SCRIPT_DIR/instruction.md"; then
|
| 21 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/reward.json
|
| 22 |
+
printf '%s' '{"final_reward": null, "reward": null, "evaluation_status": "ungraded", "eval_trustworthy": false, "verifier_status": "error"}' > /logs/verifier/reward-details.json
|
| 23 |
+
fi
|
| 24 |
+
: 'END_VERIFY_OUTPUT'
|
| 25 |
+
exit 0
|
tasks/AeneasVerif__aeneas-1401/tests/verifier.py
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, NOT a helper used at generation time. Generation emits
|
| 5 |
+
its source as ``tests/verifier.py``. Harbor delivers it at verify time,
|
| 6 |
+
and ``tests/test.sh`` invokes it with the oracle, predicted patch and instruction.
|
| 7 |
+
|
| 8 |
+
Reward = weighted sum of 6 components (5 deterministic + 1 required LLM):
|
| 9 |
+
|
| 10 |
+
format_valid (0 or 1) — predicted parses as a unified diff (guard)
|
| 11 |
+
size_sanity ([0, 1]) — min(oracle_loc, pred_loc) / max(...)
|
| 12 |
+
catches "rampage through the codebase"
|
| 13 |
+
file_targeting ([0, 1]) — F1 over changed-file sets (NOT Jaccard —
|
| 14 |
+
symmetric penalty over-punishes extras)
|
| 15 |
+
region_overlap ([0, 1]) — predicted hunks overlap oracle hunks
|
| 16 |
+
(strongest spatial-localization signal)
|
| 17 |
+
similarity ([0, 1]) — SequenceMatcher ratio over +/- lines only
|
| 18 |
+
(no free credit for context lines)
|
| 19 |
+
llm_judge ([0, 1] or null) — an LLM rates "does this address the issue?"
|
| 20 |
+
Anthropic Haiku by default; any OpenAI-
|
| 21 |
+
compatible server via ``R2E_JUDGE_ENDPOINT``.
|
| 22 |
+
null when the judge is unavailable
|
| 23 |
+
(no key or model, network, unreadable
|
| 24 |
+
reply) → ungraded, no reward file; a
|
| 25 |
+
reply without a valid score (refusal,
|
| 26 |
+
content filter, empty, no "score") → a
|
| 27 |
+
graded 0
|
| 28 |
+
|
| 29 |
+
Default weights: 0.00 / 0.08 / 0.12 / 0.20 / 0.10 / 0.50 (retuned from
|
| 30 |
+
the original 0.05 / 0.05 / 0.10 / 0.20 / 0.20 / 0.40 after a 23-task
|
| 31 |
+
pilot — see the comment block above ``_DEFAULT_WEIGHTS`` below).
|
| 32 |
+
Override per-task via ``task.toml.metadata`` or per-run via env vars
|
| 33 |
+
``R2E_W_FORMAT`` / ``R2E_W_SIZE`` / ``R2E_W_FILE`` / ``R2E_W_REGION`` /
|
| 34 |
+
``R2E_W_SIM`` / ``R2E_W_JUDGE`` (pass via harbor ``--ve`` so they
|
| 35 |
+
reach the verifier container).
|
| 36 |
+
|
| 37 |
+
Judge routing, also via ``--ve``: ``R2E_JUDGE_MODEL`` picks the model
|
| 38 |
+
(default Haiku); ``R2E_JUDGE_ENDPOINT`` points at an OpenAI-compatible
|
| 39 |
+
server (vLLM, Ollama, a gateway) and switches the request to
|
| 40 |
+
``<endpoint>/chat/completions`` with a bearer token from
|
| 41 |
+
``R2E_JUDGE_API_KEY`` — or a placeholder when unset, since self-hosted
|
| 42 |
+
servers ignore it. ``ANTHROPIC_API_KEY`` is only read on the default
|
| 43 |
+
route and is never sent to a custom endpoint.
|
| 44 |
+
|
| 45 |
+
Final reward is clipped to [0, 1] and additionally clamped to ≤ 0.40
|
| 46 |
+
when ``size_sanity < 0.10`` (catastrophic-size hard cap — stops a
|
| 47 |
+
charitable judge from inflating scores on wildly wrong-sized patches).
|
| 48 |
+
|
| 49 |
+
Outputs (mirrors `_pr_runtime_verifier.py` after #75):
|
| 50 |
+
/logs/verifier/reward.txt — single float (Harbor reads this);
|
| 51 |
+
graded runs only
|
| 52 |
+
/logs/verifier/reward-details.json — full component breakdown + status
|
| 53 |
+
(structured diagnostics; Harbor's `reward.json` schema is flat-numeric-
|
| 54 |
+
only, so the breakdown goes to the `reward-details.json` sidecar which
|
| 55 |
+
Harbor renders under Verifier Logs → Rewards)
|
| 56 |
+
|
| 57 |
+
Pure stdlib — uses only ``difflib``, ``json``, ``os``, ``re``,
|
| 58 |
+
``urllib``, ``sys``. The same module is imported by the unit tests
|
| 59 |
+
under ``tests/test_pr_diff_verifier.py`` so the in-container behavior
|
| 60 |
+
stays in lockstep with what we test.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
from __future__ import annotations
|
| 64 |
+
|
| 65 |
+
import argparse
|
| 66 |
+
import difflib
|
| 67 |
+
import json
|
| 68 |
+
import math
|
| 69 |
+
import os
|
| 70 |
+
import re
|
| 71 |
+
import sys
|
| 72 |
+
import urllib.error
|
| 73 |
+
import urllib.request
|
| 74 |
+
|
| 75 |
+
# ---------------------------------------------------------------------------
|
| 76 |
+
# Parsing helpers (shared by multiple components)
|
| 77 |
+
# ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
_DIFF_HEADER_RE = re.compile(r"^diff --git a/(\S+) b/(\S+)$")
|
| 80 |
+
_HUNK_HEADER_RE = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
| 81 |
+
_FILE_MARKER_RE = re.compile(r"^(?:---|\+\+\+) ")
|
| 82 |
+
_INDEX_RE = re.compile(r"^index ")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def file_paths(diff: str) -> set[str]:
|
| 86 |
+
"""Return the set of ``b/<path>`` paths touched by a unified diff."""
|
| 87 |
+
paths: set[str] = set()
|
| 88 |
+
for line in diff.splitlines():
|
| 89 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 90 |
+
if m:
|
| 91 |
+
paths.add(m.group(2))
|
| 92 |
+
return paths
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def hunk_ranges(diff: str) -> dict[str, list[tuple[int, int]]]:
|
| 96 |
+
"""For each touched file, return list of (start_line, end_line) ranges
|
| 97 |
+
on the **post-change** side (the ``+`` numbers in ``@@ -X +Y @@``).
|
| 98 |
+
"""
|
| 99 |
+
out: dict[str, list[tuple[int, int]]] = {}
|
| 100 |
+
current_file: str | None = None
|
| 101 |
+
for line in diff.splitlines():
|
| 102 |
+
m = _DIFF_HEADER_RE.match(line)
|
| 103 |
+
if m:
|
| 104 |
+
current_file = m.group(2)
|
| 105 |
+
out.setdefault(current_file, [])
|
| 106 |
+
continue
|
| 107 |
+
m = _HUNK_HEADER_RE.match(line)
|
| 108 |
+
if m and current_file is not None:
|
| 109 |
+
new_start = int(m.group(3))
|
| 110 |
+
new_count = int(m.group(4) or "1")
|
| 111 |
+
end = new_start + max(new_count - 1, 0)
|
| 112 |
+
out[current_file].append((new_start, end))
|
| 113 |
+
return out
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _normalize_changes_only(diff: str) -> list[str]:
|
| 117 |
+
"""Return the +/- lines (the actual changes) for similarity scoring.
|
| 118 |
+
|
| 119 |
+
Drops:
|
| 120 |
+
- ``diff --git`` / ``index abc..def`` metadata
|
| 121 |
+
- ``@@ ... @@`` hunk markers (volatile line numbers)
|
| 122 |
+
- context lines (no +/- prefix) — these are unchanged code, scoring
|
| 123 |
+
them inflates similarity for trivial patches
|
| 124 |
+
Keeps file-marker lines (``--- a/foo`` / ``+++ b/foo``) so file identity
|
| 125 |
+
stays in the comparison; normalizes off the tab+timestamp suffix git
|
| 126 |
+
sometimes appends.
|
| 127 |
+
"""
|
| 128 |
+
out: list[str] = []
|
| 129 |
+
for line in diff.splitlines():
|
| 130 |
+
if _DIFF_HEADER_RE.match(line) or _INDEX_RE.match(line):
|
| 131 |
+
continue
|
| 132 |
+
if _HUNK_HEADER_RE.match(line):
|
| 133 |
+
continue
|
| 134 |
+
if _FILE_MARKER_RE.match(line):
|
| 135 |
+
out.append(line.split("\t")[0].strip())
|
| 136 |
+
continue
|
| 137 |
+
# +/- lines (actual changes)
|
| 138 |
+
if line.startswith("+") or line.startswith("-"):
|
| 139 |
+
out.append(line)
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# ---------------------------------------------------------------------------
|
| 144 |
+
# Reward components
|
| 145 |
+
# ---------------------------------------------------------------------------
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def format_valid(predicted: str) -> float:
|
| 149 |
+
"""1.0 if the predicted text looks like a unified diff; else 0.0.
|
| 150 |
+
|
| 151 |
+
Requires both a ``diff --git`` header and at least one real +/- line
|
| 152 |
+
(not the ``---`` / ``+++`` file-marker lines).
|
| 153 |
+
"""
|
| 154 |
+
if not predicted.strip():
|
| 155 |
+
return 0.0
|
| 156 |
+
has_header = False
|
| 157 |
+
has_change = False
|
| 158 |
+
for line in predicted.splitlines():
|
| 159 |
+
if _DIFF_HEADER_RE.match(line):
|
| 160 |
+
has_header = True
|
| 161 |
+
elif (line.startswith("+") or line.startswith("-")) and not line.startswith(
|
| 162 |
+
("+++ ", "--- ")
|
| 163 |
+
):
|
| 164 |
+
has_change = True
|
| 165 |
+
if has_header and has_change:
|
| 166 |
+
return 1.0
|
| 167 |
+
return 0.0
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def file_targeting(oracle: str, predicted: str) -> float:
|
| 171 |
+
"""F1 over the changed-file sets.
|
| 172 |
+
|
| 173 |
+
Why F1 instead of Jaccard:
|
| 174 |
+
- Missing an oracle file (FN) is a *big* failure.
|
| 175 |
+
- Touching one unrelated extra file (FP) is a small one.
|
| 176 |
+
- Jaccard punishes both equally, which over-penalizes the agent
|
| 177 |
+
for any extra exploration.
|
| 178 |
+
- F1 weights TP twice, giving partial credit when the agent finds
|
| 179 |
+
most-but-not-all of the oracle files even with some noise.
|
| 180 |
+
|
| 181 |
+
Returns 1.0 if both sides touch zero files (degenerate).
|
| 182 |
+
"""
|
| 183 |
+
o = file_paths(oracle)
|
| 184 |
+
p = file_paths(predicted)
|
| 185 |
+
if not o and not p:
|
| 186 |
+
return 1.0
|
| 187 |
+
tp = len(o & p)
|
| 188 |
+
fn = len(o - p)
|
| 189 |
+
fp = len(p - o)
|
| 190 |
+
if tp == 0:
|
| 191 |
+
return 0.0
|
| 192 |
+
# F1 = 2·TP / (2·TP + FN + FP)
|
| 193 |
+
return (2 * tp) / (2 * tp + fn + fp)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _count_loc_changes(diff: str) -> int:
|
| 197 |
+
"""Number of real +/- lines (excluding file-marker lines)."""
|
| 198 |
+
n = 0
|
| 199 |
+
for line in diff.splitlines():
|
| 200 |
+
if (line.startswith("+") or line.startswith("-")) and not line.startswith(("+++ ", "--- ")):
|
| 201 |
+
n += 1
|
| 202 |
+
return n
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def size_sanity(oracle: str, predicted: str) -> float:
|
| 206 |
+
"""Penalize predicted patches that are wildly larger / smaller than the oracle.
|
| 207 |
+
|
| 208 |
+
Returns ``min(oracle_loc, predicted_loc) / max(oracle_loc, predicted_loc)``.
|
| 209 |
+
Both empty → 1.0 (degenerate but well-defined). One empty → 0.0.
|
| 210 |
+
|
| 211 |
+
This is the "don't rampage through the codebase" guard — a 200-line
|
| 212 |
+
diff for a 3-line oracle scores ~0.015 here even if every other
|
| 213 |
+
component looks OK.
|
| 214 |
+
"""
|
| 215 |
+
o_loc = _count_loc_changes(oracle)
|
| 216 |
+
p_loc = _count_loc_changes(predicted)
|
| 217 |
+
if o_loc == 0 and p_loc == 0:
|
| 218 |
+
return 1.0
|
| 219 |
+
if o_loc == 0 or p_loc == 0:
|
| 220 |
+
return 0.0
|
| 221 |
+
return min(o_loc, p_loc) / max(o_loc, p_loc)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def region_overlap(oracle: str, predicted: str, *, slack_lines: int = 5) -> float:
|
| 225 |
+
"""For each oracle hunk, did the predicted diff edit a line within
|
| 226 |
+
``slack_lines`` of that hunk in the same file?
|
| 227 |
+
|
| 228 |
+
Returns the fraction of oracle hunks that have at least one matching
|
| 229 |
+
predicted hunk. ``slack_lines`` tolerates slight line-number drift
|
| 230 |
+
when git diff renders the predicted hunk at a different offset.
|
| 231 |
+
"""
|
| 232 |
+
o_ranges = hunk_ranges(oracle)
|
| 233 |
+
p_ranges = hunk_ranges(predicted)
|
| 234 |
+
total = sum(len(v) for v in o_ranges.values())
|
| 235 |
+
if total == 0:
|
| 236 |
+
return 1.0 # oracle has no hunks (degenerate)
|
| 237 |
+
matched = 0
|
| 238 |
+
for fname, ranges in o_ranges.items():
|
| 239 |
+
p_in_file = p_ranges.get(fname, [])
|
| 240 |
+
for o_start, o_end in ranges:
|
| 241 |
+
for p_start, p_end in p_in_file:
|
| 242 |
+
# Interval overlap with slack — max(starts) <= min(ends) + slack
|
| 243 |
+
if max(o_start, p_start) <= min(o_end, p_end) + slack_lines:
|
| 244 |
+
matched += 1
|
| 245 |
+
break
|
| 246 |
+
return matched / total
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def similarity(oracle: str, predicted: str) -> float:
|
| 250 |
+
"""SequenceMatcher ratio over +/- lines only.
|
| 251 |
+
|
| 252 |
+
No free credit for context lines — fixes the v0.8.1 inflation where a
|
| 253 |
+
one-line fix scored ~0.7 just because the 3 context lines on either
|
| 254 |
+
side were "matched".
|
| 255 |
+
"""
|
| 256 |
+
if not predicted.strip():
|
| 257 |
+
return 0.0
|
| 258 |
+
o = _normalize_changes_only(oracle)
|
| 259 |
+
p = _normalize_changes_only(predicted)
|
| 260 |
+
if not o:
|
| 261 |
+
return 0.0
|
| 262 |
+
# Exact matching is quadratic-or-worse on repeated lines: 200 x 2,000
|
| 263 |
+
# identical changed lines take ~2 s, 500 x 5,000 take ~35 s, which can
|
| 264 |
+
# run the verifier past Harbor's timeout. Above this many line pairs,
|
| 265 |
+
# fall back to difflib's popular-element heuristic, which stays fast.
|
| 266 |
+
exact = len(o) * len(p) <= _SIMILARITY_EXACT_PAIRS
|
| 267 |
+
return difflib.SequenceMatcher(a=o, b=p, autojunk=not exact).ratio()
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
_SIMILARITY_EXACT_PAIRS = 400_000
|
| 271 |
+
|
| 272 |
+
# A predicted patch over 10x the oracle's changed lines is already a
|
| 273 |
+
# catastrophic size mismatch (size_sanity < 0.10). Past this floor such a
|
| 274 |
+
# patch is a graded 0 instead of being scored, so one huge file can't slow
|
| 275 |
+
# the verifier past its timeout and turn a failing episode into a dropped,
|
| 276 |
+
# ungraded one. The byte cap stops it from being read at all.
|
| 277 |
+
_MAX_PREDICTED_FACTOR = 10
|
| 278 |
+
_MAX_PREDICTED_FLOOR_LOC = 1_000
|
| 279 |
+
_MAX_PREDICTED_BYTES = 16 * 1024 * 1024
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def predicted_too_large(oracle: str, predicted: str) -> bool:
|
| 283 |
+
"""Whether the predicted patch is too large to score (a graded 0)."""
|
| 284 |
+
limit = max(_MAX_PREDICTED_FACTOR * _count_loc_changes(oracle), _MAX_PREDICTED_FLOOR_LOC)
|
| 285 |
+
return _count_loc_changes(predicted) > limit
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# ---------------------------------------------------------------------------
|
| 289 |
+
# LLM-as-judge (Anthropic Messages API, stdlib urllib)
|
| 290 |
+
# ---------------------------------------------------------------------------
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
_JUDGE_PROMPT = (
|
| 294 |
+
"You are scoring a code-fix patch on whether it logically addresses the "
|
| 295 |
+
"described issue. Output a single JSON object: "
|
| 296 |
+
'{{"score": <float in [0,1]>, "reasoning": "<<=30 words"}}.\n\n'
|
| 297 |
+
"DO NOT use the oracle to grade. Score on:\n"
|
| 298 |
+
" - Does the predicted diff touch code regions that could plausibly fix the issue?\n"
|
| 299 |
+
" - Is the change direction consistent with what the issue describes?\n"
|
| 300 |
+
" - Is it a real attempt (not boilerplate, not no-op)?\n\n"
|
| 301 |
+
"Issue:\n{instruction}\n\n"
|
| 302 |
+
"Oracle (reference fix for comparison only — don't grade on similarity to it):\n"
|
| 303 |
+
"{oracle}\n\n"
|
| 304 |
+
"Predicted:\n{predicted}\n\n"
|
| 305 |
+
"Return ONLY the JSON object."
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
_DEFAULT_JUDGE_MODEL = "claude-haiku-4-5-20251001"
|
| 310 |
+
_ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages"
|
| 311 |
+
# Bearer token for a self-hosted judge when R2E_JUDGE_API_KEY is unset. vLLM /
|
| 312 |
+
# Ollama ignore it; the OpenAI wire format still wants one. Same value llm.py uses.
|
| 313 |
+
_PLACEHOLDER_API_KEY = "EMPTY"
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def llm_judge(
|
| 317 |
+
*,
|
| 318 |
+
instruction: str,
|
| 319 |
+
oracle: str,
|
| 320 |
+
predicted: str,
|
| 321 |
+
api_key: str,
|
| 322 |
+
model: str = _DEFAULT_JUDGE_MODEL,
|
| 323 |
+
timeout: int = 60,
|
| 324 |
+
endpoint: str | None = None,
|
| 325 |
+
) -> tuple[float | None, str]:
|
| 326 |
+
"""Return ``(score, status)``.
|
| 327 |
+
|
| 328 |
+
``score`` is a float in [0, 1] on success, ``None`` on failure.
|
| 329 |
+
``status`` is a short string: ``"ok"`` / ``"no_api_key"`` /
|
| 330 |
+
``"no_judge_model"`` / ``"empty_predicted"`` / ``"network"`` /
|
| 331 |
+
``"parse"`` / ``"output_limit"`` / ``"missing_score"`` / ``"invalid_score"``.
|
| 332 |
+
``output_limit`` means the judge exhausted its configured token budget
|
| 333 |
+
(ungraded, even if a partial answer contains a score). ``parse`` means
|
| 334 |
+
the provider's body isn't JSON or has the wrong shape (ungraded); a reply
|
| 335 |
+
with no usable text (refusal, content filter, empty) or no valid score is
|
| 336 |
+
``missing_score`` / ``invalid_score`` (a graded 0). A missing score never
|
| 337 |
+
increases the other weights.
|
| 338 |
+
|
| 339 |
+
``endpoint`` — base URL of an OpenAI-compatible server. When set, the
|
| 340 |
+
request goes to ``<endpoint>/chat/completions`` with ``api_key`` as a
|
| 341 |
+
bearer token, at temperature 0, and ``model`` must be given explicitly;
|
| 342 |
+
otherwise it goes to Anthropic's Messages API unchanged.
|
| 343 |
+
"""
|
| 344 |
+
if not api_key:
|
| 345 |
+
return None, "no_api_key"
|
| 346 |
+
if endpoint and not model:
|
| 347 |
+
return None, "no_judge_model"
|
| 348 |
+
if not predicted.strip():
|
| 349 |
+
return 0.0, "empty_predicted"
|
| 350 |
+
|
| 351 |
+
# Truncate hard so we don't blow up the prompt for big diffs
|
| 352 |
+
prompt = _JUDGE_PROMPT.format(
|
| 353 |
+
instruction=instruction[:4000],
|
| 354 |
+
oracle=oracle[:4000],
|
| 355 |
+
predicted=predicted[:4000],
|
| 356 |
+
)
|
| 357 |
+
payload: dict = {
|
| 358 |
+
"model": model,
|
| 359 |
+
"max_tokens": 200,
|
| 360 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 361 |
+
}
|
| 362 |
+
if endpoint:
|
| 363 |
+
# Small self-hosted models are noisy judges at their default sampling
|
| 364 |
+
# temperature (same input scoring 0.0 one call and 1.0 the next); pin
|
| 365 |
+
# them to greedy. The Anthropic route keeps its defaults — the weights
|
| 366 |
+
# were calibrated against them.
|
| 367 |
+
payload["temperature"] = 0
|
| 368 |
+
url = endpoint.rstrip("/") + "/chat/completions"
|
| 369 |
+
headers = {
|
| 370 |
+
"authorization": f"Bearer {api_key}",
|
| 371 |
+
"content-type": "application/json",
|
| 372 |
+
}
|
| 373 |
+
else:
|
| 374 |
+
url = _ANTHROPIC_MESSAGES_URL
|
| 375 |
+
headers = {
|
| 376 |
+
"x-api-key": api_key,
|
| 377 |
+
"anthropic-version": "2023-06-01",
|
| 378 |
+
"content-type": "application/json",
|
| 379 |
+
}
|
| 380 |
+
body = json.dumps(payload).encode("utf-8")
|
| 381 |
+
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
|
| 382 |
+
try:
|
| 383 |
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
| 384 |
+
raw = resp.read().decode("utf-8")
|
| 385 |
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError):
|
| 386 |
+
return None, "network"
|
| 387 |
+
|
| 388 |
+
try:
|
| 389 |
+
response = json.loads(raw)
|
| 390 |
+
except json.JSONDecodeError:
|
| 391 |
+
return None, "parse"
|
| 392 |
+
# Provider-reported truncation is a grader capacity failure, not evidence
|
| 393 |
+
# that the submitted patch is wrong. Reasoning models can spend the entire
|
| 394 |
+
# output budget before producing visible text. Never grade a partial score.
|
| 395 |
+
if isinstance(response, dict):
|
| 396 |
+
choices = response.get("choices")
|
| 397 |
+
if endpoint:
|
| 398 |
+
if (
|
| 399 |
+
isinstance(choices, list)
|
| 400 |
+
and choices
|
| 401 |
+
and isinstance(choices[0], dict)
|
| 402 |
+
and choices[0].get("finish_reason") == "length"
|
| 403 |
+
):
|
| 404 |
+
return None, "output_limit"
|
| 405 |
+
elif response.get("stop_reason") in {"max_tokens", "model_context_window_exceeded"}:
|
| 406 |
+
return None, "output_limit"
|
| 407 |
+
text = _judge_text(response, openai_compatible=bool(endpoint))
|
| 408 |
+
if text is None:
|
| 409 |
+
return None, "parse"
|
| 410 |
+
|
| 411 |
+
# Pull the first JSON object out of the model's response
|
| 412 |
+
m = re.search(r"\{[^{}]*\"score\"[^{}]*\}", text, re.DOTALL)
|
| 413 |
+
if not m:
|
| 414 |
+
return None, "missing_score"
|
| 415 |
+
try:
|
| 416 |
+
obj = json.loads(m.group(0))
|
| 417 |
+
score = obj.get("score")
|
| 418 |
+
except (json.JSONDecodeError, ValueError, TypeError):
|
| 419 |
+
return None, "missing_score"
|
| 420 |
+
if type(score) not in (int, float) or not 0 <= score <= 1 or not math.isfinite(score):
|
| 421 |
+
return None, "invalid_score"
|
| 422 |
+
return float(score), "ok"
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _judge_text(payload: object, *, openai_compatible: bool) -> str | None:
|
| 426 |
+
"""The judge's answer text, ``""`` when it gave none, ``None`` for a wrong shape.
|
| 427 |
+
|
| 428 |
+
A refusal or a content filter is a well-formed reply with no usable text.
|
| 429 |
+
The agent's patch is in the prompt, so it can provoke one: that is ``""``,
|
| 430 |
+
which grades 0, not ``None``, which leaves the run ungraded.
|
| 431 |
+
|
| 432 |
+
Anthropic: a refusal is HTTP 200 with ``stop_reason: "refusal"`` and
|
| 433 |
+
``content`` empty or holding partial text to discard. OpenAI-compatible:
|
| 434 |
+
``message.content`` is null with a ``refusal`` string or
|
| 435 |
+
``finish_reason: "content_filter"``.
|
| 436 |
+
"""
|
| 437 |
+
if not isinstance(payload, dict):
|
| 438 |
+
return None
|
| 439 |
+
if openai_compatible:
|
| 440 |
+
choices = payload.get("choices")
|
| 441 |
+
if not isinstance(choices, list) or not choices or not isinstance(choices[0], dict):
|
| 442 |
+
return None
|
| 443 |
+
message = choices[0].get("message")
|
| 444 |
+
if not isinstance(message, dict):
|
| 445 |
+
return None
|
| 446 |
+
if message.get("refusal") or choices[0].get("finish_reason") == "content_filter":
|
| 447 |
+
return ""
|
| 448 |
+
content = message.get("content")
|
| 449 |
+
if content is None:
|
| 450 |
+
return ""
|
| 451 |
+
if isinstance(content, str):
|
| 452 |
+
return content
|
| 453 |
+
if isinstance(content, list): # content parts
|
| 454 |
+
return "".join(
|
| 455 |
+
part.get("text", "")
|
| 456 |
+
for part in content
|
| 457 |
+
if isinstance(part, dict) and isinstance(part.get("text", ""), str)
|
| 458 |
+
)
|
| 459 |
+
return None
|
| 460 |
+
content = payload.get("content")
|
| 461 |
+
if not isinstance(content, list):
|
| 462 |
+
return None
|
| 463 |
+
if payload.get("stop_reason") == "refusal":
|
| 464 |
+
return ""
|
| 465 |
+
return "".join(
|
| 466 |
+
block["text"]
|
| 467 |
+
for block in content
|
| 468 |
+
if isinstance(block, dict)
|
| 469 |
+
and block.get("type", "text") == "text"
|
| 470 |
+
and isinstance(block.get("text"), str)
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# ---------------------------------------------------------------------------
|
| 475 |
+
# Combination
|
| 476 |
+
# ---------------------------------------------------------------------------
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
# Judge replies the agent can provoke: its patch text is part of the judge
|
| 480 |
+
# prompt, so it can steer the answer away from a valid score. These are a
|
| 481 |
+
# graded 0. An unreadable provider envelope (`parse`), missing configuration,
|
| 482 |
+
# a disabled judge, transport errors and an exhausted judge output budget leave
|
| 483 |
+
# the evaluation ungraded. Truncation alone cannot establish an incorrect patch.
|
| 484 |
+
_JUDGE_GRADED_ZERO = frozenset({"missing_score", "invalid_score"})
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def evaluation_status(judge_score: float | None, judge_status: str) -> str:
|
| 488 |
+
"""`graded` when the judge scored or the agent can have caused its failure."""
|
| 489 |
+
if judge_score is not None or judge_status in _JUDGE_GRADED_ZERO:
|
| 490 |
+
return "graded"
|
| 491 |
+
return "ungraded"
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
def combine(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 495 |
+
"""Combine declared components, requiring a positively weighted judge.
|
| 496 |
+
|
| 497 |
+
Without a judge score the result is 0. ``main`` records it as a graded 0
|
| 498 |
+
when the agent can have caused the judge failure, and otherwise writes no
|
| 499 |
+
reward file, so Harbor reports the trial as VERIFIER_FAILED.
|
| 500 |
+
"""
|
| 501 |
+
if weights.get("llm_judge", 0) <= 0 or components.get("llm_judge") is None:
|
| 502 |
+
return 0.0
|
| 503 |
+
if any(w > 0 and components.get(k) is None for k, w in weights.items()):
|
| 504 |
+
return 0.0
|
| 505 |
+
return _weighted_mean(components, weights)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def _weighted_mean(components: dict[str, float | None], weights: dict[str, float]) -> float:
|
| 509 |
+
available = [(k, w) for k, w in weights.items() if w > 0 and components.get(k) is not None]
|
| 510 |
+
if not available:
|
| 511 |
+
return 0.0
|
| 512 |
+
# Relative weights need not sum to one. Scale first so large finite
|
| 513 |
+
# overrides cannot overflow the numerator or denominator into NaN.
|
| 514 |
+
scale = max(w for _, w in available)
|
| 515 |
+
normalized = [(k, w / scale) for k, w in available]
|
| 516 |
+
return sum(w * components[k] for k, w in normalized) / sum(w for _, w in normalized)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
# ---------------------------------------------------------------------------
|
| 520 |
+
# Entry point (invoked by tests/test.sh inside the container)
|
| 521 |
+
# ---------------------------------------------------------------------------
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
# Weights retuned after a 23-task pilot. Rationale (LLM-as-reward-engineer
|
| 525 |
+
# analysis grounded in per-task component data):
|
| 526 |
+
#
|
| 527 |
+
# - format_valid → 0.00: was 1.0 across ALL 21 evaluated tasks. Zero
|
| 528 |
+
# discriminative signal — its 0.05 weight was pure dead weight.
|
| 529 |
+
# - similarity → 0.10: Pearson ~0.85 correlation with region_overlap.
|
| 530 |
+
# Carrying both at 0.20 double-counts positional accuracy and
|
| 531 |
+
# additionally penalizes legitimate alternative implementations.
|
| 532 |
+
# - llm_judge → 0.50: only component capturing semantic correctness
|
| 533 |
+
# independent of textual form; diverges informatively from
|
| 534 |
+
# similarity on cases like tokenizers (judge=0.72, sim=0.08).
|
| 535 |
+
# - region_overlap stays 0.20: strongest spatial-localization signal.
|
| 536 |
+
# - file_targeting → 0.12: leading indicator, less correlated with the
|
| 537 |
+
# rest than region/similarity are with each other.
|
| 538 |
+
# - size_sanity → 0.08: useful outlier detector for catastrophic
|
| 539 |
+
# over/under-generation (prettier=0.01, serde=0.08).
|
| 540 |
+
#
|
| 541 |
+
# Total: 0.00 + 0.08 + 0.12 + 0.20 + 0.10 + 0.50 = 1.00.
|
| 542 |
+
_DEFAULT_WEIGHTS = {
|
| 543 |
+
"format_valid": 0.00,
|
| 544 |
+
"size_sanity": 0.08,
|
| 545 |
+
"file_targeting": 0.12,
|
| 546 |
+
"region_overlap": 0.20,
|
| 547 |
+
"similarity": 0.10,
|
| 548 |
+
"llm_judge": 0.50,
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
# Hard cap: when size_sanity < this threshold, clamp final reward to
|
| 552 |
+
# ≤ CATASTROPHIC_SIZE_CAP. Prevents a charitable judge from inflating
|
| 553 |
+
# the score on patches that are wildly the wrong size (catastrophic
|
| 554 |
+
# over- or under-generation).
|
| 555 |
+
_CATASTROPHIC_SIZE_THRESHOLD = 0.10
|
| 556 |
+
_CATASTROPHIC_SIZE_CAP = 0.40
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def _read_weights_from_env() -> dict[str, float]:
|
| 560 |
+
"""Override defaults via R2E_W_* env vars (set in container by harbor)."""
|
| 561 |
+
overrides = {
|
| 562 |
+
"format_valid": os.environ.get("R2E_W_FORMAT"),
|
| 563 |
+
"size_sanity": os.environ.get("R2E_W_SIZE"),
|
| 564 |
+
"file_targeting": os.environ.get("R2E_W_FILE"),
|
| 565 |
+
"region_overlap": os.environ.get("R2E_W_REGION"),
|
| 566 |
+
"similarity": os.environ.get("R2E_W_SIM"),
|
| 567 |
+
"llm_judge": os.environ.get("R2E_W_JUDGE"),
|
| 568 |
+
}
|
| 569 |
+
out = dict(_DEFAULT_WEIGHTS)
|
| 570 |
+
for k, v in overrides.items():
|
| 571 |
+
if v is None:
|
| 572 |
+
continue
|
| 573 |
+
try:
|
| 574 |
+
value = float(v)
|
| 575 |
+
if math.isfinite(value) and value >= 0:
|
| 576 |
+
out[k] = value
|
| 577 |
+
except (TypeError, ValueError):
|
| 578 |
+
continue
|
| 579 |
+
return out
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def _judge_config_from_env() -> tuple[str, str, str | None]:
|
| 583 |
+
"""``(api_key, model, endpoint)`` for the judge, from the verifier env.
|
| 584 |
+
|
| 585 |
+
With ``R2E_JUDGE_ENDPOINT`` set, the key comes from ``R2E_JUDGE_API_KEY``
|
| 586 |
+
(placeholder when unset) and ``ANTHROPIC_API_KEY`` is never forwarded to
|
| 587 |
+
the custom server. ``R2E_JUDGE_MODEL`` has no default on that route (a
|
| 588 |
+
self-hosted server won't have Haiku): when unset, ``model`` comes back
|
| 589 |
+
as ``""`` and ``llm_judge`` reports ``no_judge_model`` instead of
|
| 590 |
+
calling out. Without an endpoint the default Anthropic route is
|
| 591 |
+
unchanged.
|
| 592 |
+
"""
|
| 593 |
+
endpoint = os.environ.get("R2E_JUDGE_ENDPOINT", "").strip() or None
|
| 594 |
+
model = os.environ.get("R2E_JUDGE_MODEL", "").strip()
|
| 595 |
+
if endpoint:
|
| 596 |
+
api_key = os.environ.get("R2E_JUDGE_API_KEY", "").strip() or _PLACEHOLDER_API_KEY
|
| 597 |
+
return api_key, model, endpoint
|
| 598 |
+
return os.environ.get("ANTHROPIC_API_KEY", "").strip(), model or _DEFAULT_JUDGE_MODEL, None
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def main(argv: list[str] | None = None) -> int:
|
| 602 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 603 |
+
parser.add_argument("oracle")
|
| 604 |
+
parser.add_argument("predicted")
|
| 605 |
+
parser.add_argument("instruction")
|
| 606 |
+
parser.add_argument("--out-dir", default="/logs/verifier")
|
| 607 |
+
args = parser.parse_args(argv)
|
| 608 |
+
os.makedirs(args.out_dir, exist_ok=True)
|
| 609 |
+
# This run is the only authority on the reward: an earlier or planted
|
| 610 |
+
# reward file must not stand if this evaluation ends up ungraded.
|
| 611 |
+
for name in ("reward.txt", "reward.json"):
|
| 612 |
+
try:
|
| 613 |
+
os.unlink(os.path.join(args.out_dir, name))
|
| 614 |
+
except FileNotFoundError:
|
| 615 |
+
pass
|
| 616 |
+
oracle = _read_or_empty(args.oracle)
|
| 617 |
+
try:
|
| 618 |
+
oversized = os.path.getsize(args.predicted) > _MAX_PREDICTED_BYTES
|
| 619 |
+
except OSError:
|
| 620 |
+
oversized = False
|
| 621 |
+
predicted = "" if oversized else _read_or_empty(args.predicted)
|
| 622 |
+
if oversized or predicted_too_large(oracle, predicted):
|
| 623 |
+
breakdown = {
|
| 624 |
+
"final_reward": 0.0,
|
| 625 |
+
"evaluation_status": "graded",
|
| 626 |
+
"eval_trustworthy": False,
|
| 627 |
+
"predicted_status": "predicted_too_large",
|
| 628 |
+
}
|
| 629 |
+
_write_outputs(args.out_dir, 0.0, breakdown)
|
| 630 |
+
return 0
|
| 631 |
+
instruction = _read_or_empty(args.instruction)
|
| 632 |
+
api_key, judge_model, judge_endpoint = _judge_config_from_env()
|
| 633 |
+
|
| 634 |
+
fv = format_valid(predicted)
|
| 635 |
+
ss = size_sanity(oracle, predicted)
|
| 636 |
+
ft = file_targeting(oracle, predicted)
|
| 637 |
+
ro = region_overlap(oracle, predicted)
|
| 638 |
+
sim = similarity(oracle, predicted)
|
| 639 |
+
weights = _read_weights_from_env()
|
| 640 |
+
if weights["llm_judge"] <= 0:
|
| 641 |
+
judge_score, judge_status = None, "disabled"
|
| 642 |
+
else:
|
| 643 |
+
judge_score, judge_status = llm_judge(
|
| 644 |
+
instruction=instruction,
|
| 645 |
+
oracle=oracle,
|
| 646 |
+
predicted=predicted,
|
| 647 |
+
api_key=api_key,
|
| 648 |
+
model=judge_model,
|
| 649 |
+
endpoint=judge_endpoint,
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
components: dict[str, float | None] = {
|
| 653 |
+
"format_valid": fv,
|
| 654 |
+
"size_sanity": ss,
|
| 655 |
+
"file_targeting": ft,
|
| 656 |
+
"region_overlap": ro,
|
| 657 |
+
"similarity": sim,
|
| 658 |
+
"llm_judge": judge_score,
|
| 659 |
+
}
|
| 660 |
+
final = combine(components, weights)
|
| 661 |
+
final = max(0.0, min(1.0, final))
|
| 662 |
+
|
| 663 |
+
# Hard cap on catastrophic size mismatches. Without this, a charitable
|
| 664 |
+
# judge can inflate the reward on patches that are dramatically the
|
| 665 |
+
# wrong size (prettier scored 0.23 with size_sanity=0.011 — the judge
|
| 666 |
+
# was lenient at 0.25 despite the patch being a near-no-op vs a
|
| 667 |
+
# 500-line oracle). The cap kicks in only at the extremes.
|
| 668 |
+
if ss < _CATASTROPHIC_SIZE_THRESHOLD:
|
| 669 |
+
final = min(final, _CATASTROPHIC_SIZE_CAP)
|
| 670 |
+
|
| 671 |
+
status = evaluation_status(judge_score, judge_status)
|
| 672 |
+
breakdown = {
|
| 673 |
+
# No reward exists for an ungraded evaluation: null, not a placeholder 0.
|
| 674 |
+
"final_reward": round(final, 6) if status == "graded" else None,
|
| 675 |
+
"evaluation_status": status,
|
| 676 |
+
"eval_trustworthy": judge_score is not None,
|
| 677 |
+
"diagnostic_similarity": round(
|
| 678 |
+
_weighted_mean(components, {k: w for k, w in weights.items() if k != "llm_judge"}),
|
| 679 |
+
6,
|
| 680 |
+
),
|
| 681 |
+
"components": {k: (None if v is None else round(v, 6)) for k, v in components.items()},
|
| 682 |
+
"weights": {k: round(v, 6) for k, v in weights.items()},
|
| 683 |
+
"judge_model": judge_model if judge_status == "ok" else None,
|
| 684 |
+
"judge_endpoint": judge_endpoint,
|
| 685 |
+
"judge_status": judge_status,
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
_write_outputs(args.out_dir, final, breakdown)
|
| 689 |
+
return 0
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def _write_outputs(out_dir: str, final: float, breakdown: dict) -> None:
|
| 693 |
+
# An ungraded evaluation writes no reward file. Harbor then raises
|
| 694 |
+
# RewardFileNotFoundError: the trial is VERIFIER_FAILED, reward_valid is
|
| 695 |
+
# false, and RL consumers (OpenEnv harbor_env -> TRL) drop the rollout
|
| 696 |
+
# instead of training on a 0. Harbor's job mean and pass@k still count the
|
| 697 |
+
# trial as 0, so evaluation stays fail-closed.
|
| 698 |
+
if breakdown["evaluation_status"] == "graded":
|
| 699 |
+
with open(os.path.join(out_dir, "reward.txt"), "w", encoding="utf-8") as f:
|
| 700 |
+
f.write(f"{final:.6f}\n")
|
| 701 |
+
# Harbor's `reward.json` must be a flat map of floats/ints (spec, see
|
| 702 |
+
# <https://harborframework.com/docs/tasks>); our breakdown carries nested
|
| 703 |
+
# dicts, judge strings, and status strings, so it goes to the sidecar the
|
| 704 |
+
# Harbor UI renders under Verifier Logs → Rewards. Mirrors #75 (Neubig)
|
| 705 |
+
# for `_pr_runtime_verifier.py`.
|
| 706 |
+
with open(os.path.join(out_dir, "reward-details.json"), "w", encoding="utf-8") as f:
|
| 707 |
+
json.dump(breakdown, f, indent=2)
|
| 708 |
+
|
| 709 |
+
# Also print to stdout so harbor's log captures the breakdown
|
| 710 |
+
print(json.dumps(breakdown, indent=2))
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
def _read_or_empty(path: str) -> str:
|
| 714 |
+
try:
|
| 715 |
+
with open(path, encoding="utf-8") as f:
|
| 716 |
+
return f.read()
|
| 717 |
+
except (OSError, UnicodeDecodeError):
|
| 718 |
+
return ""
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
if __name__ == "__main__":
|
| 722 |
+
sys.exit(main())
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
__all__ = [
|
| 726 |
+
"combine",
|
| 727 |
+
"file_paths",
|
| 728 |
+
"file_targeting",
|
| 729 |
+
"format_valid",
|
| 730 |
+
"hunk_ranges",
|
| 731 |
+
"llm_judge",
|
| 732 |
+
"main",
|
| 733 |
+
"predicted_too_large",
|
| 734 |
+
"region_overlap",
|
| 735 |
+
"similarity",
|
| 736 |
+
"size_sanity",
|
| 737 |
+
]
|
tasks/AeneasVerif__aeneas-1414/environment/Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto-generated by Repo2RLEnv pr_diff — 6-component reward env.
|
| 2 |
+
# Agent-agnostic: the agent (claude-code / openhands / codex / etc.)
|
| 3 |
+
# installs itself at run time via its harbor adapter. We only ship
|
| 4 |
+
# the source repo — the oracle + verifier arrive at verify time via
|
| 5 |
+
# tests/, never baked into the agent's image.
|
| 6 |
+
FROM python:3.12-slim
|
| 7 |
+
ARG GITHUB_TOKEN=
|
| 8 |
+
RUN apt-get update \
|
| 9 |
+
&& apt-get install -y --no-install-recommends git ca-certificates curl \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
RUN git config --global --add safe.directory /workspace \
|
| 12 |
+
&& git config --global init.defaultBranch main \
|
| 13 |
+
&& git config --global advice.detachedHead false
|
| 14 |
+
RUN if [ -n "$GITHUB_TOKEN" ]; then \
|
| 15 |
+
git clone --filter=blob:none https://x-access-token:"${GITHUB_TOKEN}"@github.com/AeneasVerif/aeneas.git /workspace; \
|
| 16 |
+
else \
|
| 17 |
+
git clone --filter=blob:none https://github.com/AeneasVerif/aeneas.git /workspace; \
|
| 18 |
+
fi \
|
| 19 |
+
&& git -C /workspace remote set-url origin https://github.com/AeneasVerif/aeneas.git
|
| 20 |
+
WORKDIR /workspace
|
| 21 |
+
RUN git fetch --depth 1 origin 73b7cf9f7442c5aba550c224bd7fd212d39ba32f 2>/dev/null \
|
| 22 |
+
|| git fetch --unshallow origin 2>/dev/null || true
|
| 23 |
+
RUN git reset --hard 73b7cf9f7442c5aba550c224bd7fd212d39ba32f \
|
| 24 |
+
&& git clean -fdx -e .venv -e venv -e __pycache__
|
| 25 |
+
RUN git checkout -q -B base 73b7cf9f7442c5aba550c224bd7fd212d39ba32f \
|
| 26 |
+
&& git remote remove origin 2>/dev/null || true
|
| 27 |
+
RUN for ref in $(git branch --format='%(refname:short)' | grep -vx base); do git branch -D "$ref" 2>/dev/null || true; done \
|
| 28 |
+
&& git tag -l | xargs -r git tag -d >/dev/null 2>&1 || true \
|
| 29 |
+
&& git for-each-ref --format='%(refname)' refs/remotes 2>/dev/null | xargs -r -n1 git update-ref -d 2>/dev/null || true \
|
| 30 |
+
&& git reflog expire --expire=now --all 2>/dev/null || true \
|
| 31 |
+
&& git gc --prune=now 2>/dev/null || true
|
| 32 |
+
RUN P="$(git rev-parse --git-dir)/objects/pack"; if ls "$P"/*.promisor >/dev/null 2>&1; then \
|
| 33 |
+
git rev-list --objects --all --missing=allow-promisor > "$P/../scrub.list" \
|
| 34 |
+
&& K=$(git pack-objects -q --missing=allow-promisor "$P/scrub" < "$P/../scrub.list") \
|
| 35 |
+
&& rm -f "$P/../scrub.list" "$P"/pack-* "$P"/multi-pack-index* \
|
| 36 |
+
&& touch "$P/scrub-$K.promisor" && git prune --expire=now; \
|
| 37 |
+
fi
|
tasks/AeneasVerif__aeneas-1414/instruction.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Update `dune-project` to specify dependencies
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
I'm rather unfamiliar with the ecosystem,
|
| 8 |
+
but this allows `opam install src --deps-only --with-test`
|
| 9 |
+
to install everything so that `make` then succeeds.
|
| 10 |
+
|
| 11 |
+
## Task
|
| 12 |
+
|
| 13 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `73b7cf9f7442`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1414/solution/patch.diff
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/README.md b/README.md
|
| 2 |
+
index 7326e8ea5..26e67b4fa 100644
|
| 3 |
+
--- a/README.md
|
| 4 |
+
+++ b/README.md
|
| 5 |
+
@@ -47,9 +47,7 @@ opam switch create 5.3.0
|
| 6 |
+
|
| 7 |
+
You can then install the dependencies with the following command:
|
| 8 |
+
```
|
| 9 |
+
-opam install calendar core_unix domainslib easy_logging menhir \
|
| 10 |
+
- ocamlformat.0.27.0 ocamlgraph odoc ppx_deriving ppx_deriving_yojson \
|
| 11 |
+
- progress unionFind visitors yojson zarith
|
| 12 |
+
+opam install src --deps-only --with-test
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
Moreover, Aeneas uses the [Charon](https://github.com/AeneasVerif/charon) project and library.
|
| 16 |
+
diff --git a/src/aeneas.opam b/src/aeneas.opam
|
| 17 |
+
index 70ea2f705..53f2054d5 100644
|
| 18 |
+
--- a/src/aeneas.opam
|
| 19 |
+
+++ b/src/aeneas.opam
|
| 20 |
+
@@ -9,6 +9,22 @@ homepage: "https://github.com/AeneasVerif/aeneas"
|
| 21 |
+
bug-reports: "https://github.com/AeneasVerif/aeneas/issues"
|
| 22 |
+
depends: [
|
| 23 |
+
"dune" {>= "3.7"}
|
| 24 |
+
+ "calendar"
|
| 25 |
+
+ "core_unix"
|
| 26 |
+
+ "domainslib"
|
| 27 |
+
+ "easy_logging"
|
| 28 |
+
+ "logs"
|
| 29 |
+
+ "menhir"
|
| 30 |
+
+ "ocamlgraph"
|
| 31 |
+
+ "ppx_deriving"
|
| 32 |
+
+ "ppx_deriving_yojson"
|
| 33 |
+
+ "ppxlib"
|
| 34 |
+
+ "progress"
|
| 35 |
+
+ "unionFind"
|
| 36 |
+
+ "visitors"
|
| 37 |
+
+ "yojson"
|
| 38 |
+
+ "zarith"
|
| 39 |
+
+ "ocamlformat" {with-test}
|
| 40 |
+
"odoc" {with-doc}
|
| 41 |
+
]
|
| 42 |
+
build: [
|
| 43 |
+
diff --git a/src/aeneas.ppx.opam b/src/aeneas.ppx.opam
|
| 44 |
+
deleted file mode 100644
|
| 45 |
+
index 7e9a3e68d..000000000
|
| 46 |
+
--- a/src/aeneas.ppx.opam
|
| 47 |
+
+++ /dev/null
|
| 48 |
+
@@ -1,28 +0,0 @@
|
| 49 |
+
-# This file is generated by dune, edit dune-project instead
|
| 50 |
+
-opam-version: "2.0"
|
| 51 |
+
-version: "0.1"
|
| 52 |
+
-synopsis: "PPX to expand helpers which check raise errors"
|
| 53 |
+
-description: ""
|
| 54 |
+
-authors: ["Son Ho" "Jonathan Protzenko" "Aymeric Fromherz" "Sidney Congard"]
|
| 55 |
+
-license: "Apache-2.0"
|
| 56 |
+
-homepage: "https://github.com/AeneasVerif/aeneas"
|
| 57 |
+
-bug-reports: "https://github.com/AeneasVerif/aeneas/issues"
|
| 58 |
+
-depends: [
|
| 59 |
+
- "dune" {>= "3.7"}
|
| 60 |
+
- "odoc" {with-doc}
|
| 61 |
+
-]
|
| 62 |
+
-build: [
|
| 63 |
+
- ["dune" "subst"] {dev}
|
| 64 |
+
- [
|
| 65 |
+
- "dune"
|
| 66 |
+
- "build"
|
| 67 |
+
- "-p"
|
| 68 |
+
- name
|
| 69 |
+
- "-j"
|
| 70 |
+
- jobs
|
| 71 |
+
- "@install"
|
| 72 |
+
- "@runtest" {with-test}
|
| 73 |
+
- "@doc" {with-doc}
|
| 74 |
+
- ]
|
| 75 |
+
-]
|
| 76 |
+
-dev-repo: "git+https://github.com/AeneasVerif/aeneas.git"
|
| 77 |
+
diff --git a/src/dune-project b/src/dune-project
|
| 78 |
+
index 4656b7396..ed1cc93f3 100644
|
| 79 |
+
--- a/src/dune-project
|
| 80 |
+
+++ b/src/dune-project
|
| 81 |
+
@@ -21,3 +21,27 @@
|
| 82 |
+
"Sidney Congard")
|
| 83 |
+
|
| 84 |
+
(license Apache-2.0)
|
| 85 |
+
+
|
| 86 |
+
+(package
|
| 87 |
+
+ (name aeneas)
|
| 88 |
+
+ (synopsis "Compiler from Rust to pure code")
|
| 89 |
+
+ (description "")
|
| 90 |
+
+ (depends
|
| 91 |
+
+ calendar
|
| 92 |
+
+ core_unix
|
| 93 |
+
+ domainslib
|
| 94 |
+
+ easy_logging
|
| 95 |
+
+ logs
|
| 96 |
+
+ menhir
|
| 97 |
+
+ ocamlgraph
|
| 98 |
+
+ ppx_deriving
|
| 99 |
+
+ ppx_deriving_yojson
|
| 100 |
+
+ ppxlib
|
| 101 |
+
+ progress
|
| 102 |
+
+ unionFind
|
| 103 |
+
+ visitors
|
| 104 |
+
+ yojson
|
| 105 |
+
+ zarith
|
| 106 |
+
+ (ocamlformat :with-test)
|
| 107 |
+
+ )
|
| 108 |
+
+)
|
tasks/AeneasVerif__aeneas-1414/solution/solve.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euxo pipefail
|
| 3 |
+
cd /workspace
|
| 4 |
+
git config --global --add safe.directory /workspace
|
| 5 |
+
PATCH="$(dirname "$0")/patch.diff"
|
| 6 |
+
git apply --verbose --reject "$PATCH"
|
tasks/AeneasVerif__aeneas-1414/task.toml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[task]
|
| 4 |
+
name = "trending/AeneasVerif__aeneas-1414"
|
| 5 |
+
description = "Update `dune-project` to specify dependencies"
|
| 6 |
+
|
| 7 |
+
[metadata]
|
| 8 |
+
difficulty = "medium"
|
| 9 |
+
category = "bugfix"
|
| 10 |
+
keywords = [
|
| 11 |
+
"aeneas",
|
| 12 |
+
"pr_diff",
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
[metadata.repo2env]
|
| 16 |
+
pipeline = "pr_diff"
|
| 17 |
+
pipeline_version = "0.3.0"
|
| 18 |
+
repo = "AeneasVerif/aeneas"
|
| 19 |
+
ref = "73b7cf9f7442c5aba550c224bd7fd212d39ba32f"
|
| 20 |
+
reference = "https://github.com/AeneasVerif/aeneas/pull/1414"
|
| 21 |
+
source_access = "auto"
|
| 22 |
+
built_at = "2026-11-16T16:10:00.155517+00:00"
|
| 23 |
+
reward_kinds = [
|
| 24 |
+
"diff_similarity",
|
| 25 |
+
]
|
| 26 |
+
spec_version = "0.2.0"
|
| 27 |
+
content_hash = "sha256:2ca0e58d086125dfcb3010ab351334b97c48e0c99a54219cef28784a07a2162c"
|
| 28 |
+
|
| 29 |
+
[metadata.repo2env.pr_diff]
|
| 30 |
+
pr_merged_at = "2026-10-13T08:35:40Z"
|
| 31 |
+
diff_format = "unified"
|
| 32 |
+
context_files = [
|
| 33 |
+
"README.md",
|
| 34 |
+
"src/aeneas.opam",
|
| 35 |
+
"src/aeneas.ppx.opam",
|
| 36 |
+
"src/dune-project",
|
| 37 |
+
]
|
| 38 |
+
bootstrap_image = "python:3.12-slim"
|
| 39 |
+
|
| 40 |
+
[metadata.repo2env.reward_calibration]
|
| 41 |
+
baseline_reward = 0.0
|
| 42 |
+
loc_changed = 72
|
| 43 |
+
difficulty = "medium"
|
| 44 |
+
|
| 45 |
+
[metadata.repo2env.evaluation]
|
| 46 |
+
schema_version = "1"
|
| 47 |
+
status = "unverified"
|
| 48 |
+
stage = "generation"
|
| 49 |
+
reason_codes = [
|
| 50 |
+
"validation_not_run",
|
| 51 |
+
]
|
| 52 |
+
detail = "Generated task; validation has not been established."
|
| 53 |
+
provenance = "unknown"
|
| 54 |
+
evidence = []
|
| 55 |
+
|
| 56 |
+
[metadata.repo2env.reproducibility]
|
| 57 |
+
mode = "inline_dockerfile"
|
| 58 |
+
image_ref = "python:3.12-slim"
|
| 59 |
+
image_tag = "python:3.12-slim"
|
| 60 |
+
image_visibility = "public"
|
| 61 |
+
pushed_at = "2026-11-16T16:19:57.825135+00:00"
|
| 62 |
+
pushed_by = "scalingX"
|
| 63 |
+
inline_recipe_sha256 = "sha256:5c6a381bee73a9479904cc0c7e000c7ab82543c78348159be94dba62af70e1e8"
|
| 64 |
+
inline_recipe_lines = 37
|
| 65 |
+
inline_recipe_source = "user_dockerfile"
|
| 66 |
+
|
| 67 |
+
[agent]
|
| 68 |
+
timeout_sec = 1800.0
|
| 69 |
+
|
| 70 |
+
[verifier]
|
| 71 |
+
timeout_sec = 300.0
|
tasks/AeneasVerif__aeneas-1414/tests/capture.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standalone PR-diff capture without executing workspace Git configuration.
|
| 2 |
+
|
| 3 |
+
The emitted task uses a regular clone with a pinned base commit. Only its
|
| 4 |
+
object store is read: refs, index, config, hooks and replacement refs are not
|
| 5 |
+
used. This is a configuration boundary, not a sandbox for a malicious process
|
| 6 |
+
that can modify the verifier, binaries or object store while capture runs.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import tempfile
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def capture(workspace: Path, base_commit: str) -> bytes:
|
| 23 |
+
"""Capture tracked and new files through a fresh private Git index."""
|
| 24 |
+
if not re.fullmatch(r"[a-fA-F0-9]{40}", base_commit):
|
| 25 |
+
raise ValueError("Expected the task's pinned SHA-1 base commit")
|
| 26 |
+
objects = workspace.resolve() / ".git" / "objects"
|
| 27 |
+
if not objects.is_dir():
|
| 28 |
+
raise ValueError("The task's cloned Git object store is missing")
|
| 29 |
+
git = shutil.which("git", path=os.defpath)
|
| 30 |
+
if git is None:
|
| 31 |
+
raise FileNotFoundError("System git is unavailable")
|
| 32 |
+
with tempfile.TemporaryDirectory(prefix="r2e-diff-") as temporary:
|
| 33 |
+
private = Path(temporary)
|
| 34 |
+
# Do not forward GIT_CONFIG_PARAMETERS/COUNT, external diff programs,
|
| 35 |
+
# system/global includes, user attributes, templates or credential env.
|
| 36 |
+
env = {
|
| 37 |
+
"PATH": os.defpath,
|
| 38 |
+
"HOME": temporary,
|
| 39 |
+
"XDG_CONFIG_HOME": temporary,
|
| 40 |
+
"GIT_CONFIG_NOSYSTEM": "1",
|
| 41 |
+
"GIT_CONFIG_GLOBAL": os.devnull,
|
| 42 |
+
"GIT_ATTR_NOSYSTEM": "1",
|
| 43 |
+
"GIT_NO_REPLACE_OBJECTS": "1",
|
| 44 |
+
"GIT_NO_LAZY_FETCH": "1",
|
| 45 |
+
"GIT_TERMINAL_PROMPT": "0",
|
| 46 |
+
"LC_ALL": "C",
|
| 47 |
+
}
|
| 48 |
+
subprocess.run(
|
| 49 |
+
[git, "init", "--quiet", "--template=", str(private / "repository")],
|
| 50 |
+
env=env,
|
| 51 |
+
cwd=private,
|
| 52 |
+
check=True,
|
| 53 |
+
capture_output=True,
|
| 54 |
+
timeout=60,
|
| 55 |
+
)
|
| 56 |
+
env["GIT_ALTERNATE_OBJECT_DIRECTORIES"] = json.dumps(str(objects), ensure_ascii=False)
|
| 57 |
+
command = [
|
| 58 |
+
git,
|
| 59 |
+
f"--git-dir={private / 'repository/.git'}",
|
| 60 |
+
f"--work-tree={workspace.resolve()}",
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def run(*args: str) -> bytes:
|
| 64 |
+
return subprocess.run(
|
| 65 |
+
[*command, *args],
|
| 66 |
+
env=env,
|
| 67 |
+
cwd=workspace,
|
| 68 |
+
check=True,
|
| 69 |
+
capture_output=True,
|
| 70 |
+
timeout=60,
|
| 71 |
+
).stdout
|
| 72 |
+
|
| 73 |
+
run("read-tree", f"{base_commit}^{{tree}}")
|
| 74 |
+
# All filter drivers are undefined in the private configuration. The
|
| 75 |
+
# workspace's clean filters, fsmonitor and hooks cannot be invoked.
|
| 76 |
+
run("add", "--all", "--", ".")
|
| 77 |
+
return run("diff", "--cached", "--no-ext-diff", "--no-textconv", base_commit, "--")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def main(argv: list[str] | None = None) -> int:
|
| 81 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 82 |
+
parser.add_argument("workspace", type=Path)
|
| 83 |
+
parser.add_argument("base_commit")
|
| 84 |
+
args = parser.parse_args(argv)
|
| 85 |
+
try:
|
| 86 |
+
patch = capture(args.workspace, args.base_commit)
|
| 87 |
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
| 88 |
+
# Do not echo child stderr: it may contain workspace-controlled data.
|
| 89 |
+
sys.stderr.write(f"PR-diff capture failed ({type(exc).__name__})\n")
|
| 90 |
+
return 1
|
| 91 |
+
sys.stdout.buffer.write(patch)
|
| 92 |
+
return 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
sys.exit(main())
|
tasks/AeneasVerif__aeneas-1414/tests/instruction.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Issue
|
| 2 |
+
|
| 3 |
+
**Title:** Update `dune-project` to specify dependencies
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
I'm rather unfamiliar with the ecosystem,
|
| 8 |
+
but this allows `opam install src --deps-only --with-test`
|
| 9 |
+
to install everything so that `make` then succeeds.
|
| 10 |
+
|
| 11 |
+
## Task
|
| 12 |
+
|
| 13 |
+
Modify the repository so that the issue described above is resolved. The repository is checked out at base commit `73b7cf9f7442`. Edit files in place; the verifier captures your changes via `git diff` and scores them against an oracle patch using SWE-RL-style diff-similarity reward.
|
tasks/AeneasVerif__aeneas-1414/tests/oracle.patch
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/README.md b/README.md
|
| 2 |
+
index 7326e8ea5..26e67b4fa 100644
|
| 3 |
+
--- a/README.md
|
| 4 |
+
+++ b/README.md
|
| 5 |
+
@@ -47,9 +47,7 @@ opam switch create 5.3.0
|
| 6 |
+
|
| 7 |
+
You can then install the dependencies with the following command:
|
| 8 |
+
```
|
| 9 |
+
-opam install calendar core_unix domainslib easy_logging menhir \
|
| 10 |
+
- ocamlformat.0.27.0 ocamlgraph odoc ppx_deriving ppx_deriving_yojson \
|
| 11 |
+
- progress unionFind visitors yojson zarith
|
| 12 |
+
+opam install src --deps-only --with-test
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
Moreover, Aeneas uses the [Charon](https://github.com/AeneasVerif/charon) project and library.
|
| 16 |
+
diff --git a/src/aeneas.opam b/src/aeneas.opam
|
| 17 |
+
index 70ea2f705..53f2054d5 100644
|
| 18 |
+
--- a/src/aeneas.opam
|
| 19 |
+
+++ b/src/aeneas.opam
|
| 20 |
+
@@ -9,6 +9,22 @@ homepage: "https://github.com/AeneasVerif/aeneas"
|
| 21 |
+
bug-reports: "https://github.com/AeneasVerif/aeneas/issues"
|
| 22 |
+
depends: [
|
| 23 |
+
"dune" {>= "3.7"}
|
| 24 |
+
+ "calendar"
|
| 25 |
+
+ "core_unix"
|
| 26 |
+
+ "domainslib"
|
| 27 |
+
+ "easy_logging"
|
| 28 |
+
+ "logs"
|
| 29 |
+
+ "menhir"
|
| 30 |
+
+ "ocamlgraph"
|
| 31 |
+
+ "ppx_deriving"
|
| 32 |
+
+ "ppx_deriving_yojson"
|
| 33 |
+
+ "ppxlib"
|
| 34 |
+
+ "progress"
|
| 35 |
+
+ "unionFind"
|
| 36 |
+
+ "visitors"
|
| 37 |
+
+ "yojson"
|
| 38 |
+
+ "zarith"
|
| 39 |
+
+ "ocamlformat" {with-test}
|
| 40 |
+
"odoc" {with-doc}
|
| 41 |
+
]
|
| 42 |
+
build: [
|
| 43 |
+
diff --git a/src/aeneas.ppx.opam b/src/aeneas.ppx.opam
|
| 44 |
+
deleted file mode 100644
|
| 45 |
+
index 7e9a3e68d..000000000
|
| 46 |
+
--- a/src/aeneas.ppx.opam
|
| 47 |
+
+++ /dev/null
|
| 48 |
+
@@ -1,28 +0,0 @@
|
| 49 |
+
-# This file is generated by dune, edit dune-project instead
|
| 50 |
+
-opam-version: "2.0"
|
| 51 |
+
-version: "0.1"
|
| 52 |
+
-synopsis: "PPX to expand helpers which check raise errors"
|
| 53 |
+
-description: ""
|
| 54 |
+
-authors: ["Son Ho" "Jonathan Protzenko" "Aymeric Fromherz" "Sidney Congard"]
|
| 55 |
+
-license: "Apache-2.0"
|
| 56 |
+
-homepage: "https://github.com/AeneasVerif/aeneas"
|
| 57 |
+
-bug-reports: "https://github.com/AeneasVerif/aeneas/issues"
|
| 58 |
+
-depends: [
|
| 59 |
+
- "dune" {>= "3.7"}
|
| 60 |
+
- "odoc" {with-doc}
|
| 61 |
+
-]
|
| 62 |
+
-build: [
|
| 63 |
+
- ["dune" "subst"] {dev}
|
| 64 |
+
- [
|
| 65 |
+
- "dune"
|
| 66 |
+
- "build"
|
| 67 |
+
- "-p"
|
| 68 |
+
- name
|
| 69 |
+
- "-j"
|
| 70 |
+
- jobs
|
| 71 |
+
- "@install"
|
| 72 |
+
- "@runtest" {with-test}
|
| 73 |
+
- "@doc" {with-doc}
|
| 74 |
+
- ]
|
| 75 |
+
-]
|
| 76 |
+
-dev-repo: "git+https://github.com/AeneasVerif/aeneas.git"
|
| 77 |
+
diff --git a/src/dune-project b/src/dune-project
|
| 78 |
+
index 4656b7396..ed1cc93f3 100644
|
| 79 |
+
--- a/src/dune-project
|
| 80 |
+
+++ b/src/dune-project
|
| 81 |
+
@@ -21,3 +21,27 @@
|
| 82 |
+
"Sidney Congard")
|
| 83 |
+
|
| 84 |
+
(license Apache-2.0)
|
| 85 |
+
+
|
| 86 |
+
+(package
|
| 87 |
+
+ (name aeneas)
|
| 88 |
+
+ (synopsis "Compiler from Rust to pure code")
|
| 89 |
+
+ (description "")
|
| 90 |
+
+ (depends
|
| 91 |
+
+ calendar
|
| 92 |
+
+ core_unix
|
| 93 |
+
+ domainslib
|
| 94 |
+
+ easy_logging
|
| 95 |
+
+ logs
|
| 96 |
+
+ menhir
|
| 97 |
+
+ ocamlgraph
|
| 98 |
+
+ ppx_deriving
|
| 99 |
+
+ ppx_deriving_yojson
|
| 100 |
+
+ ppxlib
|
| 101 |
+
+ progress
|
| 102 |
+
+ unionFind
|
| 103 |
+
+ visitors
|
| 104 |
+
+ yojson
|
| 105 |
+
+ zarith
|
| 106 |
+
+ (ocamlformat :with-test)
|
| 107 |
+
+ )
|
| 108 |
+
+)
|