Skip to content

fix(desktop): recover from socket and renderer crashes - #4207

Merged
reachjalil merged 1 commit into
devfrom
fix/desktop-crash-resilience
Aug 28, 2026
Merged

reachjalil merged 1 commit into
devfrom
fix/desktop-crash-resilience

Conversation

@reachjalil

@reachjalil reachjalil commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Why this is needed

The current macOS alpha can leave users with a gray Desktop window after the Electron main process encounters this uncaught Node/Undici exception during an HTTP request:

Error: setTypeOfService EINVAL
    at Socket.setTypeOfService (node:net:684:13)
    at writeH1 (node:internal/deps/undici/undici:8006:16)

The exception is thrown by the socket Type-of-Service optimization outside the normal fetch() rejection boundary. Because it escapes the request promise, ordinary request-level error handling cannot catch it. Refreshing initiates another request and can reproduce the same main-process failure, while the existing native window remains as a blank gray shell.

This runtime behavior is documented upstream in nodejs/undici#5544. The corresponding upstream fix in nodejs/undici#5547 treats Type-of-Service application as best-effort so that an unsupported socket hint does not terminate the process.

What this changes

  • Installs an early main-process guard for the exact setTypeOfService EINVAL failure emitted by the embedded Node runtime.
  • Keeps unrelated socket and request failures observable and unchanged.
  • Contains rejected promises from detached Electron callbacks, including updater initialization, app activation, deep links, menu actions, notifications, browser-panel navigation, external-link opening, and shutdown cleanup.
  • Converts fatal startup failures into an explicit error followed by a controlled quit instead of leaving a gray shell.
  • Reloads once after an unexpected renderer-process exit so a transient renderer crash does not strand the window.
  • Stops automatic recovery after a second renderer crash within 30 seconds and reports the failure instead of creating a reload loop.
  • Adds unit coverage for the exact socket-error boundary, detached-task containment, and bounded renderer recovery.
  • Adds an Electron-runtime test that injects the observed EINVAL, verifies that a real HTTP request completes, and verifies that an unrelated EACCES still propagates.
  • Adds an app-driving test that crashes the renderer through CDP and verifies that a fresh JavaScript realm, a healthy main process, the expected route, and meaningful content return.

Objective compatibility boundary

This PR does not introduce a custom networking opinion or product policy:

  • It does not choose a QoS value, endpoint, route, proxy, VPN behavior, retry policy, or network fallback.
  • It follows the upstream Node/Undici compatibility boundary: socket Type-of-Service is a best-effort optimization, and failure to apply that hint must not terminate the application.
  • The matcher is deliberately narrow: it ignores only an Error whose code is EINVAL and whose syscall or message identifies setTypeOfService.
  • Every other socket exception is rethrown and every ordinary request failure continues through its existing error path.
  • Renderer recovery is bounded to one reload; repeated crashes remain visible rather than being hidden by an indefinite loop.

The compatibility guard can be revisited after every supported Desktop runtime includes the upstream fix, but the process-level rejection containment and bounded renderer recovery remain useful independently.

Verification

Verdict: Passed at 43d819fcbdd12101eeb6f063c8093b0a329aa0cb.

Daytona tooling is installed, but Daytona API credentials were unavailable, so the documented isolated local fallback lane was used.

  • CI=true pnpm evals:pr specs/desktop-socket-tos-resilience.test.ts
    • 1 passed, 0 failed, 0 skipped
  • CI=true pnpm evals:e2e desktop-renderer-crash-recovery --local
    • 1 passed, 0 failed, 0 skipped
  • CI=true pnpm --dir apps/desktop test
    • 282 passed, 0 failed, 1 intentional platform-specific skip
  • CI=true pnpm --dir apps/desktop typecheck:electron
    • passed
  • CI=true pnpm --dir apps/desktop check:electron
    • passed; bridge covers 52 renderer methods
  • CI=true pnpm --dir apps/desktop build:electron
    • passed
  • CI=true pnpm --dir evals lint:layers
    • passed; no dependency violations

The standalone eval workspace does not currently expose its own tsc binary, so pnpm --dir evals typecheck could not start. Invoking the root compiler against the full eval configuration surfaced broad repository/build-state errors outside this change and was not used as verdict evidence. The two changed specs themselves executed successfully through their supported Vitest/testkit lanes.

