fix(engine): force screenshot capture when GPU is software (broader than HDR-only guard)
What
In packages/engine/src/services/browserManager.ts:acquireBrowser, resolve browserGpuMode (cheap — resolveBrowserGpuMode caches its probe Promise for the process lifetime) and force captureMode = "screenshot" whenever it resolves to "software", regardless of platform/binary. Strip BeginFrame-only chrome flags (--enable-begin-frame-control, --deterministic-mode, etc.) from the launch args when the guard kicks in. Mirror the same gate in packages/engine/src/services/frameCapture.ts's preMode computation so the chromeArgs are built without BeginFrame flags up front. Thread the already-resolved mode through to acquireBrowser via a new AcquireBrowserOptions.resolvedBrowserGpuMode so the call site does not re-resolve from raw config.
Why
On hosts with no hardware GPU (SwiftShader software rendering), Chrome's HeadlessExperimental.beginFrame stalls the compositor on shader-heavy frames — the CDP call hangs and the render eventually fails with beginFrame timed out at the protocolTimeout (default 5 min). This was reproduced during a recent BeginFrame spike on a CPU-only Linux sandbox.
This is an independent, defense-in-depth guard from the producer-side captureHdrStage.ts cfg.forceScreenshot = true:
captureHdrStage.ts:211already forces screenshot unconditionally for the HDR layered-composite path onmain. That covers the HDR path on any host.- This PR adds a separate guard at
acquireBrowserfor the SDR-render-on-software-host case — whichcaptureHdrStagedoes not touch, and which is the load-bearing failure mode today (SDR renders on a software-renderer Linux host still hit the BeginFrame stall). - Belt-and-braces: even when both paths land, having the GPU-mode guard at the launch site protects future code that might add new BeginFrame entry points (e.g. a future BeginFrame-alpha path) without remembering to gate on GPU presence.
Earlier framings of this PR described it as "broadening" a narrow compositeTransfer === "srgb" guard from PR #787. That framing was wrong — no such narrow guard exists on main; the HDR path's screenshot fallback is unconditional. The contribution stands on its own as the SDR-on-software-host fix.
How
acquireBrowsernow acceptsbrowserGpuModein itsconfigPick and (optionally) a pre-resolvedresolvedBrowserGpuModeviaAcquireBrowserOptions. When the resolved mode is"software", the existing beginframe branch is skipped.- The launch args go through
stripBeginFrameFlagswhenevercaptureMode === "screenshot"— defensive against callers that built args before knowing the GPU resolution. (No-op when args are already clean.) frameCapture.ts'spreModecomputation gets the same GPU gate sobuildChromeArgsdoesn't include BeginFrame flags up-front on software hosts; the resolved mode is then threaded intoacquireBrowserto avoid a redundant re-resolve.- A one-time
console.warndocuments the resolution path for operators only when the guard actually changed the outcome — gated on!forceScreenshot && isSoftwareRenderer && headlessShell && isLinux, with a process-level latch so multi-worker renders don't spam.
resolveBrowserGpuMode caches the auto-probe Promise per process, so the threaded value is just a smell-removal — the underlying call would be free anyway after the first invocation.
Test plan
- [x] Unit tests added (
packages/engine/src/services/browserManager.test.ts, 8 new tests inacquireBrowser — software-renderer guard):software→ captureMode forced to screenshot + BeginFrame flags strippedhardware+ Linux + headless-shell → captureMode staysbeginframe, flags preservedforceScreenshot: truestill wins regardless of GPU mode (regression guard for existing behavior)- one-time software-GPU
console.warnfires when the guard changed the outcome - no warning on macOS (already screenshot anyway)
- no warning when caller set
forceScreenshot: true(guard did not change outcome) - no warning on Linux + hardware + headless-shell (positive control: the gate works in the right direction)
- fallback launch retry:
probeBeginFrameSupportfailure → close + re-launch withstripBeginFrameFlags(chromeArgs)(covers the pre-existing defense-in-depth path)
- [x]
bun run --filter @hyperframes/engine typecheck— passes - [x]
bun run --filter @hyperframes/engine build— passes - [x]
bun run --filter @hyperframes/engine test— 596/599 passing (3ffprobe.test.tsfailures are pre-existing onorigin/main, unrelated: PNG cICP metadata extraction + ffprobe binary handling) - [x]
bun run --filter @hyperframes/producer typecheck— passes (consumer of the changed types)
— Vai