Official Codebase of 3DCodeVerse
Python
scene: one asset may not eat the run's preparation budget
gaoypengb0b4f34af3d3
diff --git a/harness/codeverse/tracks/scene_assets.py b/harness/codeverse/tracks/scene_assets.pyindex 6625f49e..c475ceab 100644--- a/harness/codeverse/tracks/scene_assets.py+++ b/harness/codeverse/tracks/scene_assets.py@@ -56,9 +56,23 @@ DEGRADED_MAX_ASSETS = 4#: an asset smaller than this share of the scene bbox volume is not worth a judge callJUDGE_VOLUME_FRACTION = 0.05ASSET_AGENT_TIMEOUT_S = 420+#: no SINGLE asset session may take more than this share of the whole run. The stage+#: waits for its slowest asset, and budget.timeout_s only bites near the ceiling: on a+#: 25-minute scene (2026-08-27) seven assets finished inside 5.7 min while one escalation+#: ran the full 420 s and held the stage to 10.9 min — 28 % of the run for one asset, and+#: round 0 did not start until 18.9 min.+ASSET_SESSION_SHARE = 0.15ASSET_RUBRIC = "asset_v1"+def asset_timeout_s(ctx: Any, floor_s: int) -> int:+ """``ASSET_AGENT_TIMEOUT_S`` clipped to one asset's share of the run AND to the+ wall clock actually left (:meth:`BudgetGuard.timeout_s`)."""+ share = float(getattr(ctx.budget.budget, "max_minutes", 0.0) or 0.0) * 60.0 * ASSET_SESSION_SHARE+ want = min(ASSET_AGENT_TIMEOUT_S, share) if share > 0 else ASSET_AGENT_TIMEOUT_S+ return ctx.budget.timeout_s(max(float(floor_s), want), floor_s=floor_s)++class AssetResult(BaseModel):name: strkind: str@@ -202,7 +216,7 @@ def build_threejs_asset(ctx: RunContext, asset: AssetPlan, *, judge: bool) -> Asnotes="generator unavailable (model outage); asset skipped")if not strategy: # no chat model, or single-shot failed twice → the full agent sessionres = _generate_asset(ctx, asset, rel, language=Language.SCENE_THREEJS, attempt=0,- timeout_s=ctx.budget.timeout_s(ASSET_AGENT_TIMEOUT_S, floor_s=120))+ timeout_s=asset_timeout_s(ctx, 120))notes = res.notesstrategy = "escalated" if chk is not None else "agent"chk = check_threejs_asset(ctx, rel, pascal, expected_size_m=asset.approx_size_m) if res.ok else chk@@ -260,7 +274,7 @@ def build_blender_asset(ctx: RunContext, asset: AssetPlan, *, judge: bool) -> Asspatial_tools=True,mcp_command=["python", "-m", "codeverse.spatial.mcp_server", "--workspace", str(sub_ws.root)])res = _generate_asset(sub, asset, "src/model.py", language=Language.BLENDER, attempt=0,- timeout_s=ctx.budget.timeout_s(ASSET_AGENT_TIMEOUT_S, floor_s=180))+ timeout_s=asset_timeout_s(ctx, 180))if not res.ok:return AssetResult(name=asset.name, kind=asset.kind, ok=False, strategy="agent", notes=f"generation failed: {res.notes}")sub_ws.commit("asset generated")@@ -371,7 +385,7 @@ def _judge_and_fix(ctx: RunContext, asset: AssetPlan, result: AssetResult, rendecurrent_code=_read(ctx.ws, files[0]) if ctx.single_shot else ""))task = GenerationTask(label=f"asset_{to_snake(asset.name)}_fix", prompt=prompt, files_hint=files, round=1, kind="asset_fix",temperature=0.4, edit_only=language is Language.SCENE_THREEJS,- timeout_s=ctx.budget.timeout_s(ASSET_AGENT_TIMEOUT_S, floor_s=120))+ timeout_s=asset_timeout_s(ctx, 120))res = generate(ctx.ws, agent_id=ctx.agent_id, task=task, agent=ctx.agent, model=ctx.model, settings=ctx.settings,budget=ctx.budget, events=ctx.events)if res.ok:diff --git a/harness/tests/orchestrator_tracks/test_cost_latency.py b/harness/tests/orchestrator_tracks/test_cost_latency.pyindex bcf38aa0..2617a284 100644--- a/harness/tests/orchestrator_tracks/test_cost_latency.py+++ b/harness/tests/orchestrator_tracks/test_cost_latency.py@@ -483,3 +483,27 @@ def test_a_generation_session_never_outlives_the_wall_budget():assert 120 <= clipped <= 3 * 60, clippedg.start_time -= 10 * 60 # ceiling already crossedassert g.timeout_s(1800, floor_s=120.0) == 120 # the floor, never 1800+++def test_one_asset_cannot_eat_the_scene_run():+ """Measured 2026-08-27 (scn_med_conservatory, 25-min cap): seven assets finished+ inside 5.7 min while one escalation ran the full ASSET_AGENT_TIMEOUT_S and held the+ stage to 10.9 min — the stage waits for its slowest, so round 0 started at 18.9 min+ and the judged round only happened via the budget salvage at 25.5 min."""+ from codeverse.contracts.spec import Budget+ from codeverse.orchestrator.budget import BudgetGuard+ from codeverse.tracks.scene_assets import ASSET_AGENT_TIMEOUT_S, asset_timeout_s++ class Ctx:+ budget = BudgetGuard(Budget(max_usd=10.0, max_minutes=25.0, max_rounds=4), run="t")++ fresh = asset_timeout_s(Ctx, 120)+ assert fresh < ASSET_AGENT_TIMEOUT_S, "one asset may not have the whole preparation budget"+ assert fresh <= 25 * 60 * 0.15 + 1, "at most its share of the run"+ Ctx.budget.start_time -= 23 * 60 # 2 minutes left+ assert asset_timeout_s(Ctx, 120) == 120, "and never past the wall clock, floor aside"++ class Long:+ budget = BudgetGuard(Budget(max_usd=10.0, max_minutes=90.0, max_rounds=4), run="t")++ assert asset_timeout_s(Long, 120) == ASSET_AGENT_TIMEOUT_S, "a long run keeps the ceiling"