Skip to content

Official Codebase of 3DCodeVerse

Python

flywheel export: a compare / A-B battery dir still reported 0 runs as success

gaoypeng2e1c12e274dd
diff --git a/harness/codeverse/flywheel/record.py b/harness/codeverse/flywheel/record.py
index 73ee2ac3..f99a01ed 100644
--- a/harness/codeverse/flywheel/record.py
+++ b/harness/codeverse/flywheel/record.py
@@ -275,6 +275,32 @@ def load_record(ws: Workspace | Path | str) -> RunRecord:
raise RecordError(f"invalid record.json in {ws.root}: {e}") from e
+#: how deep to look for a nested run before giving up (ab_plan's layout is
+#: arms/<arm>/cells/<prompt>/<slug>/run — five levels below the battery root)
+_NESTED_SCAN_DEPTH = 6
+
+
+def _find_nested_run(root: Path, depth: int = _NESTED_SCAN_DEPTH) -> Path | None:
+ """The first run directory strictly below ``root``, or None. Breadth-first and
+ depth-bounded: this only has to prove that the caller pointed one level too high."""
+ level = [root]
+ for _ in range(depth):
+ nxt: list[Path] = []
+ for d in level:
+ try:
+ kids = sorted(p for p in d.iterdir() if p.is_dir())
+ except OSError: # pragma: no cover - unreadable dir
+ continue
+ for k in kids:
+ if (k / "record.json").is_file():
+ return k
+ nxt.append(k)
+ if not nxt:
+ return None
+ level = nxt
+ return None
+
+
def iter_runs(
runs_dir: Path | str, *, on_error: Callable[[Path, Exception], None] | None = None
) -> Iterator[tuple[Workspace, RunRecord]]:
@@ -287,13 +313,18 @@ def iter_runs(
if not root.is_dir():
raise FileNotFoundError(f"runs dir not found: {root}")
children = sorted(p for p in root.iterdir() if p.is_dir())
- if not any((d / "record.json").is_file() for d in children) and (root / "runs").is_dir():
- # pointing at a BATTERY dir (bench/out/<battery>) instead of its runs/ root is the
- # easy mistake, and every exporter here reports "0 runs" as a success. Silence
- # must not look like an empty dataset.
- raise FileNotFoundError(
- f"no run directories directly under {root} — did you mean {root / 'runs'}? "
- f"(a battery directory holds its runs in runs/)")
+ if not any((d / "record.json").is_file() for d in children):
+ # Pointing at a BATTERY dir instead of its runs root is the easy mistake, and every
+ # exporter here reports "0 runs" as a SUCCESS — writing an empty metadata.parquet.
+ # Silence must not look like an empty dataset. Keying the guard on root/runs alone
+ # left it silent for the two drivers that produce most batteries: compare_backends
+ # writes cells/<prompt>/<arm>/run and ab_plan writes arms/<arm>/cells/<prompt>/<slug>/run.
+ found = _find_nested_run(root)
+ if found is not None:
+ hint = (f"did you mean {root / 'runs'}?" if found.parent == root / "runs"
+ else f"e.g. {found} — batteries nest their runs (cells/<prompt>/<arm>/run)")
+ raise FileNotFoundError(
+ f"no run directories directly under {root}, but there are runs below it — {hint}")
for d in children:
if not (d / "record.json").is_file():
continue
diff --git a/harness/tests/flywheel_cli/test_flywheel.py b/harness/tests/flywheel_cli/test_flywheel.py
index 0541e71d..fc9dcafb 100644
--- a/harness/tests/flywheel_cli/test_flywheel.py
+++ b/harness/tests/flywheel_cli/test_flywheel.py
@@ -387,15 +387,47 @@ def test_pointing_at_a_battery_dir_says_so_instead_of_exporting_nothing(tmp_path
list(iter_runs(battery))
+def test_a_compare_or_ab_battery_dir_says_so_too(tmp_path):
+ """RS-8: the guard only knew the runs/ layout, but compare_backends writes
+ cells/<prompt>/<arm>/run and ab_plan writes arms/<arm>/cells/<prompt>/<slug>/run —
+ so for the two drivers that produced today's compare_v3 / A-B batteries the exact
+ mistake the guard was added for was still silent (n_runs=0 reported as success,
+ plus an empty metadata.parquet)."""
+ import pytest
+
+ from codeverse.flywheel.record import iter_runs
+
+ compare = tmp_path / "compare_v3"
+ for pid in ("p0", "p1"):
+ for arm in ("harness_codex", "oneshot_gemini"):
+ run = compare / "cells" / pid / arm / "run"
+ run.mkdir(parents=True)
+ (run / "record.json").write_text("{}")
+
+ with pytest.raises(FileNotFoundError, match="runs below it"):
+ list(iter_runs(compare))
+
+ ab = tmp_path / "ab_plan_v1"
+ deep = ab / "arms" / "control" / "cells" / "p0" / "stool_ab12" / "run"
+ deep.mkdir(parents=True)
+ (deep / "record.json").write_text("{}")
+ with pytest.raises(FileNotFoundError, match="runs below it"):
+ list(iter_runs(ab))
+
+
def test_a_genuinely_empty_runs_root_is_still_just_empty(tmp_path):
- """The hint only fires when a `runs/` sibling exists — an empty runs root is a
- legitimate empty result, not an error."""
+ """The hint fires only when a run really does exist below — an empty runs root, and
+ a tree of directories holding no record.json at all, are legitimate empty results."""
from codeverse.flywheel.record import iter_runs
empty = tmp_path / "runs"
empty.mkdir()
assert list(iter_runs(empty)) == []
+ noise = tmp_path / "noise"
+ (noise / "a" / "b" / "c").mkdir(parents=True)
+ assert list(iter_runs(noise)) == []
+
def test_parquet_keeps_the_complexity_columns_the_exporter_writes(tmp_path):
"""RS-9: ``pa.Table.from_pylist(rows, schema=...)`` DROPS any key the schema does not