AdithyaSK HF Staff commited on
Commit
d7056fd
·
verified ·
1 Parent(s): 67e6ef0

369 validated tasks; grader keeps large builds within the 10 GB disk (part 23)

Browse files

Re-ran the oracle with the updated verifier. The verifier now empties Lake's per-module setup files and generated C once each module is built, and deletes the build before writing its verdict, so a build that fills the disk scores 0 instead of leaving the trial without a result. 14 more tasks validated; not-validated list updated.

tasks/weighted-sweep-moments/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 40
23
  reference_lean_bytes = 815310
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 338
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 815310
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 329
27
  difficulty = "research"
28
 
29
  [agent]
tasks/weighted-sweep-moments/tests/grade.py CHANGED
@@ -35,6 +35,7 @@ import subprocess
35
  import sys
36
  import tarfile
37
  import tempfile
 
38
  import time
39
  from pathlib import Path
40
 
@@ -46,6 +47,7 @@ RUN_ROOT = Path("/var/lib/oai-grade")
46
  GRADER = "grader"
47
  SUCCESS_LINE = "Your solution is okay!"
48
  GRADE_THREADS = "2"
 
49
  # Lake and Comparator wording when a build process is killed for running out of memory.
50
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
51
 
@@ -240,6 +242,49 @@ def out_of_memory(out: str) -> bool:
240
  return any(m in out for m in OOM_MARKERS)
241
 
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
244
  env = {
245
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
@@ -254,10 +299,17 @@ def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) ->
254
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
255
  "lake", "env", "comparator", "config.json",
256
  ]
257
- code, stdout, stderr = run_with_timeout(
258
- cmd, cwd=run, timeout_sec=timeout_sec,
259
- kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
260
- )
 
 
 
 
 
 
 
261
  return code, stdout + "\n--- stderr ---\n" + stderr
262
 
263
 
@@ -297,6 +349,8 @@ def classify(code: int | None, out: str) -> tuple[int | None, str]:
297
  if code is None:
298
  return 0, "timed out while building or checking the submission"
299
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
 
 
300
  if out_of_memory(out):
301
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
302
  return 0, "rejected: " + " | ".join(tail)[-4000:]
@@ -311,6 +365,7 @@ def main() -> int:
311
  task = json.loads((TESTS / "task.json").read_text())
312
  details: dict = {"task": task["challenge"], "started_at": time.time()}
313
  reward: int | None = None
 
314
  try:
315
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
316
  deadline = time.time() + int(task["grade_timeout_sec"])
@@ -325,26 +380,33 @@ def main() -> int:
325
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
326
  # in a fresh directory: the first attempt's .lake was written by the submission's own
327
  # build and must not be trusted for the challenge.
 
328
  run = fresh_run(task)
329
  unpack_submission(run)
330
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
331
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
332
  kill_grader()
333
  details["retried_single_thread"] = True
334
- (VERIFIER_DIR / "comparator.log").write_text(log)
335
  reward, details["reason"] = classify(code, out)
336
  details["comparator_exit"] = code
337
  except Rejected as exc:
338
  reward, details["reason"] = 0, f"rejected: {exc}"
339
  except GradingError as exc:
340
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
341
  finally:
342
  try:
343
  kill_grader()
344
  except GradingError as exc:
345
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
 
 
346
  details["reward"] = reward
347
  details["finished_at"] = time.time()
 
348
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
349
  print(json.dumps(details, indent=2))
350
  if reward is not None:
 
35
  import sys
36
  import tarfile
37
  import tempfile
38
+ import threading
39
  import time
40
  from pathlib import Path
41
 
 
47
  GRADER = "grader"
48
  SUCCESS_LINE = "Your solution is okay!"
49
  GRADE_THREADS = "2"
50
+ SCRATCH_SWEEP_SEC = 15
51
  # Lake and Comparator wording when a build process is killed for running out of memory.
52
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
53
 
 
242
  return any(m in out for m in OOM_MARKERS)
243
 
244
 
245
+ def out_of_disk(out: str) -> bool:
246
+ return "no space left on device" in out.lower()
247
+
248
+
249
+ # Run as the grader user by `empty_build_scratch`. argv: the .lake/build/ir directory.
250
+ EMPTY_SCRATCH = r"""
251
+ import os, sys
252
+ for dirpath, _, files in os.walk(sys.argv[1]):
253
+ for name in files:
254
+ if not name.endswith(".setup.json"):
255
+ continue
256
+ base = os.path.join(dirpath, name[:-len(".setup.json")])
257
+ try:
258
+ # Lake writes X.c.hash once Lean, and leanir if the module needs it, are done with X;
259
+ # both read X.setup.json, so it may only be emptied after that.
260
+ if os.stat(base + ".c.hash").st_mtime < os.stat(base + ".setup.json").st_mtime:
261
+ continue
262
+ for path in (base + ".setup.json", base + ".c"):
263
+ if os.path.getsize(path):
264
+ os.truncate(path, 0)
265
+ except OSError:
266
+ pass
267
+ """
268
+
269
+
270
+ def empty_build_scratch(run: Path, stop: threading.Event) -> None:
271
+ """Until ``stop`` is set, empty files Lake leaves in .lake/build/ir that grading never reads.
272
+
273
+ For every module Lake writes a `.setup.json` (its imports with the path of every .olean they
274
+ pull in, about 5.5 MB with Mathlib) and the module compiled to C. Neither is used once the
275
+ module is built, and for proofs of 1,000-2,000 modules they filled the 10 GB disk before the
276
+ build finished. Lake keeps the recorded hashes, so emptied files do not trigger a rebuild.
277
+ This runs as the grader user, so it can touch nothing the build could not.
278
+ """
279
+ ir = str(run / ".lake" / "build" / "ir")
280
+ while not stop.wait(SCRATCH_SWEEP_SEC):
281
+ try:
282
+ subprocess.run(["runuser", "-u", GRADER, "--", sys.executable, "-c", EMPTY_SCRATCH, ir],
283
+ capture_output=True, timeout=600)
284
+ except subprocess.TimeoutExpired:
285
+ pass
286
+
287
+
288
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
289
  env = {
290
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
 
299
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
300
  "lake", "env", "comparator", "config.json",
301
  ]
