fix(delegate-task): recover sync results on abort race
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user