Skip to content

Commit ad6c584

Browse files
committed
fix: ignore unsupported video generation overrides
1 parent c4cc557 commit ad6c584

10 files changed

Lines changed: 382 additions & 33 deletions

File tree

‎docs/providers/openai.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ The bundled `openai` plugin also registers video generation through the shared
145145
- Default video model: `openai/sora-2`
146146
- Modes: text-to-video, image-to-video, and single-video reference/edit flows
147147
- Current limits: 1 image or 1 video reference input
148-
- Current OpenAI-specific caveat: OpenClaw does not forward `aspectRatio` or
149-
`resolution` overrides to the native OpenAI video API today
148+
- Current OpenAI-specific caveat: OpenClaw currently only forwards `size`
149+
overrides for native OpenAI video generation. Unsupported optional overrides
150+
such as `aspectRatio`, `resolution`, `audio`, and `watermark` are ignored
151+
and reported back as a tool warning.
150152

151153
To use OpenAI as the default video provider:
152154

‎docs/tools/video-generation.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Use `action: "list"` to inspect available providers and models at runtime:
8282
| `watermark` | boolean | Toggle provider watermarking when supported |
8383
| `filename` | string | Output filename hint |
8484

85-
Not all providers support all parameters. The tool validates provider capability limits before it submits the request. When a provider or model only supports a discrete set of video lengths, OpenClaw rounds `durationSeconds` to the nearest supported value and reports the normalized duration in the tool result.
85+
Not all providers support all parameters. Unsupported optional overrides are ignored on a best-effort basis and reported back in the tool result as a warning. Hard capability limits such as too many reference inputs still fail before submission. When a provider or model only supports a discrete set of video lengths, OpenClaw rounds `durationSeconds` to the nearest supported value and reports the normalized duration in the tool result.
8686

8787
## Async behavior
8888