302
+ stop = threading.Event()
303
+ sweeper = threading.Thread(target=empty_build_scratch, args=(run, stop), daemon=True)
304
+ sweeper.start()
305
+ try:
306
+ code, stdout, stderr = run_with_timeout(
307
+ cmd, cwd=run, timeout_sec=timeout_sec,
308
+ kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
309
+ )
310
+ finally:
311
+ stop.set()
312
+ sweeper.join()
313
  return code, stdout + "\n--- stderr ---\n" + stderr
314
 
315
 
 
349
  if code is None:
350
  return 0, "timed out while building or checking the submission"
351
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
352
+ if out_of_disk(out):
353
+ return 0, "rejected: the build ran out of disk space (10 GB) | " + " | ".join(tail)[-3000:]
354
  if out_of_memory(out):
355
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
356
  return 0, "rejected: " + " | ".join(tail)[-4000:]
 
365
  task = json.loads((TESTS / "task.json").read_text())
366
  details: dict = {"task": task["challenge"], "started_at": time.time()}
367
  reward: int | None = None
368
+ log = ""
369
  try:
370
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
371
  deadline = time.time() + int(task["grade_timeout_sec"])
 
380
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
381
  # in a fresh directory: the first attempt's .lake was written by the submission's own
382
  # build and must not be trusted for the challenge.
383
+ shutil.rmtree(run, ignore_errors=True)
384
  run = fresh_run(task)
385
  unpack_submission(run)
386
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
387
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
388
  kill_grader()
389
  details["retried_single_thread"] = True
 
390
  reward, details["reason"] = classify(code, out)
391
  details["comparator_exit"] = code
392
  except Rejected as exc:
393
  reward, details["reason"] = 0, f"rejected: {exc}"
394
  except GradingError as exc:
395
  reward, details["reason"] = None, f"grading error: {exc}"
396
+ except Exception as exc:
397
+ reward, details["reason"] = None, f"grading error: {type(exc).__name__}: {exc}"
398
  finally:
399
  try:
400
  kill_grader()
401
  except GradingError as exc:
402
  reward, details["reason"] = None, f"grading error: {exc}"
403
+ # Free the build before writing anything. A build that filled the disk would otherwise
404
+ # make these writes fail, and with no space left the sandbox cannot report that the
405
+ # verifier exited, so Harbor waits until its own timeout and records no verdict.
406
+ shutil.rmtree(RUN_ROOT, ignore_errors=True)
407
  details["reward"] = reward
408
  details["finished_at"] = time.time()
409
+ (VERIFIER_DIR / "comparator.log").write_text(log)
410
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
411
  print(json.dumps(details, indent=2))
412
  if reward is not None:
tasks/weisfeiler-leman/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 43
23
  reference_lean_bytes = 917937
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 401
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 917937
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 301
27
  difficulty = "research"
28
 
29
  [agent]
tasks/weisfeiler-leman/tests/grade.py CHANGED
@@ -35,6 +35,7 @@ import subprocess
35
  import sys
36
  import tarfile
37
  import tempfile
 
38
  import time
39
  from pathlib import Path
40
 
@@ -46,6 +47,7 @@ RUN_ROOT = Path("/var/lib/oai-grade")
46
  GRADER = "grader"
47
  SUCCESS_LINE = "Your solution is okay!"
48
  GRADE_THREADS = "2"
 
49
  # Lake and Comparator wording when a build process is killed for running out of memory.
50
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
51
 
@@ -240,6 +242,49 @@ def out_of_memory(out: str) -> bool:
240
  return any(m in out for m in OOM_MARKERS)
241
 
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
244
  env = {
245
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
@@ -254,10 +299,17 @@ def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) ->
254
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
255
  "lake", "env", "comparator", "config.json",
256
  ]
257
- code, stdout, stderr = run_with_timeout(
258
- cmd, cwd=run, timeout_sec=timeout_sec,
259
- kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
260
- )
 
 
 
 
 
 
 
261
  return code, stdout + "\n--- stderr ---\n" + stderr
262
 
263
 
@@ -297,6 +349,8 @@ def classify(code: int | None, out: str) -> tuple[int | None, str]:
297
  if code is None:
298
  return 0, "timed out while building or checking the submission"
299
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
 
 
300
  if out_of_memory(out):
301
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
302
  return 0, "rejected: " + " | ".join(tail)[-4000:]
@@ -311,6 +365,7 @@ def main() -> int:
311
  task = json.loads((TESTS / "task.json").read_text())
312
  details: dict = {"task": task["challenge"], "started_at": time.time()}
313
  reward: int | None = None
 
314
  try:
315
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
316
  deadline = time.time() + int(task["grade_timeout_sec"])
