Official Codebase of 3DCodeVerse
Python
budget/routing: propagate the zero sentinel and the new generator default
gaoypeng9149b7f0f9ac
diff --git a/harness/bench/compare_backends.py b/harness/bench/compare_backends.pyindex a922213f..5bc4c3bc 100644--- a/harness/bench/compare_backends.py+++ b/harness/bench/compare_backends.py@@ -82,7 +82,7 @@ from bench.run_bench import ( # noqa: E402)from codeverse.config import get_settings # noqa: E402from codeverse.contracts.artifacts import RenderSet # noqa: E402-from codeverse.contracts.common import ENTRY_FILE # noqa: E402+from codeverse.contracts.common import ENTRY_FILE, has_money_ceiling # noqa: E402from codeverse.contracts.run import RunRecord # noqa: E402from codeverse.contracts.spec import Spec # noqa: E402from codeverse.cost import run_ledger # noqa: E402@@ -339,7 +339,10 @@ def flag_degraded(res: CellResult, opts: CompareOptions) -> None:"""if res.kind != "harness" or res.status not in ("scored", "build_failed"):return- money_stop = res.gen_cost_usd >= 0.9 * opts.max_usd+ # ``max_usd == 0`` is "no ceiling", so there is no such thing as a money stop —+ # without this guard the comparison is `cost >= 0`, true for every cell, and the+ # degraded flag this function exists to raise never fires again.+ money_stop = has_money_ceiling(opts.max_usd) and res.gen_cost_usd >= 0.9 * opts.max_usdif (res.harness_stop_reason == "budget" and not money_stop and res.harness_rounds <= opts.degraded_max_roundsand res.wall_s >= opts.degraded_min_wall_s):res.degraded = Truediff --git a/harness/bench/run_bench.py b/harness/bench/run_bench.pyindex 891a91ac..028b3a84 100644--- a/harness/bench/run_bench.py+++ b/harness/bench/run_bench.py@@ -98,7 +98,7 @@ class BenchOptions(BaseModel):planner: str | None = Nonejudge: str | None = Nonerounds: int = 4- max_usd: float = 5.0+ max_usd: float = 0.0 # 0 = no money ceiling; cost is still recorded (contracts.common)max_minutes: float = 60.0#: measured (docs/COST.md Part III): one bench cell holds ~0.9 model calls#: in flight, so 8 cells sit near 7 — far inside the 64-call model knee — anddiff --git a/harness/codeverse/contracts/common.py b/harness/codeverse/contracts/common.pyindex 8dd65a64..abd39335 100644--- a/harness/codeverse/contracts/common.py+++ b/harness/codeverse/contracts/common.py@@ -128,6 +128,17 @@ class Usage(BaseModel):)+def has_money_ceiling(max_usd: float) -> bool:+ """Is there a money ceiling at all? ``max_usd == 0`` means no (owner, 2026-08-28).++ Ask this BEFORE comparing a cost against a ceiling. Without it the comparison+ silently inverts: ``spent >= 0.9 * 0`` is true for every non-negative cost, so a+ guard written as "did we stop for money?" answers yes always and the thing it+ protects never fires. That is exactly what happened to bench's degraded-cell flag.+ """+ return max_usd > 0++class Budget(BaseModel):"""Hard ceilings for a run. The orchestrator stops (cleanly) when any is hit.diff --git a/harness/codeverse/cost/profiles.py b/harness/codeverse/cost/profiles.pyindex be2e699a..7bab4a9a 100644--- a/harness/codeverse/cost/profiles.py+++ b/harness/codeverse/cost/profiles.py@@ -126,8 +126,12 @@ PROFILES: dict[str, Profile] = {judge_max_px=1024, judge_montages=3, judge_detail_crops=2,max_usd=0.0, max_minutes=60.0,expected_usd=1.47,- expected_score="0.835 mean on compare_v1, 36/61 runs passed ($2.50 per passing artifact)",- note="today's defaults — the arm every number in docs/COST.md was measured on",+ expected_score="0.835 mean on compare_v1, 36/61 runs passed ($2.50 per passing artifact) "+ "— MEASURED ON gemini-cli:gemini-3.6-flash, not on this dial's generator",+ note="today's defaults. The generator moved to 3.7-flash on 2026-08-28 and these two "+ "expectations have NOT been re-measured on it: docs/COST.md §12 puts the 3.7 CLI arm "+ "at $0.73/call against 3.6's $0.52 and 0.827 against 0.835, so expect this run to "+ "cost more and score about the same until a battery says otherwise",),"quality": Profile(name="quality",diff --git a/harness/codeverse/cost/routing.py b/harness/codeverse/cost/routing.pyindex b620972b..55306ed7 100644--- a/harness/codeverse/cost/routing.py+++ b/harness/codeverse/cost/routing.py@@ -49,14 +49,16 @@ ROUTES: tuple[Route, ...] = (# -------------------------------------------------------------- generatorRoute(Role.GENERATOR, "gemini-cli:gemini-3.6-flash", 0.52,"compare_v1: mean judge 0.835 on easy static objects (best arm measured)",- "default for every track that has tools (it is the loop, not the model, that scores)",- default=True),+ "the arm compare_v1 was measured on; kept for comparison against those numbers"),Route(Role.GENERATOR, "single-shot:gemini:gemini-3.7-flash", 0.05,"graphics track: 5/6 passed, median 0.810, $0.099 per run","glsl_shader / opengl_python — one file, compiler feedback, no tool loop needed"),+ # the runtime default since 2026-08-28 (contracts.common.Backends.generator):+ # default_route() must name what actually runs, not the arm we measured firstRoute(Role.GENERATOR, "gemini-cli:gemini-3.7-flash", 0.73,"compare_v1: 0.827 — statistically the same as the since-deleted api-agent arm at 2x the price",- "costs ~2x the 3.6-flash default for the same measured quality — prefer the default"),+ "the default; ~2x the 3.6 arm's price for quality measured as the same, so the number to beat",+ default=True),Route(Role.GENERATOR, "codex:gpt-5.6-sol", 1.93,"one-shot 0.786 for $0.20; inside the harness loop $1.93/run (long cached context at $0.40/M)","strong one-shot baseline; expensive as a loop generator"),diff --git a/harness/codeverse/orchestrator.py b/harness/codeverse/orchestrator.pyindex bd3e57b0..102368b6 100644--- a/harness/codeverse/orchestrator.py+++ b/harness/codeverse/orchestrator.py@@ -11,6 +11,7 @@ from __future__ import annotationsimport hashlibimport jsonimport logging+import mathimport reimport threadingimport time@@ -23,7 +24,7 @@ from typing import Any, Literal, TypeVarfrom pydantic import BaseModel, Field, ValidationErrorfrom codeverse.contracts.artifacts import GateReport, Judgment-from codeverse.contracts.common import Budget, Usage+from codeverse.contracts.common import Budget, Usage, has_money_ceilingfrom codeverse.contracts.plan import AcceptanceItem, Planfrom codeverse.contracts.run import RoundRecord, RunStatusfrom codeverse.conventions import to_snake@@ -1010,7 +1011,7 @@ class BudgetGuard:elapsed = self.elapsed_minutes()# max_usd == 0 means no money ceiling (the default since 2026-08-28); cost is# still accumulated above, so every report and the ledger still know what it cost.- if self.budget.max_usd > 0 and spent > self.hard_usd:+ if has_money_ceiling(self.budget.max_usd) and spent > self.hard_usd:raise BudgetExceeded(f"cost ${spent:.3f} exceeds max_usd ${self.hard_usd:.2f}",spent_usd=spent,@@ -1035,7 +1036,7 @@ class BudgetGuard:"""Reason string when the soft sub-budget is used up, else ``""``."""usd, minutes = self.soft_limits()spent, elapsed = self.billed_usd, self.elapsed_minutes()- if self.budget.max_usd > 0 and spent > usd:+ if has_money_ceiling(self.budget.max_usd) and spent > usd:return f"cost ${spent:.3f} exceeds soft cap ${usd:.2f} ({self.soft_fraction:.0%} of ${self.budget.max_usd:.2f})"if elapsed > minutes:return f"elapsed {elapsed:.1f} min exceeds soft cap {minutes:.1f} min ({self.soft_fraction:.0%} of {self.budget.max_minutes:.1f})"@@ -1063,9 +1064,12 @@ class BudgetGuard:def remaining(self) -> dict[str, float]:"""Remaining headroom: ``{"usd": ..., "minutes": ..., "fraction": ...}``."""- usd = max(0.0, self.hard_usd - self.billed_usd)+ capped = has_money_ceiling(self.budget.max_usd)+ # with no ceiling the honest answer is "unlimited", not "$0 left" — a reader+ # (or a future caller) must not read the sentinel as an exhausted budget+ usd = max(0.0, self.hard_usd - self.billed_usd) if capped else math.infminutes = max(0.0, self.hard_minutes - self.elapsed_minutes())- frac_usd = usd / self.hard_usd if self.hard_usd > 0 else 0.0+ frac_usd = (usd / self.hard_usd if self.hard_usd > 0 else 0.0) if capped else 1.0frac_min = minutes / self.hard_minutes if self.hard_minutes > 0 else 0.0return {"usd": usd, "minutes": minutes, "fraction": min(frac_usd, frac_min)}diff --git a/harness/tests/compare_bench/test_infra_failures.py b/harness/tests/compare_bench/test_infra_failures.pyindex fd69dabc..78c08270 100644--- a/harness/tests/compare_bench/test_infra_failures.py+++ b/harness/tests/compare_bench/test_infra_failures.py@@ -377,3 +377,41 @@ def test_the_ab_viewer_refuses_to_call_a_winner_it_cannot_support():a = arm("a", 0.5, 0.5) + [Run(slug="a9", arm="a", final=None, status="failed")]head, why = verdict(a, arm("b", 0.5))assert head.startswith("Inconclusive") and "1 of 1" in why+++def test_no_money_ceiling_does_not_silently_disable_the_degraded_flag():+ """`max_usd = 0` means no ceiling — it must not read as "the ceiling is $0".++ The flag exists because of compare_v4 (2026-08-25): under a day-long 503 storm 37 of+ 40 harness runs stopped on the WALL CLOCK with 0-2 rounds while the 3 that met a calm+ window scored 0.92-0.95, so a paired mean over them measured the weather. Its test+ is `did we stop for the clock rather than the dollars`, written as+ `cost >= 0.9 * max_usd` — and with max_usd 0 that is `cost >= 0`, true for every+ cell, so every time-capped cell reads as a money stop and the flag never fires again.+ """+ from bench.compare_backends import CompareOptions, flag_degraded++ def timed_out_cell(cost: float = 0.9) -> CellResult:+ return CellResult(prompt_id="p", arm="harness:x", kind="harness", status="scored",+ harness_stop_reason="budget", harness_rounds=1, wall_s=2400,+ gen_cost_usd=cost)++ for cap in (0.0, 1.5): # no ceiling, and an explicit one+ c = timed_out_cell()+ flag_degraded(c, CompareOptions(judge="g:x", loop_judge="g:x", max_usd=cap))+ assert c.degraded, f"a clock-stopped one-round cell must be flagged (max_usd={cap})"++ # a cell that really did spend its ceiling is NOT degraded — it iterated, it just ran out+ c = timed_out_cell(cost=0.99)+ flag_degraded(c, CompareOptions(judge="g:x", loop_judge="g:x", max_usd=1.0))+ assert not c.degraded, "a money stop is not the waited-instead-of-iterating case"+++def test_the_default_generator_and_the_cost_router_name_the_same_model():+ """`3dcv cost` prints default_route(GENERATOR) as "the default"; if it disagrees with+ Backends.generator the report is describing a model no run uses."""+ from codeverse.contracts.common import Backends+ from codeverse.cost.routing import default_route+ from codeverse.cost.types import Role++ assert default_route(Role.GENERATOR).model_id == Backends().generator