From 8b56d27901feafed1bbfe47304be6150ff0c26bb Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Tue, 26 May 2026 12:43:51 -0700 Subject: [PATCH] fix(core): suppress PTY resize EBADF errors (#27461) --- packages/cli/index.ts | 22 +++++++++++-------- .../src/services/shellExecutionService.ts | 5 +++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 3bcec4d301..2f0796c7d9 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -17,17 +17,21 @@ import { // --- Global Entry Point --- -// Suppress known race condition error in node-pty on Windows +// Suppress known race condition error in node-pty on Windows and Linux // Tracking bug: https://github.com/microsoft/node-pty/issues/827 process.on('uncaughtException', (error) => { - if ( - process.platform === 'win32' && - error instanceof Error && - error.message === 'Cannot resize a pty that has already exited' - ) { - // This error happens on Windows with node-pty when resizing a pty that has just exited. - // It is a race condition in node-pty that we cannot prevent, so we silence it. - return; + if (error instanceof Error) { + const isPtyResizeError = + error.message === 'Cannot resize a pty that has already exited'; + const isEbadfError = error.message.includes('EBADF'); + const isFromNodePty = + error.stack?.includes('node-pty') || error.stack?.includes('PtyResize'); + + if ((isPtyResizeError || isEbadfError) && isFromNodePty) { + // This error happens with node-pty when resizing a pty that has just exited. + // It is a race condition in node-pty that we cannot prevent, so we silence it. + return; + } } // For other errors, we rely on the default behavior, but since we attached a listener, diff --git a/packages/core/src/services/shellExecutionService.ts b/packages/core/src/services/shellExecutionService.ts index b29595df8b..2f9a6c4e52 100644 --- a/packages/core/src/services/shellExecutionService.ts +++ b/packages/core/src/services/shellExecutionService.ts @@ -1517,12 +1517,13 @@ export class ShellExecutionService { // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion const err = e as { code?: string; message?: string }; const isEsrch = err.code === 'ESRCH'; + const isEbadf = err.code === 'EBADF' || err.message?.includes('EBADF'); const isWindowsPtyError = err.message?.includes( 'Cannot resize a pty that has already exited', ); - if (isEsrch || isWindowsPtyError) { - // On Unix, we get an ESRCH error. + if (isEsrch || isEbadf || isWindowsPtyError) { + // On Unix, we get an ESRCH or EBADF error. // On Windows, we get a message-based error. // In both cases, it's safe to ignore. } else {