Official Codebase of 3DCodeVerse
Python
lifecycle: a successful re-finalise rebuild clears the stale rebuild-failed flag
gaoypengaa3302305517
diff --git a/harness/codeverse/tracks/lifecycle.py b/harness/codeverse/tracks/lifecycle.pyindex 5fa37d26..9460d6a9 100644--- a/harness/codeverse/tracks/lifecycle.py+++ b/harness/codeverse/tracks/lifecycle.py@@ -749,6 +749,7 @@ class BaseTrack:self._save_budget(ctx) # aborted-round / stage charges must survive for resumebest = ctx.state.best_roundrebuild_err = ""+ rebuild_ok = Falseif best is not None and best < len(rounds) and rounds[best].commit and self._needs_restore(ctx, rounds[best].commit):ctx.ws.restore(rounds[best].commit)ctx.ws.commit(f"restore best round r{best:02d}")@@ -757,6 +758,8 @@ class BaseTrack:ctx.events.emit("finalise.rebuild", round=best, ok=build.ok)if not build.ok: # the runtime invalidated the canonical artifact FIRST — it is gonerebuild_err = f"{build.error_type or 'BuildFailed'}: {build.error_message}"[:300]+ else:+ rebuild_ok = Trueexcept Exception as e: # noqa: BLE001 — the best round already built once; report, don't failrebuild_err = f"{type(e).__name__}: {e}"[:300]ctx.events.emit("finalise.rebuild_failed", error=rebuild_err)@@ -764,6 +767,11 @@ class BaseTrack:# keep the earned status + scores; the record says the artifact is gonectx.extra["finalise_rebuild_failed"] = rebuild_errerror = error or f"finalise rebuild failed: {rebuild_err}"+ elif rebuild_ok:+ # a rebuild that RAN and succeeded clears the stale flag a prior failed finalise+ # left (the prior-record merge would otherwise carry it forward); no-rebuild+ # resumes keep the prior flag — the artifact may still be the missing one+ ctx.extra["finalise_rebuild_failed"] = ""if rounds and not rebuild_err and self._texture_wanted(ctx):self._texture_pass(ctx)ctx.state.status, ctx.state.stop_reason, ctx.state.error = status, stop_reason, error@@ -886,6 +894,8 @@ class BaseTrack:# sessions' aborted_rounds, prompt hashes of stages not re-executed): seed from# the prior record — unknown keys preserved, this session's values win.prior_extra, prior_hashes = self._prior_record_fields(ctx.ws)+ if ctx.extra.get("finalise_rebuild_failed", None) == "": # rebuilt successfully this session+ prior_extra.pop("finalise_rebuild_failed", None)prior_aborted = prior_extra.get("aborted_rounds")for k, v in prior_extra.items():if k not in extra or extra[k] is None:diff --git a/harness/tests/orchestrator_tracks/test_fix_batch2.py b/harness/tests/orchestrator_tracks/test_fix_batch2.pyindex 9e1d317b..f458fea4 100644--- a/harness/tests/orchestrator_tracks/test_fix_batch2.py+++ b/harness/tests/orchestrator_tracks/test_fix_batch2.py@@ -351,3 +351,42 @@ def test_scene_frames_gate_errors_flow_into_refine_instructions(tmp_path, settinassert tasks, "a scene_frames ERROR must produce a refine task"joined = "\n".join(instructions)assert "dark" in joined and "FIX: raise ambient" in joined+++def test_a_successful_re_finalise_clears_the_stale_rebuild_failed_flag(tmp_path, chair_plan, settings, monkeypatch):+ """The prior-record merge carries extra keys the new record lacks — so a run that+ once recorded ``finalise_rebuild_failed`` and is later resumed to a SUCCESSFUL+ rebuild must clear the flag explicitly (a no-rebuild resume keeps it: the+ artifact may still be the missing one)."""+ import subprocess++ fail_once = {"armed": True}++ class FlakyRebuildRuntime(FakeRuntime):+ def build(self, ws, *, timeout_s=None):+ msg = subprocess.run(["git", "-C", str(ws.root), "log", "-1", "--format=%s"],+ capture_output=True, text=True).stdout.strip()+ if msg.startswith("restore best round") and fail_once["armed"]:+ fail_once["armed"] = False+ ws.stage_artifacts("object.glb").invalidate()+ return BuildResult(ok=False, language=self.language.value, error_type="Timeout",+ error_message="runtime crashed on rebuild", error_file="src/object.js")+ return super().build(ws, timeout_s=timeout_s)++ spec = make_spec(max_rounds=2)+ ws = Workspace(tmp_path / "runs" / "r")++ def track():+ return StaticObjectTrack(services=FakeServices(), judge=FakeJudge(scores=(0.7, 0.5), targets=("Seat",)),+ agent=FakeAgent(_writer), planner_model=_planner(chair_plan.model_dump(mode="json")),+ settings=settings, runtime=FlakyRebuildRuntime(Language.THREEJS))++ rec1 = track().run(spec, ws)+ assert "runtime crashed on rebuild" in rec1.extra["finalise_rebuild_failed"]+ # dirty the tree so the resume's finalise needs a restore (and hence a rebuild)+ (ws.src / "object.js").write_text((ws.src / "object.js").read_text() + "\n// scribble\n")+ ws.commit("scribble after the failed finalise")+ rec2 = track().run(spec, ws, resume=True)+ assert "finalise_rebuild_failed" not in rec2.extra, "a successful rebuild must clear the stale flag"+ assert not rec2.error.startswith("finalise rebuild failed")+ assert (ws.artifacts / "object.glb").is_file()