Official Codebase of 3DCodeVerse
Python
resume: once rounds exist a stage serves its recorded result whatever its key, and a finished zones session the clock stopped is kept (F5, Q1)
gaoypenge27cc0341ceb
diff --git a/harness/codeverse3d/orchestrator.py b/harness/codeverse3d/orchestrator.pyindex eb2d79cb..3557d703 100644--- a/harness/codeverse3d/orchestrator.py+++ b/harness/codeverse3d/orchestrator.py@@ -119,12 +119,18 @@ def _jsonable(obj: Any) -> Any:class StageRunner:- """Runs stages with resume semantics on top of ``RunState`` + ``EventLog``."""+ """Runs stages with resume semantics on top of ``RunState`` + ``EventLog``.- def __init__(self, ws: Workspace, events: EventLog, state: RunState | None = None):+ ``frozen`` (the run already has rounds): a stage with a recorded result serves it even when+ its key drifted (``stage.frozen``) — the rounds refined what it wrote, and re-running it would+ re-pay its session and overwrite that work. ``resume --force`` archives the rounds, and is+ the one way to regenerate a stage under them."""++ def __init__(self, ws: Workspace, events: EventLog, state: RunState | None = None, *, frozen: bool = False):self.ws = wsself.events = eventsself.state = state if state is not None else RunState()+ self.frozen = frozen#: the scene baseline fans sibling stages out in parallel; the bookkeeping#: (``state.stages`` + the ``run_state.json`` save) must not interleaveself._lock = threading.Lock()@@ -149,7 +155,7 @@ class StageRunner:h = hash_inputs(inputs)path = self.result_path(name)prior = self.state.stages.get(name)- if prior is not None and prior.inputs_hash == h and path.is_file():+ if prior is not None and (prior.inputs_hash == h or self.frozen) and path.is_file():# A cached result that cannot be read back is a cache MISS, not a dead run.# ``inputs_hash`` covers the INPUTS only, never the result model's schema, so a# contract that gained a field invalidates nothing — and a clobbered file@@ -165,7 +171,8 @@ class StageRunner:error=f"{type(e).__name__}: {e}")log.warning("stage %s: cached result at %s is unusable (%s); re-running", name, path, e)else:- self.events.emit("stage.cached", stage=name, inputs_hash=h, path=str(path))+ self.events.emit("stage.cached" if prior.inputs_hash == h else "stage.frozen", stage=name,+ inputs_hash=h, path=str(path))return result # type: ignore[return-value]self.events.emit("stage.start", stage=name, inputs_hash=h)diff --git a/harness/codeverse3d/tracks/lifecycle.py b/harness/codeverse3d/tracks/lifecycle.pyindex d384e8b1..5b0780b6 100644--- a/harness/codeverse3d/tracks/lifecycle.py+++ b/harness/codeverse3d/tracks/lifecycle.py@@ -233,7 +233,7 @@ class BaseTrack:# FAILED/BUDGET handlers below serialize the real rounds, never [].rounds: list[RoundRecord] = self.reconcile_resume(spec, ws, events, state, resume=resume, force=force)ctx = self.build_context(spec, ws, events, state)- runner = StageRunner(ws, events, state)+ runner = StageRunner(ws, events, state, frozen=bool(rounds))events.emit("run.start", track=self.track.value, language=spec.language.value, resume=resume,agent=ctx.agent_id, planner=spec.backends.planner, judge=spec.backends.judge)stop = RunStatus.FAILEDdiff --git a/harness/codeverse3d/tracks/scene.py b/harness/codeverse3d/tracks/scene.pyindex d4ccbacf..431a0a62 100644--- a/harness/codeverse3d/tracks/scene.py+++ b/harness/codeverse3d/tracks/scene.py@@ -239,6 +239,9 @@ class SceneTrack(BaseTrack):runner.stage("zones", lambda: self._zones_stage(ctx),inputs={"plan": plan, "asset_api": ctx.extra["asset_api"], "layouts": ctx.extra["layouts"], "agent": ctx.agent_id,**textures})+ # stage boundary, AFTER the finished zones are recorded: a run the clock stops here keeps+ # them (salvage assembles them; a resume serves them instead of paying the session again)+ ctx.budget.check()runner.stage("assemble", lambda: self._assemble_stage(ctx), inputs={"plan": plan})# ---- degradation ------------------------------------------------------@@ -327,7 +330,7 @@ class SceneTrack(BaseTrack):try:r = self._stage_session(ctx, "zones", "zone", lambda gen: self._zone_task(gen, zones))except Exception as e: # noqa: BLE001 — BudgetExceeded included: the stage is still- # recorded + committed; the guard's boundary check below stops the run+ # recorded + committed; the boundary check after the stage stops the runlog.warning("zones session failed: %s: %s", type(e).__name__, e)out = {zone.name: {"ok": False, "notes": f"{type(e).__name__}: {e}"} for zone in zones}else:@@ -341,7 +344,6 @@ class SceneTrack(BaseTrack):ok = r.ok and (len(zones) == 1 or rel in written or _touched(ctx.ws.root / rel, t0))out[zone.name] = {"ok": ok, "files": [rel] if ok else [], "notes": r.notes}ctx.events.emit("zones.done", ok=[k for k, v in out.items() if v["ok"]], failed=[k for k, v in out.items() if not v["ok"]])- ctx.budget.check() # stage boundary: stop only after the finished zones are committedreturn outdef _zone_task(self, ctx: RunContext, batch: list[ZonePlan]) -> GenerationTask:diff --git a/harness/docs/RUNBOOK.md b/harness/docs/RUNBOOK.mdindex 893fbd7d..f4c1957b 100644--- a/harness/docs/RUNBOOK.md+++ b/harness/docs/RUNBOOK.md@@ -162,7 +162,10 @@ unless you type `--host` yourself; it never serves a path outside the declared r# resumes as is; the other stops are finished. The budget# SNAPSHOT is restored: the active minutes already spent still count, so a# raised --max-minutes grants only the difference (downtime never counts);- # the money is the ledger's, and the step log (the run's minutes) carries on+ # the money is the ledger's, and the step log (the run's minutes) carries on.+ # Once rounds exist a recorded stage never runs again: one whose key drifted (a+ # code change to what it hashes) serves its recorded result (`stage.frozen`); only+ # `resume --force` — which archives the rounds — regenerates a stage under them3dcode pick <slug> [--by score|pairwise] [--round N] [--texture] [--judge MODEL]# hand over a round: deliverable/ + selection.json (addons/select). score =# highest effective score, ties → fewer gate errors → the earlier round;diff --git a/harness/tests/orchestrator_tracks/test_cost_latency.py b/harness/tests/orchestrator_tracks/test_cost_latency.pyindex a447e125..025b5010 100644--- a/harness/tests/orchestrator_tracks/test_cost_latency.py+++ b/harness/tests/orchestrator_tracks/test_cost_latency.py@@ -333,6 +333,27 @@ def test_a_budget_stop_before_round_zero_still_delivers_a_judged_round(tmp_path,assert salvage["grace_minutes"] > 0+def test_a_zones_session_the_clock_stopped_is_kept_for_the_resume(tmp_path, settings):+ """Q1: the clock is checked AFTER the zones stage is recorded, so the finished (paid) session+ is cached, and the resume under the salvaged r00 serves it — it used to re-run the zones+ session over r00's src/ (reproduced in the 2026-09-22 review)."""+ plan = _threejs_scene_plan()+ spec = make_spec(Track.SCENE, Language.SCENE_THREEJS, max_rounds=1)+ ws = Workspace(tmp_path / "runs" / "quay")+ agent = FakeAgent(lambda job, ws_: {rel: "export function build(){}\n" for rel in (job.files_hint or ["src/scene.js"])},+ cost=1.3, minutes=3.0)+ mk = lambda: SceneTrack(services=FakeServices(assemble=True), judge=FakeJudge(scores=(0.58, 0.6)), agent=agent, # noqa: E731+ planner_model=_planner(plan.model_dump(mode="json")), settings=settings,+ runtime=FakeRuntime(Language.SCENE_THREEJS))+ with fake_clock():+ rec = mk().run(spec, ws)+ assert rec.status is RunStatus.BUDGET and len(rec.rounds) == 1+ assert "zones" in RunState.load(ws).stages+ agent.jobs.clear()+ mk().run(spec.model_copy(update={"budget": spec.budget.model_copy(update={"max_minutes": 100.0})}), ws, resume=True)+ assert agent.jobs and not any(j.label.startswith("zone") for j in agent.jobs)++def test_soft_budget_notes_land_in_the_round_record(tmp_path, settings):plan = _threejs_scene_plan()spec = make_spec(Track.SCENE, Language.SCENE_THREEJS, max_rounds=0)diff --git a/harness/tests/orchestrator_tracks/test_tracks.py b/harness/tests/orchestrator_tracks/test_tracks.pyindex f8eb6cb4..c95d0d23 100644--- a/harness/tests/orchestrator_tracks/test_tracks.py+++ b/harness/tests/orchestrator_tracks/test_tracks.py@@ -281,27 +281,46 @@ def test_scene_children_are_stages_and_a_failed_env_never_repays_assets(tmp_pathassert len(rec.rounds) == 1-def test_a_mood_only_replan_invalidates_the_env_stage(tmp_path, settings):- """Review-3 V4a: the stage key is the whole plan, so a re-plan differing only in- `mood` misses the cache (it used to serve an env generated under the old mood)."""+def _mood_replanned(tmp_path, settings, name, *, force):+ """A scene run with r00, whose plan then changes ONLY in `mood`; resumed, after archiving the+ rounds the way `resume --force` does when ``force``. Returns (resumed job labels, event names)."""plan = _small_scene_plan()spec = make_spec(Track.SCENE, Language.SCENE_THREEJS, max_rounds=0)- ws = Workspace(tmp_path / "runs" / "harbour4")+ ws = Workspace(tmp_path / "runs" / name)agent = FakeAgent(_scene_writer)mk = lambda: SceneTrack(services=FakeServices(assemble=True), judge=FakeJudge(scores=(0.6, 0.6)), agent=agent, # noqa: E731planner_model=_planner(plan.model_dump(mode="json")), settings=settings,runtime=FakeRuntime(Language.SCENE_THREEJS))mk().run(spec, ws)assert "env" in [j.label for j in agent.jobs]- # simulate a `resume --force` re-plan that changed ONLY the moodstage_file = ws.root / "stages" / "plan.json"data = json.loads(stage_file.read_text())assert data["result"]["mood"] != "desolate, horror"data["result"]["mood"] = "desolate, horror"stage_file.write_text(json.dumps(data))+ if force:+ SceneTrack._archive_pre_force(ws)agent.jobs.clear()+ n_events = len(EventLog(ws.events_path).read())mk().run(spec, ws, resume=True)- assert "env" in [j.label for j in agent.jobs] # a stale cached env must not be served+ return [j.label for j in agent.jobs], [e["event"] for e in EventLog(ws.events_path).read()[n_events:]]+++def test_a_mood_only_replan_invalidates_the_env_stage(tmp_path, settings):+ """Review-3 V4a: the stage key is the whole plan, so a re-plan differing only in+ `mood` misses the cache (it used to serve an env generated under the old mood) — once the+ rounds are archived, as `resume --force` does."""+ labels, _ = _mood_replanned(tmp_path, settings, "harbour4", force=True)+ assert "env" in labels # a stale cached env must not be served+++def test_a_drifted_stage_key_never_reruns_a_stage_under_existing_rounds(tmp_path, settings):+ """F5: with r00 on disk, a drifted key (81 of 91 recorded scene runs, after ScenePlan.interior)+ serves the recorded env / zones instead of re-paying their sessions over the rounds' src/."""+ labels, events = _mood_replanned(tmp_path, settings, "harbour5", force=False)+ assert labels == []+ assert events.count("stage.frozen") >= 3 # env, zones, assets (at least)+ assert "stage.start" not in eventsclass _ProbedSceneRuntime(FakeRuntime):