AdithyaSK HF Staff commited on
Commit
f5584c0
·
verified ·
1 Parent(s): 607b89e

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

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/depth-three/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 175
23
  reference_lean_bytes = 1026594
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 776
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 1026594
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 398
27
  difficulty = "research"
28
 
29
  [agent]
tasks/depth-three/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/diamond-distortion/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 32
23
  reference_lean_bytes = 472861
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 771
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 472861
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 268
27
  difficulty = "research"
28
 
29
  [agent]
tasks/diamond-distortion/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/diluted-spin/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 405
23
  reference_lean_bytes = 2760702
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 1537
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 2760702
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 1199
27
  difficulty = "research"
28
 
29
  [agent]
tasks/diluted-spin/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/dimension-ten-channel/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 148
23
  reference_lean_bytes = 3075057
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 2360
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 3075057
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 1785
27
  difficulty = "research"
28
 
29
  [agent]
tasks/dimension-ten-channel/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/dimension-ten-pair/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 129
23
  reference_lean_bytes = 2413995
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 1766
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 2413995
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 1663
27
  difficulty = "research"
28
 
29
  [agent]
tasks/dimension-ten-pair/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/direct-crouzeix/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 42
23
  reference_lean_bytes = 314025
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 1202
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 314025
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 429
27
  difficulty = "research"
28
 
29
  [agent]
tasks/direct-crouzeix/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/directed-feedback/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 224
23
  reference_lean_bytes = 8506385
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 1662
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 8506385
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 1607
27
  difficulty = "research"
28
 
29
  [agent]
tasks/directed-feedback/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/directional-ballisticity/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 513
23
  reference_lean_bytes = 5012403
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 1730
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 5012403
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 1803
27
  difficulty = "research"
28
 
29
  [agent]
tasks/directional-ballisticity/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/directional-walk/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 69
23
  reference_lean_bytes = 951618
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 968
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 951618
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 459
27
  difficulty = "research"
28
 
29
  [agent]
tasks/directional-walk/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/discrete-lipschitz-free/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 32
23
  reference_lean_bytes = 173635
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 662
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 173635
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 199
27
  difficulty = "research"
28
 
29
  [agent]
tasks/discrete-lipschitz-free/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/disk-maximal/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 30
23
  reference_lean_bytes = 970308
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 756
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 970308
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 415
27
  difficulty = "research"
28
 
29
  [agent]
tasks/disk-maximal/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/dixmier-all-discrete/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 39
23
  reference_lean_bytes = 181502
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 471
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 181502
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 194
27
  difficulty = "research"
28
 
29
  [agent]
tasks/dixmier-all-discrete/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/dixmier/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 32
23
  reference_lean_bytes = 158919
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 332
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 158919
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 112
27
  difficulty = "research"
28
 
29
  [agent]
tasks/dixmier/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/doubling-hilbert/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 12
23
  reference_lean_bytes = 157722
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 454
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 157722
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 179
27
  difficulty = "research"
28
 
29
  [agent]
tasks/doubling-hilbert/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/dutta-domain/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 278
23
  reference_lean_bytes = 2409516
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 1913
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 2409516
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 1966
27
  difficulty = "research"
28
 
29
  [agent]
tasks/dutta-domain/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/dyadic-avoidance/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 75
23
  reference_lean_bytes = 369234
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 796
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 369234
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 198
27
  difficulty = "research"
28
 
29
  [agent]
tasks/dyadic-avoidance/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/edit-approximation/task.toml CHANGED
@@ -23,7 +23,7 @@ reference_modules = 1024
23
  reference_lean_bytes = 7591774
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
- oracle_grade_seconds = 3183
27
  difficulty = "research"
28
 
29
  [agent]
 
23
  reference_lean_bytes = 7591774
24
  reference_requires_packages = []
25
  oracle_result = "accepted"
26
+ oracle_grade_seconds = 2717
27
  difficulty = "research"
28
 
29
  [agent]