


















@@ -10,6 +10,11 @@ import { stringifyRouteThreadId } from "../../plugin-sdk/channel-route.js";
1010import { createLazyImportLoader } from "../../shared/lazy-promise.js";
1111import { normalizeOptionalString } from "../../shared/string-coerce.js";
1212import { resolveCronDeliveryPlan, type CronDeliveryPlan } from "../delivery-plan.js";
13+import {
14+createCronRunDiagnosticsFromAgentResult,
15+createCronRunDiagnosticsFromError,
16+mergeCronRunDiagnostics,
17+} from "../run-diagnostics.js";
1318import type {
1419CronAgentExecutionStarted,
1520CronDeliveryTrace,
@@ -566,7 +571,14 @@ async function prepareCronRunContext(params: {
566571if (!resolvedModelSelection.ok) {
567572return {
568573ok: false,
569-result: withRunSession({ status: "error", error: resolvedModelSelection.error }),
574+result: withRunSession({
575+status: "error",
576+error: resolvedModelSelection.error,
577+diagnostics: createCronRunDiagnosticsFromError(
578+"cron-preflight",
579+resolvedModelSelection.error,
580+),
581+}),
570582};
571583}
572584let provider = resolvedModelSelection.provider;
@@ -586,6 +598,9 @@ async function prepareCronRunContext(params: {
586598result: withRunSession({
587599status: "skipped",
588600error: preflight.reason,
601+diagnostics: createCronRunDiagnosticsFromError("model-preflight", preflight.reason, {
602+severity: "warn",
603+}),
589604 provider,
590605 model,
591606}),
@@ -862,7 +877,15 @@ async function finalizeCronRun(params: {
862877await prepared.persistSessionEntry();
863878864879if (params.isAborted()) {
865-return prepared.withRunSession({ status: "error", error: params.abortReason(), ...telemetry });
880+return prepared.withRunSession({
881+status: "error",
882+error: params.abortReason(),
883+diagnostics: mergeCronRunDiagnostics(
884+createCronRunDiagnosticsFromAgentResult(finalRunResult, { finalStatus: "error" }),
885+createCronRunDiagnosticsFromError("cron-setup", params.abortReason()),
886+),
887+ ...telemetry,
888+});
866889}
867890let {
868891 summary,
@@ -882,6 +905,9 @@ async function finalizeCronRun(params: {
882905await resolveCronChannelOutputPolicy(prepared.resolvedDelivery.channel)
883906).preferFinalAssistantVisibleText,
884907});
908+const agentDiagnostics = createCronRunDiagnosticsFromAgentResult(finalRunResult, {
909+finalStatus: hasFatalErrorPayload ? "error" : "ok",
910+});
885911const resolveRunOutcome = (result?: {
886912delivered?: boolean;
887913deliveryAttempted?: boolean;
@@ -897,6 +923,15 @@ async function finalizeCronRun(params: {
897923delivered: result?.delivered,
898924deliveryAttempted: result?.deliveryAttempted,
899925delivery: result?.delivery,
926+diagnostics: hasFatalErrorPayload
927+ ? mergeCronRunDiagnostics(
928+agentDiagnostics,
929+createCronRunDiagnosticsFromError(
930+"agent-run",
931+embeddedRunError ?? "cron isolated run returned an error payload",
932+),
933+)
934+ : agentDiagnostics,
900935 ...telemetry,
901936});
902937const failPendingPresentationWarningUnlessDelivered = (delivered?: boolean) => {
@@ -975,6 +1010,13 @@ async function finalizeCronRun(params: {
9751010deliveryAttempted:
9761011deliveryResult.result.deliveryAttempted ?? deliveryResult.deliveryAttempted,
9771012delivery: deliveryTrace,
1013+diagnostics: mergeCronRunDiagnostics(
1014+agentDiagnostics,
1015+deliveryResult.result.diagnostics,
1016+deliveryResult.result.status === "error" && deliveryResult.result.error
1017+ ? createCronRunDiagnosticsFromError("delivery", deliveryResult.result.error)
1018+ : undefined,
1019+),
9781020};
9791021failPendingPresentationWarningUnlessDelivered(
9801022resultWithDeliveryMeta.delivered ?? deliveryResult.delivered,
@@ -1066,7 +1108,11 @@ export async function runCronIsolatedAgentTurn(params: {
10661108suppressExecNotifyOnExit: prepared.context.suppressExecNotifyOnExit,
10671109});
10681110if (isAborted()) {
1069-return prepared.context.withRunSession({ status: "error", error: abortReason() });
1111+return prepared.context.withRunSession({
1112+status: "error",
1113+error: abortReason(),
1114+diagnostics: createCronRunDiagnosticsFromError("cron-setup", abortReason()),
1115+});
10701116}
10711117return await finalizeCronRun({
10721118prepared: prepared.context,
@@ -1075,6 +1121,10 @@ export async function runCronIsolatedAgentTurn(params: {
10751121 isAborted,
10761122});
10771123} catch (err) {
1078-return prepared.context.withRunSession({ status: "error", error: String(err) });
1124+return prepared.context.withRunSession({
1125+status: "error",
1126+error: String(err),
1127+diagnostics: createCronRunDiagnosticsFromError("agent-run", err),
1128+});
10791129}
10801130}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。