fix: 回填 result envelope failureKind
This commit is contained in:
+34
-4
@@ -48,7 +48,7 @@ export async function buildRunResult(store: AgentRunStore, runId: string, comman
|
||||
const commandTerminal = command ? terminalFromCommand(command) : null;
|
||||
const terminalEventStatus = terminalFromEvents(scopedEvents);
|
||||
const preliminaryTerminal = commandTerminal ?? terminalEventStatus ?? run.terminalStatus;
|
||||
const failureKind = resultFailureKind(run, command, scopedEvents, preliminaryTerminal);
|
||||
const failureKind = resultFailureKind(run, command, scopedEvents, jobs, preliminaryTerminal);
|
||||
const terminal = resultTerminal(commandTerminal, terminalEventStatus, run.terminalStatus, failureKind);
|
||||
const terminalSource = resultTerminalSource(commandTerminal, terminalEventStatus, run.terminalStatus, failureKind);
|
||||
const failureMessage = resultFailureMessage(run, command, scopedEvents, terminal);
|
||||
@@ -540,10 +540,35 @@ function failureKindFromEvents(events: RunEvent[]): FailureKind | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
function resultFailureKind(run: RunRecord, command: CommandRecord | null, events: RunEvent[], terminal: TerminalStatus | null): FailureKind | null {
|
||||
function resultFailureKind(run: RunRecord, command: CommandRecord | null, events: RunEvent[], jobs: RunnerJobRecord[], terminal: TerminalStatus | null): FailureKind | null {
|
||||
if (terminal === "completed") return null;
|
||||
if (command) return failureKindFromEvents(events);
|
||||
return run.failureKind ?? failureKindFromEvents(events);
|
||||
return failureKindValue(run.failureKind) ?? failureKindFromEvents(events) ?? failureKindFromRunnerJobs(jobs);
|
||||
}
|
||||
|
||||
function failureKindFromRunnerJobs(jobs: RunnerJobRecord[]): FailureKind | null {
|
||||
for (const job of [...jobs].reverse()) {
|
||||
const value = failureKindFromJson(job.result) ?? failureKindFromNestedRecords(job.result, ["result", "run", "command", "summary", "status", "terminal", "runner", "kubernetes"]);
|
||||
if (value) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function failureKindFromNestedRecords(record: JsonRecord, keys: string[]): FailureKind | null {
|
||||
for (const key of keys) {
|
||||
const nested = jsonRecordValue(record[key]);
|
||||
if (!nested) continue;
|
||||
const value = failureKindFromJson(nested) ?? failureKindFromNestedRecords(nested, keys);
|
||||
if (value) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function failureKindFromJson(record: JsonRecord): FailureKind | null {
|
||||
return failureKindValue(record.failureKind);
|
||||
}
|
||||
|
||||
function failureKindValue(value: unknown): FailureKind | null {
|
||||
return isFailureKind(value) ? value : null;
|
||||
}
|
||||
|
||||
function isFailureKind(value: unknown): value is FailureKind {
|
||||
@@ -557,10 +582,15 @@ function isFailureKind(value: unknown): value is FailureKind {
|
||||
"skill-unavailable",
|
||||
"runner-lease-conflict",
|
||||
"backend-failed",
|
||||
"backend-spawn-failed",
|
||||
"backend-timeout",
|
||||
"backend-response-invalid",
|
||||
"backend-json-parse-error",
|
||||
"backend-protocol-error",
|
||||
"thread-resume-failed",
|
||||
"session-store-evicted",
|
||||
"provider-auth-failed",
|
||||
"provider-http-error",
|
||||
"provider-invalid-tool-call",
|
||||
"provider-compact-unsupported",
|
||||
"provider-rate-limited",
|
||||
|
||||
Reference in New Issue
Block a user