From 500e64084391b88058dfa10d67770af48d1a63d9 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 30 Jul 2025 13:52:54 -0700 Subject: [PATCH] fix: address feedback --- src/tools/runTerminalCommand.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/tools/runTerminalCommand.ts b/src/tools/runTerminalCommand.ts index 02c7d5568..0269bf592 100644 --- a/src/tools/runTerminalCommand.ts +++ b/src/tools/runTerminalCommand.ts @@ -25,6 +25,7 @@ export const runTerminalCommandTool: Tool = { let stderr = ""; let lastOutputTime = Date.now(); let timeoutId: NodeJS.Timeout; + let isResolved = false; const TIMEOUT_MS = 30000; // 30 seconds @@ -33,6 +34,8 @@ export const runTerminalCommandTool: Tool = { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { + if (isResolved) return; + isResolved = true; child.kill(); const output = stdout + (stderr ? `\nStderr: ${stderr}` : ""); resolve( @@ -57,22 +60,28 @@ export const runTerminalCommandTool: Tool = { }); child.on("close", (code) => { + if (isResolved) return; + isResolved = true; + if (timeoutId) { clearTimeout(timeoutId); } - // Track specific git operations - if (isGitCommitCommand(command)) { - telemetryService.recordCommitCreated(); - } else if (isPullRequestCommand(command)) { - telemetryService.recordPullRequestCreated(); - } - - if (code !== 0) { + // Only reject on non-zero exit code if there's also stderr + if (code !== 0 && stderr) { reject(`Error (exit code ${code}): ${stderr}`); return; } + // Track specific git operations only after successful execution + if (code === 0) { + if (isGitCommitCommand(command)) { + telemetryService.recordCommitCreated(); + } else if (isPullRequestCommand(command)) { + telemetryService.recordPullRequestCreated(); + } + } + if (stderr) { resolve(stdout + `\nStderr: ${stderr}`); return; @@ -81,6 +90,9 @@ export const runTerminalCommandTool: Tool = { }); child.on("error", (error) => { + if (isResolved) return; + isResolved = true; + if (timeoutId) { clearTimeout(timeoutId); }