fix(delegate-task): recover sync results on abort race

This commit is contained in:
YeonGyu-Kim
2026-05-10 14:55:06 +09:00
parent 50699e3af1
commit a064e13676
6 changed files with 272 additions and 15 deletions
+30
View File
@@ -15,6 +15,11 @@ import { resolveMetadataModel } from "./resolve-metadata-model"
import { shouldRetryError } from "../../shared/model-error-classifier"
import type { ModelFallbackState } from "../../hooks/model-fallback/hook"
function shouldAttemptPollErrorRecovery(pollError: string): boolean {
const normalized = pollError.toLowerCase()
return normalized.includes("aborted") || normalized.includes("abort")
}
export async function executeSyncTask(
args: DelegateTaskArgs,
ctx: ToolContextWithMetadata,
@@ -213,6 +218,31 @@ export async function executeSyncTask(
taskId,
}, syncPollTimeoutMs)
if (pollError) {
if (shouldAttemptPollErrorRecovery(pollError)) {
const recoveredResult = await deps.fetchSyncResult(client, activeSessionID)
if (recoveredResult.ok) {
const duration = formatDuration(startTime)
const actualModelStr = effectiveCategoryModel
? `${effectiveCategoryModel.providerID}/${effectiveCategoryModel.modelID}`
: undefined
const parentModelStr = parentContext.model
? `${parentContext.model.providerID}/${parentContext.model.modelID}`
: undefined
let modelRoutingNote = ""
if (actualModelStr && parentModelStr && actualModelStr !== parentModelStr) {
modelRoutingNote = `\n⚠️ Model fallback used: requested ${parentModelStr}, executed ${actualModelStr}`
}
return `Task completed in ${duration}.\n\n---\n\n${recoveredResult.textContent || "(No text output)"}${modelRoutingNote}\n\n${buildTaskMetadataBlock({
sessionId: activeSessionID,
taskId: activeSessionID,
agent: agentToUse,
category: args.category,
})}`
}
}
const nextFallbackModel = shouldRetryError({ message: pollError })
? getNextSyncFallbackModel(activeSessionID, fallbackState)
: null