A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(gates): a retry policy that asks whether a measurement happened
esengine50d999d1df64
diff --git a/tools/lib/deadGpu.mjs b/tools/lib/deadGpu.mjsindex 6339a3f0b..847b3df94 100644--- a/tools/lib/deadGpu.mjs+++ b/tools/lib/deadGpu.mjs@@ -1,12 +1,19 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team/**- * @file deadGpu.mjs — telling "the GPU never came up" from "the game is wrong".+ * @file deadGpu.mjs — telling "the GPU never came up" from "the subject is wrong".*- * A runner whose GPU process dies during init leaves a context-lost renderer- * that cannot draw anything. That is not a verdict about the game: reporting it- * as one says the frame was wrong when there was no frame. Observed on the FIRST- * electron launch of a job, in run after run.+ * A runner whose GPU process dies during init leaves a context-lost renderer that+ * cannot draw anything. That is not a verdict about the subject: reporting it as+ * one says the frame was wrong when there was no frame.+ *+ * The question is whether a MEASUREMENT HAPPENED, and the run itself is the only+ * honest answer to that — `measured` below. Log text is not: this repo's Linux+ * runner prints "Exiting GPU process due to errors during initialization" on runs+ * that go on to succeed, so a policy keyed on that string reads every failure as+ * a dead GPU, retries all six times, and buries the real reason. One job spent+ * fourteen minutes and 71 retries that way, and the scene that actually broke was+ * never named.** One definition, because both pixel runners launch electron on the same runners* and a second copy would drift — verify-render had this and verify-golden did@@ -14,7 +21,11 @@* the other.*/-/** Did the renderer never get a GPU, whatever it then said about pixels? */+/**+ * Log-text evidence that a runner never got a GPU. UNRELIABLE ALONE — see the+ * file header — so this is the fallback for an attempt that cannot say whether it+ * reached a verdict, never the primary answer.+ */export function gpuNeverCameUp(output) {return /Exiting GPU process due to errors during initialization/.test(output)// A lost device, then resources it can no longer make — textures as well as@@ -58,25 +69,41 @@ function backoff(attempt, stepMs) {const STEP_MS = 5000;/**- * Run `attempt` (→ `{ ok, output }`) until it succeeds or fails with the GPU up.+ * Whether this attempt reached a verdict at all. `measured` is the run's own+ * answer and wins; without one the log text is all there is.+ */+function reachedNoVerdict(last) {+ if (typeof last.measured === 'boolean') return !last.measured;+ return gpuNeverCameUp(last.output ?? '');+}++/**+ * Run `attempt` until it succeeds, or fails in a way that is the subject's own.+ * `note(noVerdict)` announces each retry.*- * A failure ANYWHERE after a death in this chain is inconclusive: a restarted GPU- * process leaves the next launch context-lost, painting a blank frame and printing- * nothing about why. A game that truly draws nothing still fails on the first- * attempt, since no attempt reports a death. `note(died)` announces each retry.+ * `attempt()` returns `{ ok, output }` plus, where it can tell: `measured` (did+ * this run reach a verdict? one that did has measured something, and its failure+ * is the subject's however loud the log is) and `drew` (did anything reach the+ * screen? a blank frame right after an outage is that outage still settling).*/export function retryOnDeadGpu(attempt, note, stepMs = STEP_MS) {- let sawDeath = false;+ let sawOutage = false;let last;for (let i = 0; i < MAX_ATTEMPTS; i++) {last = attempt();if (last.ok) return { ...last, retried: i > 0 };- const died = gpuNeverCameUp(last.output);- sawDeath = sawDeath || died;- // Nothing in this chain blamed the GPU, so the failure is the game's.- if (!sawDeath) return { ...last, retried: i > 0 };++ const noVerdict = reachedNoVerdict(last);+ if (noVerdict) sawOutage = true;+ // `drew === true` is the only thing that rules out aftermath: an attempt+ // that cannot say keeps the older, more cautious behaviour.+ const aftermath = sawOutage && last.drew !== true;+ // It measured, and what it measured was wrong. Retrying that is how a+ // broken subject gets six chances to look like a flaky runner.+ if (!noVerdict && !aftermath) return { ...last, retried: i > 0 };+if (i < MAX_ATTEMPTS - 1) {- note(died);+ note(noVerdict);backoff(i, stepMs);}}diff --git a/tools/verify-golden.mjs b/tools/verify-golden.mjsindex c1570afd9..b6b40682f 100644--- a/tools/verify-golden.mjs+++ b/tools/verify-golden.mjs@@ -109,7 +109,9 @@ function captureEditorFrame(id, out) {},});const output = `${r.stdout ?? ''}${r.stderr ?? ''}`;- if (!existsSync(out)) return { ok: false, output };+ // The frame on disk is the verdict here: without one the editor never got+ // far enough to judge anything, whatever the log says about the GPU.+ if (!existsSync(out)) return { ok: false, output, measured: false };// A frame the editor was killed halfway through writing is not a frame, and// decoding it throws where a verdict belongs: one project's dead GPU took// the whole matrix's report with it.@@ -117,7 +119,8 @@ function captureEditorFrame(id, out) {const png = readPNG(readFileSync(out));return { ok: true, output, w: png.w, h: png.h };} catch (e) {- return { ok: false, output: `${output}\nthe capture is not a whole PNG: ${e.message}` };+ // Half a PNG is a run that was killed mid-write, not a frame to judge.+ return { ok: false, output: `${output}\nthe capture is not a whole PNG: ${e.message}`, measured: false };}};const run = retryOnDeadGpu(attempt, (died) => console.log(`↻ ${id} — ${died@@ -178,7 +181,16 @@ function launchPackage(id, target, args) {() => {const r = runTool('npx', ['electron', path.join('scripts', LAUNCHER(target)), ...args],{ encoding: 'utf8', cwd: DESKTOP });- return { ok: r.status === 0, output: `${r.stdout ?? ''}${r.stderr ?? ''}`, r };+ // The launcher prints a ✓/✗ line once it has looked at the frame; that+ // line existing is what says a measurement happened.+ const verdictLine = (r.stdout || '').split('\n').find((l) => l.startsWith('✓') || l.startsWith('✗'));+ return {+ ok: r.status === 0,+ output: `${r.stdout ?? ''}${r.stderr ?? ''}`,+ measured: Boolean(verdictLine),+ drew: verdictLine ? verdictLine.startsWith('✓') : undefined,+ r,+ };},(died) => console.log(`↻ ${id} ${target} — ${died? 'the GPU process died before it drew'diff --git a/tools/verify-render.mjs b/tools/verify-render.mjsindex f4de7f7ad..1bbe58fb9 100644--- a/tools/verify-render.mjs+++ b/tools/verify-render.mjs@@ -162,10 +162,22 @@ function runScene(scene) {},});const out = `${r.stdout || ''}${r.stderr || ''}`;+ // DRIVE_RESULT is the run's own verdict: printed once the page loaded, the+ // engine booted and the driver finished. Whether it is there answers "did a+ // measurement happen" far better than anything in the log text can.+ const drive = /^DRIVE_RESULT (\{.*\})$/m.exec(out);+ let result = null;+ try {+ result = drive ? JSON.parse(drive[1]) : null;+ } catch {+ result = null; // truncated line — treat as no verdict+ }return {ok: r.status === 0,out,ms: Date.now() - at,+ measured: result !== null,+ drew: result?.capture?.rendered,verdict: r.timedOut? 'the run never reached its own watchdog and was killed': ((r.stdout || '').match(/\[verify:render\][^\n]*/) ?? [''])[0].replace('[verify:render] ', ''),