Skip to content

Official Codebase of 3DCodeVerse

Python

lint/bench: three failure modes met on the calm rerun and the articulated battery

ziyao8eab8502d2b1
diff --git a/harness/bench/_infra.py b/harness/bench/_infra.py
index 68c09572..3787ca37 100644
--- a/harness/bench/_infra.py
+++ b/harness/bench/_infra.py
@@ -42,6 +42,11 @@ INFRA_MARKERS: tuple[str, ...] = (
"resource has been exhausted",
"quota exceeded",
"capacity storm",
+ # headless Chrome could not get a WebGL context — the shared GPU was saturated by
+ # another job (compare_v4_calm / compare_art_v2, 2026-08-25: six cells, all on a
+ # box whose GPU 0 sat at 100 % for someone else). A render that never started says
+ # nothing about the code it would have rendered.
+ "error creating webgl context",
)
#: HTTP statuses that mean "the provider could not serve this", not "the model was bad".
diff --git a/harness/bench/compare_backends.py b/harness/bench/compare_backends.py
index f4486fd6..d2a93376 100644
--- a/harness/bench/compare_backends.py
+++ b/harness/bench/compare_backends.py
@@ -83,6 +83,7 @@ from codeverse.contracts.run import RunRecord # noqa: E402
from codeverse.contracts.spec import Spec # noqa: E402
from codeverse.cost import run_ledger # noqa: E402
from codeverse.tracks.generation import MultiFileParseError # noqa: E402
+from codeverse.tracks.planner import PlanningError # noqa: E402
from codeverse.workspace import Workspace # noqa: E402
ArmKind = Literal["harness", "oneshot", "oneshot+repair"]
@@ -274,6 +275,13 @@ def run_cell(battery: Battery, item: BenchPrompt, arm: Arm, out: Path, opts: Com
res.status, res.score, res.passed, res.build_ok = "infra_failed", None, None, False
else:
res.status, res.score, res.passed, res.build_ok = "no_code", 0.0, False, False
+ except PlanningError as e:
+ # the harness's OWN planner gave up (its plan failed validation twice): no
+ # artifact, and nobody else's fault — a capability failure of the arm, scored 0
+ # like a one-shot answer in the wrong format (compare_art_v2, 2026-08-25: 5 of 14
+ # articulated prompts; dropping them as `error` hid a third of the harness's losses)
+ res.status, res.score, res.passed, res.build_ok = "no_code", 0.0, False, False
+ res.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
res.error = (res.error + "; " if res.error else "") + f"{type(e).__name__}: {e}\n{traceback.format_exc()[-1200:]}"
diff --git a/harness/codeverse/languages/_ast_lint.py b/harness/codeverse/languages/_ast_lint.py
index eacaff98..e67a89c4 100644
--- a/harness/codeverse/languages/_ast_lint.py
+++ b/harness/codeverse/languages/_ast_lint.py
@@ -27,6 +27,37 @@ BASE_FORBIDDEN_IMPORTS: frozenset[str] = frozenset({
})
+def safe_parse(source: str, filename: str = "<src>") -> tuple[ast.AST | None, BaseException | None]:
+ """``ast.parse`` that never raises: ``(tree, None)`` or ``(None, exception)``.
+
+ Besides ``SyntaxError``, CPython raises ``RecursionError`` (3.12+), ``SystemError``
+ ("AST constructor recursion depth mismatch", 3.11) or ``MemoryError`` on a source
+ whose expressions / literals nest deeper than the parser's C stack, and
+ ``ValueError`` on null bytes. A generated file can do any of these; a lint
+ that lets them escape crashes the whole run (compare_v4_calm 2026-08-25:
+ ``veh_easy_toy_car``'s round died in ``build_once`` instead of the agent being
+ told to flatten its literal).
+ """
+ try:
+ return ast.parse(source, filename=filename), None
+ except SyntaxError as e:
+ return None, e
+ except (RecursionError, SystemError, MemoryError, ValueError) as e: # noqa: PERF203 — one call
+ return None, e
+
+
+def describe_parse_failure(exc: BaseException) -> tuple[str, str, int | None]:
+ """(message, fix hint, line) for a :func:`safe_parse` failure, in the lints' wording."""
+ if isinstance(exc, SyntaxError):
+ return (f"SyntaxError: {exc.msg}",
+ f"fix the syntax near line {exc.lineno}: {(exc.text or '').strip()!r}", exc.lineno)
+ if isinstance(exc, (RecursionError, SystemError, MemoryError)):
+ return (f"{type(exc).__name__}: the file nests expressions or literals deeper than the parser can handle ({exc})",
+ "flatten deeply nested expressions and literals — build long vertex / face lists in a loop or "
+ "from a flat list, never as one giant nested literal", None)
+ return f"{type(exc).__name__}: {exc}", "remove null bytes / non-source content from the file", None
+
+
def dotted(node: ast.AST) -> str:
"""Dotted name of an Attribute/Name chain (e.g. ``pkg.mod.attr.call``); '' otherwise."""
parts: list[str] = []
diff --git a/harness/codeverse/languages/blender/lint.py b/harness/codeverse/languages/blender/lint.py
index 940132bd..340ce89e 100644
--- a/harness/codeverse/languages/blender/lint.py
+++ b/harness/codeverse/languages/blender/lint.py
@@ -19,7 +19,9 @@ from codeverse.contracts.artifacts import GateFinding, GateReport, Severity
from codeverse.languages._ast_lint import ( # noqa: F401 — dotted re-exported
BASE_FORBIDDEN_IMPORTS,
check_imports,
+ describe_parse_failure,
dotted,
+ safe_parse,
)
GATE = "lint:blender"
@@ -278,10 +280,10 @@ def lint_blender_source(
"""
t0 = time.monotonic()
findings: list[GateFinding] = []
- try:
- tree = ast.parse(source, filename=target)
- except SyntaxError as e:
- findings.append(_f(Severity.ERROR, f"SyntaxError: {e.msg}", e.lineno, f"fix the syntax near line {e.lineno}: {(e.text or '').strip()!r}", target))
+ tree, exc = safe_parse(source, target)
+ if tree is None:
+ msg, hint, line = describe_parse_failure(exc) # type: ignore[arg-type]
+ findings.append(_f(Severity.ERROR, msg, line, hint, target))
return GateReport(gate=GATE, passed=False, findings=findings, duration_ms=int((time.monotonic() - t0) * 1000))
c = _Collector()
c.visit(tree)
diff --git a/harness/codeverse/languages/cadquery/lint.py b/harness/codeverse/languages/cadquery/lint.py
index a970d578..a4d6a494 100644
--- a/harness/codeverse/languages/cadquery/lint.py
+++ b/harness/codeverse/languages/cadquery/lint.py
@@ -16,7 +16,9 @@ from codeverse.contracts.artifacts import GateFinding, GateReport, Severity
from codeverse.languages._ast_lint import ( # noqa: F401 — dotted re-exported
BASE_FORBIDDEN_IMPORTS,
check_imports,
+ describe_parse_failure,
dotted,
+ safe_parse,
)
GATE = "lint:cadquery"
@@ -193,10 +195,10 @@ def _rules(c: _Collector, tree: ast.Module, source: str) -> list[GateFinding]:
def lint_cadquery_source(source: str, *, target: str = "src/model.py") -> GateReport:
t0 = time.monotonic()
- try:
- tree = ast.parse(source, filename=target)
- except SyntaxError as e:
- f = _f(Severity.ERROR, f"SyntaxError: {e.msg}", e.lineno, f"fix the syntax near line {e.lineno}: {(e.text or '').strip()!r}", target)
+ tree, exc = safe_parse(source, target)
+ if tree is None:
+ msg, hint, line = describe_parse_failure(exc) # type: ignore[arg-type]
+ f = _f(Severity.ERROR, msg, line, hint, target)
return GateReport(gate=GATE, passed=False, findings=[f], duration_ms=int((time.monotonic() - t0) * 1000))
c = _Collector()
c.visit(tree)
diff --git a/harness/codeverse/languages/opengl_python/lint.py b/harness/codeverse/languages/opengl_python/lint.py
index 2938a751..4031ad82 100644
--- a/harness/codeverse/languages/opengl_python/lint.py
+++ b/harness/codeverse/languages/opengl_python/lint.py
@@ -18,7 +18,12 @@ import ast
import re
from codeverse.contracts.artifacts import GateFinding, GateReport, Severity
-from codeverse.languages._ast_lint import BASE_FORBIDDEN_IMPORTS, check_imports
+from codeverse.languages._ast_lint import (
+ BASE_FORBIDDEN_IMPORTS,
+ check_imports,
+ describe_parse_failure,
+ safe_parse,
+)
from codeverse.workspace import Workspace
GATE = "lint:opengl_python"
@@ -132,10 +137,10 @@ def lint_source(text: str) -> list[GateFinding]:
findings: list[GateFinding] = []
if len(text) > MAX_CHARS:
findings.append(_finding(Severity.WARN, "too_long", f"file is {len(text)} chars", "keep the program focused"))
- try:
- tree = ast.parse(text)
- except SyntaxError as e:
- findings.append(_finding(Severity.ERROR, "syntax", f"SyntaxError: {e.msg}", "fix the syntax at this line", e.lineno))
+ tree, exc = safe_parse(text)
+ if tree is None:
+ msg, hint, line = describe_parse_failure(exc) # type: ignore[arg-type]
+ findings.append(_finding(Severity.ERROR, "syntax", msg, hint if not isinstance(exc, SyntaxError) else "fix the syntax at this line", line))
return findings
v = _Visitor()
v.visit(tree)
diff --git a/harness/codeverse/languages/urdf/lint.py b/harness/codeverse/languages/urdf/lint.py
index d87cc847..b71717cb 100644
--- a/harness/codeverse/languages/urdf/lint.py
+++ b/harness/codeverse/languages/urdf/lint.py
@@ -16,6 +16,7 @@ from pathlib import Path
from codeverse.contracts.artifacts import GateFinding, GateReport, Severity
from codeverse.conventions import to_snake
+from codeverse.languages._ast_lint import describe_parse_failure, safe_parse
from codeverse.spatial.joints_model import JOINT_TYPES, MOVABLE_TYPES, RESERVED_LINK_NAMES
from codeverse.workspace import Workspace
@@ -324,10 +325,10 @@ class _Visitor(ast.NodeVisitor):
def lint_model_text(text: str, link_names: list[str], *, label: str = MODEL_REL) -> list[GateFinding]:
"""AST lint of model.py: forbidden APIs + every URDF link name appears as a string literal."""
- try:
- tree = ast.parse(text, filename=label)
- except SyntaxError as e:
- return [_f(Severity.ERROR, f"{label}:{e.lineno}: SyntaxError: {e.msg}", target=label, fix=str(e.text or "").strip(), line=e.lineno)]
+ tree, exc = safe_parse(text, label)
+ if tree is None:
+ msg, hint, line = describe_parse_failure(exc) # type: ignore[arg-type]
+ return [_f(Severity.ERROR, f"{label}:{line or '?'}: {msg}", target=label, fix=hint, line=line)]
v = _Visitor()
v.visit(tree)
out = v.findings
diff --git a/harness/tests/compare_bench/test_infra_failures.py b/harness/tests/compare_bench/test_infra_failures.py
index e587f59b..f1367bf5 100644
--- a/harness/tests/compare_bench/test_infra_failures.py
+++ b/harness/tests/compare_bench/test_infra_failures.py
@@ -20,6 +20,7 @@ OUTAGES = [
"KeyPoolExhausted: every key is cooling down",
"APIError: 500 Internal server error",
"ConnectionError: Connection reset by peer",
+ "RenderError: render_glb failed: node script render_glb.mjs exited 1: Error creating WebGL context.",
]
MODEL_FAILURES = [
"unparseable answer: no python block in the response",
@@ -265,3 +266,25 @@ def test_a_repair_lost_to_an_outage_drops_the_cell_instead_of_scoring_the_pre_re
CompareDeps(ev2, oneshot_backend=lambda t: StormBackend(storm_on_repair=False)))
assert (r2.status, r2.score, r2.build_ok) == ("build_failed", 0.0, False), r2
assert ev2.evaluated and r2.attempts == 2
+
+
+def test_a_harness_planning_failure_is_a_zero_not_a_dropped_cell(tmp_path):
+ """compare_art_v2 (2026-08-25): 5 of 14 articulated harness runs raised PlanningError (the
+ plan failed validation twice) and were recorded `error` / score None — dropped from the
+ mean, so a third of the harness's failures vanished. The harness delivered nothing by its
+ own doing: no_code / 0.0, exactly what a one-shot answer in the wrong format gets."""
+ from bench.compare_backends import CompareDeps, CompareOptions, parse_arm, run_cell
+ from bench.run_bench import Battery
+ from codeverse.tracks.planner import PlanningError
+ from tests.compare_bench.conftest import BATTERY, FakeEvaluator
+
+ def no_plan(spec, ws, resume):
+ raise PlanningError("plan did not validate after re-ask: joint X references unknown link(s)")
+
+ battery = Battery.load(BATTERY)
+ opts = CompareOptions(judge="gemini:x", loop_judge="gemini:x")
+ r = run_cell(battery, battery.prompts[0], parse_arm("harness:api-agent:gemini:gemini-3.7-flash"), tmp_path, opts,
+ CompareDeps(FakeEvaluator(), run_track=no_plan))
+ assert (r.status, r.score, r.passed, r.build_ok) == ("no_code", 0.0, False, False)
+ assert r.error.startswith("PlanningError:")
+
diff --git a/harness/tests/languages/test_ast_lint.py b/harness/tests/languages/test_ast_lint.py
index 525e1ce9..1fa49840 100644
--- a/harness/tests/languages/test_ast_lint.py
+++ b/harness/tests/languages/test_ast_lint.py
@@ -78,3 +78,71 @@ def test_dotted_chains() -> None:
assert dotted(expr("(a + b)")) == ""
# the same function is what the language lints re-export
assert blender_lint.dotted is dotted and cadquery_lint.dotted is dotted
+
+
+# ----------------------------------------------------------------------------- safe_parse (2026-08-25)
+def test_safe_parse_turns_parser_crashes_into_findings(monkeypatch):
+ """compare_v4_calm: a generated bpy file made CPython 3.11's ``ast.parse`` raise
+ ``SystemError: AST constructor recursion depth mismatch`` and the whole harness round
+ died in ``build_once``. Every python lint now goes through ``safe_parse`` and reports
+ a lint ERROR the agent can act on instead."""
+ import ast
+
+ from codeverse.languages._ast_lint import describe_parse_failure, safe_parse
+
+ tree, exc = safe_parse("x = 1\n")
+ assert isinstance(tree, ast.Module) and exc is None
+ tree, exc = safe_parse("x = (\n", "src/model.py")
+ assert tree is None and isinstance(exc, SyntaxError)
+ msg, hint, line = describe_parse_failure(exc)
+ assert msg.startswith("SyntaxError:") and "fix the syntax near line" in hint
+
+ def boom(*a, **k):
+ raise SystemError("AST constructor recursion depth mismatch (before=54, after=62)")
+
+ monkeypatch.setattr(ast, "parse", boom)
+ tree, exc = safe_parse("x = 1\n")
+ assert tree is None and isinstance(exc, SystemError)
+ msg, hint, line = describe_parse_failure(exc)
+ assert "SystemError" in msg and "deeper than the parser" in msg and "flatten" in hint and line is None
+ tree, exc = safe_parse("x = 1\n") # RecursionError / MemoryError take the same path
+ monkeypatch.setattr(ast, "parse", lambda *a, **k: (_ for _ in ()).throw(RecursionError("maximum recursion depth exceeded")))
+ tree, exc = safe_parse("x = 1\n")
+ assert tree is None and isinstance(exc, RecursionError)
+
+
+def test_every_python_lint_survives_a_parser_crash(monkeypatch):
+ import ast
+
+ from codeverse.contracts.artifacts import Severity
+ from codeverse.languages.blender.lint import lint_blender_source
+ from codeverse.languages.cadquery.lint import lint_cadquery_source
+ from codeverse.languages.opengl_python.lint import lint_source as lint_gl
+ from codeverse.languages.urdf.lint import lint_model_text
+
+ real = ast.parse
+
+ def crash(src, *a, **k):
+ if "DEEP" in src:
+ raise SystemError("AST constructor recursion depth mismatch (before=54, after=62)")
+ return real(src, *a, **k)
+
+ monkeypatch.setattr(ast, "parse", crash)
+ src = "import bpy\nDEEP = 1\n"
+ for name, run in (("blender", lambda: lint_blender_source(src).findings),
+ ("cadquery", lambda: lint_cadquery_source("import cadquery as cq\nDEEP = 1\n").findings),
+ ("opengl", lambda: lint_gl(src)),
+ ("urdf", lambda: lint_model_text(src, ["base"]))):
+ findings = run() # must not raise
+ errs = [f for f in findings if f.severity == Severity.ERROR]
+ assert errs and "SystemError" in errs[0].message, (name, findings)
+
+
+def test_real_deeply_nested_source_does_not_escape_the_lint():
+ """A 40 000-term binary chain: on 3.11 this is the SystemError, on 3.12+ a RecursionError,
+ on some builds a plain SyntaxError — whichever, the lint returns a report."""
+ from codeverse.languages.blender.lint import lint_blender_source
+
+ deep = "import bpy\nx = " + " + ".join(["1"] * 40_000) + "\n"
+ rep = lint_blender_source(deep)
+ assert isinstance(rep.passed, bool)