Skip to content

fix(engine): wait briefly for Chrome's exit status before reporting a lost render page - #8928

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/openpage-chrome-exit-code
Nov 26, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/openpage-chrome-exit-code

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Summary

When Chrome exits while openPage() is opening a render page, the CDP connection often closes before Node's child_process emits its exit event and populates child.exitCode / child.signalCode. Reading child?.exitCode synchronously produced Chrome exited while opening a render page (exit code unknown, signal none) instead of the real exit code or signal.

  • packages/engine/src/services/openPage.ts: when !browser.connected after newLivePage() fails, wait up to 500 ms (.unref() timer, listener always removed) for the child process exit event before constructing PageTabLostError. If the process already exited or exposes no EventEmitter methods, return immediately.
  • packages/engine/src/services/openPage.test.ts: cover a real spawned child process exiting shortly after disconnect, a delayed signal exit, and a hung process hitting the wait bound with no leaked exit listener.

Test plan

  • fails without the fix: "waits briefly for a real Chrome child process to finish exiting so its exit code is reported" and "reports a delayed signal exit and cleans up its exit listener when Chrome hangs" in packages/engine/src/services/openPage.test.ts (both fail on origin/main with exit code unknown, signal none).
  • packages/engine/src/services/openPage.test.ts: 6 passed, 0 skipped (3 consecutive runs).
  • packages/engine/src/services/frameCapture-pageTabLost.test.ts: 3 passed, 0 skipped.
  • oxlint, oxfmt --check, and packages/engine tsc --noEmit: 0 warnings, 0 errors.
  • Not exercised: Windows Chrome crash run in production (verified on Linux with a real spawned Node child process).

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 23712c0. No blocker.

What I read: the full diff, openPage.ts in full, the new tests and the existing test helpers at the top of openPage.test.ts. Not read: the callers that catch PageTabLostError. Read only, nothing run locally; checks were still running when I posted.

What I checked:

  • The wait runs only on the failure path (no page and the browser disconnected), so a healthy open is not delayed, and it is bounded at 500 ms with an unref'd timer.
  • The exit listener is removed on both the exit and the timeout paths, and the timer is cleared on exit; the tests assert a zero listener count in all three cases.
  • A process that already has a code or signal, a missing process, and a process object without listener methods all return at once, so the existing stubs and a remote browser keep the old message.
  • PageTabLostError is constructed in one place only, so the optional second argument changes no other caller.
  • The body has the fails without the fix: line and both named tests exist at this head.

Non-blocking note: the first new test depends on a real child exiting within 500 ms of its stdin closing. That should hold comfortably, but it is the one timing-dependent test in the file if a loaded runner ever flakes here.

Need: yes · Size: fits (+132 −4) · Reuse: n/a · Simpler: no · Structure: fine
Risk: low; at most 500 ms added to an already failing open.

— Rames

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 84 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 190cd29 Nov 26, 2026
96 checks passed
@miguel-heygen
miguel-heygen deleted the fix/openpage-chrome-exit-code branch November 26, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants