Official Codebase of 3DCodeVerse
Python
gpu_launch: a caller that rejects the shared browser launches its own and never supersedes it
gaoypenge988ce8e6035
diff --git a/harness/runtime_js/gpu_launch.cjs b/harness/runtime_js/gpu_launch.cjsindex e85e4fe4..11edbb78 100644--- a/harness/runtime_js/gpu_launch.cjs+++ b/harness/runtime_js/gpu_launch.cjs@@ -267,12 +267,19 @@ function spawnDaemon(backend) {async function sharedBrowser(puppeteer, backend) {let handle = await connectShared(puppeteer, backend);if (handle) return handle;+ // Still advertised = this caller REJECTED a live browser (canary timeout / page budget).+ // It is everyone else's, so this caller launches its own. Spawning a daemon here+ // superseded it, and a superseded daemon closes its browser under its clients' pages:+ // 'Target closed' across a loaded suite, six browsers in 30 s (2026-09-23).+ const rejected = () => { const cur = readJson(endpointPath(backend)); return !!cur && cur.ws === rejectedWs; };+ if (rejected()) return null;spawnDaemon(backend);const deadline = Date.now() + DAEMON_WAIT_MS;while (Date.now() < deadline) {await new Promise((r) => setTimeout(r, 50));handle = await connectShared(puppeteer, backend);if (handle) return handle;+ if (rejected()) return null;const failed = readJson(daemonFailPath(backend));if (failed) return { failed: String(failed.error || 'daemon launch failed') };}diff --git a/harness/tests/scene_runtime/lib/_probe.py b/harness/tests/scene_runtime/lib/_probe.pyindex f3c7c0cc..80d1dcf2 100644--- a/harness/tests/scene_runtime/lib/_probe.py+++ b/harness/tests/scene_runtime/lib/_probe.py@@ -19,7 +19,8 @@ from pathlib import Pathimport pytest-from codeverse3d.spatial.node import node_modules_dir, run_node, runtime_js_dir+from codeverse3d.spatial.node import node_modules_dir, run_node+from codeverse3d.spatial.render_scene import SceneRenderError, run_scene_scriptHARNESS = Path(__file__).resolve().parents[3]LIB_DIR = HARNESS / "codeverse3d" / "languages" / "scene_threejs" / "starter" / "src" / "lib"@@ -116,9 +117,14 @@ def compile_scene(scene_src: str, libs: tuple[str, ...] = (), *,(root / "src" / "scene.js").write_text(scene_src, encoding="utf-8")for rel, text in (extra or {}).items():(root / "src" / rel).write_text(text, encoding="utf-8")- out = run_node(runtime_js_dir() / "check_shaders.mjs",- ["--ws", str(root), "--timeout-ms", str(int(timeout_s * 1000))]- + (["--module", audit_module] if audit_module else [])- + (["--out", str(report)] if report else []),- cwd=runtime_js_dir(), timeout_s=timeout_s + 30, three_hook=True, check=False)+ # through the production driver runner, so a browser lost under load is retried+ # once on an owned browser exactly as a build's probe is (run_node alone had no retry)+ try:+ out = run_scene_script("check_shaders.mjs",+ ["--ws", str(root), "--timeout-ms", str(int(timeout_s * 1000))]+ + (["--module", audit_module] if audit_module else [])+ + (["--out", str(report)] if report else []),+ timeout_s=timeout_s + 30)+ except SceneRenderError as e:+ return 2, str(e)[-4000:]return out.rc, (out.stdout + "\n" + out.stderr)[-4000:]diff --git a/harness/tests/scene_runtime/test_probes.py b/harness/tests/scene_runtime/test_probes.pyindex 3dc3a1a7..cdbb4c6a 100644--- a/harness/tests/scene_runtime/test_probes.py+++ b/harness/tests/scene_runtime/test_probes.py@@ -109,7 +109,9 @@ def test_probe_scene_hanging_create_scene_times_out_as_agent_finding(starter_ws)" return { scene: new THREE.Scene(), cameras: [], update() {} };\n""}\n")- res = probe_scene(starter_ws, timeout_s=10) # createScene timeout = 6 s < watchdog+ # createScene gets 0.6 x the driver budget (host_page.createTimeoutMs): 18 s, leaving the+ # page boot 12 s before the watchdog — at 10 s (6 s + 4 s) a loaded box hit the watchdog first+ res = probe_scene(starter_ws, timeout_s=30)gate = res.gateassert not gate.passederr = next(f for f in gate.errors if f.data.get("stage") == "createScene")diff --git a/harness/tests/scene_runtime/test_runtime.py b/harness/tests/scene_runtime/test_runtime.pyindex 248341b9..eeef5966 100644--- a/harness/tests/scene_runtime/test_runtime.py+++ b/harness/tests/scene_runtime/test_runtime.py@@ -41,7 +41,9 @@ def test_build_ok_on_example(starter_ws):assert census["content_bbox"]["size"][0] > 50assert (starter_ws.artifacts / "build.json").is_file() and (starter_ws.artifacts / "census.json").is_file()probe, shaders = res.gates- assert probe.gate == "scene_probe" and probe.passed and probe.duration_ms < 15000+ # no wall-clock bound: a loaded box (load 25-30) took 15-25 s here, and a production+ # browser-loss retry is a second boot — neither is a defect of the build+ assert probe.gate == "scene_probe" and probe.passedassert json.loads((starter_ws.artifacts / "gates" / "shader_preflight.json").read_text())["passed"]assert shaders.gate == "shader_preflight"info = [f for f in shaders.findings if f.severity == Severity.INFO]diff --git a/harness/tests/threejs_render/test_runtime_js.py b/harness/tests/threejs_render/test_runtime_js.pyindex 158ea356..7a20c791 100644--- a/harness/tests/threejs_render/test_runtime_js.py+++ b/harness/tests/threejs_render/test_runtime_js.py@@ -146,6 +146,39 @@ const {{ launchBrowser, rendererInfo }} = require({json.dumps(str(runtime_js_dir_reap_daemons(tmp_path / "cache")+def test_a_rejected_shared_browser_is_never_superseded(tmp_path: Path):+ """A caller whose canary rejects the shared browser launches its own and leaves+ the advertised one alone. It used to spawn a second daemon, whose advertisement+ superseded the first; the superseded daemon then closed its browser under its+ clients' pages — "Target closed" across a loaded test suite (2026-09-23)."""+ script = tmp_path / "r.cjs"+ script.write_text(f"""+const fs = require('fs');+const {{ launchBrowser, _internal }} = require({json.dumps(str(runtime_js_dir() / 'gpu_launch.cjs'))});+(async () => {{+ const a = await launchBrowser({{ gpu: 'off' }});+ const before = _internal.readJson(_internal.endpointPath('cpu')).ws;+ const pages = [];+ for (let i = 0; i < 13; i++) pages.push(await a.browser.newPage()); // over the canary's page budget+ const b = await launchBrowser({{ gpu: 'off' }});+ await new Promise((r) => setTimeout(r, 1500)); // a spawned daemon would have advertised by now+ const after = _internal.readJson(_internal.endpointPath('cpu'));+ const out = {{ a_shared: a.shared, b_shared: b.shared, same: !!after && after.ws === before }};+ await b.release();+ for (const p of pages) await p.close();+ await a.release();+ console.log(JSON.stringify(out));+}})().catch((e) => {{ console.error(e); process.exit(1); }});+""")+ cache = tmp_path / "cache"+ try:+ out = run_node(script, [], timeout_s=120, env_extra={"C3D_CACHE_DIR": str(cache)}).last_json+ finally:+ _reap_daemons(cache)+ assert out["a_shared"] is True and out["b_shared"] is False+ assert out["same"], "the rejecting caller replaced the advertised browser"++def test_scene_server_only_mounts_src_public_assets(tmp_path: Path):"""Scene code must not read the run's spec, state, git or judge output."""ws = Workspace(tmp_path / "run").create()