Official Codebase of 3DCodeVerse
Python
fix what the review actually proved: wrong key, dead retry, two quotas, blind reaper
gaoypengf9aceefbe3a6
diff --git a/harness/codeverse/agents/cli_common.py b/harness/codeverse/agents/cli_common.pyindex 7fd392b5..05eea1ab 100644--- a/harness/codeverse/agents/cli_common.py+++ b/harness/codeverse/agents/cli_common.py@@ -249,7 +249,12 @@ def begin_session(job: AgentJob, kind: str) -> Session:live=live, ws_lock=lock)-def _enforce_scope(s: Session) -> list[str]:+def _clean(seq: Any) -> frozenset[str]:+ """Normalise a path list: str(), strip, drop empties."""+ return frozenset(p for p in (str(x).strip() for x in seq) if p)+++def _enforce_scope(s: Session) -> dict[str, str]:"""Revert a CLI session's out-of-scope writes; returns the reverted paths.Post-hoc, because every backend is a vendor CLI and none has a write-time file gate@@ -262,11 +267,12 @@ def _enforce_scope(s: Session) -> list[str]:are serialised (:data:`EXCLUSIVE_KINDS`): ``head_before`` holds no sibling'sin-flight work."""roots = tuple(r.strip("/") for r in s.job.write_roots if r.strip("/"))- frozen = frozenset(r for r in (str(x).strip() for x in s.job.read_only) if r)- narrow = (s.files_hint | frozenset(h for h in (str(x).strip() for x in s.job.always_writable) if h)+ frozen = _clean(s.job.read_only)+ narrow = (s.files_hint | _clean(s.job.always_writable)if (s.job.edit_only and s.files_hint) else frozenset())if not roots and not narrow and not frozen:- return []+ return {}+ reverted: dict[str, str] = {}restore: list[str] = []remove: list[str] = []for f in s.ws.changed_files(s.head_before):@@ -274,16 +280,19 @@ def _enforce_scope(s: Session) -> list[str]:if not parts or parts[0] in HARNESS_OWNED_DIRS or f.path in HARNESS_OWNED_FILES:continueif f.path in frozen:- pass # harness-owned: the agent calls it, never rewrites it+ why = "harness-owned: call its functions, never rewrite it"elif roots and not any(f.path == r or f.path.startswith(r + "/") for r in roots):- pass # outside write_roots: out of scope whatever its status+ why = f"outside write_roots {sorted(roots)}"elif not narrow or f.status == "added" or _hinted(f.path, narrow):continue+ else:+ why = "outside this task's files (new files stay allowed)"+ reverted[f.path] = why(remove if f.status == "added" else restore).append(f.path)s.ws.restore_paths(s.head_before, restore)for path in remove: # added files are not in head_before; the next `git add -A` stages the delete(s.ws.root / path).unlink(missing_ok=True)- return sorted(restore + remove)+ return reverteddef finish_session(@@ -306,13 +315,13 @@ def finish_session((:func:`_enforce_scope`)."""try:errors = list(errors or [])- restored = _enforce_scope(s)- if restored:+ reverted = _enforce_scope(s)+ if reverted:ok = False- msg = ("out-of-scope writes reverted: " + ", ".join(restored)- + f" — this session may only write under {sorted(s.job.write_roots)}"- + (f", limited to {sorted(s.files_hint)} (new files, and the entry file when the "- "task owns it, stay allowed)" if s.job.edit_only and s.files_hint else ""))+ # each path carries ITS reason: a read_only revert used to be blamed on+ # write_roots ("may only write under ['src']") for a file under src/+ msg = ("out-of-scope writes reverted: "+ + "; ".join(f"{p} ({why})" for p, why in sorted(reverted.items())))errors.append(msg)s.notes.append(msg)s.ws.commit(f"agent:{s.label}")diff --git a/harness/codeverse/agents/gemini_cli.py b/harness/codeverse/agents/gemini_cli.pyindex 8f91a93a..4b1e71f3 100644--- a/harness/codeverse/agents/gemini_cli.py+++ b/harness/codeverse/agents/gemini_cli.py@@ -61,16 +61,15 @@ SYSTEM_SETTINGS = {RETRY_KEY_WAIT_S = 10.0-_POOLS: dict[tuple[str, ...], KeyPool] = {}--def _key_pool(keys: list[str]) -> KeyPool:- """Process-wide pool per key set so cooldowns persist across agent runs."""- tkey = tuple(keys)- pool = _POOLS.get(tkey)- if pool is None:- pool = _POOLS[tkey] = KeyPool(keys)- return pool+ """THE process-wide pool for these keys — ``models.gemini.shared_pool``, i.e. the+ same limiter the API path uses, with quotas from ``Settings.rate``. This module+ used to build its own ``KeyPool(keys)`` with library defaults (900 RPM, no TPM+ bucket), so the CLI agent and the API path scheduled the same 22 keys under two+ different quotas (found by review 2026-08-28)."""+ from codeverse.models.gemini import shared_pool++ return shared_pool(keys)def write_system_settings(path: Path | None = None, *, mcp_command: list[str] | None = None) -> Path:diff --git a/harness/codeverse/contracts/chat.py b/harness/codeverse/contracts/chat.pyindex 08c57086..44fbc6fa 100644--- a/harness/codeverse/contracts/chat.py+++ b/harness/codeverse/contracts/chat.py@@ -84,8 +84,8 @@ class ChatRequest(BaseModel):default=None,gt=0,description="the longest this ONE logical call may spend, retries and their waits included; "- "None = the model's default (models.retry.RETRY_DEADLINE_S = 900 s). A caller clips it to "- "what it can still afford: an agent turn 20-120 s, a judge sample 240 s, the planner 300 s.",+ "None = the model's default (models.retry.RETRY_DEADLINE_S). A caller clips it to what it "+ "can still afford (owner 2026-08-27: judge-sample and planner floors are 900 s).",)diff --git a/harness/codeverse/prompts/glsl_shader/contract.md b/harness/codeverse/prompts/glsl_shader/contract.mdindex 3e6ac145..d7b19fa0 100644--- a/harness/codeverse/prompts/glsl_shader/contract.md+++ b/harness/codeverse/prompts/glsl_shader/contract.md@@ -10,7 +10,7 @@ src/shader.frag REQUIRED the image pass (your code; no #version, no uniformsrc/common.glsl optional helper functions / constants, pasted ABOVE shader.frag (and buffer_a.frag) automaticallysrc/buffer_a.frag optional ONE feedback buffer pass (Shadertoy "Buffer A"): rendered every frame before the image passsrc/recipes.glsl HARNESS-OWNED, READ-ONLY verified cookbook recipes the harness seeded for this brief, pasted ABOVE- common.glsl: call its functions, never edit, redefine or copy them (a write to it is refused)+ common.glsl: call its functions, never edit, redefine or copy them (a write is reverted and fails the session)```Nothing else is read. No textures, no files, no includes.diff --git a/harness/codeverse/prompts/tracks/generate_graphics.j2 b/harness/codeverse/prompts/tracks/generate_graphics.j2index f7097b4e..c7a7421f 100644--- a/harness/codeverse/prompts/tracks/generate_graphics.j2+++ b/harness/codeverse/prompts/tracks/generate_graphics.j2@@ -25,7 +25,7 @@ Cookbook excerpt:{% if seeded_recipes %}## Verified helpers in the harness-owned, read-only `src/recipes.glsl` — call them, do not redefine them-`src/recipes.glsl` is harness-owned and READ-ONLY (a write to it is refused); the harness pastes it above+`src/recipes.glsl` is harness-owned and READ-ONLY (a session that writes it is failed and the file restored); the harness pastes it above`src/common.glsl` and `src/shader.frag` at build time, so these VERIFIED helpers are in scope everywhere withno include. Call them and build on them: do not rewrite an aurora curtain / star field / bokeh / rain layerfrom scratch (the from-scratch versions are the comb of bars, the twenty sparkles and the opaque discs thediff --git a/harness/codeverse/spatial/tool_common.py b/harness/codeverse/spatial/tool_common.pyindex 397d8a90..e6fb8ba5 100644--- a/harness/codeverse/spatial/tool_common.py+++ b/harness/codeverse/spatial/tool_common.py@@ -96,18 +96,18 @@ def _latest_build_status(ws: Workspace) -> dict[str, Any] | None:``artifacts/build.json`` (written by the language runtimes), or None whenneither is readable — a workspace whose GLB was placed by hand (tests,imports, first-measure flows) stays usable."""- newest: dict[str, Any] | None = None- newest_mtime = float("-inf")+ cands: list[tuple[float, Path]] = []for name in ("build_last.json", "build.json"):p = ws.artifacts / nametry:- mtime = p.stat().st_mtime+ cands.append((p.stat().st_mtime, p))except OSError:continue+ for _, p in sorted(cands, key=lambda c: c[0], reverse=True):data = read_json_or_none(p)- if data is not None and mtime > newest_mtime:- newest, newest_mtime = data, mtime- return newest+ if data is not None:+ return data+ return Nonedef glb_path(ctx: ToolContext) -> Path:@@ -123,7 +123,9 @@ def glb_path(ctx: ToolContext) -> Path:# failed on RestPenetration and spent the rest of its turns looking for the# wrong problem (measured 2026-08-27, art_med_tool_chest).if status is not None and not status.get("ok"):- why = str(status.get("error") or status.get("error_type") or "see the build output")+ # BuildResult serialises error_message, not "error" — reading the wrong key cost+ # the agent the message and left only the type (found by review 2026-08-28)+ why = str(status.get("error_message") or status.get("error_type") or "see the build output")raise ToolUsageError(f"the last build FAILED ({why[:200]}) — there is no current object.glb to read. ""Fix the code for that error and build again; do not measure or render until it passes.",diff --git a/harness/codeverse/tracks/generation.py b/harness/codeverse/tracks/generation.pyindex 04a0b083..d0660955 100644--- a/harness/codeverse/tracks/generation.py+++ b/harness/codeverse/tracks/generation.py@@ -226,20 +226,25 @@ def generate_files(_charge(budget, usage, task=task, label=task.label, outcome=str(resp.finish_reason or "ok"),enforce=False)if _is_truncated(resp):- # cut off by max_output_tokens: the envelope is unterminated — one retry with- # a doubled budget beats writing a half-file and burning repair attempts on it+ # cut off by max_output_tokens: the envelope is unterminated — one retry with a+ # DOUBLED budget beats writing a half-file. Already at the 65,536 model ceiling+ # there is nothing to grow: a re-ask would be byte-identical and full price, so+ # it is not bought (the default task budget IS the ceiling since 2026-08-27).+ grown = min(task.max_output_tokens * 2, 65_536)+ retry = grown > int(req.max_output_tokens or 0)if events is not None:events.emit("generate.truncated",label=task.label,finish_reason=str(resp.finish_reason),- retry=True,+ retry=retry,)- req = req.model_copy(update={"max_output_tokens": min(task.max_output_tokens * 2, 65536)})- resp = model.generate(req)- usage = usage + resp.usage- _charge(budget, resp.usage, task=task, label=f"{task.label}.retry", outcome="truncated",- enforce=False)+ if retry:+ req = req.model_copy(update={"max_output_tokens": grown})+ resp = model.generate(req)+ usage = usage + resp.usage+ _charge(budget, resp.usage, task=task, label=f"{task.label}.retry", outcome="truncated",+ enforce=False)traj = ws.trajectory_dir(task.label.replace("/", "_"), task.round)(traj / "prompt.md").write_text(f"# system\n{system}\n\n# user\n{task.prompt}\n")(traj / "response.md").write_text(resp.text or "")diff --git a/harness/codeverse/tracks/scene_asset_gen.py b/harness/codeverse/tracks/scene_asset_gen.pyindex 62b71cc8..da940522 100644--- a/harness/codeverse/tracks/scene_asset_gen.py+++ b/harness/codeverse/tracks/scene_asset_gen.py@@ -53,7 +53,10 @@ def single_shot_agent_id(agent_id: str, chat_model_id: str = "") -> str:that backend is gone."""if is_single_shot(agent_id):return agent_id- return SINGLE_SHOT_PREFIX + chat_model_id if chat_model_id.count(":") >= 1 else ""+ # a SHAPE check only, deliberately not models.registry.parse_model_id: whether the+ # id resolves is the SERVICES' call (tests run fake providers like "fake:planner"),+ # and single_shot_ctx already degrades to the agent path when chat_model() raises+ return SINGLE_SHOT_PREFIX + chat_model_id if ":" in chat_model_id else ""def single_shot_ctx(ctx: RunContext) -> RunContext | None:@@ -62,7 +65,7 @@ def single_shot_ctx(ctx: RunContext) -> RunContext | None:cached = ctx.extra.get("_single_shot_ctx")if cached is not None:return cached or None # False = known-unavailable- sid = single_shot_agent_id(ctx.agent_id, getattr(ctx.spec.backends, "planner", ""))+ sid = single_shot_agent_id(ctx.agent_id, ctx.spec.backends.planner)sub: RunContext | None = Noneif sid:try:diff --git a/harness/codeverse/tracks/scene_assets.py b/harness/codeverse/tracks/scene_assets.pyindex c475ceab..a879eb66 100644--- a/harness/codeverse/tracks/scene_assets.py+++ b/harness/codeverse/tracks/scene_assets.py@@ -67,10 +67,10 @@ ASSET_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)+ wall clock actually left (:meth:`BudgetGuard.timeout_s`, which owns the floor)."""+ share = ctx.budget.budget.max_minutes * 60.0 * ASSET_SESSION_SHARE+ return ctx.budget.timeout_s(min(ASSET_AGENT_TIMEOUT_S, share) if share else ASSET_AGENT_TIMEOUT_S,+ floor_s=floor_s)class AssetResult(BaseModel):diff --git a/harness/runtime_js/browser_daemon.cjs b/harness/runtime_js/browser_daemon.cjsindex 39f0270d..100b9ccc 100644--- a/harness/runtime_js/browser_daemon.cjs+++ b/harness/runtime_js/browser_daemon.cjs@@ -62,19 +62,29 @@ async function main() {fs.writeFileSync(epPath, JSON.stringify(record, null, 2));fs.rmSync(lockPath, { force: true });- const bail = async (code) => {+ // One CDP probe, bounded: a wedged browser answers pages() only after+ // protocolTimeout (15 min), which must never stall the reaper or the exit path.+ const boundedPages = () => Promise.race([+ browser.pages(),+ new Promise((_res, rej) => { const t = setTimeout(() => rej(new Error('pages timeout')), 5000); if (t.unref) t.unref(); }),+ ]);++ const bail = async (code, { pages = null, advertise = true } = {}) => {// Never close a browser somebody is using: pages beyond the initial about:blank- // mean live work, and closing it kills their page mid-call. Re-advertise instead;- // the HARD_REAP_MS check below is the backstop for a client that never came back.+ // mean live work, and closing it kills their page mid-call. Re-advertise instead+ // (never when a NEWER daemon owns the endpoint — its advertisement must not be+ // clobbered); the hard reap in the poll loop is the backstop for a client that+ // never came back.try {- if ((await browser.pages()).length > 1) {- fs.writeFileSync(epPath, JSON.stringify(record, null, 2));+ const n = pages !== null ? pages : (await boundedPages()).length;+ if (n > 1) {+ if (advertise) fs.writeFileSync(epPath, JSON.stringify(record, null, 2));return;}- } catch (_e) { /* browser gone: fall through and exit */ }+ } catch (_e) { /* browser gone or wedged: fall through and exit */ }const cur = (() => { try { return JSON.parse(fs.readFileSync(epPath, 'utf8')); } catch (_e) { return null; } })();if (cur && cur.ws === record.ws) fs.rmSync(epPath, { force: true });- try { await browser.close(); } catch (_e) { /* already dead */ }+ try { await Promise.race([browser.close(), new Promise((res) => setTimeout(res, 5000))]); } catch (_e) { /* already dead */ }process.exit(code);};@@ -93,33 +103,30 @@ async function main() {return bail(0); // endpoint deleted (poisoned verdict or manual cleanup)}const cur = (() => { try { return JSON.parse(fs.readFileSync(epPath, 'utf8')); } catch (_e) { return null; } })();- if (!cur || cur.ws !== record.ws) return bail(0); // superseded by another daemon+ if (!cur || cur.ws !== record.ws) return bail(0, { advertise: false }); // superseded: never clobber the newer daemonconst idle = Date.now() - st.mtimeMs;// Reap leaked pages only when NOBODY is working: clients tick the heartbeat every- // 30 s while connected, so a fresh one means an old page belongs to live work. It- // used to tick on connect/release only, and a 16-minute scene probe had its page- // closed under it — 'Protocol error: Target closed'.+ // 30 s while connected, so a fresh one means an old page belongs to live work.+ if (idle < IDLE_REAP_MS) return;+ let pages = 2;try {- if (idle < IDLE_REAP_MS) return;- const open = await browser.pages();+ const open = await boundedPages(); // ONE probe per tick (it used to be three)const now = Date.now();const live = new Set(open);for (const p of open.slice(1)) if (!firstSeen.has(p)) firstSeen.set(p, now);for (const [p, at] of firstSeen) {if (!live.has(p)) firstSeen.delete(p);- else if (now - at > PAGE_TTL_MS) { firstSeen.delete(p); await p.close().catch(() => {}); }+ else if (now - at > PAGE_TTL_MS) { firstSeen.delete(p); live.delete(p); await p.close().catch(() => {}); }}- } catch (_e) { /* browser mid-shutdown; the checks below handle it */ }- if (idle < IDLE_REAP_MS) return;- let pages = 2;- try {- pages = (await browser.pages()).length;+ pages = live.size;} catch (_e) {- return bail(0);+ return bail(0, { pages: 0 }); // wedged or mid-shutdown: nothing left to protect}- // >1 page = a client is mid-render (its heartbeat only ticks on connect/- // release); reap anyway once VERY stale — that is a crashed client's leak.- if (pages <= 1 || idle > HARD_REAP_MS) return bail(0);+ // Very stale + still >1 page = a crashed client's leak: FORCE the exit instead of+ // re-advertising (the old disjunct re-wrote the endpoint, reset its mtime, and so+ // could never fire — the hard reap was unreachable).+ if (idle > HARD_REAP_MS) return bail(0, { pages: 1 });+ if (pages <= 1) return bail(0, { pages });}, POLL_MS);}diff --git a/harness/runtime_js/gpu_launch.cjs b/harness/runtime_js/gpu_launch.cjsindex fd2861fc..70a639a5 100644--- a/harness/runtime_js/gpu_launch.cjs+++ b/harness/runtime_js/gpu_launch.cjs@@ -160,10 +160,16 @@ function heartbeat(backend) {} catch (_e) { /* endpoint may be gone; connect error handling covers it */ }}+// The ws this process last REJECTED (canary timeout / page overflow). The endpoint+// file stays for everyone else (only the daemon retires the browser), but re-testing+// the same wedged ws in sharedBrowser's 50 ms wait loop costs a 6 s canary per+// iteration — up to ~24 s of pure wait. Skip it until a NEW ws is advertised.+let rejectedWs = null;+/** Connect to the shared browser advertised for `backend`; null when absent/poisoned. */async function connectShared(puppeteer, backend) {const info = readJson(endpointPath(backend));- if (!info || !info.ws) return null;+ if (!info || !info.ws || info.ws === rejectedWs) return null;try {const browser = await puppeteer.connect({ browserWSEndpoint: info.ws, protocolTimeout: PROTOCOL_TIMEOUT_MS });// Health canary: a long-lived shared browser can wedge (WSL GPU decay plus pages@@ -185,6 +191,7 @@ async function connectShared(puppeteer, backend) {if (timer) clearTimeout(timer);} catch (_e) { pages = null; }if (!pages || pages.length > MAX_SHARED_PAGES) {+ rejectedWs = info.ws;try { await browser.disconnect(); } catch (_e) { /* ignore */ }return null; // own launch for this caller; the endpoint stays for everyone else}@@ -207,7 +214,10 @@ async function connectShared(puppeteer, backend) {},};} catch (_e) {- // poisoned: the advertised browser is gone/unresponsive — forget it+ // connect itself REFUSED: nothing listens at that ws, so the daemon (the browser's+ // parent) is gone too — clearing a DEAD advertisement does not violate "only the+ // daemon retires the browser"; a merely-slow browser is the canary's case above,+ // and the canary never touches the file.try { fs.rmSync(endpointPath(backend), { force: true }); } catch (_e2) { /* ignore */ }return null;}diff --git a/harness/tests/agents/test_cli_write_scope.py b/harness/tests/agents/test_cli_write_scope.pyindex a973ab60..67c91ed2 100644--- a/harness/tests/agents/test_cli_write_scope.py+++ b/harness/tests/agents/test_cli_write_scope.py@@ -1,7 +1,7 @@"""CLI write-scope enforcement: per-workspace serialisation + post-hoc edit_only restore.-CLI backends (claude-code / codex / gemini-cli / agy) have no write-time file gate —-``FileTools`` guards only the in-process api-agent — and both session snapshots run+No backend has a write-time file gate (the in-process one that did was deleted+2026-08-28), and both session snapshots run``git add -A``, so two concurrent CLI sessions in one workspace make provenance (andany per-path rollback) unfixable. ``begin_session`` therefore serialises``EXCLUSIVE_KINDS`` per workspace, and ``finish_session`` reverts writes outside@@ -29,9 +29,9 @@ def _finish(s, *, ok: bool = True):# --------------------------------------------------------------------------- serialisation-def test_the_cli_kinds_are_exclusive_and_the_api_agent_is_not():+def test_every_vendor_cli_kind_is_exclusive():assert {"claude-code", "codex", "gemini-cli", "agy"} == EXCLUSIVE_KINDS- assert "api-agent" not in EXCLUSIVE_KINDS and "fake" not in EXCLUSIVE_KINDS+ assert "fake" not in EXCLUSIVE_KINDS # test doubles stay lock-freedef test_two_cli_sessions_on_one_workspace_are_serialized(tmp_ws: Workspace):@@ -59,10 +59,10 @@ def test_two_cli_sessions_on_one_workspace_are_serialized(tmp_ws: Workspace):assert a1 <= b0 or b1 <= a0, f"sessions interleaved: a={windows['a']} b={windows['b']}"-def test_api_agent_sessions_do_not_take_the_lock(tmp_ws: Workspace):- s1 = begin_session(_job(tmp_ws, "s1"), "api-agent")+def test_an_unknown_kind_takes_no_lock(tmp_ws: Workspace):+ s1 = begin_session(_job(tmp_ws, "s1"), "fake")assert s1.ws_lock is None- s2 = begin_session(_job(tmp_ws, "s2"), "api-agent") # would deadlock if locked+ s2 = begin_session(_job(tmp_ws, "s2"), "fake") # would deadlock if locked_finish(s2)_finish(s1)diff --git a/harness/tests/agents/test_gemini_cli.py b/harness/tests/agents/test_gemini_cli.pyindex 490d455d..0cde80a2 100644--- a/harness/tests/agents/test_gemini_cli.py+++ b/harness/tests/agents/test_gemini_cli.py@@ -125,10 +125,11 @@ def test_transient_failure_retries_once_with_other_key(tmp_ws: Workspace, agent:def test_single_key_transient_failure_retries_same_key_and_never_raises(tmp_ws: Workspace, agent: GeminiCliAgent, monkeypatch):"""Settings with ONE key: the retry must reuse it (no KeyPoolExhausted out of run())."""- from codeverse.agents import gemini_cli as gcmonkeypatch.setattr(get_settings(), "gemini_api_keys", ["only"])- gc._POOLS.pop(("only",), None)+ from codeverse.models import gemini as gm+ for sig in [s for s in list(gm._pools) if s and s[0] == "only"]:+ gm._pools.pop(sig, None)monkeypatch.setenv("FAKE_MODE", "fail_once_503")res = agent.run(_job(tmp_ws))assert res.ok, res.errors@@ -143,7 +144,9 @@ def test_single_key_quota_failure_returns_budget_without_retry(tmp_ws: Workspacemonkeypatch.setattr(get_settings(), "gemini_api_keys", ["solo"])monkeypatch.setattr(gc, "RETRY_KEY_WAIT_S", 0.2)- gc._POOLS.pop(("solo",), None)+ from codeverse.models import gemini as gm+ for sig in [s for s in list(gm._pools) if s and s[0] == "solo"]:+ gm._pools.pop(sig, None)monkeypatch.setenv("FAKE_MODE", "fail_always")res = agent.run(_job(tmp_ws))assert not res.ok and res.exit_reason == "budget"diff --git a/harness/tests/compare_bench/test_ab_plan.py b/harness/tests/compare_bench/test_ab_plan.pyindex 0713ece9..e9978077 100644--- a/harness/tests/compare_bench/test_ab_plan.py+++ b/harness/tests/compare_bench/test_ab_plan.py@@ -246,7 +246,7 @@ def test_worker_argv_carries_the_whole_option_block(tmp_path: Path):argv = worker_argv(BATTERY, tmp_path, "cmp_easy_stool", VARIANT, opts)assert argv[1].endswith("ab_plan.py") and argv[2] == "cell" and "--arm" in argvassert AbOptions.model_validate_json(argv[-1]) == opts- assert cell_dir(tmp_path, CONTROL, "x", "api-agent:gemini:g").parent.parts[-4:] == ("arms", "control", "cells", "x")+ assert cell_dir(tmp_path, CONTROL, "x", "gemini-cli:gemini-3.6-flash").parent.parts[-4:] == ("arms", "control", "cells", "x")def test_a_child_that_dies_without_a_cell_is_an_error_not_a_score(tmp_path: Path):@@ -440,7 +440,7 @@ def test_report_only_uses_the_runs_own_options_not_this_invocations_flags(tmp_paout = tmp_path / "run"out.mkdir()- opts = AbOptions(variant_env={"CV3D_SKILLS": "on"}, rounds=1, generator="api-agent:gemini:x")+ opts = AbOptions(variant_env={"CV3D_SKILLS": "on"}, rounds=1, generator="gemini-cli:gemini-3.6-flash")(out / "ab.json").write_text(json.dumps({"options": json.loads(opts.model_dump_json())}))got = _stored_options(out)diff --git a/harness/tests/compare_bench/test_compare_matrix.py b/harness/tests/compare_bench/test_compare_matrix.pyindex 96e5f395..4761baac 100644--- a/harness/tests/compare_bench/test_compare_matrix.py+++ b/harness/tests/compare_bench/test_compare_matrix.py@@ -165,10 +165,10 @@ def test_cell_errors_are_recorded_not_raised(tmp_path: Path):deps = CompareDeps(Exploding(), run_track=failing_track, oneshot_backend=lambda t: FakeBackend([GOOD.format(score=0.5)]),pairwise_judge=FakePairwise)- rows = run_matrix(BATTERY, tmp_path / "o", parse_arms("harness:api-agent:gemini:x,oneshot:codex"),+ rows = run_matrix(BATTERY, tmp_path / "o", parse_arms("harness:gemini-cli:gemini-3.6-flash,oneshot:codex"),CompareOptions(limit=1, parallel=1), deps)by = {r.arm: r for r in rows}- assert by["harness:api-agent:gemini:x"].status == "error" and "planner down" in by["harness:api-agent:gemini:x"].error+ assert by["harness:gemini-cli:gemini-3.6-flash"].status == "error" and "planner down" in by["harness:gemini-cli:gemini-3.6-flash"].errorassert by["oneshot:codex"].status == "error" and "blender missing" in by["oneshot:codex"].errorassert (tmp_path / "o" / "report.md").is_file()diff --git a/harness/tests/compare_bench/test_paired_compare.py b/harness/tests/compare_bench/test_paired_compare.pyindex b7da21ba..c58dff78 100644--- a/harness/tests/compare_bench/test_paired_compare.py+++ b/harness/tests/compare_bench/test_paired_compare.py@@ -13,7 +13,7 @@ if str(REPO) not in sys.path:from bench._compare_report import CellResult # noqa: E402from bench.paired_compare import analyse, latest_cells, main, paired, t975 # noqa: E402-HA, OA = "harness:api-agent:gemini:x", "oneshot:gemini:x"+HA, OA = "harness:gemini-cli:gemini-3.6-flash", "oneshot:gemini:x"def _cell(pid: str, arm: str, score: float | None, *, tier: str = "hard", status: str = "scored",diff --git a/harness/tests/core/test_run_layout.py b/harness/tests/core/test_run_layout.pyindex c40ba59d..c076df57 100644--- a/harness/tests/core/test_run_layout.py+++ b/harness/tests/core/test_run_layout.py@@ -96,7 +96,7 @@ def _moved_run(tmp_path: Path):sheet_a = a / "artifacts" / "renders" / "r01" / "sheet.png"sheet_a.write_bytes(b"PNG")spec = Spec(id="run1", track=Track.STATIC_OBJECT, language=Language.BLENDER,- prompt="a wooden chair", backends=Backends(generator="api-agent:gemini:x"))+ prompt="a wooden chair", backends=Backends(generator="gemini-cli:gemini-3.6-flash"))rec = RunRecord(spec=spec, workspace=str(a), status=RunStatus.PASSED, best_round=0,rounds=[RoundRecord(index=0, kind="generate",renders=RenderSet(views=[], contact_sheet=str(sheet_a)))])diff --git a/harness/tests/orchestrator_tracks/test_cost_latency.py b/harness/tests/orchestrator_tracks/test_cost_latency.pyindex 3dd1fa56..dadda70f 100644--- a/harness/tests/orchestrator_tracks/test_cost_latency.py+++ b/harness/tests/orchestrator_tracks/test_cost_latency.py@@ -165,7 +165,7 @@ def _envelope(rel: str, body: str) -> str:return f"=== FILE: {rel} ===\n{body}\n=== END FILE ===\n"-def _scene_ctx(tmp_path, settings, *, services, agent=None, plan=None, agent_id="api-agent:gemini:x",+def _scene_ctx(tmp_path, settings, *, services, agent=None, plan=None, agent_id="fake-agent:gemini:x",max_usd=5.0) -> RunContext:plan = plan or ScenePlan.model_validate(plan_example(Track.SCENE))spec = make_spec(Track.SCENE, Language.SCENE_THREEJS, generator=agent_id, max_usd=max_usd)@@ -270,7 +270,7 @@ def test_asset_check_names_the_file_that_was_never_written(tmp_path, settings):def test_single_shot_ctx_is_none_for_cli_backends(tmp_path, settings):ctx = _scene_ctx(tmp_path, settings, services=FakeServices(), agent_id="gemini-cli:gemini-3.7-flash")assert single_shot_ctx(ctx) is None- ctx2 = _scene_ctx(tmp_path, settings, services=FakeServices(), agent_id="api-agent:gemini:x")+ ctx2 = _scene_ctx(tmp_path, settings, services=FakeServices(), agent_id="fake-agent:gemini:x")assert single_shot_ctx(ctx2) is None # FakeServices has no chat model → agent path stays@@ -495,14 +495,18 @@ def test_one_asset_cannot_eat_the_scene_run():and the judged round only happened via the budget salvage at 25.5 min."""from codeverse.contracts.spec import Budgetfrom codeverse.orchestrator.budget import BudgetGuard- from codeverse.tracks.scene_assets import ASSET_AGENT_TIMEOUT_S, asset_timeout_s+ from codeverse.tracks.scene_assets import (+ ASSET_AGENT_TIMEOUT_S,+ ASSET_SESSION_SHARE,+ 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"+ assert fresh <= 25 * 60 * ASSET_SESSION_SHARE + 1, "at most its share of the run"Ctx.budget.start_time -= 23 * 60 # 2 minutes leftassert asset_timeout_s(Ctx, 120) == 120, "and never past the wall clock, floor aside"diff --git a/harness/tests/orchestrator_tracks/test_fix_generation.py b/harness/tests/orchestrator_tracks/test_fix_generation.pyindex 78e5ee50..de1bfce7 100644--- a/harness/tests/orchestrator_tracks/test_fix_generation.py+++ b/harness/tests/orchestrator_tracks/test_fix_generation.py@@ -54,12 +54,23 @@ def test_generate_files_retries_once_on_max_tokens_then_succeeds(tmp_path):def test_generate_files_still_truncated_after_retry_fails_cleanly(tmp_path):ws = Workspace(tmp_path / "ws").create()model = ScriptedModel([(TRUNCATED, "MAX_TOKENS"), (TRUNCATED, "length")])- task = GenerationTask(label="baseline", prompt="p", files_hint=["src/model.py"])+ task = GenerationTask(label="baseline", prompt="p", files_hint=["src/model.py"], max_output_tokens=32000)res = generate_files(ws, model=model, task=task, events=EventLog(tmp_path / "e.jsonl"))assert not res.ok and res.notes.startswith("truncated")assert not (ws.root / "src" / "model.py").exists() # never write a half-file+def test_no_identical_retry_at_the_output_ceiling(tmp_path):+ """A task already at the 65,536 model ceiling cannot 'double the budget' — the re-ask+ would be byte-identical at full price, so it must not be bought (review 2026-08-28)."""+ ws = Workspace(tmp_path / "ws").create()+ model = ScriptedModel([(TRUNCATED, "MAX_TOKENS")])+ task = GenerationTask(label="baseline", prompt="p", files_hint=["src/model.py"]) # default = ceiling+ res = generate_files(ws, model=model, task=task, events=EventLog(tmp_path / "e.jsonl"))+ assert not res.ok and res.notes.startswith("truncated")+ assert len(model.requests) == 1, "an identical full-price retry must not be bought"++# --------------------------------------------------------------------- finding: out-of-root path aborted the whole writedef test_out_of_root_paths_are_skipped_not_fatal(tmp_path):ws = Workspace(tmp_path / "ws").create()diff --git a/harness/tests/orchestrator_tracks/test_generation_planner_repair.py b/harness/tests/orchestrator_tracks/test_generation_planner_repair.pyindex 98c223da..92b90583 100644--- a/harness/tests/orchestrator_tracks/test_generation_planner_repair.py+++ b/harness/tests/orchestrator_tracks/test_generation_planner_repair.py@@ -180,15 +180,12 @@ def test_planner_validates_retries_and_writes(tmp_ws):assert isinstance(p, StaticPlan) and p.object_name == "DiningChair" and tmp_ws.plan_path.is_file()assert len(model.requests) == 2 and "failed validation" in model.requests[1].messages[-1].textassert model.requests[0].response_schema is not None and "PascalCase" in model.requests[0].system- # audit 2026-08-26 §2: the plan stage waited 492 s median per storm-day run for 39 s of- # model time; one planner call may now retry for 300 s (~4x the worst observed call), not 900- # the deadline scales with the answer size it asked for (measured: 60 tok/s p10), never- # below the 300 s floor — a flat 300 s guaranteed a timeout once a re-ask grew the budget- from codeverse.tracks.planner import plan_wait_s-- # never below the 300 s floor, never more than the answer size justifies; the run's- # own wall clock clips it in between (plan_wait_s(tokens, guard))- assert all(300.0 <= r.max_wait_s <= plan_wait_s(r.max_output_tokens) for r in model.requests)+ # the deadline scales with the answer size it asked for (measured: 60 tok/s p10) and+ # never sits below the owner's PLAN_MAX_WAIT_S floor — the old flat 300 s guaranteed+ # a timeout the moment a re-ask grew the budget (audit 2026-08-27)+ from codeverse.tracks.planner import PLAN_MAX_WAIT_S, plan_wait_s++ assert all(PLAN_MAX_WAIT_S <= r.max_wait_s <= plan_wait_s(r.max_output_tokens) for r in model.requests)# deterministic acceptance items from constraints were appendedtexts = " ".join(a.text for a in p.acceptance)assert "height = 0.820" in texts and "Includes: armrests" in textsdiff --git a/harness/tests/orchestrator_tracks/test_round_economics.py b/harness/tests/orchestrator_tracks/test_round_economics.pyindex 7b735712..0aa7f6e3 100644--- a/harness/tests/orchestrator_tracks/test_round_economics.py+++ b/harness/tests/orchestrator_tracks/test_round_economics.py@@ -180,9 +180,9 @@ def test_the_stop_order_is_exhausted_regression_then_marginal_then_switch_then_p# ----------------------------------------------------------------------------- turn budgetclass _TurnAgent:- """Burns turns; reports the api-agent's own 'max_turns (N) reached' when it runs out."""+ """Burns turns; reports 'max_turns (N) reached' when it runs out."""- kind = "api-agent"+ kind = "fake"model = "gemini:gemini-3.7-flash"def __init__(self, *, writes_on: int = 2, cost: float = 0.2):@@ -346,7 +346,7 @@ def test_a_round_that_changed_no_file_never_reaches_the_judge_question(tmp_path,from codeverse.tracks.steps import RoundFailed, run_generation_tasksclass _Idle:- kind, model = "api-agent", "m"+ kind, model = "fake", "m"def run(self, job: AgentJob) -> AgentResult:return AgentResult(ok=True, exit_reason="completed", files_changed=[], usage=Usage(cost_usd=0.01))diff --git a/harness/tests/skills/test_budget.py b/harness/tests/skills/test_budget.pyindex 3d1da556..ac84a681 100644--- a/harness/tests/skills/test_budget.py+++ b/harness/tests/skills/test_budget.py@@ -26,7 +26,7 @@ pytestmark = pytest.mark.skipif(not bundle_dirs(), reason=f"no bundles in {skillLIBRARY = all_skills()-#: the api-agent index is the only index we write; five skills must fit in this+#: the routed index (an unclassified, loaderless backend) is the only index we writeAPI_INDEX_TOKENS_MAX = 400API_INDEX_BYTES_MAX = 2048#: a native loader gets one sentence — its own loader writes the real index@@ -59,7 +59,7 @@ def test_the_api_agent_index_stays_inside_its_budget_with_the_whole_library_instworst = max(_every_session(), key=lambda row: index_tokens(row[3], "api-agent"))tokens = index_tokens(worst[3], "api-agent")assert tokens <= API_INDEX_TOKENS_MAX, f"{worst[:3]} costs {tokens} tokens of message 0"- assert len(index_block(worst[3], "api-agent").encode()) <= API_INDEX_BYTES_MAX+ assert len(index_block(worst[3], "unknown-backend").encode()) <= API_INDEX_BYTES_MAX@pytest.mark.parametrize("kind", NATIVE_LOADERS)diff --git a/harness/tests/skills/test_hook.py b/harness/tests/skills/test_hook.pyindex 8227ed1e..a53ecc90 100644--- a/harness/tests/skills/test_hook.py+++ b/harness/tests/skills/test_hook.py@@ -32,7 +32,7 @@ def ctx(tmp_path: Path, library_dir: Path, monkeypatch):parts = [NS(name=f"P{i}", instances=1, symmetry="none", children=[]) for i in range(3)]hashes: dict[str, str] = {}return NS(ws=NS(root=root), spec=NS(track=NS(value="static_object")), language=NS(value="blender"),- agent_id="api-agent:gemini-3.7-flash", plan=NS(parts=parts, summary="a chair"),+ agent_id="unknown-backend:gemini-3.7-flash", plan=NS(parts=parts, summary="a chair"),single_shot=False, extra={}, events=Events(), prompt_hashes=hashes,record_prompt=lambda name, text: hashes.__setitem__(name, str(len(text))))diff --git a/harness/tests/skills/test_only_switch.py b/harness/tests/skills/test_only_switch.pyindex 953b9d3e..1928d897 100644--- a/harness/tests/skills/test_only_switch.py+++ b/harness/tests/skills/test_only_switch.py@@ -33,7 +33,7 @@ def ws(tmp_path):def _listed(ws, **kw):return attach_skills(ws, track="static_object", language="blender", kind="baseline",- agent_kind="api-agent", plan=_Plan(), **kw).listed+ agent_kind="unknown-backend", plan=_Plan(), **kw).listeddef test_unset_routes_the_whole_set(ws):diff --git a/harness/tests/skills/test_telemetry.py b/harness/tests/skills/test_telemetry.pyindex a6077c21..5b8bb3fc 100644--- a/harness/tests/skills/test_telemetry.py+++ b/harness/tests/skills/test_telemetry.py@@ -40,7 +40,7 @@ def _plan(n=3):def _attach(ws, library, **kw):return attach_skills(ws, track="static_object", language="blender", kind="baseline",- agent_kind="api-agent", plan=_plan(), library=library,+ agent_kind="unknown-backend", plan=_plan(), library=library,max_skills=5, allow_unverified=False, **kw)diff --git a/harness/tests/spatial_tools/test_tools.py b/harness/tests/spatial_tools/test_tools.pyindex d5d7e895..6dd1d06a 100644--- a/harness/tests/spatial_tools/test_tools.py+++ b/harness/tests/spatial_tools/test_tools.py@@ -476,8 +476,8 @@ def test_a_failed_build_tells_the_agent_WHY_not_to_build_again(tmp_ws):ctx = ToolContext(workspace=tmp_ws, language="urdf_blender", track="articulated_object")tmp_ws.artifacts.mkdir(parents=True, exist_ok=True)tmp_ws.write_json(tmp_ws.artifacts / "build_last.json",- {"ok": False, "glb_path": None, "error_type": "RestPenetration",- "error": "links interpenetrate by 140.0 mm at lid/base"})+ BuildResult(ok=False, language="urdf_blender", error_type="RestPenetration",+ error_message="links interpenetrate by 140.0 mm at lid/base"))with pytest.raises(ToolUsageError) as e:glb_path(ctx)msg = str(e.value)