Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): survive macOS setTypeOfService EINVAL #8389

ClosedMaWoo96(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8389/headopened View on GitHub

Node 24’s bundled Undici calls socket.setTypeOfService() on every HTTP/1 write to apply best-effort QoS. On macOS the kernel rejects that option on reused sockets with EINVAL, and because the call happens inside a socket event handler the throw is uncaught and kills the whole server process with exit 1.

On one nightly install (0.0.36-nightly, Node v24.15.0) this fired 52 times between Aug 17 and Aug 24. The desktop backend child restarts on crash, but the final burst on Aug 24 left the server down until the app was relaunched by hand.

node:net:683
      throw new ErrnoException(err, 'setTypeOfService');
      ^

Error: setTypeOfService EINVAL
    at Socket.setTypeOfService (node:net:683:13)
    at writeH1 (node:internal/deps/undici/undici:7836:16)
    at Object.write (node:internal/deps/undici/undici:7632:18)
    at _resume (node:internal/deps/undici/undici:9460:54)
  errno: -22, code: 'EINVAL', syscall: 'setTypeOfService'

The fix wraps Socket.prototype.setTypeOfService on darwin at the server entrypoint: an EINVAL from the QoS hint is swallowed (the request itself is still valid), and every other failure still propagates. Guard installation is darwin-only and no-ops if the method is absent.

Verified with vp test run apps/server/src/bin.test.ts (19 passed, including two new cases covering the swallow and the propagate paths), tsgo --noEmit on apps/server (exit 0), plus targeted lint and vp fmt --check.

Model: Claude Opus 5 (1M context). Harness: Claude Code.


Note

Medium Risk Runtime prototype patching on the Node net stack affects all outbound HTTP on macOS; EINVAL is narrowed but the change sits on a critical networking path.

Overview Prevents the server process from crashing on macOS when Node 24’s Undici calls socket.setTypeOfService() during HTTP/1 writes and the kernel returns EINVAL on reused sockets.

At CLI startup (darwin only), the entrypoint patches Socket.prototype.setTypeOfService via a new guardSetTypeOfService helper that ignores EINVAL and still rethrows other errors (e.g. EPERM). Guard installation runs through installNodeNetworkCompatibility before Command.run.

Adds two unit tests in bin.test.ts for the swallow and propagate paths.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9a89b52ff92314431448439317f98548258e8821. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Guard Socket.setTypeOfService against EINVAL on macOS

  • Adds guardSetTypeOfService in bin.ts, a higher-order wrapper that catches EINVAL errors from setTypeOfService and returns the socket instead of throwing; non-EINVAL errors are rethrown
  • Adds installNodeNetworkCompatibility, an Effect that mutates NodeNet.Socket.prototype.setTypeOfService with the guard only on darwin platforms, then runs it before Command.run in the module entrypoint
  • Adds tests in bin.test.ts covering both the EINVAL-swallowing and non-EINVAL-rethrow paths
  • Behavioral Change: on macOS, Socket.prototype.setTypeOfService is monkey-patched at startup; EINVAL errors that previously propagated are now silently ignored
Macroscope summarized 9a89b52.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: dde3bcd1-bae2-4013-b274-074ef7e33c50

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR changes production networking behavior on macOS by monkey-patching Node socket behavior globally. It also adds a new file-level static-analysis suppression directive, so the change warrants human review.

      Notes:

      • Diff unchanged. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. I confirmed this crash on T3 Code 0.0.39-nightly.20260902.1257 on Apple Silicon macOS.

      Runtime details:

      • macOS 27.0 build 26A5425a
      • Architecture arm64
      • Electron 43.4.1
      • Node 24.18.1
      • Bundled Undici 7.29.0
      • Backend launch flag ELECTRON_RUN_AS_NODE=1

      server-child.log showed the exact uncaught setTypeOfService EINVAL stack. The backend exited with code 1 and restarted about once per minute. The desktop parent remained alive.

      I cherry-picked commit 9a89b52ff onto current main. The cherry-pick needed one import conflict resolution in apps/server/src/bin.test.ts.

      Verification results:

      • vp test run apps/server/src/bin.test.ts: 19 of 19 tests passed.
      • The server typecheck passed.
      • Targeted lint passed for bin.ts and bin.test.ts.
      • An unsigned arm64 package built as 0.0.39-pr.8389.

      I ran the packaged backend against an isolated snapshot of the same database and settings. The patched backend remained stable for one hour. The unpatched nightly crashed about once per minute. No setTypeOfService EINVAL errors appeared after the patch.

      This PR fixes the crash in my environment.

    5. juliusmarminge added labelsmacroscope-review

    6. Still crashing on 0.0.45-nightly.20261002.2572 (Node v24.21.0, macOS 27.0.1 GA): 41 backend deaths in 2 days, same setTypeOfService EINVAL stack from undici writeH1. Details in https://github.com/pingdotgg/t3code/issues/9264#issuecomment-5953582731.

      Could this be rebased onto main? It now conflicts. It might also be worth adding Closes #9264 so the PR and the issue are linked.

    7. Still crashing on the latest nightly, 0.0.46-nightly.20261005.2667 (Electron 44.4.2, Node 24.21.0, undici 7.29.1), macOS 27.0.1.

      114 backend deaths since 2026-09-25, 14 of them today, all with the same setTypeOfService EINVAL from undici writeH1 reported in #9264. Each one kills every running Claude turn mid-task. When the session resumes, Claude Code puts a synthetic "No response requested." into the transcript, so the agent thinks it stopped by itself and tells the user so.

      @MaWoo96 could you rebase this onto main? And could a maintainer vouch for it so it gets a review? It's the only fix for #9264 so far.

    8. Note

      Written by claude-opus-5-5 on behalf of Maria

      Hi! We are cleaning up open PRs, and this one appears to have been created with an older model (opus 5). If this change is really important, we recommend rebuilding the PR with a newer model if possible.

    9. maria-rcks closed this

Sign in to join this conversation.