fix: hard-cap detail plan runtime with true timeout race
This commit is contained in:
parent
b6a12ced9f
commit
6df4d37bf4
@ -17,8 +17,8 @@ export const maxDuration = 180;
|
||||
const DETAIL_PLAN_INLINE_MAX_IMAGES = 4;
|
||||
const DETAIL_PLAN_INLINE_TIMEOUT_MS = 4000;
|
||||
const DETAIL_PLAN_INLINE_RETRIES = 1;
|
||||
const DETAIL_PLAN_MAIN_TIMEOUT_MS = 55000;
|
||||
const DETAIL_PLAN_PREFLIGHT_TIMEOUT_MS = 35000;
|
||||
const DETAIL_PLAN_MAIN_TIMEOUT_MS = 20000;
|
||||
const DETAIL_PLAN_PREFLIGHT_TIMEOUT_MS = 10000;
|
||||
|
||||
function isAbortError(error: unknown): boolean {
|
||||
const target = error as {
|
||||
@ -63,14 +63,23 @@ function isVolcanoResponsesPlanner(config: {
|
||||
|
||||
async function generateTextWithTimeout(params: any, timeoutMs: number) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||
timer = setTimeout(() => {
|
||||
controller.abort();
|
||||
reject(new Error(`OperationTimeoutError: generateText timed out after ${timeoutMs}ms`));
|
||||
}, timeoutMs);
|
||||
});
|
||||
try {
|
||||
return await generateText({
|
||||
...params,
|
||||
abortSignal: controller.signal,
|
||||
} as any);
|
||||
return await Promise.race([
|
||||
generateText({
|
||||
...params,
|
||||
abortSignal: controller.signal,
|
||||
} as any),
|
||||
timeoutPromise,
|
||||
]);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
if (timer) clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1749,7 +1758,11 @@ export async function POST(request: Request) {
|
||||
text = String(result?.text || "");
|
||||
} catch (error) {
|
||||
const message = String((error as Error)?.message || "");
|
||||
if (isAbortError(error) || /invalid scheme/i.test(message)) {
|
||||
if (
|
||||
isAbortError(error) ||
|
||||
/invalid scheme/i.test(message) ||
|
||||
/operationtimeouterror|timed out|timeout/i.test(message)
|
||||
) {
|
||||
console.error("[Canvas Detail Plan] Primary planning aborted, fallback applied:", error);
|
||||
const fallbackReason = /invalid scheme/i.test(message)
|
||||
? "规划模型图片输入协议不兼容,已回退到稳定分镜模板。"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user