diff --git a/agents/opencode.ts b/agents/opencode.ts index 69a8d40..02080a5 100644 --- a/agents/opencode.ts +++ b/agents/opencode.ts @@ -437,6 +437,15 @@ export const opencode = agent({ }; } + if (eventCount === 0 && lastProviderError) { + return { + success: false, + output: finalOutput || output, + error: `provider error: ${lastProviderError}`, + usage, + }; + } + return { success: true, output: finalOutput || output, diff --git a/entry b/entry index e109205..43f8f8c 100755 --- a/entry +++ b/entry @@ -146353,6 +146353,14 @@ ${stderrContext}`); usage }; } + if (eventCount === 0 && lastProviderError) { + return { + success: false, + output: finalOutput || output, + error: `provider error: ${lastProviderError}`, + usage + }; + } return { success: true, output: finalOutput || output, @@ -147335,18 +147343,34 @@ function resolvePayload(resolvedPromptInput, repoSettings) { } // utils/run.ts -function handleAgentResult(result) { - if (!result.success) { +async function handleAgentResult(ctx) { + if (!ctx.result.success) { return { success: false, - error: result.error || "Agent execution failed", - output: result.output + error: ctx.result.error || "Agent execution failed", + output: ctx.result.output + }; + } + if (!ctx.toolState.wasUpdated && ctx.toolState.progressCommentId && !ctx.silent) { + const error49 = ctx.result.error || "agent completed without reporting progress"; + try { + await reportErrorToComment({ + toolState: ctx.toolState, + error: error49, + title: "Error" + }); + } catch { + } + return { + success: false, + error: error49, + output: ctx.result.output || "" }; } log.success("Task complete."); return { success: true, - output: result.output || "" + output: ctx.result.output || "" }; } @@ -147696,8 +147720,13 @@ ${instructions.user}` : null, if (toolState.output) { log.info(`::pullfrog-output::${Buffer.from(toolState.output).toString("base64")}`); } + const mainResult = await handleAgentResult({ + result, + toolState, + silent: payload.event.silent ?? false + }); return { - ...handleAgentResult(result), + ...mainResult, result: toolState.output }; } catch (_) { diff --git a/main.ts b/main.ts index 1ae3697..fc475ee 100644 --- a/main.ts +++ b/main.ts @@ -235,8 +235,14 @@ export async function main(): Promise { log.info(`::pullfrog-output::${Buffer.from(toolState.output).toString("base64")}`); } + const mainResult = await handleAgentResult({ + result, + toolState, + silent: payload.event.silent ?? false, + }); + return { - ...handleAgentResult(result), + ...mainResult, result: toolState.output, }; } catch (error) { diff --git a/utils/run.ts b/utils/run.ts index 3a46104..ece4d1d 100644 --- a/utils/run.ts +++ b/utils/run.ts @@ -1,13 +1,37 @@ import type { AgentResult } from "../agents/shared.ts"; import type { MainResult } from "../main.ts"; +import type { ToolState } from "../mcp/server.ts"; import { log } from "./cli.ts"; +import { reportErrorToComment } from "./errorReport.ts"; -export function handleAgentResult(result: AgentResult): MainResult { - if (!result.success) { +export interface HandleAgentResultParams { + result: AgentResult; + toolState: ToolState; + silent: boolean | undefined; +} + +export async function handleAgentResult(ctx: HandleAgentResultParams): Promise { + if (!ctx.result.success) { return { success: false, - error: result.error || "Agent execution failed", - output: result.output!, + error: ctx.result.error || "Agent execution failed", + output: ctx.result.output!, + }; + } + + if (!ctx.toolState.wasUpdated && ctx.toolState.progressCommentId && !ctx.silent) { + const error = ctx.result.error || "agent completed without reporting progress"; + try { + await reportErrorToComment({ + toolState: ctx.toolState, + error, + title: "Error", + }); + } catch {} + return { + success: false, + error, + output: ctx.result.output || "", }; } @@ -15,6 +39,6 @@ export function handleAgentResult(result: AgentResult): MainResult { return { success: true, - output: result.output || "", + output: ctx.result.output || "", }; }