Skip to content

Official Codebase of 3DCodeVerse

Python

languages: one run_wrapper_build for the blender and cadquery builds — the invalidate / missing-entry / subprocess prologue was written twice

gaoypeng9596af54eae4
diff --git a/harness/codeverse3d/languages/_common.py b/harness/codeverse3d/languages/_common.py
index 50ebd538..bb539664 100644
--- a/harness/codeverse3d/languages/_common.py
+++ b/harness/codeverse3d/languages/_common.py
@@ -4,6 +4,8 @@ Runtimes execute a *wrapper script* in a subprocess (Blender's python or the
harness python). The wrapper writes ``artifacts/build.json`` (+ ``census.json``)
and the runtime turns those into a :class:`BuildResult`. This module owns:
+* :func:`run_wrapper_build` — the blender / cadquery build: invalidate, missing entry,
+ wrapper subprocess, then :func:`compose_build_result`;
* :func:`compose_build_result` — wrapper json + process outcome → BuildResult,
failing loud when the wrapper did not report, published as ``build.json``;
* :func:`read_json_file` / :func:`strip_blender_noise`.
@@ -20,7 +22,8 @@ from pathlib import Path
from typing import Any
from codeverse3d.contracts.artifacts import BuildResult
-from codeverse3d.proc import ProcResult, tail, write_json_atomic
+from codeverse3d.proc import ProcResult, run_subprocess, tail, write_json_atomic
+from codeverse3d.workspace import Workspace
#: The one spelling of every runtime's typed build failures — recorded in build.json /
#: record.json / bench cells, so the strings stay as first recorded (2026-08-29: threejs,
@@ -75,6 +78,28 @@ def read_json_file(path: Path) -> dict[str, Any]:
return data
+def run_wrapper_build(ws: Workspace, *, language: str, entry_rel: str, extras: Mapping[str, str],
+ argv: Callable[[], list[str]], env: dict[str, str], timeout_s: float,
+ output_filter: Callable[[str], str] | None = None) -> BuildResult:
+ """Run a python wrapper build; ``extras`` maps a ``BuildResult.extra_paths`` key to its
+ artifact file name. The outputs are invalidated BEFORE the missing-entry early return
+ (a deleted model.py must not leave the previous round's object.glb + build.json
+ (ok: true) looking current), and ``argv`` is called only after that check, so a
+ missing Blender binary raises where it always did."""
+ ws.artifacts.mkdir(parents=True, exist_ok=True)
+ build_json = ws.artifacts / "build.json"
+ ws.stage_artifacts("build.json", "census.json", "object.glb", *extras.values()).invalidate()
+ if not (ws.root / entry_rel).is_file():
+ result = BuildResult(ok=False, language=language, error_type=MISSING_ENTRY,
+ error_message=f"{entry_rel} does not exist", error_file=entry_rel)
+ ws.write_json(build_json, result)
+ return result
+ proc = run_subprocess(argv(), cwd=ws.root, env=env, timeout_s=timeout_s)
+ return compose_build_result(language=language, proc=proc, build_json=build_json, census_json=ws.artifacts / "census.json",
+ glb_path=ws.artifacts / "object.glb", extra_paths={k: ws.artifacts / v for k, v in extras.items()},
+ output_filter=output_filter)
+
+
def compose_build_result(
*,
language: str,
diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.py
index 50a5c6a4..c0b6d13b 100644
--- a/harness/codeverse3d/languages/blender/__init__.py
+++ b/harness/codeverse3d/languages/blender/__init__.py
@@ -20,9 +20,9 @@ from codeverse3d.languages._ast_lint import (
dotted,
safe_parse,
)
-from codeverse3d.languages._common import MISSING_ENTRY, compose_build_result, strip_blender_noise
+from codeverse3d.languages._common import run_wrapper_build, strip_blender_noise
from codeverse3d.languages.base import RuntimeLayout
-from codeverse3d.proc import run_subprocess, scrub_secrets
+from codeverse3d.proc import scrub_secrets
from codeverse3d.workspace import Workspace
# ===================================================================== lint
@@ -738,28 +738,8 @@ class BlenderRuntime(RuntimeLayout):
seed: int = 0, tri_limit: int = MAX_TRIS_OBJECT,
) -> BuildResult:
"""Run the wrapper; never raises for agent-code failures (typed BuildResult instead)."""
- ws.artifacts.mkdir(parents=True, exist_ok=True)
- build_json = ws.artifacts / "build.json"
- census_json = ws.artifacts / "census.json"
- glb = ws.artifacts / "object.glb"
- stl_path = ws.artifacts / "object.stl"
- blend_path = ws.artifacts / "object.blend"
- # invalidate BEFORE the missing-entry early return: a deleted model.py must not
- # leave the previous round's object.glb + build.json (ok: true) looking current
- ws.stage_artifacts("build.json", "census.json", "object.glb", "object.stl", "object.blend").invalidate()
- entry = self.entry_file(ws)
- if not entry.is_file():
- result = BuildResult(ok=False, language=self.language.value, error_type=MISSING_ENTRY,
- error_message=f"{ENTRY_REL} does not exist", error_file=ENTRY_REL)
- ws.write_json(build_json, result)
- return result
- cmd = self.build_command(ws, stl=stl, blend=blend, seed=seed, tri_limit=tri_limit)
- proc = run_subprocess(
- cmd, cwd=ws.root, env=blender_env(),
- timeout_s=timeout_s or self._settings.limits.build_timeout_s,
- )
- return compose_build_result(
- language=self.language.value, proc=proc, build_json=build_json, census_json=census_json,
- glb_path=glb, extra_paths={"stl": stl_path, "blend": blend_path}, output_filter=strip_blender_noise,
- )
+ return run_wrapper_build(
+ ws, language=self.language.value, entry_rel=ENTRY_REL, extras={"stl": "object.stl", "blend": "object.blend"},
+ argv=lambda: self.build_command(ws, stl=stl, blend=blend, seed=seed, tri_limit=tri_limit),
+ env=blender_env(), timeout_s=timeout_s or self._settings.limits.build_timeout_s, output_filter=strip_blender_noise)
diff --git a/harness/codeverse3d/languages/cadquery/__init__.py b/harness/codeverse3d/languages/cadquery/__init__.py
index e38ff5e3..d83d033a 100644
--- a/harness/codeverse3d/languages/cadquery/__init__.py
+++ b/harness/codeverse3d/languages/cadquery/__init__.py
@@ -21,10 +21,10 @@ from codeverse3d.languages._ast_lint import (
dotted,
safe_parse,
)
-from codeverse3d.languages._common import MISSING_ENTRY, compose_build_result
+from codeverse3d.languages._common import run_wrapper_build
from codeverse3d.languages.base import RuntimeLayout
from codeverse3d.languages.blender import _fmt, finish_for, instance_centers
-from codeverse3d.proc import run_subprocess, scrub_secrets
+from codeverse3d.proc import scrub_secrets
from codeverse3d.workspace import Workspace
# ===================================================================== lint
@@ -356,19 +356,8 @@ class CadQueryRuntime(RuntimeLayout):
def build(self, ws: Workspace, *, timeout_s: int | None = None, seed: int = 0,
tri_limit: int = MAX_TRIS_OBJECT) -> BuildResult:
- ws.artifacts.mkdir(parents=True, exist_ok=True)
- build_json, census_json = ws.artifacts / "build.json", ws.artifacts / "census.json"
- glb, step, stl = ws.artifacts / "object.glb", ws.artifacts / "object.step", ws.artifacts / "object.stl"
- # invalidate BEFORE the missing-entry early return (same reasoning as BlenderRuntime.build)
- ws.stage_artifacts("build.json", "census.json", "object.glb", "object.step", "object.stl").invalidate()
- entry = self.entry_file(ws)
- if not entry.is_file():
- result = BuildResult(ok=False, language=self.language.value, error_type=MISSING_ENTRY,
- error_message="src/model.py does not exist", error_file="src/model.py")
- ws.write_json(build_json, result)
- return result
- proc = run_subprocess(self.build_command(ws, seed=seed, tri_limit=tri_limit), cwd=ws.root, env=cadquery_env(),
- timeout_s=timeout_s or self._settings.limits.build_timeout_s)
- return compose_build_result(language=self.language.value, proc=proc, build_json=build_json, census_json=census_json,
- glb_path=glb, extra_paths={"step": step, "stl": stl})
+ return run_wrapper_build(
+ ws, language=self.language.value, entry_rel=ENTRY_FILE[Language.CADQUERY], extras={"step": "object.step", "stl": "object.stl"},
+ argv=lambda: self.build_command(ws, seed=seed, tri_limit=tri_limit),
+ env=cadquery_env(), timeout_s=timeout_s or self._settings.limits.build_timeout_s)
diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.md
index 0d6379c5..622a988b 100644
--- a/harness/docs/INTERFACES.md
+++ b/harness/docs/INTERFACES.md
@@ -272,7 +272,8 @@ together in `languages/wrappers/` — `run_bpy.py`, `run_bpy_links.py` (Blender'
`sys.path`, traceback → `src/<file>:<line>`, `sys.exit(0)` is not a failure, the atomic
report) and `_census.py` (the Blender census, blender AND urdf_blender); copy the directory
whole. Each writes its report as `build.json` + `census.json`, which the runtime reads
-once through `_common.compose_build_result` and replaces with the final `BuildResult` — for
+once through `_common.compose_build_result` (blender and cadquery: `_common.run_wrapper_build`, the
+invalidate → missing entry → subprocess prologue around it) and replaces with the final `BuildResult` — for
EVERY runtime `artifacts/build.json` is the BuildResult (urdf_blender after its post-wrapper
checks). `opengl_python/wrappers/run_gl.py` is the moderngl runner; threejs/scene
export+render live in `runtime_js/` (`export_glb.mjs`, `render_glb.mjs`,
diff --git a/harness/docs/RUNBOOK.md b/harness/docs/RUNBOOK.md
index 48165608..893fbd7d 100644
--- a/harness/docs/RUNBOOK.md
+++ b/harness/docs/RUNBOOK.md
@@ -373,8 +373,8 @@ weather: they leave the provider's errors out (docs/COST.md §31); the ceiling d
(entry + `extra_files`, and `part_file` for a one-file-per-part language) or answer
`expected_files(plan)` / `files_for(plan, target)` yourself, as the scene runtime does; the
tracks never restate it. A python-executed build wrapper goes beside the others in
- `languages/wrappers/` (import `_wrapper_common`; read its report with
- `_common.compose_build_result`, which publishes the final `build.json`); branch in
+ `languages/wrappers/` (import `_wrapper_common`; run it with `_common.run_wrapper_build`, or
+ read its report with `_common.compose_build_result`, which publishes the final `build.json`); branch in
`languages/base.py::get_runtime`; `prompts/<lang>/{system,contract,cookbook}.md` (found by
`prompts/catalog.language_prompt`; every cookbook snippet must run — `tests/prompts`
executes them).