@@ -325,26 +380,33 @@ def main() -> int:
325
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
326
  # in a fresh directory: the first attempt's .lake was written by the submission's own
327
  # build and must not be trusted for the challenge.
 
328
  run = fresh_run(task)
329
  unpack_submission(run)
330
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
331
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
332
  kill_grader()
333
  details["retried_single_thread"] = True
334
- (VERIFIER_DIR / "comparator.log").write_text(log)
335
  reward, details["reason"] = classify(code, out)
336
  details["comparator_exit"] = code
337
  except Rejected as exc:
338
  reward, details["reason"] = 0, f"rejected: {exc}"
339
  except GradingError as exc:
340
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
341
  finally:
342
  try:
343
  kill_grader()
344
  except GradingError as exc:
345
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
 
 
346
  details["reward"] = reward
347
  details["finished_at"] = time.time()
 
348
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
349
  print(json.dumps(details, indent=2))
350
  if reward is not None:
 
35
  import sys
36
  import tarfile
37
  import tempfile
38
+ import threading
39
  import time
40
  from pathlib import Path
41
 
 
47
  GRADER = "grader"
48
  SUCCESS_LINE = "Your solution is okay!"
49
  GRADE_THREADS = "2"
50
+ SCRATCH_SWEEP_SEC = 15
51
  # Lake and Comparator wording when a build process is killed for running out of memory.
52
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
53
 
 
242
  return any(m in out for m in OOM_MARKERS)
243
 
244
 
245
+ def out_of_disk(out: str) -> bool:
246
+ return "no space left on device" in out.lower()
247
+
248
+
249
+ # Run as the grader user by `empty_build_scratch`. argv: the .lake/build/ir directory.
250
+ EMPTY_SCRATCH = r"""
251
+ import os, sys
252
+ for dirpath, _, files in os.walk(sys.argv[1]):
253
+ for name in files:
254
+ if not name.endswith(".setup.json"):
255
+ continue
256
+ base = os.path.join(dirpath, name[:-len(".setup.json")])
257
+ try:
258
+ # Lake writes X.c.hash once Lean, and leanir if the module needs it, are done with X;
259
+ # both read X.setup.json, so it may only be emptied after that.
260
+ if os.stat(base + ".c.hash").st_mtime < os.stat(base + ".setup.json").st_mtime:
261
+ continue
262
+ for path in (base + ".setup.json", base + ".c"):
263
+ if os.path.getsize(path):
264
+ os.truncate(path, 0)
265
+ except OSError:
266
+ pass
267
+ """
268
+
269
+
270
+ def empty_build_scratch(run: Path, stop: threading.Event) -> None:
271
+ """Until ``stop`` is set, empty files Lake leaves in .lake/build/ir that grading never reads.
272
+
273
+ For every module Lake writes a `.setup.json` (its imports with the path of every .olean they
274
+ pull in, about 5.5 MB with Mathlib) and the module compiled to C. Neither is used once the
275
+ module is built, and for proofs of 1,000-2,000 modules they filled the 10 GB disk before the
276
+ build finished. Lake keeps the recorded hashes, so emptied files do not trigger a rebuild.
277
+ This runs as the grader user, so it can touch nothing the build could not.
278
+ """
279
+ ir = str(run / ".lake" / "build" / "ir")
280
+ while not stop.wait(SCRATCH_SWEEP_SEC):
281
+ try:
282
+ subprocess.run(["runuser", "-u", GRADER, "--", sys.executable, "-c", EMPTY_SCRATCH, ir],
283
+ capture_output=True, timeout=600)
284
+ except subprocess.TimeoutExpired:
285
+ pass
286
+
287
+
288
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
289
  env = {
290
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
 
299
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
300
  "lake", "env", "comparator", "config.json",
301
  ]
302
+ stop = threading.Event()
303
+ sweeper = threading.Thread(target=empty_build_scratch, args=(run, stop), daemon=True)
304
+ sweeper.start()
305
+ try:
306
+ code, stdout, stderr = run_with_timeout(
307
+ cmd, cwd=run, timeout_sec=timeout_sec,
308
+ kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
309
+ )
310
+ finally:
311
+ stop.set()
312
+ sweeper.join()
313
  return code, stdout + "\n--- stderr ---\n" + stderr
314
 
315
 
 
349
  if code is None:
350
  return 0, "timed out while building or checking the submission"
351
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
352
+ if out_of_disk(out):
353
+ return 0, "rejected: the build ran out of disk space (10 GB) | " + " | ".join(tail)[-3000:]
354
  if out_of_memory(out):
355
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
356
  return 0, "rejected: " + " | ".join(tail)[-4000:]
 
365
  task = json.loads((TESTS / "task.json").read_text())
366
  details: dict = {"task": task["challenge"], "started_at": time.time()}
367
  reward: int | None = None
368
+ log = ""
369
  try:
370
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
371
  deadline = time.time() + int(task["grade_timeout_sec"])
 
380
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
381
  # in a fresh directory: the first attempt's .lake was written by the submission's own
382
  # build and must not be trusted for the challenge.
383
+ shutil.rmtree(run, ignore_errors=True)
384
  run = fresh_run(task)
385
  unpack_submission(run)
386
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
387
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
388
  kill_grader()
389
  details["retried_single_thread"] = True
 
390
  reward, details["reason"] = classify(code, out)
391
  details["comparator_exit"] = code
392
  except Rejected as exc:
