From 741aa436e39bb03fde8a8a9dc315529643e41375 Mon Sep 17 00:00:00 2001 From: tanzhenxin Date: Wed, 11 Mar 2026 18:40:04 +0800 Subject: [PATCH] fix(cli): suppress Windows pty resize race condition Add global uncaught exception handler to suppress known race condition in @lydell/node-pty where a deferred resize fires after the pty process has already exited on Windows. Tracking bug: https://github.com/microsoft/node-pty/issues/827 Co-authored-by: Qwen-Coder --- packages/cli/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 8e9912f10..3b00b9546 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -9,8 +9,30 @@ import './src/gemini.js'; import { main } from './src/gemini.js'; import { FatalError } from '@qwen-code/qwen-code-core'; +import { writeStderrLine } from './src/utils/stdioHelpers.js'; // --- Global Entry Point --- + +// Suppress known race condition in @lydell/node-pty on Windows where a +// deferred resize fires after the pty process has already exited. +// 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' + ) { + return; + } + + if (error instanceof Error) { + writeStderrLine(error.stack ?? error.message); + } else { + writeStderrLine(String(error)); + } + process.exit(1); +}); + main().catch((error) => { if (error instanceof FatalError) { let errorMessage = error.message;