Official Codebase of 3DCodeVerse
Python
cost: a single-shot call is booked by its task's kind and round, like its agent session
gaoypengc2e15b4c2319
diff --git a/harness/codeverse3d/tracks/generation.py b/harness/codeverse3d/tracks/generation.pyindex c34836f7..0ff33986 100644--- a/harness/codeverse3d/tracks/generation.py+++ b/harness/codeverse3d/tracks/generation.py@@ -52,6 +52,8 @@ from codeverse3d.contracts.common import (Usage,is_harness_owned,)+from codeverse3d.cost.context import call_context+from codeverse3d.cost.types import stage_for_labelfrom codeverse3d.models import get_chat_modelfrom codeverse3d.orchestrator import BudgetExceededfrom codeverse3d.proc import NULL_EVENTS, read_json_or_none@@ -400,11 +402,16 @@ def generate_files(# the RUN's remaining wall clock, not the models' 1800 s default — and past# the hard ceiling this refuses to buy the call at all (agent-path symmetry)max_wait_s=_deadline_preflight(budget, RETRY_DEADLINE_S),- # the round tag is the cost ledger's only way to attribute a single-shot call:- # it has no agent session to inherit an ambient round from (codeverse3d.cost.context)label=f"{task.label}:r{task.round:02d}",)- resp = model.generate(req)++ def ask(r: ChatRequest) -> Any:+ # attributed like ``MeteredAgent.run``: stage from the task's kind, its round — the+ # label alone filed ``zones_*`` under ``other`` (audit 2026-09-24 N72)+ with call_context(round=task.round, stage=stage_for_label(task.kind or task.label)):+ return model.generate(r)++ resp = ask(req)usage = resp.usage# the clock is not enforced here: the response is already paid for, and raising would# discard it before transcript/parse/write_files — the round's phase boundary does@@ -423,7 +430,7 @@ def generate_files(# hand it only what is left of the run (BudgetExceeded past the ceiling)req = req.model_copy(update={"max_output_tokens": grown,"max_wait_s": _deadline_preflight(budget, RETRY_DEADLINE_S)})- resp = model.generate(req)+ resp = ask(req)usage = usage + resp.usagetraj = ws.trajectory_dir(task.label.replace("/", "_"), task.round)(traj / "prompt.md").write_text(f"# system\n{system}\n\n# user\n{task.prompt}\n")diff --git a/harness/codeverse3d/tracks/scene_assets.py b/harness/codeverse3d/tracks/scene_assets.pyindex 3205c078..0f440f0c 100644--- a/harness/codeverse3d/tracks/scene_assets.py+++ b/harness/codeverse3d/tracks/scene_assets.py@@ -329,13 +329,14 @@ def _ladder(ctx: RunContext, asset: AssetPlan, rel: str, *, language: Language,def _generate_asset(ctx: RunContext, asset: AssetPlan, rel: str, *, language: Language, attempt: int,feedback: str = "", timeout_s: int | None = None, files: list[str] | None = None) -> Any:files = list(files or [rel])- label = f"asset_{to_snake(asset.name)}" + ("_retry" if attempt else "")+ # pre-round work is round 0 (the ledger's round dimension); the attempt lives in the label+ label = f"asset_{to_snake(asset.name)}" + (f"_retry{attempt}" if attempt else "")prompt = _asset_prompt(ctx, asset, rel, language=language, files=files)if feedback:prompt = prompt + "\n\n" + feedback + "## Current file(s) (rewrite COMPLETELY)\n" + _inline(ctx, files)task = GenerationTask(label=label, prompt=prompt,system=_asset_system(ctx, language),- files_hint=files, round=attempt, kind="asset", temperature=0.5, timeout_s=timeout_s,+ files_hint=files, round=0, kind="asset", temperature=0.5, timeout_s=timeout_s,images=reference_images(ctx),# threejs assets share the scene workspace (a stray write would hit# zones/env); blender heroes own their whole sub-workspace@@ -654,7 +655,7 @@ def _judge_and_fix(ctx: RunContext, asset: AssetPlan, result: AssetResult, rendeasset_size=asset.approx_size_m, asset_file=files[0], asset_files=files, asset_language=language.value,fix_instructions=instructions, current_code=current, skeleton_files={}, **_scene_context(ctx)))task = GenerationTask(label=f"asset_{to_snake(asset.name)}_fix", prompt=prompt, system=_asset_system(gen, language),- files_hint=files, round=1, kind="asset_fix", temperature=0.4,+ files_hint=files, round=0, kind="asset_fix", temperature=0.4,edit_only=language is Language.SCENE_THREEJS, timeout_s=asset_timeout_s(ctx, 120))restore = snapshot() if snapshot is not None else None # BEFORE the fix rewrites the filesres = generate_for(gen, task)diff --git a/harness/tests/cost/test_instrument.py b/harness/tests/cost/test_instrument.pyindex 052e0e7d..e6be7193 100644--- a/harness/tests/cost/test_instrument.py+++ b/harness/tests/cost/test_instrument.py@@ -293,3 +293,22 @@ def test_a_failed_call_is_recorded_re_raised_and_carries_what_was_billed(tmp_patassert row.stage is Stage.PLAN and row.key == ""assert (row.outcome, row.attempts, row.input_tokens) == tuple(want.values()), errassert (row.cost_usd > 0) is (want["input_tokens"] > 0), "a billed failure is no longer a $0 row"++[email protected]("kind,label,stage", [+ ("zone", "zones_quay_water", Stage.ZONES), # N72: single-shot filed it under `other`+ ("candidate", "baseline_c0", Stage.CANDIDATE),+])+def test_a_single_shot_task_is_booked_where_its_agent_session_would_be(tmp_path: Path, kind, label, stage):+ from codeverse3d.tracks.generation import GenerationTask, generate_files+ from codeverse3d.workspace import Workspace++ ws = Workspace(tmp_path / "run").create()+ with run_ledger(tmp_path / "ss", run="r1"):+ generate_files(ws, model=MeteredChatModel(FakeChat()),+ task=GenerationTask(label=label, prompt="p", round=0, kind=kind))+ with run_ledger(tmp_path / "ag", run="r1"):+ MeteredAgent(CliAgent(FakeChat())).run(+ AgentJob(workspace=str(ws.root), prompt="p", label=label, round=0, kind=kind))+ (single,), (session,) = load_ledger(tmp_path / "ss"), load_ledger(tmp_path / "ag")+ assert (single.stage, single.round) == (session.stage, session.round) == (stage, 0)diff --git a/harness/tests/orchestrator_tracks/test_cost_latency.py b/harness/tests/orchestrator_tracks/test_cost_latency.pyindex d2804530..d4d40323 100644--- a/harness/tests/orchestrator_tracks/test_cost_latency.py+++ b/harness/tests/orchestrator_tracks/test_cost_latency.py@@ -343,9 +343,12 @@ def test_the_shot_after_an_outage_is_a_plain_generation_not_a_repair(tmp_path, sreturn _envelope("src/assets/bollard.js", _module("Bollard", 0.3, 0.5, 0.3))agent = FakeAgent(lambda job, ws: {"src/nope.js": "// should not run\n"})- services = _ChatServices(FakeChatModel(respond, cost=0.02), judge=FakeJudge(scores=(0.9,)))+ chat = FakeChatModel(respond, cost=0.02)+ services = _ChatServices(chat, judge=FakeJudge(scores=(0.9,)))ctx = _scene_ctx(tmp_path, settings, services=services, agent=agent, plan=plan)results = run_asset_stage(ctx)assert results["Bollard"].ok and results["Bollard"].strategy == "single-shot" and not agent.jobs+ # pre-round work is round 0 in the ledger; the attempt is in the label (N72: was r01)+ assert [r.label for r in chat.requests] == ["asset_bollard:r00", "asset_bollard_retry1:r00"]assert len(prompts) == 2 and prompts[1] == prompts[0], "the model wrote nothing: there is nothing to repair"assert "did NOT pass" not in prompts[1] and "rewrite COMPLETELY" not in prompts[1]