Repository navigation
Description
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:
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:
- Guard the call to match the rest of the SDK:
exitFallback.unref?.();
- Import timers explicitly in the Node SDK (
import { setTimeout, clearTimeout } from "node:timers"), so it always gets NodeTimeoutobjects 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-sdk1.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
mohitkumar123658995-hash commentedon Oct 23, 2026
thirdsamsan-svg commentedon Oct 26, 2026
Open foles
thirdsamsan-svg commentedon Oct 26, 2026
Reopen
thahamusathaha-max commentedon Oct 29, 2026
[email protected]