393
  reward, details["reason"] = 0, f"rejected: {exc}"
394
  except GradingError as exc:
395
  reward, details["reason"] = None, f"grading error: {exc}"
396
+ except Exception as exc:
397
+ reward, details["reason"] = None, f"grading error: {type(exc).__name__}: {exc}"
398
  finally:
399
  try:
400
  kill_grader()
401
  except GradingError as exc:
402
  reward, details["reason"] = None, f"grading error: {exc}"
403
+ # Free the build before writing anything. A build that filled the disk would otherwise
404
+ # make these writes fail, and with no space left the sandbox cannot report that the
405
+ # verifier exited, so Harbor waits until its own timeout and records no verdict.
406
+ shutil.rmtree(RUN_ROOT, ignore_errors=True)
407
  details["reward"] = reward
408
  details["finished_at"] = time.time()
409
+ (VERIFIER_DIR / "comparator.log").write_text(log)
410
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
411
  print(json.dumps(details, indent=2))
412
  if reward is not None:
tasks/witnessed-choice/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 27
23
  reference_lean_bytes = 1118157
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 585
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 1118157
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 485
27
  difficulty = "research"
28
 
29
  [agent]
tasks/witnessed-choice/tests/grade.py CHANGED
@@ -35,6 +35,7 @@ import subprocess
35
  import sys
36
  import tarfile
37
  import tempfile
 
38
  import time
39
  from pathlib import Path
40
 
@@ -46,6 +47,7 @@ RUN_ROOT = Path("/var/lib/oai-grade")
46
  GRADER = "grader"
47
  SUCCESS_LINE = "Your solution is okay!"
48
  GRADE_THREADS = "2"
 
49
  # Lake and Comparator wording when a build process is killed for running out of memory.
50
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
51
 
@@ -240,6 +242,49 @@ def out_of_memory(out: str) -> bool:
240
  return any(m in out for m in OOM_MARKERS)
241
 
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
244
  env = {
245
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
@@ -254,10 +299,17 @@ def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) ->
254
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
255
  "lake", "env", "comparator", "config.json",
256
  ]
257
- code, stdout, stderr = run_with_timeout(
258
- cmd, cwd=run, timeout_sec=timeout_sec,
259
- kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
260
- )
 
 
 
 
 
 
 
261
  return code, stdout + "\n--- stderr ---\n" + stderr
262
 
263
 
@@ -297,6 +349,8 @@ def classify(code: int | None, out: str) -> tuple[int | None, str]:
297
  if code is None:
298
  return 0, "timed out while building or checking the submission"
299
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
 
 
300
  if out_of_memory(out):
301
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
302
  return 0, "rejected: " + " | ".join(tail)[-4000:]
@@ -311,6 +365,7 @@ def main() -> int:
311
  task = json.loads((TESTS / "task.json").read_text())
312
  details: dict = {"task": task["challenge"], "started_at": time.time()}
313
  reward: int | None = None
 
314
  try:
315
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
316
  deadline = time.time() + int(task["grade_timeout_sec"])
@@ -325,26 +380,33 @@ def main() -> int:
325
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
326
  # in a fresh directory: the first attempt's .lake was written by the submission's own
327
  # build and must not be trusted for the challenge.
 
328
  run = fresh_run(task)
329
  unpack_submission(run)
330
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
331
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
332
  kill_grader()
333
  details["retried_single_thread"] = True
334
- (VERIFIER_DIR / "comparator.log").write_text(log)
335
  reward, details["reason"] = classify(code, out)
336
  details["comparator_exit"] = code
337
  except Rejected as exc:
338
  reward, details["reason"] = 0, f"rejected: {exc}"
339
  except GradingError as exc:
340
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
341
  finally:
342
  try:
343
  kill_grader()
344
  except GradingError as exc:
345
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
 
 
346
  details["reward"] = reward
347
  details["finished_at"] = time.time()
 
348
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
349
  print(json.dumps(details, indent=2))
350
  if reward is not None:
 
35
  import sys
36
  import tarfile
37
  import tempfile
38
+ import threading
39
  import time
40
  from pathlib import Path
41
 
 
47
  GRADER = "grader"
48
  SUCCESS_LINE = "Your solution is okay!"
49
  GRADE_THREADS = "2"
50
+ SCRATCH_SWEEP_SEC = 15
51
  # Lake and Comparator wording when a build process is killed for running out of memory.
52
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
53
 
 
242
  return any(m in out for m in OOM_MARKERS)
243
 
244
 
