fix: surface agentrun terminal errors in final response
This commit is contained in:
@@ -1447,6 +1447,14 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId, a
|
||||
const code = canceled ? "agentrun_canceled" : result?.failureKind ?? (terminalStatus === "blocked" ? "agentrun_blocked" : "agentrun_failed");
|
||||
const message = result?.failureMessage ?? result?.blocker?.message ?? (canceled ? "AgentRun command was canceled" : "AgentRun command failed");
|
||||
const attribution = agentRunFailureAttribution({ code, message, canceled });
|
||||
const finalResponse = agentRunTerminalFailureFinalResponse({
|
||||
base,
|
||||
traceId,
|
||||
now,
|
||||
status: canceled ? "canceled" : "failed",
|
||||
text: firstNonEmpty(message, attribution.summary, attribution.userMessage)
|
||||
});
|
||||
const traceSummary = agentRunTerminalFailureTraceSummary({ base, runnerTrace, finalResponse, traceId, terminalStatus: canceled ? "canceled" : terminalStatus || "failed" });
|
||||
if (appendResultEvent) {
|
||||
traceStore.append(traceId, {
|
||||
type: "result",
|
||||
@@ -1477,6 +1485,8 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId, a
|
||||
toolCalls: agentRunToolCalls(result, canceled ? "canceled" : "failed"),
|
||||
skills: { status: "delegated", provider: ADAPTER_ID, count: 0, items: [], valuesPrinted: false },
|
||||
providerTrace,
|
||||
finalResponse,
|
||||
traceSummary,
|
||||
error: {
|
||||
code,
|
||||
layer: "agentrun",
|
||||
@@ -1520,6 +1530,47 @@ function agentRunCompletedFinalResponse({ base, result, traceId, now }) {
|
||||
};
|
||||
}
|
||||
|
||||
function agentRunTerminalFailureFinalResponse({ base, traceId, now, status, text }) {
|
||||
const textValue = String(text ?? "").trim();
|
||||
return {
|
||||
text: textValue || "AgentRun command failed.",
|
||||
textChars: (textValue || "AgentRun command failed.").length,
|
||||
role: "assistant",
|
||||
status,
|
||||
traceId,
|
||||
messageId: base.messageId ?? base.reply?.messageId ?? `msg_${traceId.slice(4)}`,
|
||||
createdAt: base.reply?.createdAt ?? base.createdAt ?? now,
|
||||
updatedAt: now,
|
||||
valuesPrinted: false
|
||||
};
|
||||
}
|
||||
|
||||
function agentRunTerminalFailureTraceSummary({ base, runnerTrace, finalResponse, traceId, terminalStatus }) {
|
||||
const events = Array.isArray(runnerTrace?.events) ? runnerTrace.events : [];
|
||||
const lastSeq = Math.max(0, ...events.map((event) => Number(event?.seq ?? 0)).filter(Number.isFinite));
|
||||
return {
|
||||
traceId,
|
||||
source: "agentrun-command-result",
|
||||
sourceEventCount: Number(runnerTrace?.eventCount ?? events.length ?? 0),
|
||||
terminalStatus,
|
||||
finalAssistantRow: {
|
||||
role: finalResponse.role,
|
||||
status: finalResponse.status,
|
||||
textChars: finalResponse.textChars,
|
||||
textPreview: finalResponse.text.slice(0, 240),
|
||||
messageId: finalResponse.messageId,
|
||||
valuesPrinted: false
|
||||
},
|
||||
agentRun: {
|
||||
runId: base.agentRun?.runId ?? null,
|
||||
commandId: base.agentRun?.commandId ?? null,
|
||||
lastSeq,
|
||||
valuesPrinted: false
|
||||
},
|
||||
valuesPrinted: false
|
||||
};
|
||||
}
|
||||
|
||||
function agentRunCompletedTraceSummary({ base, runnerTrace, finalResponse, traceId }) {
|
||||
const events = Array.isArray(runnerTrace?.events) ? runnerTrace.events : [];
|
||||
const lastSeq = Math.max(0, ...events.map((event) => Number(event?.seq ?? 0)).filter(Number.isFinite));
|
||||
|
||||
Reference in New Issue
Block a user