From a6e8aec7f4a5dfe6d75c72b2068db978e6254b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=90=E7=9B=AE?= Date: Thu, 19 Mar 2026 11:53:13 +0800 Subject: [PATCH] fix: destroy both stdin and stdout on shutdown, guard against duplicate signals - Close stdout in addition to stdin to prevent hanging writes during shutdown - Add shuttingDown guard to ensure cleanup runs only once Made-with: Cursor --- packages/cli/src/acp-integration/acpAgent.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/cli/src/acp-integration/acpAgent.ts b/packages/cli/src/acp-integration/acpAgent.ts index 777171cca..0cbace59e 100644 --- a/packages/cli/src/acp-integration/acpAgent.ts +++ b/packages/cli/src/acp-integration/acpAgent.ts @@ -91,13 +91,21 @@ export async function runAcpAgent( // Without this, signal handlers registered elsewhere in the CLI // (e.g., stdin raw mode restoration) override the default exit behavior, // causing the ACP process to ignore termination signals. + let shuttingDown = false; const shutdownHandler = () => { + if (shuttingDown) return; + shuttingDown = true; debugLogger.debug('[ACP] Shutdown signal received, closing streams'); try { process.stdin.destroy(); } catch { // stdin may already be closed } + try { + process.stdout.destroy(); + } catch { + // stdout may already be closed + } }; process.on('SIGTERM', shutdownHandler); process.on('SIGINT', shutdownHandler);