Skip to content

Commit 414616f

Browse files
steipetePeter Steinberger
andauthored
fix(video): harden DashScope task and media lifecycle (#117303)
* fix(video): validate DashScope task outputs and release request guards * fix(video): validate DashScope task outputs and release request guards * refactor(video): use shared empty-asset validation * fix(video): align DashScope Wan request contracts * refactor(video): use shared empty-asset validation * fix(video): enforce catalog modes before provider calls * fix(video): keep model checks fallback-aware * fix(video): centralize fallback-aware capability checks * docs(video): document Wan 2.7 fixed audio --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 0a99a85 commit 414616f

18 files changed

Lines changed: 993 additions & 209 deletions

‎docs/providers/alibaba.md‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,22 @@ The bundled `alibaba` plugin registers a video-generation provider for Wan model
8282

8383
## Capabilities and limits
8484

85-
All three modes share the same per-request video count and duration cap; only the input shape differs.
86-
87-
| Mode | Max output videos | Max input images | Max input videos | Max duration | Supported controls |
88-
| ------------------ | ----------------- | ---------------- | ---------------- | ------------ | --------------------------------------------------------- |
89-
| Text-to-video | 1 | n/a | n/a | 10 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
90-
| Image-to-video | 1 | 1 | n/a | 10 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
91-
| Reference-to-video | 1 | n/a | 4 | 10 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
92-
93-
A request that omits `durationSeconds` gets DashScope's accepted default of **5 seconds**. Set `durationSeconds` explicitly on the [video generation tool](/tools/video-generation) to extend up to 10 s.
85+
Each model advertises only its matching runtime mode. Geometry also follows the
86+
vendor protocol for that model family instead of sending one generic parameter shape.
87+
88+
| Mode | Max output videos | Reference limits | Max duration | Supported controls |
89+
| ---------------------------- | ----------------- | ------------------------------------- | ------------ | -------------------------------------------------------------------- |
90+
| Text-to-video | 1 | n/a | 15 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
91+
| Image-to-video | 1 | 1 image | 15 s | `resolution`, `audio`, `watermark` |
92+
| Reference-to-video (Wan 2.6) | 1 | 5 total images/videos; up to 3 videos | 10 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
93+
| Reference-to-video (Wan 2.7) | 1 | 5 total images/videos; up to 3 videos | 10 s | `size`, `aspectRatio`, `resolution`, `watermark`; audio is always on |
94+
95+
Wan 2.6 text/reference models translate `resolution` plus `aspectRatio` to the
96+
documented exact `size`. Wan 2.6 image-to-video sends the `resolution` tier and
97+
uses the input image's aspect ratio. Wan 2.7 reference-to-video sends the newer
98+
`media`, `resolution`, and `ratio` fields and always generates audio.
99+
100+
A request that omits `durationSeconds` gets DashScope's accepted default of **5 seconds**.
94101

95102
<Warning>
96103
Reference image and video inputs must be remote `http(s)` URLs; DashScope's reference modes reject local file paths. Upload to object storage first, or use the [media tool](/tools/media-overview) flow that already produces a public URL.

‎docs/providers/qwen.md‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,23 @@ To make Qwen the default video provider:
284284
}
285285
```
286286

287-
Video-generation limits: 1 output video per request, up to 1 input image
288-
(image-to-video), up to 4 input videos (video-to-video), max 10 seconds
289-
duration. Supports `size`, `aspectRatio`, `resolution`, `audio`, and
290-
`watermark`. Reference image/video inputs require remote http(s) URLs; local
291-
file paths are rejected up front because the DashScope video endpoint does not
292-
accept uploaded local buffers for those references.
287+
Each Wan model advertises only its matching runtime mode:
288+
289+
| Mode | Models | Reference limits | Max duration | Supported controls |
290+
| ---------------------------- | -------------------------------- | ------------------------------------- | ------------ | -------------------------------------------------------------------- |
291+
| Text-to-video | `wan2.6-t2v` | n/a | 15 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
292+
| Image-to-video | `wan2.6-i2v` | 1 image | 15 s | `resolution`, `audio`, `watermark` |
293+
| Reference-to-video (Wan 2.6) | `wan2.6-r2v`, `wan2.6-r2v-flash` | 5 total images/videos; up to 3 videos | 10 s | `size`, `aspectRatio`, `resolution`, `audio`, `watermark` |
294+
| Reference-to-video (Wan 2.7) | `wan2.7-r2v` | 5 total images/videos; up to 3 videos | 10 s | `size`, `aspectRatio`, `resolution`, `watermark`; audio is always on |
295+
296+
Wan 2.6 text/reference models translate `resolution` plus `aspectRatio` to the
297+
documented exact `size`. Wan 2.6 image-to-video sends the `resolution` tier and
298+
uses the input image's aspect ratio. Wan 2.7 reference-to-video sends
299+
`media`, `resolution`, and `ratio` and always generates audio.
300+
301+
Reference image/video inputs require remote http(s) URLs; local file paths are
302+
rejected up front because the DashScope video endpoint does not accept uploaded
303+
local buffers for those references.
293304

294305
<Note>
295306
See [Video generation](/tools/video-generation) for shared tool parameters, provider selection, and failover behavior.

‎extensions/alibaba/video-generation-provider.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ describe("alibaba video generation provider", () => {
282282
expect(body.model).toBe("wan2.6-r2v-flash");
283283
const input = requireRecord(body.input, "DashScope request input");
284284
expect(input.prompt).toBe("animate this shot");
285-
expect(input.img_url).toBe("https://example.com/ref.png");
285+
expect(input.reference_urls).toEqual(["https://example.com/ref.png"]);
286286
const parameters = requireRecord(body.parameters, "DashScope request parameters");
287287
expect(parameters.duration).toBe(6);
288-
expect(parameters.enable_audio).toBe(true);
288+
expect(parameters.audio).toBe(true);
289289
expect(parameters.watermark).toBe(false);
290290
expectDashscopeVideoTaskPoll(fetchWithTimeoutMock);
291291
expectSuccessfulDashscopeVideoResult(result);

‎extensions/qwen/video-generation-provider.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ describe("qwen video generation provider", () => {
255255
model: "wan2.6-r2v-flash",
256256
input: {
257257
prompt: "animate this shot",
258-
img_url: "https://example.com/ref.png",
258+
reference_urls: ["https://example.com/ref.png"],
259259
},
260260
parameters: {
261261
duration: 6,
262-
enable_audio: true,
262+
audio: true,
263263
},
264264
},
265265
});
@@ -378,7 +378,7 @@ describe("qwen video generation provider", () => {
378378
await expect(
379379
provider.generateVideo({
380380
provider: "qwen",
381-
model: "wan2.6-r2v-flash",
381+
model: "wan2.6-t2v",
382382
prompt: "short video",
383383
cfg: { agents: { defaults: { mediaMaxMb: 0.000001 } } },
384384
}),

‎src/agents/tools/video-generate-tool.test.ts‎

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ describe("createVideoGenerateTool", () => {
16411641
});
16421642
});
16431643

1644-
it("rejects image-to-video when the provider disables that mode", async () => {
1644+
it("defers disabled primary modes to the fallback-aware runtime", async () => {
16451645
vi.spyOn(videoGenerationRuntime, "listRuntimeVideoGenerationProviders").mockReturnValue([
16461646
{
16471647
id: "video-plugin",
@@ -1657,7 +1657,7 @@ describe("createVideoGenerateTool", () => {
16571657
}),
16581658
},
16591659
]);
1660-
const generateSpy = vi.spyOn(videoGenerationRuntime, "generateVideo");
1660+
const generateSpy = mockSavedVideoResult();
16611661

16621662
const tool = createVideoGenerateTool({
16631663
config: asConfig({
@@ -1672,13 +1672,64 @@ describe("createVideoGenerateTool", () => {
16721672
throw new Error("expected video_generate tool");
16731673
}
16741674

1675-
await expect(
1676-
tool.execute("call-1", {
1677-
prompt: "lobster timelapse",
1678-
image: "data:image/png;base64,cG5n",
1675+
await tool.execute("call-1", {
1676+
prompt: "lobster timelapse",
1677+
image: "data:image/png;base64,cG5n",
1678+
});
1679+
1680+
const request = firstMockCallArg(generateSpy) as { inputImages?: unknown[] };
1681+
expect(request.inputImages).toHaveLength(1);
1682+
});
1683+
1684+
it("defers model-specific reference limits to runtime overlays", async () => {
1685+
vi.spyOn(videoGenerationRuntime, "listRuntimeVideoGenerationProviders").mockReturnValue([
1686+
{
1687+
id: "video-plugin",
1688+
defaultModel: "r2v",
1689+
models: ["r2v"],
1690+
capabilities: {
1691+
imageToVideo: {
1692+
enabled: true,
1693+
maxInputImages: 1,
1694+
},
1695+
},
1696+
catalogByModel: {
1697+
r2v: {
1698+
modes: ["imageToVideo"],
1699+
capabilities: {
1700+
imageToVideo: {
1701+
enabled: true,
1702+
maxInputImages: 5,
1703+
},
1704+
},
1705+
},
1706+
},
1707+
generateVideo: vi.fn(async () => {
1708+
throw new Error("not used");
1709+
}),
1710+
},
1711+
]);
1712+
const generateSpy = mockSavedVideoResult();
1713+
const tool = createVideoGenerateTool({
1714+
config: asConfig({
1715+
agents: {
1716+
defaults: {
1717+
videoGenerationModel: { primary: "video-plugin/r2v" },
1718+
},
1719+
},
16791720
}),
1680-
).rejects.toThrow("video-plugin does not support image-to-video reference inputs.");
1681-
expect(generateSpy).not.toHaveBeenCalled();
1721+
});
1722+
if (!tool) {
1723+
throw new Error("expected video_generate tool");
1724+
}
1725+
1726+
await tool.execute("call-r2v", {
1727+
prompt: "animate both references",
1728+
images: ["data:image/png;base64,cG5n", "data:image/png;base64,cG5nMg=="],
1729+
});
1730+
1731+
const request = firstMockCallArg(generateSpy) as { inputImages?: unknown[] };
1732+
expect(request.inputImages).toHaveLength(2);
16821733
});
16831734

16841735
it("warns when optional provider overrides are ignored", async () => {

‎src/agents/tools/video-generate-tool.ts‎

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import { isManifestPluginAvailableForControlPlane } from "../../plugins/manifest
1717
import type { PluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.types.js";
1818
import { resolveUserPath } from "../../utils.js";
1919
import type { DeliveryContext } from "../../utils/delivery-context.js";
20-
import {
21-
resolveVideoGenerationMode,
22-
resolveVideoGenerationModeCapabilities,
23-
} from "../../video-generation/capabilities.js";
2420
import { parseVideoGenerationModelRef } from "../../video-generation/model-ref.js";
2521
import {
2622
generateVideo,
@@ -459,85 +455,6 @@ function resolveSelectedVideoGenerationProvider(params: {
459455
});
460456
}
461457

462-
function validateVideoGenerationCapabilities(params: {
463-
provider: VideoGenerationProvider | undefined;
464-
model?: string;
465-
inputImageCount: number;
466-
inputVideoCount: number;
467-
inputAudioCount: number;
468-
size?: string;
469-
aspectRatio?: string;
470-
resolution?: VideoGenerationResolution;
471-
durationSeconds?: number;
472-
audio?: boolean;
473-
watermark?: boolean;
474-
}) {
475-
const provider = params.provider;
476-
if (!provider) {
477-
return;
478-
}
479-
const mode = resolveVideoGenerationMode({
480-
inputImageCount: params.inputImageCount,
481-
inputVideoCount: params.inputVideoCount,
482-
});
483-
const { capabilities: caps } = resolveVideoGenerationModeCapabilities({
484-
provider,
485-
model: params.model,
486-
inputImageCount: params.inputImageCount,
487-
inputVideoCount: params.inputVideoCount,
488-
});
489-
if (!caps && mode === "imageToVideo" && params.inputVideoCount === 0) {
490-
throw new ToolInputError(`${provider.id} does not support image-to-video reference inputs.`);
491-
}
492-
if (!caps && mode === "videoToVideo" && params.inputImageCount === 0) {
493-
throw new ToolInputError(`${provider.id} does not support video-to-video reference inputs.`);
494-
}
495-
if (!caps) {
496-
return;
497-
}
498-
if (
499-
mode === "imageToVideo" &&
500-
"enabled" in caps &&
501-
!caps.enabled &&
502-
params.inputVideoCount === 0
503-
) {
504-
throw new ToolInputError(`${provider.id} does not support image-to-video reference inputs.`);
505-
}
506-
if (
507-
mode === "videoToVideo" &&
508-
"enabled" in caps &&
509-
!caps.enabled &&
510-
params.inputImageCount === 0
511-
) {
512-
throw new ToolInputError(`${provider.id} does not support video-to-video reference inputs.`);
513-
}
514-
if (params.inputImageCount > 0) {
515-
const maxInputImages = caps.maxInputImages ?? MAX_INPUT_IMAGES;
516-
if (params.inputImageCount > maxInputImages) {
517-
throw new ToolInputError(
518-
`${provider.id} supports at most ${maxInputImages} reference image${maxInputImages === 1 ? "" : "s"}.`,
519-
);
520-
}
521-
}
522-
if (params.inputVideoCount > 0) {
523-
const maxInputVideos = caps.maxInputVideos ?? MAX_INPUT_VIDEOS;
524-
if (params.inputVideoCount > maxInputVideos) {
525-
throw new ToolInputError(
526-
`${provider.id} supports at most ${maxInputVideos} reference video${maxInputVideos === 1 ? "" : "s"}.`,
527-
);
528-
}
529-
}
530-
// Audio-count validation is intentionally deferred to runtime.ts (generateVideo).
531-
// The runtime guard skips per-candidate providers that lack audio support, allowing
532-
// fallback candidates that do support audio to run. A ToolInputError here would fire
533-
// against only the primary provider and prevent valid fallback-based audio requests.
534-
// maxDurationSeconds validation is intentionally deferred to runtime.ts (generateVideo).
535-
// The runtime guard skips per-candidate providers whose hard cap is below the requested
536-
// duration, allowing a fallback with a higher cap to run — same rationale as the audio
537-
// check above. When providers declare an explicit supportedDurationSeconds list, runtime
538-
// normalization snaps to the nearest valid value instead of skipping.
539-
}
540-
541458
function formatIgnoredVideoGenerationOverride(override: VideoGenerationIgnoredOverride): string {
542459
return `${sanitizeGeneratedMediaDisplayText(override.key)}=${sanitizeGeneratedMediaDisplayText(String(override.value))}`;
543460
}
@@ -1223,20 +1140,6 @@ export function createVideoGenerateTool(options?: {
12231140
asset.sourceAsset.role = role;
12241141
}
12251142
}
1226-
validateVideoGenerationCapabilities({
1227-
provider: selectedProvider,
1228-
model:
1229-
parseVideoGenerationModelRef(model)?.model ?? model ?? selectedProvider?.defaultModel,
1230-
inputImageCount: loadedReferenceImages.length,
1231-
inputVideoCount: loadedReferenceVideos.length,
1232-
inputAudioCount: loadedReferenceAudios.length,
1233-
size,
1234-
aspectRatio,
1235-
resolution,
1236-
durationSeconds,
1237-
audio,
1238-
watermark,
1239-
});
12401143
// Accepted tasks own their paid work independently; cancellation applies only before admission.
12411144
signal?.throwIfAborted();
12421145
const taskHandle = createVideoGenerationTaskRun({

‎src/plugin-sdk/video-generation.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import type { AuthProfileStore } from "../agents/auth-profiles/types.js";
77
import type { OpenClawConfig } from "../config/types.openclaw.js";
88
import {
9+
DASHSCOPE_WAN_VIDEO_CATALOG_BY_MODEL,
910
DASHSCOPE_WAN_VIDEO_CAPABILITIES,
1011
DASHSCOPE_WAN_VIDEO_MODELS,
1112
DEFAULT_DASHSCOPE_WAN_VIDEO_MODEL,
@@ -288,6 +289,9 @@ export function buildDashscopeVideoGenerationProvider(
288289
label: options.label,
289290
defaultModel: DEFAULT_DASHSCOPE_WAN_VIDEO_MODEL,
290291
models: [...DASHSCOPE_WAN_VIDEO_MODELS],
292+
catalogByModel: DASHSCOPE_WAN_VIDEO_CATALOG_BY_MODEL,
293+
resolveModelCapabilities: ({ model }) =>
294+
DASHSCOPE_WAN_VIDEO_CATALOG_BY_MODEL[model]?.capabilities,
291295
isConfigured: (ctx) => {
292296
const baseUrl = ctx.cfg?.models?.providers?.[options.providerId]?.baseUrl;
293297
if (options.credentialPolicy?.acceptsBaseUrl?.(baseUrl) === false) {

‎src/video-generation/capabilities.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { describe, expect, it } from "vitest";
33
import {
44
listSupportedVideoGenerationModes,
5-
resolveVideoGenerationMode,
65
resolveVideoGenerationModeCapabilities,
76
} from "./capabilities.js";
87
import type { VideoGenerationProvider } from "./types.js";
@@ -64,7 +63,6 @@ describe("video-generation capabilities", () => {
6463
supportsAudio: true,
6564
});
6665

67-
expect(resolveVideoGenerationMode({ inputImageCount: 1, inputVideoCount: 1 })).toBeNull();
6866
expect(
6967
resolveVideoGenerationModeCapabilities({
7068
provider,
@@ -91,7 +89,6 @@ describe("video-generation capabilities", () => {
9189
},
9290
});
9391

94-
expect(resolveVideoGenerationMode({ inputImageCount: 1, inputVideoCount: 1 })).toBeNull();
9592
expect(
9693
resolveVideoGenerationModeCapabilities({
9794
provider,

‎src/video-generation/capabilities.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88

99
// Video generation mode helpers derive the active mode from reference inputs
1010
// and expose the provider capability block that applies to that mode/model.
11-
export function resolveVideoGenerationMode(params: {
11+
function resolveVideoGenerationMode(params: {
1212
inputImageCount?: number;
1313
inputVideoCount?: number;
1414
}): VideoGenerationMode | null {

0 commit comments

Comments
 (0)