Skip to content

Official Codebase of 3DCodeVerse

Python

eval/llm: read_rows is the harness's lenient JSONL reader, so a bad byte costs one row

gaoypeng42bb0e605d92
diff --git a/eval/llm/_jsonl.py b/eval/llm/_jsonl.py
index afcba63b..6ec0aeba 100644
--- a/eval/llm/_jsonl.py
+++ b/eval/llm/_jsonl.py
@@ -4,28 +4,19 @@ The stages rewrite their ``*.jsonl`` whole at the end. That rewrite truncated t
first, so a process killed during it lost every row after the tear (re-paid on the next
``--resume``) and left a torn line that a strict ``json.loads`` per line then crashed on.
``write_rows`` publishes the new file in one rename (``codeverse3d.proc.write_text_atomic``);
-``read_rows`` still skips a line that does not parse — that row simply runs again."""
+``read_rows`` is the harness's lenient reader: a line that does not parse (a torn tail, a bad
+byte) is skipped and that row simply runs again; a missing file has no rows."""
from __future__ import annotations
import json
+from functools import partial
from pathlib import Path
-from codeverse3d.proc import write_text_atomic
+from codeverse3d.proc import read_jsonl_lenient, write_text_atomic
-
-def read_rows(path: Path) -> list[dict]:
- """Every JSON object line of ``path``, in order; blank and torn lines are skipped."""
- rows = []
- with Path(path).open() as f:
- for line in f:
- try:
- row = json.loads(line)
- except ValueError:
- continue
- if isinstance(row, dict):
- rows.append(row)
- return rows
+#: every JSON object line of a file, in order
+read_rows = partial(read_jsonl_lenient, dicts_only=True)
def write_rows(path: Path, rows: list[dict], *, ensure_ascii: bool = True) -> None:
diff --git a/eval/llm/tests/test_smoke.py b/eval/llm/tests/test_smoke.py
index 07699ec4..b1eea1bc 100644
--- a/eval/llm/tests/test_smoke.py
+++ b/eval/llm/tests/test_smoke.py
@@ -99,7 +99,8 @@ def test_a_torn_results_line_does_not_crash_the_render_stage():
"""render_views / score read exec_results.jsonl strictly: one torn line crashed the stage."""
render_views = importlib.import_module(f"{PKG}.render_views")
with tempfile.TemporaryDirectory() as d:
- (Path(d) / "exec_results.jsonl").write_text('{"id": "a", "status": "FAIL"}\n{"id": "b", "sta')
+ # and a bad byte (N85: read_rows decoded strictly — UnicodeDecodeError lost the whole file)
+ (Path(d) / "exec_results.jsonl").write_bytes(b'{"id": "a", "status": "FAIL"}\n{"id": "b\xff", "status": "FAIL"}\n{"id": "c", "sta')
assert render_views.render_dir(Path(d)) == {}