Skip to content

Official Codebase of 3DCodeVerse

Python

bench reports: --report-only averaged the arms table over stale re-run rows

gaoypeng4cef7855d06a
diff --git a/harness/bench/_compare_report.py b/harness/bench/_compare_report.py
index d9383c26..6962e5ab 100644
--- a/harness/bench/_compare_report.py
+++ b/harness/bench/_compare_report.py
@@ -13,7 +13,7 @@ import json
import shutil
import statistics
from pathlib import Path
-from typing import TypeVar
+from typing import Any, TypeVar
from pydantic import BaseModel, Field
@@ -51,6 +51,11 @@ class CellResult(BaseModel):
workspace: str = ""
error: str = ""
+ def natural_key(self) -> tuple[str, ...]:
+ """Row identity: one cell is one (prompt, arm). results.jsonl is append-only, so
+ a resume / ``--redo-status`` re-run appends a SECOND row for the same key."""
+ return (self.prompt_id, self.arm)
+
class PairRow(BaseModel):
prompt_id: str
@@ -64,16 +69,32 @@ class PairRow(BaseModel):
judged: bool = Field(default=True, description="False when decided by a missing build (no judge call)")
error: str = ""
+ def natural_key(self) -> tuple[str, ...]:
+ """Row identity: one pairwise verdict is one (prompt, arm A, arm B)."""
+ return (self.prompt_id, self.arm_a, self.arm_b)
+
def load_jsonl(path: Path, model: type[T]) -> list[T]:
- """Latest row wins per natural key (re-appended rows on resume)."""
+ """Rows in first-seen order, latest row winning per ``natural_key`` (models without
+ one keep every row).
+
+ The dedup lives HERE, once, because the files are append-only and every reader needs
+ the same rows: ``ab_plan --report-only`` used to hand the raw rows to ``render_summary``
+ while the live driver passed deduped ones, so one summary.md printed the variant's mean
+ as 0.400 in the arms table, 0.800 per prompt, and based its verdict on 0.800 — and the
+ "lost to outages" footer counted infra_failed cells that had already been re-run and
+ scored, advising ``--redo-status infra_failed`` for nothing.
+ """
if not path.is_file():
return []
- rows: list[T] = []
- for line in path.read_text().splitlines():
- if line.strip():
- rows.append(model.model_validate_json(line))
- return rows
+ rows: dict[Any, T] = {}
+ for i, line in enumerate(path.read_text().splitlines()):
+ if not line.strip():
+ continue
+ row = model.model_validate_json(line)
+ key = row.natural_key() if hasattr(row, "natural_key") else i
+ rows[key] = row # first appearance fixes the order, the last row wins the slot
+ return list(rows.values())
# ----------------------------------------------------------------------------- aggregates
diff --git a/harness/tests/compare_bench/test_ab_plan.py b/harness/tests/compare_bench/test_ab_plan.py
index f66fb5d5..d8b970ec 100644
--- a/harness/tests/compare_bench/test_ab_plan.py
+++ b/harness/tests/compare_bench/test_ab_plan.py
@@ -323,9 +323,11 @@ def test_resume_skips_done_pairs_and_redo_reruns_both_arms(tmp_path: Path):
v = run_ab(BATTERY, tmp_path, opts.model_copy(update={"redo_status": ["infra_failed"]}), run_cell_fn=redo)
assert sorted(redo.calls) == [(ids[1], CONTROL), (ids[1], VARIANT)]
assert v.n_pairs == 2
+ assert len((tmp_path / "results.jsonl").read_text().strip().splitlines()) == 6, "the file is append-only"
rows = load_jsonl(tmp_path / "results.jsonl", CellResult)
latest = {(r.prompt_id, r.arm): r for r in rows}
- assert latest[(ids[1], VARIANT)].status == "scored" and len(rows) == 6
+ assert latest[(ids[1], VARIANT)].status == "scored"
+ assert len(rows) == 4, "readers see one row per (prompt, arm): the redo replaces the stale attempt"
def test_an_interrupted_pair_runs_only_its_missing_arm():
@@ -397,3 +399,21 @@ def test_ab_plan_children_count_as_harness_processes():
assert _is_harness_argv([sys.executable, str(REPO / "bench" / "ab_plan.py"), "cell", "--arm", "control"])
assert os.environ is not None
+
+
+def test_report_only_reads_the_same_rows_the_live_driver_wrote(tmp_path: Path):
+ """CG-5: results.jsonl is append-only and a redo re-appends, so a stale attempt and its
+ redo both sit in the file. load_jsonl promised "latest row wins per natural key" and
+ deduped nothing: run_ab passed deduped rows to write_report while `--report-only`
+ passed the raw ones, so ONE summary.md said the variant's mean was 0.400 in the Arms
+ table, 0.800 per prompt, and based its verdict on 0.800 — and the footer counted an
+ infra_failed cell that had already been re-run and scored."""
+ rows = [_row("p1", CONTROL, 0.60),
+ _row("p1", VARIANT, None, "infra_failed"), # lost to the outage
+ _row("p1", VARIANT, 0.80)] # ... and re-run afterwards
+ (tmp_path / "results.jsonl").write_text("".join(r.model_dump_json() + "\n" for r in rows))
+ loaded = load_jsonl(tmp_path / "results.jsonl", CellResult)
+ assert [(r.prompt_id, r.arm) for r in loaded] == [("p1", CONTROL), ("p1", VARIANT)]
+ assert arm_summary(loaded, VARIANT).mean_score == 0.80
+ assert arm_summary(loaded, VARIANT).n == 1 and arm_summary(loaded, VARIANT).n_infra_failed == 0
+ assert [r for r in loaded if r.status == "infra_failed"] == [], "a redone cell is not still lost"