From 20ad40092c1667bfea05991d448d8e465d4f656d Mon Sep 17 00:00:00 2001 From: shrutip90 Date: Tue, 16 Sep 2025 14:47:45 -0700 Subject: [PATCH] =?UTF-8?q?fix(cli):=20Fix=20performance=20issues=20on=20r?= =?UTF-8?q?elaunching=20CLI=20in=20inner=20node=20pro=E2=80=A6=20(#8571)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli/src/gemini.tsx | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 8deafa8600..b7525bffd6 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -106,16 +106,33 @@ function getNodeMemoryArgs(config: Config): string[] { } async function relaunchWithAdditionalArgs(additionalArgs: string[]) { - const nodeArgs = [...additionalArgs, ...process.argv.slice(1)]; - const newEnv = { ...process.env, GEMINI_CLI_NO_RELAUNCH: 'true' }; + try { + const nodeArgs = [...additionalArgs, ...process.argv.slice(1)]; + const newEnv = { ...process.env, GEMINI_CLI_NO_RELAUNCH: 'true' }; - const child = spawn(process.execPath, nodeArgs, { - stdio: 'inherit', - env: newEnv, - }); + // The parent process should not be reading from stdin while the child is running. + process.stdin.pause(); - await new Promise((resolve) => child.on('close', resolve)); - process.exit(0); + const child = spawn(process.execPath, nodeArgs, { + stdio: 'inherit', + env: newEnv, + }); + + await new Promise((resolve, reject) => { + child.on('error', reject); + child.on('close', () => { + // Resume stdin before the parent process exits. + process.stdin.resume(); + resolve(); + }); + }); + + process.exit(0); + } catch (error) { + process.stdin.resume(); + console.error('Failed to relaunch CLI:', error); + process.exit(1); + } } import { runZedIntegration } from './zed-integration/zedIntegration.js';