fix: 修正 provider retry 与完成结果归因

This commit is contained in:
Codex
2026-06-10 00:27:26 +08:00
parent da5072eaf6
commit 72042f7bff
4 changed files with 57 additions and 3 deletions
+14 -2
View File
@@ -37,8 +37,8 @@ export async function buildRunResult(store: AgentRunStore, runId: string, comman
const terminalEventStatus = terminalFromEvents(scopedEvents);
const terminal = commandTerminal ?? terminalEventStatus ?? run.terminalStatus;
const terminalSource = commandTerminal ? "command-record" : terminalEventStatus ? "terminal_status-event" : run.terminalStatus ? "run-record" : "none";
const failureKind = command ? failureKindFromEvents(scopedEvents) : run.failureKind ?? failureKindFromEvents(scopedEvents);
const failureMessage = command ? messageFromEvents(scopedEvents) : run.failureMessage ?? messageFromEvents(scopedEvents);
const failureKind = resultFailureKind(run, command, scopedEvents, terminal);
const failureMessage = resultFailureMessage(run, command, scopedEvents, terminal);
const reply = assistantReply(scopedEvents);
const blocker = terminal === "blocked" || terminal === "failed" ? { failureKind, message: failureMessage } : null;
const liveness = livenessSnapshot(run, command, events, scopedEvents, terminal);
@@ -305,6 +305,12 @@ function failureKindFromEvents(events: RunEvent[]): string | null {
return null;
}
function resultFailureKind(run: RunRecord, command: CommandRecord | null, events: RunEvent[], terminal: TerminalStatus | null): string | null {
if (terminal === "completed") return null;
if (command) return failureKindFromEvents(events);
return run.failureKind ?? failureKindFromEvents(events);
}
function messageFromEvents(events: RunEvent[]): string | null {
for (const event of [...events].reverse()) {
const value = event.payload.message;
@@ -313,6 +319,12 @@ function messageFromEvents(events: RunEvent[]): string | null {
return null;
}
function resultFailureMessage(run: RunRecord, command: CommandRecord | null, events: RunEvent[], terminal: TerminalStatus | null): string | null {
if (terminal === "completed") return null;
if (command) return messageFromEvents(events);
return run.failureMessage ?? messageFromEvents(events);
}
function assistantReply(events: RunEvent[]): AssistantReplySummary {
const assistantEvents = events.filter((event) => event.type === "assistant_message");
const latestAuthoritative = [...assistantEvents].reverse().find((event) => (event.payload.replyAuthority === true || event.payload.final === true) && textPayload(event.payload).length > 0);