Skip to content

Official Codebase of 3DCodeVerse

Python

record: every round keeps its build under artifacts/rNN/, and any round can be packaged

gaoypengbbe3c5e015ad
diff --git a/harness/codeverse3d/cli/_judge.py b/harness/codeverse3d/cli/_judge.py
index 0687c14c..29509347 100644
--- a/harness/codeverse3d/cli/_judge.py
+++ b/harness/codeverse3d/cli/_judge.py
@@ -114,7 +114,8 @@ def stored_glb_path(ws: Workspace, rec: RunRecord, rnd: RoundRecord) -> str | No
``3dcode judge`` reproduce the D48 conditional slice payload from the stored gates."""
if rec.spec.track.value not in SLICE_TRACKS or rnd.build is None or not rnd.build.glb_path:
return None
- p = ws.rebase(rnd.build.glb_path)
+ kept = ws.round_artifacts(rnd.index) / "object.glb" # the round's own GLB; the stored path is
+ p = kept if kept.is_file() else ws.rebase(rnd.build.glb_path) # the canonical one, rebuilt since
return str(p) if p.is_file() else None
diff --git a/harness/codeverse3d/contracts/run.py b/harness/codeverse3d/contracts/run.py
index 9dd7137f..fe092976 100644
--- a/harness/codeverse3d/contracts/run.py
+++ b/harness/codeverse3d/contracts/run.py
@@ -15,7 +15,7 @@ from enum import StrEnum
from pathlib import PurePosixPath
from typing import Any, Literal
-from pydantic import BaseModel, ConfigDict, Field
+from pydantic import AliasChoices, BaseModel, ConfigDict, Field
from codeverse3d.contracts.artifacts import (
BuildResult,
@@ -339,11 +339,12 @@ class DeliverableFile(BaseModel):
class RunDeliverable(BaseModel):
- """``record.deliverable`` — what the run produced, as paths + hashes + sizes."""
+ """``deliverable/manifest.json`` — the round that was handed over, as paths + hashes + sizes."""
schema_version: int = 1
dir: str = "deliverable"
- best_round: int | None = None
+ round: int | None = Field(default=None, validation_alias=AliasChoices("round", "best_round"),
+ description="the packaged round (manifests before 2026-09-22 call it best_round)")
commit: str = ""
code_source: str = Field(default="", description="commit | working_tree")
entry: str = Field(default="", description="run-relative entry file of the code snapshot")
diff --git a/harness/codeverse3d/record/deliverable.py b/harness/codeverse3d/record/deliverable.py
index b1e15651..aa775e52 100644
--- a/harness/codeverse3d/record/deliverable.py
+++ b/harness/codeverse3d/record/deliverable.py
@@ -1,20 +1,24 @@
-"""``<run>/deliverable/`` — the hand-over folder: what the user actually asked for.
-
-Everything in here is a *copy*, regenerated from the run's own evidence, so the
-folder can be zipped and sent on its own:
-
-* ``src/**`` (+ ``public/**`` for scenes) — the raw code at the BEST round's commit;
-* the canonical artifact — ``object.glb`` (+ ``.stl`` / ``.step`` / textured GLB),
- or ``robot.urdf`` + ``meshes/*.glb``, or ``frames/*.png`` + ``preview.gif``;
-* ``sheet.png`` — the best round's contact sheet (one picture of the result);
+"""``<run>/deliverable/`` — the hand-over folder for ONE round, and what every round keeps
+so that any of them can be handed over later without a rebuild.
+
+Everything in the folder is a *copy*, regenerated from the run's own evidence, so it can
+be zipped and sent on its own:
+
+* ``src/**`` (+ ``public/**`` for scenes, their GLB assets included) — the raw code at the
+ round's commit;
+* the round's artifact — ``object.glb`` (+ ``.stl`` / ``.step`` / textured GLB), or
+ ``robot.urdf`` + ``meshes/*.glb``, or ``frames/*.png`` (the judged frames) +
+ ``frames_sheet.png`` + ``preview.gif`` — from ``artifacts/rNN/`` (:func:`keep_round_artifacts`);
+* ``sheet.png`` — the round's contact sheet (one picture of the result);
* ``captions.json`` when the run is captioned;
-* ``manifest.json`` — every OTHER file with its role, size and sha256 (mirrored
- into ``record.deliverable``). It does not list itself: a file cannot carry its
- own hash, and the returned object must be exactly what is on disk.
-
-Renders per round, gates, judge verdicts and measurements stay in the evidence
-bucket (``artifacts/`` = ``evidence/``); tokens, prices and settings stay in
-``telemetry/``. Nothing else belongs here.
+* ``manifest.json`` — every OTHER file with its role, size and sha256. It does not list
+ itself: a file cannot carry its own hash, and the returned object must be exactly what
+ is on disk.
+
+WHICH round is not decided here: since 2026-09-22 the run keeps every round and ends at the
+last one, and ``codeverse3d.addons.select`` picks a round and packages it. Renders per
+round, gates, judge verdicts and measurements stay in the evidence bucket (``artifacts/`` =
+``evidence/``); tokens, prices and settings stay in ``telemetry/``.
"""
from __future__ import annotations
@@ -26,9 +30,9 @@ import shutil
from datetime import UTC, datetime
from pathlib import Path
-from codeverse3d.contracts.common import ENTRY_FILE, Language
+from codeverse3d.contracts.common import ENTRY_FILE, Language, Track
from codeverse3d.contracts.run import DeliverableFile, RoundRecord, RunDeliverable, RunRecord
-from codeverse3d.proc import sha256_file, write_json_atomic
+from codeverse3d.proc import read_json_or_none, sha256_file, write_json_atomic
from codeverse3d.record import _git
from codeverse3d.workspace import Workspace
@@ -37,16 +41,40 @@ log = logging.getLogger(__name__)
MAX_FILE_BYTES = 128 * 1024 * 1024
MAX_TOTAL_BYTES = 512 * 1024 * 1024
-#: artifact file → role, copied when present (object tracks / articulated / graphics)
+#: a round's build output → its role in the hand-over. Exactly these (and ``meshes/``)
+#: are what a round keeps under ``artifacts/rNN/``: the census, build.json, the .blend and
+#: the export scratch dirs are evidence of the build, not part of what was built.
_ARTIFACT_ROLES: tuple[tuple[str, str], ...] = (
("object.glb", "model"),
("object.stl", "model"),
("object.step", "model"),
- ("object_textured.glb", "model"),
("robot.urdf", "urdf"),
("preview.gif", "preview"),
("frames_sheet.png", "sheet"),
)
+#: per-link meshes of an articulated round (``robot.urdf`` references them)
+_MESH_DIR = "meshes"
+
+
+def keep_round_artifacts(ws: Workspace, round_index: int) -> list[str]:
+ """Copy the round's build outputs to ``artifacts/rNN/`` (names relative to
+ ``artifacts/``); ``[]`` when the round built nothing to keep.
+
+ Only the files a hand-over needs, and real copies: the next round's build replaces the
+ canonical ones, and a kept round must never change under a writer that happens to
+ write in place (a hard link would share that inode). A scene keeps nothing here — its
+ hand-over (``src/`` + ``public/``, GLB assets included) is the round's git commit — and
+ a graphics round keeps its sheet and GIF; its judged frames are in ``renders/rNN/``."""
+ dest = ws.round_artifacts(round_index)
+ if dest.exists(): # the same round built again (a transport retry): its last build wins
+ shutil.rmtree(dest)
+ names = [n for n, _ in _ARTIFACT_ROLES if (ws.artifacts / n).is_file()]
+ meshes = sorted((ws.artifacts / _MESH_DIR).glob("*.glb")) if (ws.artifacts / _MESH_DIR).is_dir() else []
+ names += [p.relative_to(ws.artifacts).as_posix() for p in meshes]
+ for rel in names:
+ (dest / rel).parent.mkdir(parents=True, exist_ok=True)
+ shutil.copy2(ws.artifacts / rel, dest / rel)
+ return names
class _Writer:
@@ -99,7 +127,7 @@ def _place(src: Path, dest: Path) -> None:
def _code_tree(ws: Workspace, rnd: RoundRecord | None) -> tuple[dict[str, bytes], str]:
- """``src/**`` (+ ``public/**``) at the best round's commit, else the working tree."""
+ """``src/**`` (+ ``public/**``) at the round's commit, else the working tree."""
if rnd is not None and rnd.commit:
try:
if _git.commit_exists(ws, rnd.commit):
@@ -113,23 +141,48 @@ def _code_tree(ws: Workspace, rnd: RoundRecord | None) -> tuple[dict[str, bytes]
return {}, "working_tree"
-def _copy_artifacts(ws: Workspace, record: RunRecord, w: _Writer) -> None:
- tex = record.extra.get("texturing") or {}
+def _round_outputs(ws: Workspace, rnd: RoundRecord | None) -> Path | None:
+ """Where the round's build outputs are: ``artifacts/rNN/``, or — a run recorded before
+ rounds kept their own (2026-09-22) — ``artifacts/`` itself, but only for the round
+ that run's finalise rebuilt there (the ``best_round`` its record.json still names)."""
+ if rnd is None:
+ return None
+ kept = ws.round_artifacts(rnd.index)
+ if kept.is_dir():
+ return kept
+ legacy = (read_json_or_none(ws.record_path) or {}).get("best_round")
+ return ws.artifacts if legacy == rnd.index else None
+
+
+def _texture_is_for(ws: Workspace, glb: Path) -> bool:
+ """Did the SHIPPED texture pass start from these exact bytes? The report names the GLB
+ it consumed; a pack made mid-round, or for another round, is not this round's."""
+ from codeverse3d.texturing.run import report_path
+
+ rep = read_json_or_none(report_path(ws)) or {}
+ src = ws.rebase(str(rep.get("glb_in") or "")) if rep.get("glb_in") else None
+ return (bool(rep.get("shipped")) and src is not None and src.is_file() and glb.is_file()
+ and sha256_file(src) == sha256_file(glb))
+
+
+def _copy_artifacts(ws: Workspace, record: RunRecord, rnd: RoundRecord | None, w: _Writer) -> None:
+ out = _round_outputs(ws, rnd)
+ if out is None:
+ return
for name, role in _ARTIFACT_ROLES:
- if name == "object_textured.glb" and not tex.get("shipped"):
- # a texture pass that did not ship is not a deliverable, even if a stray
- # canonical file exists (same gate addons/dataset/sample.copy_textured applies)
- continue
- w.add_file(ws.artifacts / name, name, role)
- meshes = ws.artifacts / "meshes"
- if record.spec.language is Language.URDF_BLENDER and meshes.is_dir():
- for p in sorted(meshes.glob("*.glb")):
- w.add_file(p, f"meshes/{p.name}", "mesh")
- frames = ws.artifacts / "frames"
- if frames.is_dir():
- for p in sorted(frames.glob("*.png")):
- w.add_file(p, f"frames/{p.name}", "frames")
- if tex.get("shipped"):
+ w.add_file(out / name, name, role)
+ if record.spec.language is Language.URDF_BLENDER and (out / _MESH_DIR).is_dir():
+ for p in sorted((out / _MESH_DIR).glob("*.glb")):
+ w.add_file(p, f"{_MESH_DIR}/{p.name}", "mesh")
+ if record.spec.track is Track.GRAPHICS and rnd is not None and rnd.renders is not None:
+ for v in rnd.renders.views: # the judged frames (renders/rNN), one per sampled time
+ src = ws.rebase(v.path)
+ w.add_file(src, f"frames/{src.name}", "frames")
+ tex = record.extra.get("texturing") or {}
+ # old layout: the one canonical pack belonged to the one round finalise rebuilt
+ shipped = tex.get("shipped") if out == ws.artifacts else _texture_is_for(ws, out / "object.glb")
+ if shipped:
+ w.add_file(ws.artifacts / "object_textured.glb", "object_textured.glb", "model")
tex_dir = ws.root / str(tex.get("textures_dir") or "artifacts/textures")
for p in sorted(tex_dir.glob("*.png")) if tex_dir.is_dir() else []:
w.add_file(p, f"textures/{p.name}", "texture")
@@ -165,14 +218,12 @@ def _stable_timestamp(previous: RunDeliverable | None, current: RunDeliverable)
return previous.generated_at if same else (current.generated_at or datetime.now(UTC))
-def build_deliverable(ws: Workspace, record: RunRecord, *, clean: bool = True) -> RunDeliverable:
- """(Re)build ``<run>/deliverable/`` and return the typed manifest.
+def build_deliverable(ws: Workspace, record: RunRecord, round_index: int | None, *, clean: bool = True) -> RunDeliverable:
+ """(Re)build ``<run>/deliverable/`` for round ``round_index`` and return the typed manifest.
Idempotent: the folder is rebuilt from scratch every time, so a second call
on an unchanged run produces byte-identical content."""
- from codeverse3d.record.record import best_round_record
-
- rnd = best_round_record(record)
+ rnd = next((r for r in record.rounds if r.index == round_index), None)
previous = load_deliverable(ws) if ws.deliverable_manifest_path.is_file() else None
if clean and ws.deliverable.exists():
shutil.rmtree(ws.deliverable)
@@ -181,12 +232,12 @@ def build_deliverable(ws: Workspace, record: RunRecord, *, clean: bool = True) -
files, code_source = _code_tree(ws, rnd)
for rel, data in sorted(files.items()):
w.add_bytes(rel, data, "code" if rel.startswith("src/") else "bundle")
- _copy_artifacts(ws, record, w)
+ _copy_artifacts(ws, record, rnd, w)
_copy_sheet(ws, rnd, w)
_copy_captions(ws, record, w)
entry = ENTRY_FILE.get(record.spec.language, "")
manifest = RunDeliverable(
- best_round=(rnd.index if rnd is not None else None), commit=(rnd.commit if rnd is not None else ""), code_source=code_source,
+ round=(rnd.index if rnd is not None else None), commit=(rnd.commit if rnd is not None else ""), code_source=code_source,
entry=f"deliverable/{entry}" if entry in files else "",
files=sorted(w.files, key=lambda f: f.path), total_bytes=w.total, skipped=w.skipped,
generated_at=datetime.now(UTC),
diff --git a/harness/codeverse3d/record/record.py b/harness/codeverse3d/record/record.py
index 09a6b814..872a96fd 100644
--- a/harness/codeverse3d/record/record.py
+++ b/harness/codeverse3d/record/record.py
@@ -265,7 +265,7 @@ def package_run(ws: Workspace, record: RunRecord) -> None:
log.warning("run layout not created in %s: %s", ws.root, e)
return
try:
- record.deliverable = build_deliverable(ws, record)
+ record.deliverable = build_deliverable(ws, record, best_round_index(record))
except Exception as e: # noqa: BLE001 - never fail a finished run over packaging
log.warning("deliverable not built for %s: %s", ws.root, e)
try:
diff --git a/harness/codeverse3d/tracks/steps.py b/harness/codeverse3d/tracks/steps.py
index 57f0b07b..536fffe7 100644
--- a/harness/codeverse3d/tracks/steps.py
+++ b/harness/codeverse3d/tracks/steps.py
@@ -2,8 +2,9 @@
``run_round`` is track-agnostic; a ``RoundPipeline`` supplies the track-specific
gates / measurement / rendering. Every step writes its artifact under the
-workspace (gates/rNN, renders/rNN, judge/rNN.json, rounds/rNN.json) so a run
-can be resumed and the flywheel can replay it.
+workspace (gates/rNN, renders/rNN, judge/rNN.json, rounds/rNN.json, and the build
+outputs a hand-over needs under artifacts/rNN/) so a run can be resumed, the flywheel
+can replay it, and any round can be packaged later without a rebuild.
Two cost rules live here (docs/COST.md §5, §6):
@@ -41,6 +42,7 @@ from codeverse3d.judges.base import SLICE_TRACKS, JudgeInput
from codeverse3d.judges.rubrics import is_degraded
from codeverse3d.orchestrator import BudgetExceeded, usage_delta
from codeverse3d.proc import fan_out
+from codeverse3d.record.deliverable import keep_round_artifacts
from codeverse3d.spatial.render import RenderError
from codeverse3d.tracks import skills_hook
from codeverse3d.tracks.common import RunContext, generate_for
@@ -334,6 +336,9 @@ def _run_round(
_write_gate_reports(ctx, index, gates)
rec.commit = ctx.ws.commit(f"r{index:02d} {kind}")
+ if outcome.build.ok:
+ # every round keeps what a hand-over of it needs: the next build replaces artifacts/
+ keep_round_artifacts(ctx.ws, index)
rec.usage = usage
rec.duration_s = round(time.time() - t0, 2)
rec.notes = "; ".join(notes)
diff --git a/harness/codeverse3d/workspace.py b/harness/codeverse3d/workspace.py
index 10d66602..3a363683 100644
--- a/harness/codeverse3d/workspace.py
+++ b/harness/codeverse3d/workspace.py
@@ -220,6 +220,11 @@ class Workspace:
def judge_path(self, round_index: int, suffix: str = "") -> Path:
return self.artifacts / "judge" / f"r{round_index:02d}{suffix}.json"
+ def round_artifacts(self, round_index: int) -> Path:
+ """``artifacts/rNN/`` — the round's own copy of the build outputs a hand-over needs
+ (``record.deliverable.keep_round_artifacts``; docs/RUN_LAYOUT.md)."""
+ return self.artifacts / f"r{round_index:02d}"
+
def trajectory_dir(self, stage: str, round_index: int) -> Path:
d = self.trajectories / f"{stage}_r{round_index:02d}"
d.mkdir(parents=True, exist_ok=True)
diff --git a/harness/tests/core/test_run_layout.py b/harness/tests/core/test_run_layout.py
index c480f827..b3848ef3 100644
--- a/harness/tests/core/test_run_layout.py
+++ b/harness/tests/core/test_run_layout.py
@@ -76,9 +76,9 @@ def test_record_blocks_are_additive(tmp_path: Path):
rec = RunRecord.model_validate(old)
assert rec.telemetry is None and rec.deliverable is None
rec.telemetry = RunTelemetry()
- rec.deliverable = RunDeliverable(best_round=1, commit="abc")
+ rec.deliverable = RunDeliverable.model_validate({"best_round": 1, "commit": "abc"}) # a pre-2026-09-22 manifest
again = RunRecord.model_validate_json(rec.model_dump_json())
- assert again.deliverable is not None and again.deliverable.best_round == 1
+ assert again.deliverable is not None and again.deliverable.round == 1
assert again.telemetry is not None and again.telemetry.schema_version == 1
diff --git a/harness/tests/flywheel_cli/test_run_layout_cli.py b/harness/tests/flywheel_cli/test_run_layout_cli.py
index 3eef911c..6011c4cb 100644
--- a/harness/tests/flywheel_cli/test_run_layout_cli.py
+++ b/harness/tests/flywheel_cli/test_run_layout_cli.py
@@ -66,7 +66,7 @@ def test_package_run_builds_a_stable_independent_and_loadable_handover(fake_run)
# returned object used to have one more file (and a smaller total) than the disk
assert {"code", "model", "sheet"} <= roles and "manifest" not in roles
assert load_deliverable(ws) == d and d.total_bytes == sum(f.bytes for f in d.files)
- assert d.best_round == 1 and d.code_source == "commit"
+ assert d.round == 1 and d.code_source == "commit"
assert d.entry == "deliverable/src/model.py"
assert (ws.deliverable / "src" / "model.py").read_text().startswith("# round 1")
assert (ws.deliverable / "object.glb").is_file() and (ws.deliverable / "sheet.png").is_file()
@@ -85,7 +85,7 @@ def test_package_run_builds_a_stable_independent_and_loadable_handover(fake_run)
# Rebuilding unchanged content is byte-for-byte stable.
first = rec.deliverable
files_before = sorted(p.relative_to(ws.deliverable).as_posix() for p in ws.deliverable.rglob("*") if p.is_file())
- second = build_deliverable(ws, rec)
+ second = build_deliverable(ws, rec, 1)
files_after = sorted(p.relative_to(ws.deliverable).as_posix() for p in ws.deliverable.rglob("*") if p.is_file())
assert files_before == files_after
assert first.generated_at == second.generated_at # unchanged content → no diff
@@ -158,13 +158,13 @@ def test_rejected_texture_pass_is_not_delivered_or_linked(fake_run):
ws, rec = fake_run
(ws.artifacts / "object_textured.glb").write_bytes(b"glTF\x02" + b"\0" * 16)
rec.extra["texturing"] = {"shipped": False, "glb_textured": "artifacts/object_textured.glb"}
- build_deliverable(ws, rec)
+ build_deliverable(ws, rec, 1)
assert not (ws.deliverable / "object_textured.glb").exists()
entry = entry_from_record("runs", ws, rec)
assert "textured glb" not in {ln.label for ln in entry.links}
# ... and a SHIPPED pass is delivered and linked
rec.extra["texturing"] = {"shipped": True, "glb_textured": "artifacts/object_textured.glb"}
- build_deliverable(ws, rec)
+ build_deliverable(ws, rec, 1)
assert (ws.deliverable / "object_textured.glb").is_file()
entry = entry_from_record("runs", ws, rec)
assert "textured glb" in {ln.label for ln in entry.links}
diff --git a/harness/tests/orchestrator_tracks/test_fixed_rounds.py b/harness/tests/orchestrator_tracks/test_fixed_rounds.py
index 6338a32a..5b894cb4 100644
--- a/harness/tests/orchestrator_tracks/test_fixed_rounds.py
+++ b/harness/tests/orchestrator_tracks/test_fixed_rounds.py
@@ -72,3 +72,46 @@ def test_every_refine_starts_from_the_previous_rounds_commit(tmp_path, chair_pla
assert rec.rounds[2].instructions, "the tasks come from r01's verdict and gates"
events = [e["event"] for e in EventLog(ws.events_path).read()]
assert "round.refine_from_best" not in events and "strategy.switch" not in events
+
+
+class _RoundStampRuntime(FakeRuntime):
+ """A build whose GLB differs per round (the box width is the round the code says it is)."""
+
+ def build(self, ws, *, timeout_s=None):
+ import re
+
+ import trimesh
+
+ res = super().build(ws, timeout_s=timeout_s)
+ if res.ok:
+ m = re.search(r"written in r(\d+)", (ws.src / "model.py").read_text())
+ box = trimesh.creation.box(extents=(0.1 * (int(m.group(1)) + 1) if m else 0.05, 0.2, 0.2))
+ glb = ws.artifacts / "object.glb"
+ glb.unlink() # a runtime REPLACES its canonical artifact (ArtifactStage)
+ glb.write_bytes(trimesh.Scene(box).export(file_type="glb"))
+ (ws.artifacts / "object.stl").write_bytes(box.export(file_type="stl"))
+ return res
+
+
+def test_every_round_keeps_its_build_and_any_round_can_be_packaged(tmp_path, chair_plan, settings):
+ from codeverse3d.record.deliverable import build_deliverable
+
+ ws = Workspace(tmp_path / "runs" / "kept")
+ track = StaticObjectTrack(services=FakeServices(), judge=FakeJudge(scores=(0.5, 0.8, 0.6)),
+ agent=FakeAgent(lambda job, ws: {"src/model.py": f"import bpy # written in r{job.round}\n"}),
+ planner_model=_planner(chair_plan.model_dump(mode="json")), settings=settings,
+ runtime=_RoundStampRuntime(Language.BLENDER))
+ rec = track.run(make_spec(language=Language.BLENDER, max_rounds=2), ws)
+ kept = [ws.round_artifacts(i) / "object.glb" for i in range(3)]
+ assert all(p.is_file() for p in kept) and (ws.round_artifacts(1) / "object.stl").is_file()
+ assert len({p.read_bytes() for p in kept}) == 3, "each round keeps its OWN build"
+ assert not (ws.round_artifacts(1) / "census.json").exists(), "only what a hand-over needs is kept"
+ # any round packages without a rebuild: its commit's code + its own GLB
+ builds = track._runtime.builds
+ for i in (1, 0):
+ d = build_deliverable(ws, rec, i)
+ assert d.round == i and d.commit == rec.rounds[i].commit
+ assert (ws.deliverable / "object.glb").read_bytes() == kept[i].read_bytes()
+ assert (ws.deliverable / "src" / "model.py").read_text() == f"import bpy # written in r{i}\n"
+ assert (ws.deliverable / "sheet.png").is_file()
+ assert track._runtime.builds == builds, "packaging never rebuilds"