|
11 | 11 | * dedup, no describeImages/structuredOutput, no recordSidecarOutcome. |
12 | 12 | */ |
13 | 13 | import type { AdapterRequest, ProviderAdapter } from "../adapters/base"; |
| 14 | +import { existsSync } from "node:fs"; |
14 | 15 | import { createAdapterEventQueue } from "../adapters/run-turn-queue"; |
15 | 16 | import type { AdapterEvent, OcxMessage, OcxParsedRequest, OcxProviderContinuationState, OcxRequestOptions, OcxThinkingContent, OcxUsage } from "../types"; |
16 | 17 | import { namespacedToolName } from "../types"; |
@@ -609,11 +610,11 @@ export async function runWithImageBridge(deps: ImageBridgeDeps): Promise<Respons |
609 | 610 | vResult = { ok: false, model: videoPlan!.model, prompt: "", files: [], count: 0, error: vArgs.error }; |
610 | 611 | } else { |
611 | 612 | paidVideoCalls += 1; |
| 613 | + const videoTimeout = videoTimeoutMs ?? 300_000; |
| 614 | + const deadlineSignal = AbortSignal.timeout(videoTimeout); |
612 | 615 | try { |
613 | | - const videoTimeout = videoTimeoutMs ?? 300_000; |
614 | 616 | const videoDeadline = Date.now() + videoTimeout; |
615 | 617 | // Bind submit to the shared deadline so submit + poll fit one budget. |
616 | | - const deadlineSignal = AbortSignal.timeout(videoTimeout); |
617 | 618 | const linkedDeadline = signal |
618 | 619 | ? AbortSignal.any([signal, deadlineSignal]) |
619 | 620 | : deadlineSignal; |
@@ -650,9 +651,14 @@ export async function runWithImageBridge(deps: ImageBridgeDeps): Promise<Respons |
650 | 651 | } |
651 | 652 | } |
652 | 653 | } catch (e) { |
653 | | - if (signal.aborted) throw new LoopError(499, "client closed request during video-bridge"); |
654 | | - const error = e instanceof Error ? e.message : String(e); |
655 | | - vResult = { ok: false, model: videoPlan!.model, prompt: vArgs.prompt ?? "", files: [], count: 0, error }; |
| 654 | + if (deadlineSignal.aborted && !signal.aborted) { |
| 655 | + vResult = { ok: false, model: videoPlan!.model, prompt: vArgs.prompt ?? "", files: [], count: 0, error: `video generation timed out after ${Math.floor(videoTimeout / 1000)}s` }; |
| 656 | + } else if (signal.aborted) { |
| 657 | + throw new LoopError(499, "client closed request during video-bridge"); |
| 658 | + } else { |
| 659 | + const error = e instanceof Error ? e.message : String(e); |
| 660 | + vResult = { ok: false, model: videoPlan!.model, prompt: vArgs.prompt ?? "", files: [], count: 0, error }; |
| 661 | + } |
656 | 662 | } |
657 | 663 | } |
658 | 664 | if (signal.aborted) throw new LoopError(499, "client closed request during video-bridge"); |
@@ -696,6 +702,12 @@ export async function runWithImageBridge(deps: ImageBridgeDeps): Promise<Respons |
696 | 702 | // Prune artifacts once after the entire batch so a tight keepCount |
697 | 703 | // cannot delete a video from an earlier call in this same iteration. |
698 | 704 | pruneArtifacts(videoPlan?.artifactsKeepCount ?? plan?.artifactsKeepCount); |
| 705 | + // Drop results whose artifact files were pruned — never hand the model a dead path. |
| 706 | + for (const f of fulfilled) { |
| 707 | + if (f.result.ok && f.result.path && !existsSync(f.result.path)) { |
| 708 | + f.result = { ...f.result, ok: false, path: undefined, files: [], count: 0, error: "artifact was pruned before delivery (increase artifactsKeepCount)" }; |
| 709 | + } |
| 710 | + } |
699 | 711 | const now = Date.now(); |
700 | 712 | messages.push({ |
701 | 713 | role: "assistant", |
|
0 commit comments