Skip to content

Official Codebase of 3DCodeVerse

Python

doctor, prompts: the GPU probe releases a shared browser instead of killing it; one jinja environment

gaoypengb7188a06a279
diff --git a/harness/codeverse3d/config.py b/harness/codeverse3d/config.py
index 91b6ef71..b6c58882 100644
--- a/harness/codeverse3d/config.py
+++ b/harness/codeverse3d/config.py
@@ -97,7 +97,7 @@ class Limits(BaseModel):
"write_file / edit_file, inline the files a refine task edits, and ask the baseline "
"session for every file in its first turn (docs/COST.md §29). OFF until the A/B "
"reads out; `C3D_FEWER_TURNS=1` (read at call time by `fewer_turns_enabled`) is "
- "what `bench/ab_plan.py --variant-env` flips.",
+ "what `eval/bench/ab_plan.py --variant-env` flips.",
)
seed_recipes: bool = Field(
default=True,
@@ -107,7 +107,7 @@ class Limits(BaseModel):
"(tracks/graphics.py:seed_recipes; pasted above src/common.glsl at build time). "
"ON by default: measured 2026-08-26 (refs_v2_graphics, aurora brief, gemini-3.7-flash) "
"the prompt carried the verified curtain() recipe five times and the agent used it zero "
- "times — round 0 was again a comb of bars (comb_artefact, 0.33); and (bench/out/seed_v1) "
+ "times — round 0 was again a comb of bars (comb_artefact, 0.33); and (eval/bench/out/seed_v1) "
"recipes seeded into the agent's own common.glsl were overwritten before the end of the run. "
"`C3D_SEED_RECIPES=0` (read at call time by `seed_recipes_enabled`) is the control arm.",
)
@@ -145,7 +145,7 @@ class Rate(BaseModel):
"LOST — 30.0/45.4 calls/min without it vs 18.2/20.0 with it, because Gemini's 503s are "
"intermittent rather than a clean outage, so parking every worker starves the unlucky call "
"(docs/COST.md §21). The mechanism and its counters are kept so the experiment is "
- "reproducible: C3D_RATE__STORM_GATE=1, or bench/concurrency_probe.py --storm-gate.")
+ "reproducible: C3D_RATE__STORM_GATE=1, or eval/bench/concurrency_probe.py --storm-gate.")
hedge: int = Field(
default=2, ge=1,
description="keys a retry is raced on once a call has met its first 503 (1 = off). Measured "
@@ -171,7 +171,7 @@ class Judge(BaseModel):
#: The fewer-turns switch (docs/COST.md §29). Read at CALL time by
-#: :func:`fewer_turns_enabled`, never only through the cached Settings: ``bench/ab_plan.py``
+#: :func:`fewer_turns_enabled`, never only through the cached Settings: ``eval/bench/ab_plan.py``
#: differs its arms by environment alone, and a value frozen at first ``get_settings()``
#: would hand the variant the control's behaviour (the CQ-5 lesson, tracks/plan_features.py).
FEWER_TURNS_ENV = "C3D_FEWER_TURNS"
@@ -223,7 +223,7 @@ def scene_textures_enabled() -> bool:
describes it (``texture_pack_prompt`` — whose docstring already says "for zone/env
generation") have existed since the texturing work, but nothing in ``tracks/scene.py``
called either: the switch `Spec.options.texture` does nothing on this track and the
- generator was never told a pack could exist. Measured on bench/out/scene_baseline
+ generator was never told a pack could exist. Measured on eval/bench/out/scene_baseline
(2026-09-05): four of the five scored cells' judge complaints are the GROUND being a
flat untextured colour, in near-identical words, and that is the most consistent
defect in the battery.
diff --git a/harness/codeverse3d/doctor.py b/harness/codeverse3d/doctor.py
index 7dfb55cc..b4a5bbac 100644
--- a/harness/codeverse3d/doctor.py
+++ b/harness/codeverse3d/doctor.py
@@ -105,10 +105,13 @@ def check_node() -> list[Row]:
return rows
+#: ``release()``, never ``browser.close()``: by default the handle is the daemon's SHARED
+#: browser, and close() sends CDP Browser.close, which takes it down under any concurrent
+#: run rendering on it. release() disconnects a shared browser and closes an owned one.
_PROBE_JS = (
"const {launchBrowser}=require(process.argv[1]);"
"launchBrowser({gpu:'auto'}).then(async r=>{console.log(JSON.stringify({gpu:r.gpu,renderer:r.renderer}));"
- "await r.browser.close();process.exit(0)}).catch(e=>{console.log(JSON.stringify({error:String(e&&e.message||e)}));process.exit(1)})"
+ "await r.release();process.exit(0)}).catch(e=>{console.log(JSON.stringify({error:String(e&&e.message||e)}));process.exit(1)})"
)
@@ -188,12 +191,6 @@ def check_pool(live: bool) -> list[Row]:
return rows
-def _rate_cap() -> int:
- from codeverse3d.config import get_settings
-
- return int(getattr(get_settings().rate, "max_in_flight", 0) or 0)
-
-
def check_keys(live: bool) -> list[Row]:
s = get_settings()
n = len(s.gemini_api_keys)
@@ -202,7 +199,7 @@ def check_keys(live: bool) -> list[Row]:
from codeverse3d.models.health import pool_budget
pb = pool_budget()
- cap = _rate_cap()
+ cap = int(s.rate.max_in_flight or 0)
rows.append((
"pool sharing",
"OK" if pb.fits(cap) else "WARN",
diff --git a/harness/codeverse3d/proc.py b/harness/codeverse3d/proc.py
index 9868cac0..17cfa796 100644
--- a/harness/codeverse3d/proc.py
+++ b/harness/codeverse3d/proc.py
@@ -453,7 +453,7 @@ def read_json_or_none(path: Path | str, *, errors: str | None = None) -> dict[st
The one tolerant reader behind every "use it if it is there" side-car: it
replaced identical ``try: json.loads(read_text()) except (OSError, ValueError)``
- copies in ``flywheel/telemetry.read_json``, ``bench/complexity_report._read_json``,
+ copies in ``record/telemetry.read_json``, ``eval/bench/complexity_report._read_json``,
``gallery/index._measurement_complexity`` / ``_spec_fields``,
``cli/inspect_cmd._best_round_of_record``, ``runlock._holder``,
``languages/threejs/__init__.py``'s plan loader, ``cost/reconstruct._read_json``,
@@ -480,7 +480,7 @@ def iter_jsonl_lines(path: Path | str) -> Iterator[tuple[int, str]]:
Missing file → nothing; decoded UTF-8 with ``errors="replace"`` so one bad byte
(or a SIGKILL mid-append) costs at most that line. Shared by
:func:`read_jsonl_lenient` and by the model-validating readers that keep their own
- per-line parse (``cost/ledger.load_ledger``, ``bench/_jsonl.read_jsonl``).
+ per-line parse (``cost/ledger.load_ledger``, ``eval/bench/_jsonl.read_jsonl``).
"""
p = Path(path)
if not p.is_file():
diff --git a/harness/codeverse3d/prompts/__init__.py b/harness/codeverse3d/prompts/__init__.py
index ebcdef2e..0ee4a008 100644
--- a/harness/codeverse3d/prompts/__init__.py
+++ b/harness/codeverse3d/prompts/__init__.py
@@ -24,16 +24,9 @@ _env = Environment(
autoescape=False,
)
-#: same environment, but an unknown name renders empty instead of raising — used only
-#: as the fallback above, never as the default.
-_lenient_env = Environment(
- loader=FileSystemLoader(str(PROMPTS_DIR)),
- undefined=ChainableUndefined,
- trim_blocks=True,
- lstrip_blocks=True,
- keep_trailing_newline=True,
- autoescape=False,
-)
+#: same environment (loader + flags; its own template cache), but an unknown name renders
+#: empty instead of raising — used only as the fallback in :func:`render`, never as the default.
+_lenient_env = _env.overlay(undefined=ChainableUndefined)
@lru_cache(maxsize=256)
diff --git a/harness/tests/core/test_doctor.py b/harness/tests/core/test_doctor.py
new file mode 100644
index 00000000..5e210296
--- /dev/null
+++ b/harness/tests/core/test_doctor.py
@@ -0,0 +1,26 @@
+"""``3dcode doctor``'s GPU probe must hand the browser back, never close it."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+import pytest
+
+from codeverse3d.doctor import check_gpu_probe
+
+
+def test_the_gpu_probe_releases_the_browser_instead_of_closing_it(tmp_path: Path, monkeypatch):
+ """launchBrowser hands back the daemon's SHARED browser by default: ``browser.close()``
+ sends CDP Browser.close and takes it down under every concurrent run, ``release()``
+ disconnects. A stand-in gpu_launch.cjs records which one the probe called."""
+ mark = tmp_path / "mark"
+ (tmp_path / "gpu_launch.cjs").write_text(
+ f"const fs = require('fs'), mark = {json.dumps(str(mark))};\n"
+ "exports.launchBrowser = async () => ({gpu: true, renderer: 'fake', shared: true,\n"
+ " browser: {close: async () => fs.writeFileSync(mark, 'close')},\n"
+ " release: async () => fs.writeFileSync(mark, 'release')});\n")
+ monkeypatch.setenv("C3D_RUNTIME_JS", str(tmp_path))
+ assert check_gpu_probe(timeout_s=60) == [("chrome webgl", "OK", "GPU: fake")]
+ assert mark.read_text() == "release"