245
+ def out_of_disk(out: str) -> bool:
246
+ return "no space left on device" in out.lower()
247
+
248
+
249
+ # Run as the grader user by `empty_build_scratch`. argv: the .lake/build/ir directory.
250
+ EMPTY_SCRATCH = r"""
251
+ import os, sys
252
+ for dirpath, _, files in os.walk(sys.argv[1]):
253
+ for name in files:
254
+ if not name.endswith(".setup.json"):
255
+ continue
256
+ base = os.path.join(dirpath, name[:-len(".setup.json")])
257
+ try:
258
+ # Lake writes X.c.hash once Lean, and leanir if the module needs it, are done with X;
259
+ # both read X.setup.json, so it may only be emptied after that.
260
+ if os.stat(base + ".c.hash").st_mtime < os.stat(base + ".setup.json").st_mtime:
261
+ continue
262
+ for path in (base + ".setup.json", base + ".c"):
263
+ if os.path.getsize(path):
264
+ os.truncate(path, 0)
265
+ except OSError:
266
+ pass
267
+ """
268
+
269
+
270
+ def empty_build_scratch(run: Path, stop: threading.Event) -> None:
271
+ """Until ``stop`` is set, empty files Lake leaves in .lake/build/ir that grading never reads.
272
+
273
+ For every module Lake writes a `.setup.json` (its imports with the path of every .olean they
274
+ pull in, about 5.5 MB with Mathlib) and the module compiled to C. Neither is used once the
275
+ module is built, and for proofs of 1,000-2,000 modules they filled the 10 GB disk before the
276
+ build finished. Lake keeps the recorded hashes, so emptied files do not trigger a rebuild.
277
+ This runs as the grader user, so it can touch nothing the build could not.
278
+ """
279
+ ir = str(run / ".lake" / "build" / "ir")
280
+ while not stop.wait(SCRATCH_SWEEP_SEC):
281
+ try:
282
+ subprocess.run(["runuser", "-u", GRADER, "--", sys.executable, "-c", EMPTY_SCRATCH, ir],
283
+ capture_output=True, timeout=600)
284
+ except subprocess.TimeoutExpired:
285
+ pass
286
+
287
+
288
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
289
  env = {
290
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
 
299
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
300
  "lake", "env", "comparator", "config.json",
301
  ]
302
+ stop = threading.Event()
303
+ sweeper = threading.Thread(target=empty_build_scratch, args=(run, stop), daemon=True)
304
+ sweeper.start()
305
+ try:
306
+ code, stdout, stderr = run_with_timeout(
307
+ cmd, cwd=run, timeout_sec=timeout_sec,
308
+ kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
309
+ )
310
+ finally:
311
+ stop.set()
312
+ sweeper.join()
313
  return code, stdout + "\n--- stderr ---\n" + stderr
314
 
315
 
 
349
  if code is None:
350
  return 0, "timed out while building or checking the submission"
351
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
352
+ if out_of_disk(out):
353
+ return 0, "rejected: the build ran out of disk space (10 GB) | " + " | ".join(tail)[-3000:]
354
  if out_of_memory(out):
355
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
356
  return 0, "rejected: " + " | ".join(tail)[-4000:]
 
365
  task = json.loads((TESTS / "task.json").read_text())
366
  details: dict = {"task": task["challenge"], "started_at": time.time()}
367
  reward: int | None = None
368
+ log = ""
369
  try:
370
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
371
  deadline = time.time() + int(task["grade_timeout_sec"])
 
380
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
381
  # in a fresh directory: the first attempt's .lake was written by the submission's own
382
  # build and must not be trusted for the challenge.
383
+ shutil.rmtree(run, ignore_errors=True)
384
  run = fresh_run(task)
385
  unpack_submission(run)
386
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
387
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
388
  kill_grader()
389
  details["retried_single_thread"] = True
 
390
  reward, details["reason"] = classify(code, out)
391
  details["comparator_exit"] = code
392
  except Rejected as exc:
393
  reward, details["reason"] = 0, f"rejected: {exc}"
394
  except GradingError as exc:
395
  reward, details["reason"] = None, f"grading error: {exc}"
396
+ except Exception as exc:
397
+ reward, details["reason"] = None, f"grading error: {type(exc).__name__}: {exc}"
398
  finally:
399
  try:
400
  kill_grader()
401
  except GradingError as exc:
402
  reward, details["reason"] = None, f"grading error: {exc}"
403
+ # Free the build before writing anything. A build that filled the disk would otherwise
404
+ # make these writes fail, and with no space left the sandbox cannot report that the
405
+ # verifier exited, so Harbor waits until its own timeout and records no verdict.
406
+ shutil.rmtree(RUN_ROOT, ignore_errors=True)
407
  details["reward"] = reward
408
  details["finished_at"] = time.time()
409
+ (VERIFIER_DIR / "comparator.log").write_text(log)
410
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
411
  print(json.dumps(details, indent=2))
412
  if reward is not None:
tasks/wl-identification/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 67
23
  reference_lean_bytes = 765224
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 529
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 765224
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 358
27
  difficulty = "research"
28
 
29
  [agent]
tasks/wl-identification/tests/grade.py CHANGED
@@ -35,6 +35,7 @@ import subprocess
35
  import sys
36
  import tarfile
37
  import tempfile
 
38
  import time
39
  from pathlib import Path
40
 
@@ -46,6 +47,7 @@ RUN_ROOT = Path("/var/lib/oai-grade")
46
  GRADER = "grader"
47
  SUCCESS_LINE = "Your solution is okay!"
48
  GRADE_THREADS = "2"
 
49
  # Lake and Comparator wording when a build process is killed for running out of memory.
50
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
51
 
@@ -240,6 +242,49 @@ def out_of_memory(out: str) -> bool:
240
  return any(m in out for m in OOM_MARKERS)
241
 
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
244
  env = {
245
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
@@ -254,10 +299,17 @@ def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) ->
254
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
255
  "lake", "env", "comparator", "config.json",
256
  ]
257
- code, stdout, stderr = run_with_timeout(
258
- cmd, cwd=run, timeout_sec=timeout_sec,
259
- kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
260
- )
 
 
 
 
 
 
 
261
  return code, stdout + "\n--- stderr ---\n" + stderr
262
 
263
 
@@ -297,6 +349,8 @@ def classify(code: int | None, out: str) -> tuple[int | None, str]:
297
  if code is None:
