Official Codebase of 3DCodeVerse
Python
bench: is_infra_failure walks a cyclic cause chain; run_cell/run_matrix never lose a cell
ziyaob07b6b45358f
diff --git a/harness/bench/_infra.py b/harness/bench/_infra.pyindex 3787ca37..799c501b 100644--- a/harness/bench/_infra.py+++ b/harness/bench/_infra.py@@ -73,9 +73,26 @@ def is_infra_failure(err: object) -> bool:return Trueif isinstance(err, TimeoutError):return True- # a wrapped cause is common: `raise ModelError(...) from urllib.error.HTTPError`- if err.__cause__ is not None and is_infra_failure(err.__cause__):- return True+ # a wrapped cause is common: `raise ModelError(...) from urllib.error.HTTPError`.+ # Walk the chain ITERATIVELY with a visited set: retry.py's `raise err from exc`+ # can close the chain into a cycle (compare_art_v3, 2026-08-27: a truncated plan's+ # ModelError → RecursionError inside run_cell's except handler → the matrix loop+ # died and 11 finished cells went unrecorded).+ seen: set[int] = {id(err)}+ cause = err.__cause__ if err.__cause__ is not None else err.__context__+ while cause is not None and id(cause) not in seen and len(seen) < 32:+ seen.add(id(cause))+ if isinstance(cause, BaseException):+ if type(cause).__name__ == "KeyPoolExhausted" or isinstance(cause, TimeoutError):+ return True+ status = getattr(cause, "status", None)+ if isinstance(status, int) and status in INFRA_STATUSES:+ return True+ if any(marker in f"{type(cause).__name__}: {cause}".lower() for marker in INFRA_MARKERS):+ return True+ cause = cause.__cause__ if cause.__cause__ is not None else cause.__context__+ else:+ breakerr = f"{type(err).__name__}: {err}"text = str(err).lower()return any(marker in text for marker in INFRA_MARKERS)diff --git a/harness/bench/compare_backends.py b/harness/bench/compare_backends.pyindex b973e7ca..78313e3a 100644--- a/harness/bench/compare_backends.py+++ b/harness/bench/compare_backends.py@@ -302,11 +302,19 @@ def run_cell(battery: Battery, item: BenchPrompt, arm: Arm, out: Path, opts: Comres.status, res.score, res.passed, res.build_ok = "no_code", 0.0, False, Falseres.error = f"PlanningError: {e}"except Exception as e: # noqa: BLE001 — one cell must never kill the matrix- res.status = "infra_failed" if is_infra_failure(e) else "error" # same rule as the no-code path+ try:+ infra = is_infra_failure(e)+ except Exception as classify_error: # noqa: BLE001 — a classifier bug is not a reason to lose the cell+ infra = False+ res.error = (res.error + "; " if res.error else "") + f"[classifier failed: {type(classify_error).__name__}] "+ res.status = "infra_failed" if infra else "error" # same rule as the no-code pathres.error = (res.error + "; " if res.error else "") + f"{type(e).__name__}: {e}\n{traceback.format_exc()[-1200:]}"res.wall_s = round(time.time() - t0, 1)- flag_degraded(res, opts)- eval_ws.write_json(cell / "cell.json", res)+ try:+ flag_degraded(res, opts)+ eval_ws.write_json(cell / "cell.json", res)+ except Exception as e: # noqa: BLE001 — the row is the record of last resort+ res.error = (res.error + "; " if res.error else "") + f"[cell.json not written: {type(e).__name__}: {e}]"return res@@ -423,7 +431,12 @@ def run_matrix(battery_path: Path | str, out_dir: Path | str, arms: Sequence[Armwith ThreadPoolExecutor(max_workers=max(1, opts.parallel)) as pool, results.open("a") as fh:futs = {pool.submit(run_cell, battery, p, a, out, opts, deps): (p, a) for p, a in todo}for fut in as_completed(futs):- r = fut.result()+ try:+ r = fut.result()+ except Exception as e: # noqa: BLE001 — run_cell must not raise; if it does, record the cell, keep the matrix+ p, a = futs[fut]+ r = CellResult(prompt_id=p.id, tier=p.tier, arm=a.raw, kind=a.kind, target=a.target, judge=opts.judge,+ status="error", error=f"run_cell raised {type(e).__name__}: {e}"[:800])done[(r.prompt_id, r.arm)] = rfh.write(r.model_dump_json() + "\n")fh.flush()diff --git a/harness/tests/compare_bench/test_infra_failures.py b/harness/tests/compare_bench/test_infra_failures.pyindex 3ea23a79..4219a059 100644--- a/harness/tests/compare_bench/test_infra_failures.py+++ b/harness/tests/compare_bench/test_infra_failures.py@@ -288,3 +288,38 @@ def test_a_harness_planning_failure_is_a_zero_not_a_dropped_cell(tmp_path):assert (r.status, r.score, r.passed, r.build_ok) == ("no_code", 0.0, False, False)assert r.error.startswith("PlanningError:")++def test_a_cyclic_cause_chain_does_not_recurse():+ """compare_art_v3 (2026-08-27): retry.py's `raise err from exc` closed the __cause__ chain+ into a cycle; is_infra_failure recursed to RecursionError inside run_cell's except+ handler, the matrix loop died, and 11 finished cells went unrecorded."""+ class ModelError(Exception):+ def __init__(self, msg, status=None):+ super().__init__(msg)+ self.status = status++ a = ModelError("structured output unavailable (finish_reason=MAX_TOKENS)")+ b = ModelError("attempt failed")+ a.__cause__, b.__cause__ = b, a # the cycle+ assert is_infra_failure(a) is False+ c = ModelError("wrapped")+ c.__cause__ = ModelError("upstream said no", status=503)+ c.__cause__.__cause__ = c # cycle through an infra cause+ assert is_infra_failure(c) is True+++def test_a_classifier_crash_still_records_the_cell(tmp_path, monkeypatch):+ from bench import compare_backends as cb+ from bench.run_bench import Battery+ from tests.compare_bench.conftest import BATTERY, FakeEvaluator++ def boom(spec, ws, resume):+ raise RuntimeError("planner died")++ monkeypatch.setattr(cb, "is_infra_failure", lambda e: (_ for _ in ()).throw(RecursionError("cycle")))+ battery = Battery.load(BATTERY)+ r = cb.run_cell(battery, battery.prompts[0], cb.parse_arm("harness:api-agent:gemini:gemini-3.7-flash"), tmp_path,+ cb.CompareOptions(judge="gemini:x", loop_judge="gemini:x"), cb.CompareDeps(FakeEvaluator(), run_track=boom))+ assert r.status == "error" and "classifier failed: RecursionError" in r.error and "planner died" in r.error+ assert (tmp_path / "cells" / battery.prompts[0].id / "harness_api-agent_gemini_gemini-3.7-flash" / "cell.json").is_file()+