Skip to content

Official Codebase of 3DCodeVerse

Python

cleanup: one scene-run walker and one JSONL reader in the bench readers; D53–D58 once in DECISIONS

gaoypenga9a9c360f656
diff --git a/harness/bench/bestofk_report.py b/harness/bench/bestofk_report.py
index c35c1f16..b54052a0 100644
--- a/harness/bench/bestofk_report.py
+++ b/harness/bench/bestofk_report.py
@@ -29,7 +29,6 @@ is not a loss.
from __future__ import annotations
import argparse
-import json
import math
import statistics
import sys
@@ -38,21 +37,19 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
+from codeverse.proc import read_jsonl_lenient # noqa: E402
+
#: judge repeatability on the calibration set (docs/PAPER_WRITING.md §2), used only to
#: state how much of a best-of-k maximum is selection noise
JUDGE_SIGMA = 0.030
-def _rows(path: Path) -> list[dict]:
- return [json.loads(x) for x in path.read_text().splitlines() if x.strip()]
-
-
def one_shot_samples(root: Path) -> dict[str, list[float]]:
"""``{prompt: [score per rep]}`` — one entry per rep that scored that prompt."""
out: dict[str, list[float]] = defaultdict(list)
for rep in sorted(root.glob("rep*/results.jsonl")):
seen: dict[str, float] = {}
- for r in _rows(rep):
+ for r in read_jsonl_lenient(rep, dicts_only=True):
if r.get("score") is None:
continue
seen[r["prompt_id"]] = float(r["score"]) # last row wins, as paired_compare does
@@ -64,7 +61,7 @@ def one_shot_samples(root: Path) -> dict[str, list[float]]:
def harness_scores(root: Path, *, arm_prefix: str = "harness:") -> dict[str, float]:
"""``{prompt: score}`` for the recorded harness arm, last row per prompt."""
out: dict[str, float] = {}
- for r in _rows(root / "results.jsonl"):
+ for r in read_jsonl_lenient(root / "results.jsonl", dicts_only=True):
if not str(r.get("arm", "")).startswith(arm_prefix) or r.get("score") is None:
continue
out[r["prompt_id"]] = float(r["score"])
@@ -83,7 +80,7 @@ def harness_repeat_spread(root: Path, *, arm_prefix: str = "harness:") -> tuple[
"""
per: dict[str, list[float]] = {}
rows = 0
- for r in _rows(root / "results.jsonl"):
+ for r in read_jsonl_lenient(root / "results.jsonl", dicts_only=True):
if not str(r.get("arm", "")).startswith(arm_prefix):
continue
rows += 1
@@ -98,7 +95,7 @@ def gen_costs(root: Path, arm_prefix: str) -> list[float]:
`paired_compare` pairs on. Taken over every appended row instead, resumed and failed
cells drag the median down and the equal-compute k comes out too small."""
last: dict[str, float] = {}
- for r in _rows(root / "results.jsonl"):
+ for r in read_jsonl_lenient(root / "results.jsonl", dicts_only=True):
if str(r.get("arm", "")).startswith(arm_prefix):
last[r["prompt_id"]] = float(r.get("gen_cost_usd") or 0.0)
return [v for v in last.values() if v > 0]
diff --git a/harness/bench/h2h_scene.py b/harness/bench/h2h_scene.py
index cc287384..3a08c205 100644
--- a/harness/bench/h2h_scene.py
+++ b/harness/bench/h2h_scene.py
@@ -44,6 +44,7 @@ from bench.run_bench import Battery, BenchPrompt # noqa: E402
from codeverse.contracts.artifacts import RenderSet, RenderView # noqa: E402
from codeverse.contracts.common import Language, Track # noqa: E402
from codeverse.contracts.spec import Spec # noqa: E402
+from codeverse.proc import read_jsonl_lenient # noqa: E402
HERE = Path(__file__).resolve().parent
BATTERY = HERE / "prompts" / "h2h_scene_v1.yaml"
@@ -142,11 +143,7 @@ def our_frames(run_dir: Path) -> tuple[list[RenderView], dict[str, Any]] | None:
flagged = [v for v in stills if v.judge] or stills
chosen = flagged[:MAX_VIEWS]
minutes = None
- for line in (run_dir.parent.parent / "results.jsonl").read_text().splitlines() if (run_dir.parent.parent / "results.jsonl").is_file() else []:
- try:
- r = json.loads(line)
- except json.JSONDecodeError:
- continue
+ for r in read_jsonl_lenient(run_dir.parent.parent / "results.jsonl", dicts_only=True):
if r.get("id") == run_dir.name:
minutes = float(r.get("minutes") or 0.0)
if minutes is None and rec.get("started_at") and rec.get("finished_at"):
diff --git a/harness/bench/scene_regate.py b/harness/bench/scene_regate.py
index f7952e21..fc4c93cf 100644
--- a/harness/bench/scene_regate.py
+++ b/harness/bench/scene_regate.py
@@ -31,6 +31,7 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # this tree's codeverse
+from bench.scene_stats import scene_records # noqa: E402
from codeverse.config import get_settings # noqa: E402
from codeverse.contracts.artifacts import Severity # noqa: E402
from codeverse.spatial.scene_placement import placement_gate_safe # noqa: E402
@@ -39,22 +40,8 @@ GATE = "scene_placement"
def scene_runs(root: Path) -> list[Path]:
- """Every recorded scene run under ``root``, once, newest layout or old."""
- out, seen = [], set()
- for rec in sorted(root.rglob("record.json")):
- if "_assets" in rec.parts or "_cand" in rec.parts or rec.resolve() in seen:
- continue
- try:
- data = json.loads(rec.read_text())
- except (OSError, ValueError):
- continue
- if (data.get("spec") or {}).get("track") != "scene":
- continue
- if not (rec.parent / "src" / "scene.js").is_file():
- continue
- seen.add(rec.resolve())
- out.append(rec.parent)
- return out
+ """Every recorded scene run under ``root`` that still has a workspace to probe."""
+ return [run for run, _ in scene_records(root) if (run / "src" / "scene.js").is_file()]
def recorded_errors(record: dict) -> list[str]:
diff --git a/harness/bench/scene_stats.py b/harness/bench/scene_stats.py
index ce05543c..4cbe67b3 100644
--- a/harness/bench/scene_stats.py
+++ b/harness/bench/scene_stats.py
@@ -27,31 +27,36 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) # this tree's codeverse, not the editable install
from codeverse.flywheel.record import unique_files # noqa: E402
+from codeverse.proc import read_jsonl_lenient # noqa: E402
from codeverse.spatial.node import browser_was_lost # noqa: E402
#: pipeline stages in the order the scene track runs them
STAGES = ("plan", "skeleton", "assets", "env", "layouts", "assemble", "generate", "build")
-def runs(root: Path) -> list[tuple[str, dict, list[dict]]]:
- """``(prompt id, record, events)`` per scene run under ``root``, once per run."""
+def scene_records(root: Path) -> list[tuple[Path, dict]]:
+ """``(run dir, record)`` for every scene run under ``root``, once per run on disk.
+
+ The walk is ``flywheel.record.unique_files`` (symlinked cells collapsed, the
+ ``_assets`` / ``_cand`` sub-workspaces skipped) — the one walker every scene survey
+ shares (``scene_regate`` re-gates exactly the runs this counts)."""
out = []
for rec in unique_files(root, "record.json"):
try:
data = json.loads(rec.read_text())
except (OSError, ValueError):
continue
- if (data.get("spec") or {}).get("track") != "scene":
- continue
- ev = rec.parent / "events.jsonl"
- events = []
- if ev.is_file():
- for line in ev.read_text().splitlines():
- try:
- events.append(json.loads(line))
- except ValueError:
- continue
- out.append((str((data.get("spec") or {}).get("id", rec.parent.name)).split("/")[-1], data, events))
+ if (data.get("spec") or {}).get("track") == "scene":
+ out.append((rec.parent, data))
+ return out
+
+
+def runs(root: Path) -> list[tuple[str, dict, list[dict]]]:
+ """``(prompt id, record, events)`` per scene run under ``root``, once per run."""
+ out = []
+ for run, data in scene_records(root):
+ events = read_jsonl_lenient(run / "events.jsonl", dicts_only=True)
+ out.append((str((data.get("spec") or {}).get("id", run.name)).split("/")[-1], data, events))
# by id, then by path: two runs of one prompt (a battery with reps) share the id, and a
# bare sorted() would then compare their record dicts and raise. unique_files yields
# paths sorted, and the sort is stable, so the key is the id alone.
diff --git a/harness/docs/DECISIONS.md b/harness/docs/DECISIONS.md
index d3f95855..b5a575fc 100644
--- a/harness/docs/DECISIONS.md
+++ b/harness/docs/DECISIONS.md
@@ -916,159 +916,6 @@ written) that were accepted because the code works that way and the tests pin it
`medieval_cobblestone` first — against a judge complaint reading "no cobblestone
texture or material blending".)
-* **D53 Interpenetration is measured twice, and the two probes are asking different
- questions (found 2026-09-04, corrected 2026-09-06, NOT changed).** `spatial/connectivity`
- draws 600 points per surface, requires a minimum share of them inside the other part, and
- calls **2 mm** a WARN and **10 mm** an ERROR at the REST pose. `joint_sweep` poses the
- mechanism through fk and probes densely: it records an overlap from **2 mm**
- (`sweep_collisions(tol_m=)`, the default every caller takes) and treats a REST overlap as
- an ERROR only above **5 mm** (`sweep_findings(rest_max_m=)`, which
- `urdf.REST_PENETRATION_MAX_M` matches). So at rest the two share a WARN line and differ
- 2x on ERROR — not 10x, and `bench/penetration_thresholds.py` now imports both numbers
- instead of restating them.
-
- Measured over 374 recorded articulated rounds: the connectivity ERROR has fired **0
- times**, its WARN 50, and the depths it records are median 2.0 mm, max 9.9 mm — its ERROR
- threshold is unreachable in practice. The sweep raises **295 ERROR findings across 191
- distinct link pairs**, median 5.0 mm, max 34.3.
-
- **A correction to how that gap was first read.** This entry used to say the sweep
- measures "2-3x deeper on the same link pairs (8.8 vs 3.0 mm, 5.9 vs 3.8, 8.0 vs 3.0)".
- That comparison was not about one pose: the sweep number was its worst over ALL sampled
- poses and the connectivity number was the rest pose. Restricted to the pairs whose worst
- sweep pose IS the rest pose — `data["pose"]` empty, which is the filter that makes the
- comparison mean what it says — there are 19 such pairs in the corpus, 4 of them also
- recorded by connectivity in the same round, and on those four **the two probes agree
- exactly**: 4.4/4.4, 4.4/4.4, 2.2/2.2, 2.5/2.5 mm. The probes do not disagree about depth.
- What differs is the question: 288 of the sweep's pairs are overlaps that exist only in a
- moved pose, which a rest-pose check cannot see by construction.
-
- **And the threshold experiment answered itself, offline: do not change it.** Using the
- dense probe as the reference — for every pair connectivity records at or over a candidate
- threshold, did the SAME round's sweep flag that pair? — an ERROR at 2 mm would fire on 50
- pairs of which only **7 are corroborated**, while the 43 uncorroborated ones are static
- contacts the design intends (`shoulder_lock_knob|swivel_post`, `base_underframe|center_top`)
- that a 600-point surface draw reads as penetration; the dense probe would still be alone on
- **288** pairs. At 5 mm: 2 pairs, 0 corroborated. A shared threshold would create
- uncorroborated failures and still miss what the sweep finds. What was wrong is that the
- two read as one check with two dials; the fix belongs in what each is called and documented
- to do, not in the numbers.
-
-* **D54 A gate never reports the machine as a defect, and a render is retried once when
- the browser dies (2026-09-05).** The first recorded `scenes_v1` battery produced six
- cells of which three built, passed every gate that does not need pixels, and kept ZERO
- renders: `driver: Attempted to use detached Frame '<id>'` — Chrome reaping the render
- tab on a box at load 93 with swap full and all eight GPUs at ~100 %. The judge was
- skipped for want of images, so $6.75 of already-paid generation produced no verdict, and
- `bench/scene_stats.py` attributed the whole thing to `render_console`. Three separate
- rules came out of it, and they are the general form, not three patches:
- 1. **A driver that lost its browser is retried once, on a browser of its own.** The
- scene funnel (`spatial/render_scene.run_scene_script`) had no retry at all; the object
- path had one since 2026-08-28 but its marker tuple knew only the "Target closed"
- spelling. One vocabulary, `spatial/node.BROWSER_LOST_MARKERS`, now serves both, and
- the retry runs with `CV3D_BROWSER_REUSE=off` because the shared browser advertised in
- the cache is the suspect. Exactly one retry: a box out of memory stays out of memory.
- 2. **Two runtime trees never share a browser.** The daemon endpoint, its spawn lock and
- its failure file carry a digest of the `runtime_js` that spawned them, so a worktree
- and the main checkout cannot advertise over each other inside one `CV3D_CACHE_DIR`.
- RUNBOOK had asked operators to remember this since the coupled battery lost an arm to
- it; nothing enforced it.
- 3. **A finding that names a dead browser is reported apart from a defect.**
- `scene_stats.py` puts it in a `lost to the box` column and does not count the gate as
- failed. A battery whose report shows that column non-zero is not yet a statement
- about the generator.
- Consequence: a red browser test is checked against `uptime` and `free -g` before it is
- believed, and `test_studio_render_is_reproducible_and_stamps_the_rig_version` is
- documented as flaky-by-construction under CPU contention (SwiftShader is not
- bit-reproducible when the box is busy) rather than weakened.
-
-* **D55 `scene_placement` measures matter, and matter writes depth (2026-09-05).** Two of
- the first six recorded scene cells failed the gate on nothing but their own atmosphere:
- "BlackPine_5 is sunken 3.46 m into AtmosphereHaze" and "WindowSnowView/Mesh_49 and
- Environment/MoonlightShaft overlap (100 % of the smaller box)". Both scenes were
- correct; both offenders are `MeshBasicMaterial` at opacity 0.035-0.04 with
- `depthWrite: false`, and all nine recorded scenes use that idiom 34-42 times each. A
- pass that writes no depth occludes nothing, so it cannot support an object, nothing can
- sink into it, and passing through it is what it is for. `host_placement.nonSolid` keeps
- such meshes out of the column index entirely; an asset made only of them is listed with
- the exempt reason `volumetric` rather than dropped. **Opacity is deliberately not part
- of the rule** — glass sits at 0.3-0.6 and keeps writing depth, and a greenhouse pane
- really is a surface; a solid wall the model mistakenly marked `depthWrite: false` stops
- being a support, which is the cheaper error and matches what the frame shows. Measured
- on the recorded workspaces: cozy_cabin FAIL → PASS, japanese_garden's 3.46 m becomes a
- 0.044 m embed and the gate now fails on a real defect it had been reporting alongside
- the fog (`SubmergedRock_1 is sunken 0.48 m into ArchedBridge`).
-
- The same rule belongs in `nearGeometry`, and there it does more than quiet a report.
- `repairCameraSpec` is driven by `camera_in_geometry`, so a false "inside" RETREATS the
- authored lens: of the battery's seven recorded camera repairs, three were triggered by
- fog, and cozy_cabin's two were each moved back 4 m and up 2 m for standing in a
- `MoonlightShaft` — one of them ending NEARER geometry than it started (2.358 → 0.916 m).
- Re-rendering that workspace under the battery's own `--camera-repair` flag with the rule
- in place: `ArmchairHearthEye` goes from mean luminance 0.126 / 48 % near black to
- **0.263 / 0.5 %**, `WindowFrostSnow` from 0.149 / 56 % to **0.298 / 17 %**, and both
- cross from `dark_frame` ERROR to passing, while the two cameras that were never moved
- are unchanged (one of them still genuinely dark). So **two of that cell's three
- dark-frame ERRORs were manufactured by the harness**: fog → a false "camera in
- geometry" → a 4 m retreat → a dark frame → a second gate's ERROR → a judge complaint.
- Since "the frame is too dark" is this track's most recorded defect (153 findings over 32
- runs, per the scene prompt itself), some unknown share of that history is the
- instrument rather than the model. Across all 113 recorded camera checks in the battery
- the RAY term (`nearest < 0.3 m`) never fired once; every `camera_in_geometry` finding
- came from the bbox term, and every one of those was a volumetric or a scatter field.
-
-* **D56 A loaded GLB root is named after its asset (2026-09-05).** rooftop_garden's plan
- asked for one `blender_glb` asset; the Blender sub-run built it, the assembler wrote the
- loader, the browser loaded it and the census confirmed it was in the scene
- (`meshes_in_scene: 1, in_scene: true`) — and `scene_placement` still reported
- "zone PergolaLounge is missing planned contents: LoungeSofa", because the object was
- called `Scene`. A glTF root carries whatever the exporter wrote and Blender writes
- "Scene". The three assembled entry points that load GLBs (`render_scene_js`, the
- assembler's probe module, and the plan-written `scene.js`) had drifted into three copies
- of the same loop with three different error messages; they are now one emitter,
- `_glb_preload_js`, which stamps `to_pascal(key)` on the loaded root. Consequence for the
- Blender-scene question: **the cross-language seam is not what fails.** The Blender asset
- path works end to end and only lost a name; an argument for a Blender assembly layer has
- to be made on other grounds.
-
-* **D57 A frame rate is a measurement of the renderer that produced it (2026-09-05).**
- Inside one `scenes_v1` battery `fps` was measured on two different backends — 11.5 fps on
- an RTX 6000 Ada for one cell, 2.0 / 5.1 / 7.1 on SwiftShader for the next three, because
- `gpu_launch.cjs` caches a negative GPU verdict for 20 minutes and the box's GPUs were at
- ~100 % from other work. `render_console` raised "low frame rate … merge static geometry"
- for all four, and the judge was handed "PROBE: measured N fps" as a fact; two of the four
- **critical** judge issues across the scored cells were frame-rate complaints. Decision:
- `RenderSet.hardware_fps` is the only form a gate or a judge may read, and
- `RenderSet.software_rendered` reads the renderer string with the same words
- `gpu_launch.cjs` uses to decide whether a GPU attempt is trusted at all. The judge prompt
- keeps a software number but LABELS it, rather than dropping it silently — a genuinely
- heavy scene should still be visible to a reader — and an unrecognised renderer string is
- never claimed as software. Consequence: an fps comparison across cells is only valid
- within one backend, which is a property of any battery run on a shared machine, not of
- this one.
-
-* **D58 The scene texture pack is wired into the loop, behind a switch that is off
- (2026-09-05).** Of 24 judge issues over the five scored cells of the first `scenes_v1`
- battery, four say the GROUND is a flat untextured colour, in near-identical words —
- "single flat brown color", "single flat color with no cobblestone texture", "flat,
- untextured blueish plane with no material blending", "a hard, unblended circular seam".
- It is the most consistent defect in the battery. It is also a harness gap:
- `texturing.plan.scene_texture_pack` writes a tileable pack and `texture_pack_prompt`
- renders the list plus the loading idiom — its docstring says "Prompt snippet for
- zone/env generation" — and NOTHING in `tracks/scene.py` called either. The pack was
- reachable only through `3dcv texture scene-pack`, whose output `cli/texture_cmd.py`
- prints for a human to paste, and `Spec.options.texture` does nothing on this track.
- Decision: a `textures` stage runs before env and zones (they can only name files that
- exist when their prompts are built) and `_ctx` — the one place both prompts get their
- context — carries the manifest. **`CV3D_SCENE_TEXTURES` is off by default**: it costs
- an image-model call per run, measured at $0.15 for two 512 px textures (seam score
- 0.001) and an estimated $1-2 per run at ten 1024 px ones, and what that buys is a
- measurement nobody has made. Consequence for the Blender question: the material class
- cannot be counted as evidence for changing renderer until this arm has run. (The
- pack planner, given medieval_market's plan and told nothing about its judgment, planned
- `medieval_cobblestone` first — against a judge complaint reading "no cobblestone
- texture or material blending".)
-
* **D59 A check that reads the scene graph by name walks the whole zone subtree
(2026-09-06).** All five `scene_placement` ERRORs left in the fixed arm were
"zone X is missing planned contents", and none of them was absent content. A zone
diff --git a/harness/tests/scene_runtime/test_skeleton.py b/harness/tests/scene_runtime/test_skeleton.py
index 400596a9..b6c1b89c 100644
--- a/harness/tests/scene_runtime/test_skeleton.py
+++ b/harness/tests/scene_runtime/test_skeleton.py
@@ -52,7 +52,7 @@ def test_plan_skeleton_writes_zone_and_asset_stubs_and_lints(ws):
scene = (ws.src / "scene.js").read_text()
assert "export async function createScene" in scene
assert "'/assets/crane.glb'" in scene
- assert "buildPier(ctx)" in scene and "buildFishMarket(ctx)" in scene
+ assert "addZone(buildPier, 'Pier')" in scene and "addZone(buildFishMarket, 'FishMarket')" in scene
assert "name: 'pier_low'" in scene
pier = (ws.src / "zones" / "pier.js").read_text()
assert "zone.name = 'Pier'" in pier and "buildCrate" in pier and "ctx.assets.crane" in pier