298
  return 0, "timed out while building or checking the submission"
299
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
 
 
300
  if out_of_memory(out):
301
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
302
  return 0, "rejected: " + " | ".join(tail)[-4000:]
@@ -311,6 +365,7 @@ def main() -> int:
311
  task = json.loads((TESTS / "task.json").read_text())
312
  details: dict = {"task": task["challenge"], "started_at": time.time()}
313
  reward: int | None = None
 
314
  try:
315
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
316
  deadline = time.time() + int(task["grade_timeout_sec"])
@@ -325,26 +380,33 @@ def main() -> int:
325
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
326
  # in a fresh directory: the first attempt's .lake was written by the submission's own
327
  # build and must not be trusted for the challenge.
 
328
  run = fresh_run(task)
329
  unpack_submission(run)
330
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
331
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
332
  kill_grader()
333
  details["retried_single_thread"] = True
334
- (VERIFIER_DIR / "comparator.log").write_text(log)
335
  reward, details["reason"] = classify(code, out)
336
  details["comparator_exit"] = code
337
  except Rejected as exc:
338
  reward, details["reason"] = 0, f"rejected: {exc}"
339
  except GradingError as exc:
340
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
341
  finally:
342
  try:
343
  kill_grader()
344
  except GradingError as exc:
345
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
 
 
346
  details["reward"] = reward
347
  details["finished_at"] = time.time()
 
348
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
349
  print(json.dumps(details, indent=2))
350
  if reward is not None:
 
35
  import sys
36
  import tarfile
37
  import tempfile
38
+ import threading
39
  import time
40
  from pathlib import Path
41
 
 
47
  GRADER = "grader"
48
  SUCCESS_LINE = "Your solution is okay!"
49
  GRADE_THREADS = "2"
50
+ SCRATCH_SWEEP_SEC = 15
51
  # Lake and Comparator wording when a build process is killed for running out of memory.
52
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
53
 
 
242
  return any(m in out for m in OOM_MARKERS)
243
 
244
 
245
+ def out_of_disk(out: str) -> bool:
246
+ return "no space left on device" in out.lower()
247
+
248
+
249
+ # Run as the grader user by `empty_build_scratch`. argv: the .lake/build/ir directory.
250
+ EMPTY_SCRATCH = r"""
251
+ import os, sys
252
+ for dirpath, _, files in os.walk(sys.argv[1]):
253
+ for name in files:
254
+ if not name.endswith(".setup.json"):
255
+ continue
256
+ base = os.path.join(dirpath, name[:-len(".setup.json")])
257
+ try:
258
+ # Lake writes X.c.hash once Lean, and leanir if the module needs it, are done with X;
259
+ # both read X.setup.json, so it may only be emptied after that.
260
+ if os.stat(base + ".c.hash").st_mtime < os.stat(base + ".setup.json").st_mtime:
261
+ continue
262
+ for path in (base + ".setup.json", base + ".c"):
263
+ if os.path.getsize(path):
264
+ os.truncate(path, 0)
265
+ except OSError:
266
+ pass
267
+ """
268
+
269
+
270
+ def empty_build_scratch(run: Path, stop: threading.Event) -> None:
271
+ """Until ``stop`` is set, empty files Lake leaves in .lake/build/ir that grading never reads.
272
+
273
+ For every module Lake writes a `.setup.json` (its imports with the path of every .olean they
274
+ pull in, about 5.5 MB with Mathlib) and the module compiled to C. Neither is used once the
275
+ module is built, and for proofs of 1,000-2,000 modules they filled the 10 GB disk before the
276
+ build finished. Lake keeps the recorded hashes, so emptied files do not trigger a rebuild.
277
+ This runs as the grader user, so it can touch nothing the build could not.
278
+ """
279
+ ir = str(run / ".lake" / "build" / "ir")
280
+ while not stop.wait(SCRATCH_SWEEP_SEC):
281
+ try:
282
+ subprocess.run(["runuser", "-u", GRADER, "--", sys.executable, "-c", EMPTY_SCRATCH, ir],
283
+ capture_output=True, timeout=600)
284
+ except subprocess.TimeoutExpired:
285
+ pass
286
+
287
+
288
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
289
  env = {
290
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
 
299
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
300
  "lake", "env", "comparator", "config.json",
301
  ]
302
+ stop = threading.Event()
303
+ sweeper = threading.Thread(target=empty_build_scratch, args=(run, stop), daemon=True)
304
+ sweeper.start()
305
+ try:
306
+ code, stdout, stderr = run_with_timeout(
307
+ cmd, cwd=run, timeout_sec=timeout_sec,
308
+ kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
309
+ )
310
+ finally:
311
+ stop.set()
312
+ sweeper.join()
313
  return code, stdout + "\n--- stderr ---\n" + stderr
314
 
315
 
 
349
  if code is None:
350
  return 0, "timed out while building or checking the submission"
351
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
352
+ if out_of_disk(out):
353
+ return 0, "rejected: the build ran out of disk space (10 GB) | " + " | ".join(tail)[-3000:]
354
  if out_of_memory(out):
355
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
356
  return 0, "rejected: " + " | ".join(tail)[-4000:]
 
365
  task = json.loads((TESTS / "task.json").read_text())
366
  details: dict = {"task": task["challenge"], "started_at": time.time()}
367
  reward: int | None = None
368
+ log = ""
369
  try:
370
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
371
  deadline = time.time() + int(task["grade_timeout_sec"])
 
