fix: keep recoverable dispatch failures nonterminal

This commit is contained in:
lyon
2026-06-22 06:13:29 +08:00
parent ba49294ea7
commit b3f7175a3c
+10 -8
View File
@@ -297,7 +297,8 @@ export async function submitAgentRunChatTurn({ params = {}, options = {}, traceI
traceId,
backendProfile,
runId: reusable.mapping.runId,
stage: "command-create-reused"
stage: "command-create-reused",
terminalOnFailure: false
});
const commandId = requiredString(command?.id, "command.id");
traceStore.append(traceId, agentRunTraceEvent({
@@ -324,7 +325,8 @@ export async function submitAgentRunChatTurn({ params = {}, options = {}, traceI
backendProfile,
runId: reusable.mapping.runId,
commandId,
stage: "runner-job-ensure-reused"
stage: "runner-job-ensure-reused",
terminalOnFailure: false
});
} catch (error) {
if (!isAgentRunCommandAlreadyClaimed(error)) throw error;
@@ -488,7 +490,7 @@ export async function submitAgentRunChatTurn({ params = {}, options = {}, traceI
return decorateAgentRunRunningResult({ base: initialAgentRunChatResult({ params: finalDispatchParams, options, traceId }), mapping, traceStore, traceId });
}
async function agentRunDispatchJson({ fetchImpl, managerUrl, path, method = "GET", body = undefined, timeoutMs, env = process.env, traceStore = defaultCodeAgentTraceStore, traceId, backendProfile, runId = null, commandId = null, stage = "agentrun-dispatch" } = {}) {
async function agentRunDispatchJson({ fetchImpl, managerUrl, path, method = "GET", body = undefined, timeoutMs, env = process.env, traceStore = defaultCodeAgentTraceStore, traceId, backendProfile, runId = null, commandId = null, stage = "agentrun-dispatch", terminalOnFailure = true } = {}) {
const policy = agentRunDispatchRetryPolicy(env);
let retryAttempt = 0;
for (;;) {
@@ -501,7 +503,7 @@ async function agentRunDispatchJson({ fetchImpl, managerUrl, path, method = "GET
traceStore.append(traceId, agentRunTraceEvent({
type: "error",
eventType: "error",
status: "failed",
status: terminalOnFailure ? "failed" : "blocked",
label: retryable ? `agentrun:dispatch-retry-exhausted:${failureKind}` : `agentrun:dispatch-failed:${failureKind}`,
errorCode: failureKind,
failureKind,
@@ -512,11 +514,11 @@ async function agentRunDispatchJson({ fetchImpl, managerUrl, path, method = "GET
retryExhausted: retryable && retryAttempt >= policy.maxRetries,
runId,
commandId,
waitingFor: "agentrun-dispatch-failed",
waitingFor: terminalOnFailure ? "agentrun-dispatch-failed" : "agentrun-dispatch-recovery",
message: retryable
? `AgentRun dispatch transient ${failureKind}; retry ${retryAttempt}/${policy.maxRetries} exhausted at stage ${stage}. Code Agent stopped this turn.`
: `AgentRun dispatch failed with non-retryable ${failureKind} at stage ${stage}. Code Agent stopped this turn.`,
terminal: true,
? `AgentRun dispatch transient ${failureKind}; retry ${retryAttempt}/${policy.maxRetries} exhausted at stage ${stage}. ${terminalOnFailure ? "Code Agent stopped this turn." : "HWLAB will continue with the next recovery path for this turn."}`
: `AgentRun dispatch failed with non-retryable ${failureKind} at stage ${stage}. ${terminalOnFailure ? "Code Agent stopped this turn." : "HWLAB will continue with the next recovery path for this turn."}`,
terminal: terminalOnFailure,
valuesPrinted: false
}, backendProfile));
throw Object.assign(error, { retryAttempt, retryMax: policy.maxRetries, failureKind, retryExhausted: retryable && retryAttempt >= policy.maxRetries });