fix(server): report synchronous HTML browser spawn failures #21782
main fromrefs/pull/21782/head·opened View on GitHubProblem#
When Node's spawn throws synchronously, launching the headless browser fails with a defect instead of HtmlRenderBrowserError. The reported Windows policy block (spawn UNKNOWN) takes this path, so html_preview and html_render both return only "Internal error".
Change#
launchBrowser now maps defects from the spawn call to the existing HtmlRenderBrowserError, with the reason "the browser could not be started" and the original error as cause. processRunner.ts already guards its spawn the same way.
html_previewfails with "Headless Chrome could not render the page: the browser could not be started."html_renderuses its existing fallback for browser errors. It saves the page and returns it without measured heights.
The new error carries no browser output, so host diagnosis is unchanged.
Scope and approval#
Closes #21686 within its triaged scope, which is the error for a synchronous spawn throw. Choosing another browser location stays in Ideas #17465.
Verification#
The new tests point the preview browser at a path beneath a regular file, so the real NodeServices spawner throws spawn ENOTDIR synchronously on Linux. Both that error and the reported spawn UNKNOWN throw at node:internal/child_process:458.
Command: cd apps/server && T3CODE_TEST_HEADLESS_SHELL=<chrome-headless-shell path> vp test run src/htmlRender/HtmlRender.test.ts. The variable enables the existing real-browser tests.
- 10 tests pass in
apps/server/src/htmlRender/HtmlRender.test.ts. - With
apps/server/src/htmlRender/headlessChrome.tsreverted to066c8fc0cd, 2 tests fail with assertion errors: "HtmlRender > when the browser spawn throws synchronously > reports a typed preview error", "HtmlRender > when the browser spawn throws synchronously > publishes the page without measured heights". vp fmt --checkandvp lintreport no errors and no new warnings on the 2 changed TS files.- Typecheck passes for
t3.
A separate run of the real HtmlRender service on Linux (Node v24.21.0) showed the same behavior. On main, both methods died with spawn ENOTDIR. With the fix, preview returned the named error, and publish saved the page without heights. Pointing the same service at a working chrome-headless-shell then rendered the preview and measured all nine widths.
Not run: Windows with AppLocker or SRP (spawn UNKNOWN), or an MCP client call. The MCP handlers return the typed error's message as the tool failure.
Rebased onto 066c8fc0cd; checks above rerun at cbdd6e8fbb.
Model: GPT-6.1-Sol, Claude Opus 5.5 (review), GPT-6-Astra (review). Harness: Codex, Claude Code.
- 1
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5f153ba7-488a-4960-89fa-634f20a31d19
📥 Commits
-
Reviewing files that changed from the base of the PR and between b3ee7f354b5aad1638abf28539068a961b848ef1 and cbdd6e8fbb00bb3239c4e56095fae75810050963.
📒 Files selected for processing: 1
-
apps/server/src/htmlRender/HtmlRender.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The browser launcher now maps synchronous spawn defects to a typed browser error. Tests verify preview error details and publishing behavior when browser startup fails.
Changes: Browser spawn handling
Layer / File(s) Summary Spawn error handling and validation
apps/server/src/htmlRender/headlessChrome.ts,apps/server/src/htmlRender/HtmlRender.test.tslaunchBrowserconverts synchronous spawn defects into the browser-start error. Non-Windows tests verify the typed preview error, itsENOTDIRcause, and publishing behavior. Publishing retains the requested height and saves the page HTML.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
cbdd6-
Browser startup failures now produce a useful preview error while rendering can still publish the page. No issue identified here needs resolution before merge.
Architecture risk: 🔵 Low · up to
b3ee7-
The change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
-
Systems and components
- observed — apps/server (service) was modified; 2 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in apps/server/src/htmlRender/headlessChrome.ts:
launchBrowsernow converts synchronous spawn defects into the same “the browser could not be started” error used for typed spawn failures. - observed — Modified behavior in apps/server/src/htmlRender/HtmlRender.test.ts: Added the
asserttest utility import. - observed — Modified behavior in apps/server/src/htmlRender/HtmlRender.test.ts: Added the
Exiteffect import for inspecting successful and failed outcomes. - observed — Modified behavior in apps/server/src/htmlRender/HtmlRender.test.ts: Added the
HtmlRenderBrowserErrorimport used to validate typed browser failures.
-
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Linked Issues check Issue #21686requests a supported browser location in an approved folder or a configurable browser/tools path. It also requests a clear policy-block error that identifies the browser location. The PR …Add a supported approved-location or configurable browser/tools-path mechanism. Report the policy-block condition and the resolved browser location. Add automated tests for the selected path configuration and diagnostic behavior. Passed checks: 3 passed-
Check name Status Explanation Title check The title clearly and concisely describes the main change: reporting synchronous HTML browser spawn failures in the server. Description check The description includes all required sections. It explains the problem, change, scope and approval, focused verification, observed results, limitations, and agent details. Out of Scope Changes check The production change in headlessChrome.tsmaps synchronous browser-spawn defects to the existingHtmlRenderBrowserError. The tests verify the linked preview error and publish fallback. These chan…Full details: Out of Scope Changes check
-
Explanation
The production change in
headlessChrome.tsmaps synchronous browser-spawn defects to the existingHtmlRenderBrowserError. The tests verify the linked preview error and publish fallback. These changes support the synchronous-failure objective in issue#21686. No unrelated change is demonstrated.
-
Full details: Linked Issues check
-
Explanation
Issue
#21686requests a supported browser location in an approved folder or a configurable browser/tools path. It also requests a clear policy-block error that identifies the browser location. The PR catches synchronousspawndefects and maps them toHtmlRenderBrowserError, so it addresses the synchronous error-reporting part. It does not add a browser-location or path-configuration mechanism. Its error reason remainsthe browser could not be startedand does not identify a policy block or browser location. The added tests cover the typed synchronous failure and publish fallback, but they do not cover the unmet location or diagnostic requirements.Resolution
Add a supported approved-location or configurable browser/tools-path mechanism. Report the policy-block condition and the resolved browser location. Add automated tests for the selected path configuration and diagnostic behavior.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
227c930Macroscope's review found this PR approvable — This is a small, localized server bug fix that normalizes synchronous browser-spawn failures into the existing typed error flow. Added tests cover both preview reporting and HTML publication fallback, with no changes to defaults, schemas, deployment, or static-analysis configuration.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).