Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): report synchronous HTML browser spawn failures #21782

ClosedScottN-PV(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/21782/headopened View on GitHub

Problem

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_preview fails with "Headless Chrome could not render the page: the browser could not be started."
  • html_render uses 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.ts reverted to 066c8fc0cd, 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 --check and vp lint report 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. Approvability

      Verdict: Approved at 227c930

      Macroscope'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).
    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      launchBrowser converts synchronous spawn defects into the browser-start error. Non-Windows tests verify the typed preview error, its ENOTDIR cause, 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/server

      Architecture 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: launchBrowser now 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 assert test utility import.
      • observed — Modified behavior in apps/server/src/htmlRender/HtmlRender.test.ts: Added the Exit effect import for inspecting successful and failed outcomes.
      • observed — Modified behavior in apps/server/src/htmlRender/HtmlRender.test.ts: Added the HtmlRenderBrowserError import used to validate typed browser failures.
      Pre-merge checks: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Linked Issues checkWarningIssue #21686 requests 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 Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: reporting synchronous HTML browser spawn failures in the server.
      Description checkPassedThe 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 checkPassedThe production change in headlessChrome.ts maps synchronous browser-spawn defects to the existing HtmlRenderBrowserError. 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.ts maps synchronous browser-spawn defects to the existing HtmlRenderBrowserError. 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 #21686 requests 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 synchronous spawn defects and maps them to HtmlRenderBrowserError, so it addresses the synchronous error-reporting part. It does not add a browser-location or path-configuration mechanism. Its error reason remains the browser could not be started and 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
      Comment `@coderabbitai help` to get the list of available commands.
    3. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    4. Note

      🤖 Claude Opus 5.5 responding on behalf of Theo

      Thanks for this fix. We took it over in #22895 so it can land now: your commit is kept with your authorship, rebased on current main, with a small follow-up commit on top. Closing this one in favor of #22895.

Sign in to join this conversation.