diff --git a/packages/cli/src/acp-integration/acpAgent.ts b/packages/cli/src/acp-integration/acpAgent.ts index 246d80019..777171cca 100644 --- a/packages/cli/src/acp-integration/acpAgent.ts +++ b/packages/cli/src/acp-integration/acpAgent.ts @@ -87,7 +87,25 @@ export async function runAcpAgent( stream, ); + // Handle SIGTERM/SIGINT for graceful shutdown. + // 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. + const shutdownHandler = () => { + debugLogger.debug('[ACP] Shutdown signal received, closing streams'); + try { + process.stdin.destroy(); + } catch { + // stdin may already be closed + } + }; + process.on('SIGTERM', shutdownHandler); + process.on('SIGINT', shutdownHandler); + await connection.closed; + + process.off('SIGTERM', shutdownHandler); + process.off('SIGINT', shutdownHandler); } function toStdioServer(server: McpServer): McpServerStdio | undefined {