380
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
381
  # in a fresh directory: the first attempt's .lake was written by the submission's own
382
  # build and must not be trusted for the challenge.
383
+ shutil.rmtree(run, ignore_errors=True)
384
  run = fresh_run(task)
385
  unpack_submission(run)
386
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
387
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
388
  kill_grader()
389
  details["retried_single_thread"] = True
 
390
  reward, details["reason"] = classify(code, out)
391
  details["comparator_exit"] = code
392
  except Rejected as exc:
393
  reward, details["reason"] = 0, f"rejected: {exc}"
394
  except GradingError as exc:
395
  reward, details["reason"] = None, f"grading error: {exc}"
396
+ except Exception as exc:
397
+ reward, details["reason"] = None, f"grading error: {type(exc).__name__}: {exc}"
398
  finally:
399
  try:
400
  kill_grader()
401
  except GradingError as exc:
402
  reward, details["reason"] = None, f"grading error: {exc}"
403
+ # Free the build before writing anything. A build that filled the disk would otherwise
404
+ # make these writes fail, and with no space left the sandbox cannot report that the
405
+ # verifier exited, so Harbor waits until its own timeout and records no verdict.
406
+ shutil.rmtree(RUN_ROOT, ignore_errors=True)
407
  details["reward"] = reward
408
  details["finished_at"] = time.time()
409
+ (VERIFIER_DIR / "comparator.log").write_text(log)
410
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
411
  print(json.dumps(details, indent=2))
412
  if reward is not None:
tasks/yau-counterexample/tests/grade.py CHANGED
@@ -35,6 +35,7 @@ import subprocess
35
  import sys
36
  import tarfile
37
  import tempfile
 
38
  import time
39
  from pathlib import Path
40
 
@@ -46,6 +47,7 @@ RUN_ROOT = Path("/var/lib/oai-grade")
46
  GRADER = "grader"
47
  SUCCESS_LINE = "Your solution is okay!"
48
  GRADE_THREADS = "2"
 
49
  # Lake and Comparator wording when a build process is killed for running out of memory.
50
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
51
 
@@ -240,6 +242,49 @@ def out_of_memory(out: str) -> bool:
240
  return any(m in out for m in OOM_MARKERS)
241
 
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
244
  env = {
245
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
@@ -254,10 +299,17 @@ def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) ->
254
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
255
  "lake", "env", "comparator", "config.json",
256
  ]
257
- code, stdout, stderr = run_with_timeout(
258
- cmd, cwd=run, timeout_sec=timeout_sec,
259
- kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
260
- )
 
 
 
 
 
 
 
261
  return code, stdout + "\n--- stderr ---\n" + stderr
262
 
263
 
@@ -297,6 +349,8 @@ def classify(code: int | None, out: str) -> tuple[int | None, str]:
297
  if code is None:
298
  return 0, "timed out while building or checking the submission"
299
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
 
 
300
  if out_of_memory(out):
301
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
302
  return 0, "rejected: " + " | ".join(tail)[-4000:]
@@ -311,6 +365,7 @@ def main() -> int:
311
  task = json.loads((TESTS / "task.json").read_text())
312
  details: dict = {"task": task["challenge"], "started_at": time.time()}
313
  reward: int | None = None
 
314
  try:
315
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
316
  deadline = time.time() + int(task["grade_timeout_sec"])
@@ -325,26 +380,33 @@ def main() -> int:
325
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
326
  # in a fresh directory: the first attempt's .lake was written by the submission's own
327
  # build and must not be trusted for the challenge.
 
328
  run = fresh_run(task)
329
  unpack_submission(run)
330
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
331
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
332
  kill_grader()
333
  details["retried_single_thread"] = True
334
- (VERIFIER_DIR / "comparator.log").write_text(log)
335
  reward, details["reason"] = classify(code, out)
336
  details["comparator_exit"] = code
337
  except Rejected as exc:
338
  reward, details["reason"] = 0, f"rejected: {exc}"
339
  except GradingError as exc:
340
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
341
  finally:
342
  try:
343
  kill_grader()
344
  except GradingError as exc:
345
  reward, details["reason"] = None, f"grading error: {exc}"
 
 
 
 
346
  details["reward"] = reward
347
  details["finished_at"] = time.time()
 
348
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
349
  print(json.dumps(details, indent=2))
350
  if reward is not None:
 
35
  import sys
36
  import tarfile
37
  import tempfile
38
+ import threading
39
  import time
40
  from pathlib import Path
41
 
 
47
  GRADER = "grader"
48
  SUCCESS_LINE = "Your solution is okay!"
49
  GRADE_THREADS = "2"
50
+ SCRATCH_SWEEP_SEC = 15
51
  # Lake and Comparator wording when a build process is killed for running out of memory.
52
  OOM_MARKERS = ("Lean exited with code 137", "Child exited with 137")
53
 
 
242
  return any(m in out for m in OOM_MARKERS)
243
 
244
 
