diff --git a/internal/cloud/code-agent-agentrun-adapter.ts b/internal/cloud/code-agent-agentrun-adapter.ts index f048039e..277333a7 100644 --- a/internal/cloud/code-agent-agentrun-adapter.ts +++ b/internal/cloud/code-agent-agentrun-adapter.ts @@ -2527,13 +2527,17 @@ function mapAgentRunEvent(event, mapping = {}) { return { ...base, type: "diff", eventType: "status", status: "running", label: "agentrun:diff", message: textPayload(payload, "diff") }; } if (event.type === "error") { - if (isRetryableProviderInterruptionPayload(payload, { activeError: true })) return agentRunProviderRetryEvent({ base, payload: { ...payload, willRetry: true }, status: "retrying", label: `agentrun:provider-retry:${String(payload.failureKind ?? "provider-stream-disconnected")}` }); - return { ...base, type: "error", eventType: "error", status: "failed", label: `agentrun:error:${String(payload.failureKind ?? "backend")}`, errorCode: payload.failureKind ?? "agentrun_error", failureKind: payload.failureKind ?? null, willRetry: payload.willRetry === true ? true : undefined, message: textPayload(payload, "AgentRun error") }; + const failureKind = normalizedFailureKind(payload.failureKind ?? payload.errorCode ?? "backend") ?? "backend"; + const normalizedPayload = { ...payload, failureKind, errorCode: failureKind }; + if (isRetryableProviderInterruptionPayload(normalizedPayload, { activeError: true })) return agentRunProviderRetryEvent({ base, payload: { ...normalizedPayload, willRetry: true }, status: "retrying", label: `agentrun:provider-retry:${failureKind}` }); + return { ...base, type: "error", eventType: "error", status: "failed", label: `agentrun:error:${failureKind}`, errorCode: failureKind, failureKind, willRetry: payload.willRetry === true ? true : undefined, message: textPayload(payload, "AgentRun error") }; } if (event.type === "terminal_status") { const terminalStatus = String(payload.terminalStatus ?? "failed"); - if (isRetryableProviderInterruptionPayload(payload)) return agentRunProviderRetryEvent({ base, payload, status: "retrying", label: `agentrun:provider-retry:${terminalStatus}` }); - return { ...base, type: "result", eventType: "terminal", status: terminalStatus === "cancelled" ? "canceled" : terminalStatus, label: `agentrun:terminal:${terminalStatus}`, errorCode: payload.failureKind ?? null, failureKind: payload.failureKind ?? null, willRetry: payload.willRetry === true ? true : undefined, message: textPayload(payload, `AgentRun terminal status ${terminalStatus}`), terminal: true }; + const failureKind = normalizedFailureKind(payload.failureKind ?? payload.errorCode) ?? null; + const normalizedPayload = failureKind ? { ...payload, failureKind, errorCode: failureKind } : payload; + if (isRetryableProviderInterruptionPayload(normalizedPayload)) return agentRunProviderRetryEvent({ base, payload: normalizedPayload, status: "retrying", label: `agentrun:provider-retry:${terminalStatus}` }); + return { ...base, type: "result", eventType: "terminal", status: terminalStatus === "cancelled" ? "canceled" : terminalStatus, label: `agentrun:terminal:${terminalStatus}`, errorCode: failureKind, failureKind, willRetry: payload.willRetry === true ? true : undefined, message: textPayload(payload, `AgentRun terminal status ${terminalStatus}`), terminal: true }; } return { ...base, type: "backend", eventType: "backend", status: "running", label: `agentrun:event:${String(event.type ?? "unknown")}`, message: textPayload(payload, "AgentRun event") }; } diff --git a/internal/cloud/server-code-agent-http.ts b/internal/cloud/server-code-agent-http.ts index 588636b2..db597f0c 100644 --- a/internal/cloud/server-code-agent-http.ts +++ b/internal/cloud/server-code-agent-http.ts @@ -1510,7 +1510,7 @@ async function resumeAgentRunProjectionCandidate({ candidate, options = {}, trac currentResult, options: resumeOptions, traceStore, - forceResultSync: false, + forceResultSync: true, refreshEvents: true }); const payload = codeAgentPayloadWithObservedTerminalStatus(synced?.result ?? currentResult, synced?.runnerTrace ?? traceStore?.snapshot?.(candidate.traceId)) ?? (synced?.result ?? currentResult); diff --git a/internal/cloud/server-workbench-http.test.ts b/internal/cloud/server-workbench-http.test.ts index 2daf1229..25a1ec33 100644 --- a/internal/cloud/server-workbench-http.test.ts +++ b/internal/cloud/server-workbench-http.test.ts @@ -115,7 +115,7 @@ test("workbench turn projection treats retryable provider stream disconnect as a assert.equal(completedProjection.finalResponse?.text, "retry recovered"); }); -test("workbench turn projection treats legacy agentrun-unreachable as retryable AgentRun transport interruption (#1853)", () => { +test("workbench turn projection sanitizes legacy agentrun-unreachable into retryable AgentRun transport interruption (#1853)", () => { const traceId = "trc_retryable_legacy_agentrun_unreachable"; const result = { traceId, @@ -144,6 +144,8 @@ test("workbench turn projection treats legacy agentrun-unreachable as retryable assert.equal(projection.running, true); assert.equal(projection.terminal, false); assert.equal(projection.finalResponse, null); + assert.equal(projection.source, "provider-retry"); + assert.equal(projection.terminalEvidence, null); assert.equal(durableTraceStatus(trace.events), "retrying"); assert.equal(traceTerminalEvidence(trace), null); });