Skip to content

Official Codebase of 3DCodeVerse

Python

scene review nits: asset reuse keyed by the plan slice, zone probe gets the flags, one flag vocabulary

gaoypengf7e60577569e
diff --git a/harness/codeverse/languages/scene_threejs/__init__.py b/harness/codeverse/languages/scene_threejs/__init__.py
index 0f637d01..cb38c4ea 100644
--- a/harness/codeverse/languages/scene_threejs/__init__.py
+++ b/harness/codeverse/languages/scene_threejs/__init__.py
@@ -457,7 +457,10 @@ def probe_zone_modules(ws: Workspace, *, timeout_s: float = 90.0, sun_azimuth_de
zones = zone_files(ws)
probe_path = ws.root / PROBE_REL
probe_path.write_text(_probe_module(zones, glb_assets(ws)))
+ from codeverse.spatial.render_scene import probe_env_args
+
args = ["--ws", str(ws.root), "--scene", PROBE_REL, "--timeout-ms", str(int(timeout_s * 1000))]
+ args += probe_env_args() # the zone probe sees the same settle/repair/exposure world as the renders
if sun_azimuth_deg is not None:
args += ["--sun-azimuth", str(sun_azimuth_deg)]
try:
diff --git a/harness/codeverse/tracks/scene.py b/harness/codeverse/tracks/scene.py
index ccb47323..b3da07eb 100644
--- a/harness/codeverse/tracks/scene.py
+++ b/harness/codeverse/tracks/scene.py
@@ -201,9 +201,9 @@ class SceneTrack(BaseTrack):
# so the two stages' commits cannot race.
def _layouts() -> dict[str, Any]:
"""L2 zone layouts (optional accelerator): planner-model calls, never fatal."""
- import os
+ from codeverse.config import env_flag
- if os.environ.get("CV3D_ZONE_LAYOUTS") == "0": # A/B switch, default on
+ if not env_flag("CV3D_ZONE_LAYOUTS", True): # A/B switch, default on; canonical words
return {}
try:
model = self._planner_model
diff --git a/harness/codeverse/tracks/scene_assets.py b/harness/codeverse/tracks/scene_assets.py
index d83c7869..97c24eb3 100644
--- a/harness/codeverse/tracks/scene_assets.py
+++ b/harness/codeverse/tracks/scene_assets.py
@@ -17,6 +17,8 @@ matter in frame).
from __future__ import annotations
+import hashlib
+import json
import logging
import shutil
from dataclasses import replace
@@ -155,6 +157,7 @@ def run_asset_stage(ctx: RunContext, *, judge_assets: bool = True) -> dict[str,
else:
out[asset.name] = r
shims = write_variant_shims(ctx.ws, alias, {n for n, r in out.items() if r.ok})
+ _record_spec_hashes(ctx, out, assets) # the reuse guard's identity registry (rounds/ bookkeeping)
ctx.ws.commit("assets")
ctx.events.emit("assets.done", ok=[n for n, r in out.items() if r.ok], failed=[n for n, r in out.items() if not r.ok],
strategies={n: r.strategy for n, r in out.items() if r.strategy}, variant_shims=shims)
@@ -162,6 +165,38 @@ def run_asset_stage(ctx: RunContext, *, judge_assets: bool = True) -> dict[str,
return out
+# ------------------------------------------------------------- committed-asset identity
+def _asset_spec_hash(asset: AssetPlan) -> str:
+ """The reuse guard's identity: the whole plan slice, not just the file name."""
+ return hashlib.sha1(asset.model_dump_json().encode()).hexdigest()[:12]
+
+
+def _spec_hashes_path(ctx: RunContext) -> Path:
+ return ctx.ws.root / "rounds" / "asset_spec_hashes.json"
+
+
+def _spec_hash_matches(ctx: RunContext, asset: AssetPlan) -> bool:
+ """False when unrecorded (pre-fix runs regenerate once, then reuse)."""
+ try:
+ recorded = json.loads(_spec_hashes_path(ctx).read_text())
+ except (OSError, ValueError):
+ return False
+ return recorded.get(asset.name) == _asset_spec_hash(asset)
+
+
+def _record_spec_hashes(ctx: RunContext, results: dict[str, AssetResult], assets: list[AssetPlan]) -> None:
+ by_name = {a.name: a for a in assets}
+ path = _spec_hashes_path(ctx)
+ try:
+ recorded = json.loads(path.read_text())
+ except (OSError, ValueError):
+ recorded = {}
+ for name, r in results.items():
+ if r.ok and name in by_name:
+ recorded[name] = _asset_spec_hash(by_name[name])
+ write_json_atomic(path, recorded)
+
+
# ----------------------------------------------------------------------------- threejs asset
def build_threejs_asset(ctx: RunContext, asset: AssetPlan, *, judge: bool) -> AssetResult:
"""Single-shot → deterministic check → ONE repair → (only then) an agent session."""
@@ -170,7 +205,7 @@ def build_threejs_asset(ctx: RunContext, asset: AssetPlan, *, judge: bool) -> As
# stop after the commit, or a failed sibling — must not re-pay a finished asset.
# Deterministic node import-check only, no model call; the skeleton stub never
# passes it (single low-poly box), and `ran` guards the checker-unavailable path.
- if (ctx.ws.root / rel).is_file():
+ if (ctx.ws.root / rel).is_file() and _spec_hash_matches(ctx, asset):
chk0 = check_threejs_asset(ctx, rel, pascal, expected_size_m=asset.approx_size_m)
if chk0.ran and chk0.ok:
ctx.events.emit("asset.generated", asset=asset.name, strategy="reused", ok=True, tris=chk0.tris, errors=[])
@@ -257,7 +292,8 @@ def build_blender_asset(ctx: RunContext, asset: AssetPlan, *, judge: bool) -> As
# committed-child reuse (review-3 S2), blender twin: a GLB only exists at this
# path when a previous session finished the build+copy; a measurable one is done.
glb = ctx.ws.root / asset_file(asset)
- if glb.is_file() and glb.stat().st_size > 0 and (size := _measure_size(ctx, glb)) is not None:
+ if glb.is_file() and glb.stat().st_size > 0 and _spec_hash_matches(ctx, asset) \
+ and (size := _measure_size(ctx, glb)) is not None:
ctx.events.emit("asset.generated", asset=asset.name, strategy="reused", ok=True, tris=0, errors=[])
return AssetResult(name=asset.name, kind=asset.kind, ok=True, path=asset_file(asset), size_m=size,
strategy="reused", notes="committed GLB reused")
diff --git a/harness/tests/orchestrator_tracks/test_prompts_assets.py b/harness/tests/orchestrator_tracks/test_prompts_assets.py
index 70c2b07b..16c8a774 100644
--- a/harness/tests/orchestrator_tracks/test_prompts_assets.py
+++ b/harness/tests/orchestrator_tracks/test_prompts_assets.py
@@ -150,6 +150,30 @@ def test_a_committed_asset_is_reused_on_a_second_stage_run(tmp_ws, settings):
assert len(agent.jobs) > n_jobs and results3["FishingBoat"].strategy != "reused"
+def test_a_replanned_asset_with_the_same_name_is_not_reused(tmp_ws, settings):
+ """Review-3 S2 sharp edge: after a --force re-plan, a committed module that kept
+ its NAME but changed its plan slice (description/dims) must regenerate — the reuse
+ guard's identity is the whole AssetPlan hash, not the file path."""
+ plan = ScenePlan.model_validate(plan_example(Track.SCENE))
+ plan.assets = [a for a in plan.assets if a.kind == "threejs"]
+ spec = make_spec(Track.SCENE, Language.SCENE_THREEJS)
+ agent = FakeAgent(lambda job, ws: {job.prompt.split("write `")[1].split("`")[0] if "write `" in job.prompt else "src/x.js": _asset_module(job)})
+ ctx = _ctx(tmp_ws, settings, spec, plan, agent_id="fake:x", services=FakeServices(judge=FakeJudge(scores=(0.9, 0.9))), agent=agent)
+ ctx.runtime.skeleton(tmp_ws, plan)
+ tmp_ws.commit("skeleton")
+ run_asset_stage(ctx)
+ n_jobs = len(agent.jobs)
+ # the re-plan keeps the asset's name but changes what it IS
+ boat = next(a for a in ctx.plan.assets if a.name == "FishingBoat")
+ boat.description = "a rusted iron rowboat, half-sunk, barnacle-crusted"
+ results = run_asset_stage(ctx)
+ assert len(agent.jobs) > n_jobs, "a changed plan slice must regenerate, file presence is not identity"
+ assert results["FishingBoat"].strategy != "reused"
+ # and the regenerated module is reusable again under the NEW identity
+ n2 = len(agent.jobs)
+ assert run_asset_stage(ctx)["FishingBoat"].strategy == "reused" and len(agent.jobs) == n2
+
+
def test_a_model_outage_is_not_an_escalation_signal() -> None:
"""A 503 reaches the asset stage only after models.retry spent its whole storm budget
waiting; escalating to a full agent session then costs 10× and hits the same wall."""