Skip to content

Node SDK: exitFallback.unref is not a function crashes Electron renderer hosts (regression in 1.0.17) #2863

Done

Description

@tidy-dev

Summary

GitHub Desktop 3.6.8 updated @github/copilot-sdk from 1.0.13 to 1.0.25. Since the release, Sentry has reported 49 crashes from 7 users in its first 3 hours:

TypeError: o.unref is not a function
    at ChildProcess.<anonymous> (app/node_modules/@github/copilot-sdk/dist/client.js:2790)

GitHub Desktop runs the SDK in an Electron renderer process (Node integration enabled, bundled with webpack target electron-renderer). In that environment the global setTimeout is the DOM implementation and returns a numeric ID, not a Node Timeout object, so .unref() doesn't exist. The exception is uncaught, so Desktop shows its crash dialog and the user has to relaunch the app.

Cause

In attachConnectionHandlers(), the stdio child-process exit handler arms a fallback timer and calls .unref() on it without a guard:

https://github.com/github/copilot-sdk/blob/f2b720c8ec368e035a4d5c72b012fd41b0d533e4/nodejs/src/client.ts#L3817-L3818

exitFallback = setTimeout(disconnectAfterDrain, RUNTIME_SHUTDOWN_TIMEOUT_MS);
exitFallback.unref();

We checked the published dist/client.js of each version. This code isn't in 1.0.13 through 1.0.16; it appears in 1.0.17 and is still present in 1.0.25, 1.0.26 (current latest), and on main.

The handler only reaches this line when the runtime child process emits exit while its connection is still current, before stdout EOF has started the disconnect. That depends on event timing, so it happens only some of the time. The likely triggers are the runtime exiting or being killed during a request, or exit and stdout close arriving out of order.

Other places in the SDK already guard this, for example flushTimer.unref?.() and pollHandle.unref?.() in session.ts.

Reproduction

We reproduced the crash deterministically with a test in our repo. It bundles the SDK with our renderer webpack config and runs it in a VM context whose setTimeout returns numbers, like a browser or Electron renderer. Emitting exit on the mocked CLI child process throws:

TypeError: exitFallback.unref is not a function

Proposed fix

Either change would fix the crash. We'd prefer both:

  1. Guard the call to match the rest of the SDK:
    exitFallback.unref?.();
  2. Import timers explicitly in the Node SDK (import { setTimeout, clearTimeout } from "node:timers"), so it always gets Node Timeout objects whatever the host's globals are. Electron renderers, and any environment where the DOM timers shadow Node's, would then behave the same as plain Node.

Environment

  • @github/copilot-sdk 1.0.25 (bundled CLI 1.0.102); the code first appears in 1.0.17 and is still in 1.0.26
  • GitHub Desktop 3.6.8, Electron renderer, RuntimeConnection.forStdio

Activity

  1. thirdsamsan-svg commented on Oct 26, 2026

    @thirdsamsan-svg

    Open foles

  2. thirdsamsan-svg commented on Oct 26, 2026

    @thirdsamsan-svg

    Reopen

  3. thahamusathaha-max commented on Oct 29, 2026

    @thahamusathaha-max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions