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.
This commit is contained in:
misterdas
2026-02-16 23:39:02 +05:30
committed by Peter Steinberger
parent 91903bac15
commit 312a7f7880

View File

@@ -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,