rootxhacker commited on
Commit
83d78dc
·
verified ·
1 Parent(s): 6d546c8

harness v0.8: rust shared CARGO_TARGET_DIR, disk guard + reclaim, disk logging

Browse files
Files changed (1) hide show
  1. scripts/verify.py +50 -7
scripts/verify.py CHANGED
@@ -1,4 +1,4 @@
1
- """PatchBench row verification + context expansion harness (v0.7).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
@@ -22,11 +22,16 @@ Native (non-Docker) reproduction of the upstream env:
22
  reports/<lang>-test-results.json`; the row's print_cmds list is often empty)
23
  - JS/TS: if package.json exists without node_modules, deps are installed with the
24
  repo's own package manager (detected from lockfile)
25
- - rust: cargo target dirs are wiped between rows to stay inside the ephemeral
26
- storage quota
27
 
28
  v0.7: TimeoutExpired.stdout/stderr can be bytes (python quirk under capture_output) --
29
  decode before concatenating. This crashed slow maven builds at the 2100s timeout.
 
 
 
 
 
30
 
31
  Usage (inside a job with the right language toolchain image):
32
  python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
@@ -38,6 +43,9 @@ CACHE = "/tmp/cache/repos"
38
  CMD_TIMEOUT_S = 2100
39
  GIT_TIMEOUT_S = 900
40
  MAX_CONTEXT_LINES = 1500
 
 
 
41
 
42
  LANG_PATH_PREPEND = {
43
  "go": ["/usr/local/go/bin"],
@@ -76,6 +84,36 @@ def sh(cmds, cwd, timeout=CMD_TIMEOUT_S):
76
  return True, ""
77
 
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  def apply_patch(text, cwd):
80
  pf = os.path.join(cwd, ".pb_patch")
81
  with open(pf, "w") as f:
@@ -92,8 +130,8 @@ def apply_patch(text, cwd):
92
  def clean_state(repo_dir, lang=None):
93
  run("git checkout -f HEAD -- . && git clean -fdxq", repo_dir, 120)
94
  if lang == "rust":
95
- # cargo target dirs can be 10-30GB per repo; the job has 50G ephemeral storage
96
  run("find . -name target -type d -prune -exec rm -rf {} +", repo_dir, 300)
 
97
 
98
 
99
  def get_parser(row):
@@ -124,9 +162,10 @@ def ensure_js_deps(repo_dir):
124
  return None if ok else f"js deps install failed: {err}"
125
 
126
 
127
- def run_tests(row, repo_dir, lang):
128
  """Run rebuild_cmds, test_cmds, print_cmds, then surface any reports/* the test
129
  commands wrote. Returns (tests_dict, combined_output_tail)."""
 
130
  parser = get_parser(row)
131
  dep_err = ensure_js_deps(repo_dir)
132
  sh(row.get("rebuild_cmds"), repo_dir)
@@ -142,6 +181,7 @@ def run_tests(row, repo_dir, lang):
142
  out += o + "\n"
143
  _, o, _ = run("for f in reports/*; do [ -f \"$f\" ] && cat \"$f\"; done", repo_dir, 120)
144
  out += o + "\n"
 
145
  return parser(out), out[-3000:]
146
 
147
 
@@ -226,7 +266,10 @@ def verify_row(row, lang):
226
  if rc != 0:
227
  rec["error"] = f"checkout failed: {out[-500:]}"
228
  return rec
 
229
 
 
 
230
  os.environ["PATH"] = ":".join(LANG_PATH_PREPEND.get(lang, [])) + ":" + os.environ["PATH"]
231
  def tb(cmds):
232
  return [c.replace(TESTBED, repo_dir) for c in (cmds or [])]
@@ -244,7 +287,7 @@ def verify_row(row, lang):
244
  pre_runs = []
245
  for i in range(2):
246
  s = time.time()
247
- tests, tail = run_tests(row, repo_dir, lang)
248
  pre_runs.append((tests, tail))
249
  rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)
250
  pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail", allow_missing=True)[1]
@@ -269,7 +312,7 @@ def verify_row(row, lang):
269
  post_runs = []
270
  for i in range(2):
271
  s = time.time()
272
- tests, tail = run_tests(row, repo_dir, lang)
273
  post_runs.append((tests, tail))
274
  rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)
275
  f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)
 
1
+ """PatchBench row verification + context expansion harness (v0.8).
2
 
3
  For each candidate row:
4
  1. clone the repo at base_commit
 
22
  reports/<lang>-test-results.json`; the row's print_cmds list is often empty)
23
  - JS/TS: if package.json exists without node_modules, deps are installed with the
24
  repo's own package manager (detected from lockfile)
25
+ - rust: cargo target dirs are wiped between rows AND all builds go to one shared
26
+ CARGO_TARGET_DIR outside the repo, so disk usage is monitorable and reclaimable
27
 
28
  v0.7: TimeoutExpired.stdout/stderr can be bytes (python quirk under capture_output) --
29
  decode before concatenating. This crashed slow maven builds at the 2100s timeout.
30
+ v0.8: disk guard. Three rust jobs died on the 50G ephemeral-storage quota mid-row.
31
+ Now: shared CARGO_TARGET_DIR, a check before every test phase that wipes build
32
+ caches when free space < 6G (raising "disk_pressure" instead of getting the pod
33
+ evicted, which loses every remaining row), and df/du logging after each phase so
34
+ the next quota failure is diagnosable from the log.
35
 
36
  Usage (inside a job with the right language toolchain image):
37
  python verify.py --lang go --file pilot/candidates/go.jsonl --limit 6
 
43
  CMD_TIMEOUT_S = 2100
44
  GIT_TIMEOUT_S = 900
45
  MAX_CONTEXT_LINES = 1500
46
+ DISK_FREE_MIN_BYTES = 6 * 1024**3 # reclaim below this
47
+ DISK_ABORT_BYTES = 2 * 1024**3 # abort row below this after reclaim
48
+ RUST_SHARED_TARGET = "/tmp/pb-cargo-target"
49
 
50
  LANG_PATH_PREPEND = {
51
  "go": ["/usr/local/go/bin"],
 
84
  return True, ""
85
 
86
 
87
+ def free_bytes(path="/tmp"):
88
+ try:
89
+ st = os.statvfs(path)
90
+ return st.f_bavail * st.f_frsize
91
+ except OSError:
92
+ return 1 << 62
93
+
94
+
95
+ def log_disk(tag):
96
+ _, out, _ = run("df -h /tmp 2>/dev/null | tail -n +2; "
97
+ "du -sh /tmp/pb-cargo-target /tmp/cache /usr/local/cargo/registry 2>/dev/null",
98
+ "/tmp", 120)
99
+ print(f"[disk:{tag}] free={free_bytes() >> 30}G | {out.strip()[:400]}", flush=True)
100
+
101
+
102
+ def reclaim_disk():
103
+ """Wipe build artifacts (not .git clones, not the registry) to free space."""
104
+ run("rm -rf /tmp/pb-cargo-target", "/tmp", 600)
105
+
106
+
107
+ def disk_guard(tag):
108
+ """Raise instead of letting the pod get evicted -- an eviction loses all rows."""
109
+ if free_bytes() < DISK_FREE_MIN_BYTES:
110
+ print(f"[disk:{tag}] low, reclaiming shared target dir", flush=True)
111
+ reclaim_disk()
112
+ if free_bytes() < DISK_ABORT_BYTES:
113
+ raise RuntimeError(f"disk_pressure: only {free_bytes() >> 30}G free after reclaim "
114
+ f"(tag={tag}); aborting row to save the remaining rows")
115
+
116
+
117
  def apply_patch(text, cwd):
118
  pf = os.path.join(cwd, ".pb_patch")
119
  with open(pf, "w") as f:
 
130
  def clean_state(repo_dir, lang=None):
131
  run("git checkout -f HEAD -- . && git clean -fdxq", repo_dir, 120)
132
  if lang == "rust":
 
133
  run("find . -name target -type d -prune -exec rm -rf {} +", repo_dir, 300)
134
+ run(f"rm -rf {RUST_SHARED_TARGET}", "/tmp", 300)
135
 
136
 
137
  def get_parser(row):
 
162
  return None if ok else f"js deps install failed: {err}"
163
 
164
 
165
+ def run_tests(row, repo_dir, lang, phase_tag=""):
166
  """Run rebuild_cmds, test_cmds, print_cmds, then surface any reports/* the test
167
  commands wrote. Returns (tests_dict, combined_output_tail)."""
168
+ disk_guard(f"{phase_tag}-pre")
169
  parser = get_parser(row)
170
  dep_err = ensure_js_deps(repo_dir)
171
  sh(row.get("rebuild_cmds"), repo_dir)
 
181
  out += o + "\n"
182
  _, o, _ = run("for f in reports/*; do [ -f \"$f\" ] && cat \"$f\"; done", repo_dir, 120)
183
  out += o + "\n"
184
+ log_disk(f"{phase_tag}-post")
185
  return parser(out), out[-3000:]
186
 
187
 
 
266
  if rc != 0:
267
  rec["error"] = f"checkout failed: {out[-500:]}"
268
  return rec
269
+ log_disk(f"cloned:{row['id']}")
270
 
271
+ if lang == "rust":
272
+ os.environ["CARGO_TARGET_DIR"] = RUST_SHARED_TARGET
273
  os.environ["PATH"] = ":".join(LANG_PATH_PREPEND.get(lang, [])) + ":" + os.environ["PATH"]
274
  def tb(cmds):
275
  return [c.replace(TESTBED, repo_dir) for c in (cmds or [])]
 
287
  pre_runs = []
288
  for i in range(2):
289
  s = time.time()
290
+ tests, tail = run_tests(row, repo_dir, lang, f"pre{i}:{row['id']}")
291
  pre_runs.append((tests, tail))
292
  rec["timing"][f"pre_test_{i}"] = round(time.time() - s, 1)
293
  pre_detail = grade(pre_runs[0][0], row["fail_to_pass"], "fail", allow_missing=True)[1]
 
312
  post_runs = []
313
  for i in range(2):
314
  s = time.time()
315
+ tests, tail = run_tests(row, repo_dir, lang, f"post{i}:{row['id']}")
316
  post_runs.append((tests, tail))
317
  rec["timing"][f"post_test_{i}"] = round(time.time() - s, 1)
318
  f2p_ok_post = all(grade(t, row["fail_to_pass"], "pass")[0] for t, _ in post_runs)