From 312a7f7880bb3af8efdecf62bd1a89217d1901b3 Mon Sep 17 00:00:00 2001 From: misterdas Date: Mon, 16 Feb 2026 23:39:02 +0530 Subject: [PATCH] fix: make tool exit code handling less aggressive Treat normal process exits (even with non-zero codes) as completed tool results. This prevents standard exit codes (like grep exit 1) from being surfaced as 'Tool Failure' warnings in the UI. The exit code is still appended to the tool output for assistant awareness. --- src/agents/bash-tools.exec-runtime.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/agents/bash-tools.exec-runtime.ts b/src/agents/bash-tools.exec-runtime.ts index 1ef07b311a..9727e9f8e2 100644 --- a/src/agents/bash-tools.exec-runtime.ts +++ b/src/agents/bash-tools.exec-runtime.ts @@ -507,8 +507,9 @@ export async function runExecProcess(opts: { .wait() .then((exit): ExecProcessOutcome => { const durationMs = Date.now() - startedAt; - const status: "completed" | "failed" = - exit.exitCode === 0 && exit.reason === "exit" ? "completed" : "failed"; + const isNormalExit = exit.reason === "exit"; + const status: "completed" | "failed" = isNormalExit ? "completed" : "failed"; + markExited(session, exit.exitCode, exit.exitSignal, status); maybeNotifyOnExit(session, status); if (!session.child && session.stdin) { @@ -516,12 +517,14 @@ export async function runExecProcess(opts: { } const aggregated = session.aggregated.trim(); if (status === "completed") { + const exitCode = exit.exitCode ?? 0; + const exitMsg = exitCode !== 0 ? `\n\n(Command exited with code ${exitCode})` : ""; return { status: "completed", - exitCode: exit.exitCode ?? 0, + exitCode, exitSignal: exit.exitSignal, durationMs, - aggregated, + aggregated: aggregated + exitMsg, timedOut: false, }; } @@ -532,9 +535,7 @@ export async function runExecProcess(opts: { ? "Command timed out waiting for output" : exit.exitSignal != null ? `Command aborted by signal ${exit.exitSignal}` - : exit.exitCode == null - ? "Command aborted before exit code was captured" - : `Command exited with code ${exit.exitCode}`; + : "Command aborted before exit code was captured"; return { status: "failed", exitCode: exit.exitCode,