Skip to content

Commit 50752e5

Browse files
yuranichcursoragent
andcommitted
fix: wait for worker stderr drain
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6064f93 commit 50752e5

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/sdk/client/rpc/node-rpc-client.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,20 @@ async function ensureRPC(): Promise<RPC> {
406406
);
407407
return;
408408
}
409-
// Worker died before handshake — reject the init promise.
409+
// Pre-handshake failures are rejected from "close" so stderr has
410+
// drained before we assemble the startup error cause.
411+
},
412+
);
413+
414+
bareWorkerProc.on(
415+
"close",
416+
(...args: unknown[]) => {
417+
if (settled) return;
418+
const code = typeof args[0] === "number" ? args[0] : null;
419+
const exitSignal = typeof args[1] === "string" ? args[1] : null;
420+
421+
// Worker died before handshake. Use close, not exit, so piped
422+
// stderr has drained before we build the error cause.
410423
settled = true;
411424
clearTimeout(timer);
412425
const serverToClose = ipcServer;
@@ -422,7 +435,7 @@ async function ensureRPC(): Promise<RPC> {
422435
new RPCInitTimeoutError(
423436
RPC_INIT_TIMEOUT_MS,
424437
createWorkerStartupError(
425-
`Worker process exited with code ${code} before IPC connection was established`,
438+
`Worker process exited with code ${code}, signal ${exitSignal} before IPC connection was established`,
426439
workerStderrTail,
427440
),
428441
),

0 commit comments

Comments
 (0)