‎extensions/video-generation-core/src/runtime.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe("video-generation runtime", () => {
108108
expect(result.provider).toBe("video-plugin");
109109
expect(result.model).toBe("vid-v1");
110110
expect(result.attempts).toEqual([]);
111+
expect(result.ignoredOverrides).toEqual([]);
111112
expect(seenAuthStore).toEqual(authStore);
112113
expect(result.videos).toEqual([
113114
{
@@ -161,4 +162,66 @@ describe("video-generation runtime", () => {
161162
);
162163
await expect(promise).rejects.toThrow("qwen: QWEN_API_KEY");
163164
});
165+
166+
it("ignores unsupported optional overrides per provider", async () => {
167+
let seenRequest:
168+
| {
169+
size?: string;
170+
aspectRatio?: string;
171+
resolution?: string;
172+
audio?: boolean;
173+
watermark?: boolean;
174+
}
175+
| undefined;
176+
mocks.resolveAgentModelPrimaryValue.mockReturnValue("openai/sora-2");
177+
mocks.getVideoGenerationProvider.mockReturnValue({
178+
id: "openai",
179+
capabilities: {
180+
supportsSize: true,
181+
},
182+
generateVideo: async (req) => {
183+
seenRequest = {
184+
size: req.size,
185+
aspectRatio: req.aspectRatio,
186+
resolution: req.resolution,
187+
audio: req.audio,
188+
watermark: req.watermark,
189+
};
190+
return {
191+
videos: [{ buffer: Buffer.from("mp4-bytes"), mimeType: "video/mp4" }],
192+
model: "sora-2",
193+
};
194+
},
195+
});
196+
197+
const result = await generateVideo({
198+
cfg: {
199+
agents: {
200+
defaults: {
201+
videoGenerationModel: { primary: "openai/sora-2" },
202+
},
203+
},
204+
} as OpenClawConfig,
205+
prompt: "animate a lobster",
206+
size: "1280x720",
207+
aspectRatio: "16:9",
208+
resolution: "720P",
209+
audio: false,
210+
watermark: false,
211+
});
212+
213+
expect(seenRequest).toEqual({
214+
size: "1280x720",
215+
aspectRatio: undefined,
216+
resolution: undefined,
217+
audio: undefined,
218+
watermark: undefined,
219+
});
220+
expect(result.ignoredOverrides).toEqual([
221+
{ key: "aspectRatio", value: "16:9" },
222+
{ key: "resolution", value: "720P" },
223+
{ key: "audio", value: false },
224+
{ key: "watermark", value: false },
225+
]);
226+
});
164227
});

‎extensions/video-generation-core/src/runtime.ts‎

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type FallbackAttempt,
1313
type GeneratedVideoAsset,
1414
type OpenClawConfig,
15+
type VideoGenerationIgnoredOverride,
1516
type VideoGenerationResolution,
1617
type VideoGenerationResult,
1718
type VideoGenerationSourceAsset,
@@ -41,6 +42,7 @@ export type GenerateVideoRuntimeResult = {
4142
model: string;
4243
attempts: FallbackAttempt[];
4344
metadata?: Record<string, unknown>;
45+
ignoredOverrides: VideoGenerationIgnoredOverride[];
4446
};
4547

4648
function resolveVideoGenerationCandidates(params: {
@@ -116,6 +118,57 @@ export function listRuntimeVideoGenerationProviders(params?: { config?: OpenClaw
116118
return listVideoGenerationProviders(params?.config);
117119
}
118120

121+
function resolveProviderVideoGenerationOverrides(params: {
122+
provider: NonNullable<ReturnType<typeof getVideoGenerationProvider>>;
123+
size?: string;
124+
aspectRatio?: string;
125+
resolution?: VideoGenerationResolution;
126+
audio?: boolean;
127+
watermark?: boolean;
128+
}) {
129+
const caps = params.provider.capabilities;
130+
const ignoredOverrides: VideoGenerationIgnoredOverride[] = [];
131+
let size = params.size;
132+
let aspectRatio = params.aspectRatio;
133+
let resolution = params.resolution;
134+
let audio = params.audio;
135+
let watermark = params.watermark;
136+
137+
if (size && !caps.supportsSize) {
138+
ignoredOverrides.push({ key: "size", value: size });
139+
size = undefined;
140+
}
141+
142+
if (aspectRatio && !caps.supportsAspectRatio) {
143+
ignoredOverrides.push({ key: "aspectRatio", value: aspectRatio });
144+
aspectRatio = undefined;
145+
}
146+
147+
if (resolution && !caps.supportsResolution) {
148+
ignoredOverrides.push({ key: "resolution", value: resolution });
149+
resolution = undefined;
150+
}
151+
152+
if (typeof audio === "boolean" && !caps.supportsAudio) {
153+
ignoredOverrides.push({ key: "audio", value: audio });
154+
audio = undefined;
155+
}
156+
157+
if (typeof watermark === "boolean" && !caps.supportsWatermark) {
158+
ignoredOverrides.push({ key: "watermark", value: watermark });
159+
watermark = undefined;
160+
}
161+
162+
return {
163+
size,
164+
aspectRatio,
165+
resolution,
166+
audio,
167+
watermark,
168+
ignoredOverrides,
169+
};
170+
}
171+
119172
export async function generateVideo(
120173
params: GenerateVideoParams,
121174
): Promise<GenerateVideoRuntimeResult> {
@@ -144,19 +197,27 @@ export async function generateVideo(
144197
}
145198

146199
try {
200+
const sanitized = resolveProviderVideoGenerationOverrides({
201+
provider,
202+
size: params.size,
203+
aspectRatio: params.aspectRatio,
204+
resolution: params.resolution,
205+
audio: params.audio,
206+
watermark: params.watermark,
207+
});
147208
const result: VideoGenerationResult = await provider.generateVideo({
148209
provider: candidate.provider,
149210
model: candidate.model,
150211
prompt: params.prompt,
151212
cfg: params.cfg,
152213
agentDir: params.agentDir,
153214
authStore: params.authStore,
154-
size: params.size,
155-
aspectRatio: params.aspectRatio,
156-
resolution: params.resolution,
215+
size: sanitized.size,
216+
aspectRatio: sanitized.aspectRatio,
217+
resolution: sanitized.resolution,
157218
durationSeconds: params.durationSeconds,
158-
audio: params.audio,
159-
watermark: params.watermark,
219+
audio: sanitized.audio,
220+
watermark: sanitized.watermark,
160221
inputImages: params.inputImages,
161222
inputVideos: params.inputVideos,
162223
});
@@ -168,6 +229,7 @@ export async function generateVideo(
168229
provider: candidate.provider,
169230
model: result.model ?? candidate.model,
170231
attempts,
232+
ignoredOverrides: sanitized.ignoredOverrides,
171233
metadata: result.metadata,
172234
};
173235
} catch (err) {

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe("createVideoGenerateTool", () => {
7070
provider: "qwen",
7171
model: "wan2.6-t2v",
7272
attempts: [],
73+
ignoredOverrides: [],
7374
videos: [
7475
{
7576
buffer: Buffer.from("video-bytes"),
@@ -240,6 +241,7 @@ describe("createVideoGenerateTool", () => {
240241
provider: "google",
241242
model: "veo-3.1-fast-generate-preview",
242243
attempts: [],
244+
ignoredOverrides: [],
243245
videos: [
244246
{
245247
buffer: Buffer.from("video-bytes"),
@@ -320,4 +322,85 @@ describe("createVideoGenerateTool", () => {
320322
const text = (result.content?.[0] as { text: string } | undefined)?.text ?? "";
321323
expect(text).toContain("supportedDurationSeconds=4/6/8");
322324
});
325+
326+
it("warns when optional provider overrides are ignored", async () => {
327+
vi.spyOn(videoGenerationRuntime, "listRuntimeVideoGenerationProviders").mockReturnValue([
328+
{
329+
id: "openai",
330+
defaultModel: "sora-2",
331+
models: ["sora-2"],
332+
capabilities: {
333+
supportsSize: true,
334+
},
335+
generateVideo: vi.fn(async () => {
336+
throw new Error("not used");
337+
}),
338+
},
339+
]);
340+
vi.spyOn(videoGenerationRuntime, "generateVideo").mockResolvedValue({
341+
provider: "openai",
342+
model: "sora-2",
343+
attempts: [],
344+
ignoredOverrides: [
345+
{ key: "resolution", value: "720P" },
346+
{ key: "audio", value: false },
347+
{ key: "watermark", value: false },
348+
],
349+
videos: [
350+
{
351+
buffer: Buffer.from("video-bytes"),
352+
mimeType: "video/mp4",
353+
fileName: "lobster.mp4",
354+
},
355+
],
356+
});
357+
vi.spyOn(mediaStore, "saveMediaBuffer").mockResolvedValueOnce({
358+
path: "/tmp/generated-lobster.mp4",
359+
id: "generated-lobster.mp4",
360+
size: 11,
361+
contentType: "video/mp4",
362+
});
363+
364+
const tool = createVideoGenerateTool({
365+
config: asConfig({
366+
agents: {
367+
defaults: {
368+
videoGenerationModel: { primary: "openai/sora-2" },
369+
},
370+
},
371+
}),
372+
});
373+
if (!tool) {
374+
throw new Error("expected video_generate tool");
375+
}
376+
377+
const result = await tool.execute("call-openai-generate", {
378+
prompt: "A lobster on a neon bridge",
379+
size: "1280x720",
380+
resolution: "720P",
381+
audio: false,
382+
watermark: false,
383+
});
384+
const text = (result.content?.[0] as { text: string } | undefined)?.text ?? "";
385+
386+
expect(text).toContain("Generated 1 video with openai/sora-2.");
387+
expect(text).toContain(
388+
"Warning: Ignored unsupported overrides for openai/sora-2: resolution=720P, audio=false, watermark=false.",
389+
);
390+
expect(result).toMatchObject({
391+
details: {
392+
size: "1280x720",
393+
warning:
394+
"Ignored unsupported overrides for openai/sora-2: resolution=720P, audio=false, watermark=false.",
395+
ignoredOverrides: [
396+
{ key: "resolution", value: "720P" },
397+
{ key: "audio", value: false },
398+
{ key: "watermark", value: false },
399+
],
400+
},
401+
});
402+
expect(result.details).not.toHaveProperty("resolution");
403+
expect(result.details).not.toHaveProperty("audio");
404+
expect(result.details).not.toHaveProperty("watermark");
405+
});
323406
});

0 commit comments

Comments
 (0)