245
+ def out_of_disk(out: str) -> bool:
246
+ return "no space left on device" in out.lower()
247
+
248
+
249
+ # Run as the grader user by `empty_build_scratch`. argv: the .lake/build/ir directory.
250
+ EMPTY_SCRATCH = r"""
251
+ import os, sys
252
+ for dirpath, _, files in os.walk(sys.argv[1]):
253
+ for name in files:
254
+ if not name.endswith(".setup.json"):
255
+ continue
256
+ base = os.path.join(dirpath, name[:-len(".setup.json")])
257
+ try:
258
+ # Lake writes X.c.hash once Lean, and leanir if the module needs it, are done with X;
259
+ # both read X.setup.json, so it may only be emptied after that.
260
+ if os.stat(base + ".c.hash").st_mtime < os.stat(base + ".setup.json").st_mtime:
261
+ continue
262
+ for path in (base + ".setup.json", base + ".c"):
263
+ if os.path.getsize(path):
264
+ os.truncate(path, 0)
265
+ except OSError:
266
+ pass
267
+ """
268
+
269
+
270
+ def empty_build_scratch(run: Path, stop: threading.Event) -> None:
271
+ """Until ``stop`` is set, empty files Lake leaves in .lake/build/ir that grading never reads.
272
+
273
+ For every module Lake writes a `.setup.json` (its imports with the path of every .olean they
274
+ pull in, about 5.5 MB with Mathlib) and the module compiled to C. Neither is used once the
275
+ module is built, and for proofs of 1,000-2,000 modules they filled the 10 GB disk before the
276
+ build finished. Lake keeps the recorded hashes, so emptied files do not trigger a rebuild.
277
+ This runs as the grader user, so it can touch nothing the build could not.
278
+ """
279
+ ir = str(run / ".lake" / "build" / "ir")
280
+ while not stop.wait(SCRATCH_SWEEP_SEC):
281
+ try:
282
+ subprocess.run(["runuser", "-u", GRADER, "--", sys.executable, "-c", EMPTY_SCRATCH, ir],
283
+ capture_output=True, timeout=600)
284
+ except subprocess.TimeoutExpired:
285
+ pass
286
+
287
+
288
  def run_comparator(run: Path, timeout_sec: int, threads: str = GRADE_THREADS) -> tuple[int | None, str]:
289
  env = {
290
  "PATH": f"{toolchain_bin()}:/usr/local/bin:/usr/bin:/bin",
 
299
  "runuser", "-u", GRADER, "--", "env", "-i", *(f"{k}={v}" for k, v in env.items()),
300
  "lake", "env", "comparator", "config.json",
301
  ]
302
+ stop = threading.Event()
303
+ sweeper = threading.Thread(target=empty_build_scratch, args=(run, stop), daemon=True)
304
+ sweeper.start()
305
+ try:
306
+ code, stdout, stderr = run_with_timeout(
307
+ cmd, cwd=run, timeout_sec=timeout_sec,
308
+ kill_extra=lambda: subprocess.run(["pkill", "-9", "-u", GRADER], capture_output=True),
309
+ )
310
+ finally:
311
+ stop.set()
312
+ sweeper.join()
313
  return code, stdout + "\n--- stderr ---\n" + stderr
314
 
315
 
 
349
  if code is None:
350
  return 0, "timed out while building or checking the submission"
351
  tail = [l for l in out.splitlines() if l.strip() and "has local changes" not in l][-25:]
352
+ if out_of_disk(out):
353
+ return 0, "rejected: the build ran out of disk space (10 GB) | " + " | ".join(tail)[-3000:]
354
  if out_of_memory(out):
355
  return 0, "rejected: the build was killed, most likely out of memory (8 GB) | " + " | ".join(tail)[-3000:]
356
  return 0, "rejected: " + " | ".join(tail)[-4000:]
 
365
  task = json.loads((TESTS / "task.json").read_text())
366
  details: dict = {"task": task["challenge"], "started_at": time.time()}
367
  reward: int | None = None
368
+ log = ""
369
  try:
370
  RUN_ROOT.mkdir(mode=0o711, parents=True, exist_ok=True)
371
  deadline = time.time() + int(task["grade_timeout_sec"])
 
380
  # Two Lean processes in parallel can exceed 8 GB on a heavy module. Retry once with one,
381
  # in a fresh directory: the first attempt's .lake was written by the submission's own
382
  # build and must not be trusted for the challenge.
383
+ shutil.rmtree(run, ignore_errors=True)
384
  run = fresh_run(task)
385
  unpack_submission(run)
386
  code, out = run_comparator(run, int(deadline - time.time()), threads="1")
387
  log += "\n\n=== retried with one Lean process after running out of memory ===\n\n" + out
388
  kill_grader()
389
  details["retried_single_thread"] = True
 
390
  reward, details["reason"] = classify(code, out)
391
  details["comparator_exit"] = code
392
  except Rejected as exc:
393
  reward, details["reason"] = 0, f"rejected: {exc}"
394
  except GradingError as exc:
395
  reward, details["reason"] = None, f"grading error: {exc}"
396
+ except Exception as exc:
397
+ reward, details["reason"] = None, f"grading error: {type(exc).__name__}: {exc}"
398
  finally:
399
  try:
400
  kill_grader()
401
  except GradingError as exc:
402
  reward, details["reason"] = None, f"grading error: {exc}"
403
+ # Free the build before writing anything. A build that filled the disk would otherwise
404
+ # make these writes fail, and with no space left the sandbox cannot report that the
405
+ # verifier exited, so Harbor waits until its own timeout and records no verdict.
406
+ shutil.rmtree(RUN_ROOT, ignore_errors=True)
407
  details["reward"] = reward
408
  details["finished_at"] = time.time()
409
+ (VERIFIER_DIR / "comparator.log").write_text(log)
410
  (VERIFIER_DIR / "grading.json").write_text(json.dumps(details, indent=2))
411
  print(json.dumps(details, indent=2))
412
  if reward is not None: