Skip to content

Commit 02c2d34

Browse files
authored
Merge pull request #15 from tylerbessire/codex/fix-memoryerror-during-submission-process
Handle MemoryError in submission pipeline
2 parents d609fc6 + d483b12 commit 02c2d34

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ class MetaCognition:
495495
Notes: Episode loader and DSL cast dy/dx/fill and mapping entries to int
496496

497497

498+
[X] Step 4.3 UPDATE4 - Submission script handles memory errors with fallback
499+
Date: 2025-09-13
500+
Test Result: pytest tests/test_solve_with_budget_memory.py -q
501+
Notes: solve_with_budget catches MemoryError, reports memerror count, runs gc per task
502+
498503

499504
```
500505

arc_submit.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import annotations
1010

11+
import gc
1112
import json
1213
import os
1314
import random
@@ -72,19 +73,32 @@ def solve_with_budget(task: Dict[str, Any], solver: ARCSolver) -> Tuple[List[Dic
7273
dictionaries of the form ``{"output": grid}`` and ``metadata``
7374
contains diagnostic information such as elapsed time and timeout flag.
7475
"""
75-
76+
# [S:ALG v1] fallback=best_so_far memlimit=soft pass
7677
_set_mem_limit()
7778
signal.signal(signal.SIGALRM, _alarm)
7879
signal.alarm(int(HARD_TIMEOUT_SEC))
7980
start = time.time()
8081
try:
8182
attempt1, attempt2 = solver.solve_task_two_attempts(task)
8283
elapsed = time.time() - start
83-
return [{"output": attempt1}, {"output": attempt2}], {"elapsed": elapsed, "timeout": False}
84+
return [
85+
{"output": attempt1},
86+
{"output": attempt2},
87+
], {"elapsed": elapsed, "timeout": False, "memerror": False}
8488
except Timeout:
8589
best = solver.best_so_far(task)
8690
elapsed = time.time() - start
87-
return [{"output": best}, {"output": best}], {"elapsed": elapsed, "timeout": True}
91+
return [
92+
{"output": best},
93+
{"output": best},
94+
], {"elapsed": elapsed, "timeout": True, "memerror": False}
95+
except MemoryError:
96+
best = solver.best_so_far(task)
97+
elapsed = time.time() - start
98+
return [
99+
{"output": best},
100+
{"output": best},
101+
], {"elapsed": elapsed, "timeout": False, "memerror": True}
88102
finally:
89103
signal.alarm(0)
90104

@@ -95,19 +109,23 @@ def main() -> None:
95109
solver = ARCSolver(use_enhancements=True)
96110
solutions: Dict[str, Dict[str, List[List[int]]]] = {}
97111

112+
mem_error_count = 0
98113
for task_id, task in data.items():
99114
attempts, meta = solve_with_budget(task, solver)
100115
solutions[task_id] = {
101116
"attempt_1": attempts[0]["output"],
102117
"attempt_2": attempts[1]["output"],
103118
}
119+
if meta.get("memerror"):
120+
mem_error_count += 1
104121
print(
105-
f"[task {task_id}] t={meta['elapsed']:.2f}s timeout={meta['timeout']}",
122+
f"[task {task_id}] t={meta['elapsed']:.2f}s timeout={meta['timeout']} memerror={meta['memerror']}",
106123
file=sys.stderr,
107124
)
125+
gc.collect()
108126

109127
path = save_submission(solutions, "submission.json")
110-
print(f"Saved {path} with {len(solutions)} tasks.")
128+
print(f"Saved {path} with {len(solutions)} tasks. memory_errors={mem_error_count}")
111129

112130

113131
if __name__ == "__main__":
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
sys.path.append(str(Path(__file__).resolve().parents[1]))
7+
from arc_submit import solve_with_budget
8+
9+
class DummySolver:
10+
def solve_task_two_attempts(self, task):
11+
raise MemoryError("boom")
12+
13+
def best_so_far(self, task):
14+
return [[0]]
15+
16+
def test_memory_error_fallback():
17+
attempts, meta = solve_with_budget({}, DummySolver())
18+
assert attempts[0]["output"] == [[0]]
19+
assert meta["memerror"] is True
20+
assert meta["timeout"] is False

0 commit comments

Comments
 (0)