fix(coding-agent): handled provider error finish reasons and preserve subprocess failure codes

- Added detection for provider error finish reasons occurring before tool calls to identify fatal messages.
- Prevented subprocess tool execution finalization from resetting a non-zero exit code when yield items exist.
- Ensured a default error message is set in stderr when a subprocess fails after yielding a result.
This commit is contained in:
can1357
2026-06-18 01:11:10 +02:00
parent 5a0c04f7ff
commit 17ce678468
4 changed files with 114 additions and 7 deletions
+11 -6
View File
@@ -516,6 +516,7 @@ export function finalizeSubprocessOutput(args: FinalizeSubprocessOutputArgs): Fi
const { yieldItems, reportFindings, doneAborted, signalAborted, outputSchema } = args;
let abortedViaYield = false;
const hasYield = Array.isArray(yieldItems) && yieldItems.length > 0;
const hadFailureBeforeYield = exitCode !== 0 && stderr.trim().length > 0;
if (hasYield) {
const lastYield = yieldItems[yieldItems.length - 1];
@@ -553,12 +554,16 @@ export function finalizeSubprocessOutput(args: FinalizeSubprocessOutputArgs): Fi
const errorMessage = err instanceof Error ? err.message : String(err);
rawOutput = `{"error":"Failed to serialize yield data: ${errorMessage}"}`;
}
exitCode = 0;
stderr = overridden
? SUBAGENT_WARNING_SCHEMA_OVERRIDDEN
: schemaError
? `invalid output schema: ${schemaError}`
: "";
if (!hadFailureBeforeYield) {
exitCode = 0;
stderr = overridden
? SUBAGENT_WARNING_SCHEMA_OVERRIDDEN
: schemaError
? `invalid output schema: ${schemaError}`
: "";
} else if (!stderr) {
stderr = "Subagent failed after yielding a result.";
}
}
}
}