No updater-channel, release, deployment, or installed-application change is included in this PR.

@vercel

vercel Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview Aug 28, 2026 9:43pm
openwork-den Ready Ready Preview Aug 28, 2026 9:43pm
openwork-diagnostics Ready Ready Preview Aug 28, 2026 9:43pm
openwork-landing Ready Ready Preview, v0 Aug 28, 2026 9:43pm

@reachjalil

reachjalil commented Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

Test evidence — desktop crash resilience

Exact PR head: 43d819fcbdd12101eeb6f063c8093b0a329aa0cb

Embedded Electron socket Type-of-Service containment — 0/0 screenshots · 1 assertion

✅ 1 expectation passed · 0 failed · 0 pending

Screenshots not uploaded (no BLOB_READ_WRITE_TOKEN); this test has assertion evidence only.

ℹ️ ASSERTION — The embedded runtime continues after the exact EINVAL but preserves unrelated socket failures

status=200; body=ok; injectedCalls=1; unrelatedCode=EACCES

  • ✅ PASS A real HTTP request completed after the injected setTypeOfService EINVAL, while the injected unrelated EACCES still propagated.

Test run created 2026-08-28T21:41:44.361Z · Source: evals/results/test-runs/2026-08-28T21-41-44-360Z-the-embedded-electron-runtime-contains-only-the-known-socket-type-of-service-fai/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4207 --test-run 2026-08-28T21-41-44-360Z-the-embedded-electron-runtime-contains-only-the-known-socket-type-of-service-fai

Renderer crash recovery — 0/0 screenshots · 1 assertion

✅ 1 expectation passed · 0 failed · 0 pending

Screenshots not uploaded (no BLOB_READ_WRITE_TOKEN); this test has assertion evidence only.

ℹ️ ASSERTION — A crashed renderer is replaced by a usable OpenWork page

rendererMarkerReset=true; mainProcessCdpHealthy=true; route=/welcome

  • ✅ PASS The renderer JavaScript realm was replaced, the Electron main-process CDP endpoint remained healthy, and the recovered page returned to /welcome.

Test run created 2026-08-28T21:41:50.904Z · Source: evals/results/test-runs/2026-08-28T21-41-50-903Z-an-unexpected-renderer-exit-recovers-once-without-stranding-a-blank-window/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4207 --test-run 2026-08-28T21-41-50-903Z-an-unexpected-renderer-exit-recovers-once-without-stranding-a-blank-window

@reachjalil
reachjalil marked this pull request as draft August 28, 2026 17:42
diff-warden[bot]
diff-warden Bot previously approved these changes Aug 28, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (77bfd06ed8f72a126ab1aac765a978dfd9c775f8). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@reachjalil
reachjalil force-pushed the fix/desktop-crash-resilience branch from 77bfd06 to 27101da Compare August 28, 2026 17:45
@reachjalil
reachjalil force-pushed the fix/desktop-crash-resilience branch from 27101da to 1a926e6 Compare August 28, 2026 17:55
@reachjalil
reachjalil marked this pull request as ready for review August 28, 2026 17:56
@reachjalil
reachjalil marked this pull request as draft August 28, 2026 18:11
@reachjalil
reachjalil marked this pull request as ready for review August 28, 2026 18:12
@reachjalil reachjalil closed this Aug 28, 2026
@reachjalil reachjalil reopened this Aug 28, 2026
@reachjalil
reachjalil force-pushed the fix/desktop-crash-resilience branch from 1a926e6 to 0da1e6c Compare August 28, 2026 18:14
diff-warden[bot]
diff-warden Bot previously approved these changes Aug 28, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (0da1e6c27a461077fc5fcad6815425760d666a4e). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (43d819fcbdd12101eeb6f063c8093b0a329aa0cb). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@reachjalil
reachjalil merged commit 2134e42 into dev Aug 28, 2026
18 checks passed
@reachjalil
reachjalil deleted the fix/desktop-crash-resilience branch August 28, 2026 21:56

This branch was successfully deployed

4 active deployments
Preview – openwork-den — 43d819fc Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-landing — 43d819fc Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-app — 43d819fc Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-diagnostics — 43d819fc Deployed Aug 28, 2026 by vercel[bot]
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.

1 participant