Official Codebase of 3DCodeVerse
Python
browser daemon: only the daemon may retire the shared browser
gaoypeng8a3cc95e8ac2
diff --git a/harness/runtime_js/browser_daemon.cjs b/harness/runtime_js/browser_daemon.cjsindex 4b4ef7c7..39f0270d 100644--- a/harness/runtime_js/browser_daemon.cjs+++ b/harness/runtime_js/browser_daemon.cjs@@ -63,6 +63,15 @@ async function main() {fs.rmSync(lockPath, { force: true });const bail = async (code) => {+ // 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.+ try {+ if ((await browser.pages()).length > 1) {+ fs.writeFileSync(epPath, JSON.stringify(record, null, 2));+ return;+ }+ } catch (_e) { /* browser gone: 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 */ }diff --git a/harness/runtime_js/gpu_launch.cjs b/harness/runtime_js/gpu_launch.cjsindex 6ef29a7e..fd2861fc 100644--- a/harness/runtime_js/gpu_launch.cjs+++ b/harness/runtime_js/gpu_launch.cjs@@ -166,12 +166,15 @@ async function connectShared(puppeteer, backend) {if (!info || !info.ws) return null;try {const browser = await puppeteer.connect({ browserWSEndpoint: info.ws, protocolTimeout: PROTOCOL_TIMEOUT_MS });- // Health canary: a long-lived shared browser can wedge (hours of WSL GPU decay- // plus pages leaked by SIGKILLed clients) — then every CDP roundtrip stalls for- // ~100 s and every render pays it. One bounded pages() catches both failure- // modes: unresponsive, or overgrown with leaked pages. A bad verdict poisons- // the endpoint (the daemon sees it vanish, bails and closes the browser) and- // the caller spawns a fresh daemon (~1 s once, instead of minutes per render).+ // Health canary: a long-lived shared browser can wedge (WSL GPU decay plus pages+ // leaked by SIGKILLed clients) and then every CDP roundtrip stalls ~100 s. One+ // bounded pages() decides whether THIS caller uses it — nothing more. It must not+ // retire the browser: deleting the endpoint makes the daemon close it, and a+ // busy box (four runs, blender pegging the CPU) answers pages() slowly, so a+ // false verdict killed a live scene probe's page mid-call with+ // 'Protocol error: Target closed' (measured 2026-08-27). Only the daemon, which+ // knows whether anyone is working, may retire the browser; a caller that does not+ // like what it sees simply launches its own.let pages = null;try {let timer = null;@@ -183,8 +186,7 @@ async function connectShared(puppeteer, backend) {} catch (_e) { pages = null; }if (!pages || pages.length > MAX_SHARED_PAGES) {try { await browser.disconnect(); } catch (_e) { /* ignore */ }- try { fs.rmSync(endpointPath(backend), { force: true }); } catch (_e2) { /* ignore */ }- return null;+ return null; // own launch for this caller; the endpoint stays for everyone else}heartbeat(backend);// Keep the heartbeat fresh WHILE the client works: it used to tick only on