fix(engine): warn once per process about unverified hardware GPU

This commit is contained in:
Miguel Angel Simon Sierra
2026-08-04 11:04:35 -07:00
parent 131780fe96
commit 6703ea7e04
2 changed files with 14 additions and 1 deletions
@@ -261,6 +261,11 @@ describe("resolveBrowserGpuMode", () => {
const warning = warn.mock.calls.map((call) => String(call[0])).join("\n");
expect(warning).toContain("browserGpuMode=hardware was requested");
expect(warning).toContain("--gpus all");
// Once per process, not once per worker — the render path resolves the
// mode for the probe browser plus every parallel worker.
await resolveBrowserGpuMode("hardware", { platform: "linux" });
await resolveBrowserGpuMode("hardware", { platform: "linux" });
expect(warn).toHaveBeenCalledTimes(1);
});
it("stays quiet when explicit 'hardware' probes to hardware", async () => {
@@ -438,6 +438,7 @@ let _autoBrowserGpuModeCache: Promise<"software" | "hardware"> | undefined;
/** Test-only: reset the cached probe result. */
export function _resetAutoBrowserGpuModeCacheForTests(): void {
_autoBrowserGpuModeCache = undefined;
_unverifiedHardwareGpuWarned = false;
}
async function getPuppeteerOrNull(): Promise<PuppeteerNode | null> {
@@ -544,13 +545,20 @@ export function resolveBrowserGpuMode(
if (mode === "auto") return _autoBrowserGpuModeCache;
return _autoBrowserGpuModeCache.then((probed) => {
if (probed === "software") {
// Warn once per process, not once per caller: `createCaptureSession`
// resolves the mode for the probe browser AND every parallel worker, so
// an un-deduplicated warning prints N+1 times and buries itself.
if (probed === "software" && !_unverifiedHardwareGpuWarned) {
_unverifiedHardwareGpuWarned = true;
console.warn(buildUnverifiedHardwareGpuWarning(options.platform ?? process.platform));
}
return "hardware";
});
}
/** One-shot latch for the explicit-hardware-probed-to-software warning. */
let _unverifiedHardwareGpuWarned = false;
/**
* Warning text for "you asked for hardware GPU, the probe found none".
*