Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): address adversarial review findings on video parameter recall

Lincoln Stein2d4323c408f4
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts
index 1609df6eb9..c88ccdd4b6 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts
@@ -7,6 +7,7 @@ import { galleryImages, galleryItems, galleryVideos } from '@features/gallery';
import {
createDefaultVideoWidgetValues,
createVideoSourceClip,
+ getVideoModelPolicy,
normalizeVideoWidgetValues,
syncVideoWidgetValuesWithModels,
} from '@features/video';
@@ -151,16 +152,28 @@ export const executeVideoRecall = async ({
assertAccountScopeCurrent(owner);
if (sourceItem?.kind === 'video') {
+ const rebuiltClip = createVideoSourceClip({
+ durationSeconds: sourceItem.durationSeconds,
+ fps: sourceItem.fps,
+ height: sourceItem.height,
+ name: sourceItem.name,
+ width: sourceItem.width,
+ });
+ // Restore the recorded trim, clamped to the fresh estimate (which
+ // can differ from the run's own) — the default trim would extend
+ // from a completely different frame than the run did.
+ const trim = rebuiltClip.numFrames >= 2 ? result.mediaNames.sourceVideoTrim : null;
+ const startFrame = trim
+ ? Math.min(Math.max(trim.startFrame, 0), rebuiltClip.numFrames - 2)
+ : rebuiltClip.startFrame;
+ const endFrame = trim
+ ? Math.min(Math.max(trim.endFrame, startFrame + 1), rebuiltClip.numFrames - 1)
+ : rebuiltClip.endFrame;
+
result.values = {
...result.values,
firstFrameImage: null,
- sourceVideo: createVideoSourceClip({
- durationSeconds: sourceItem.durationSeconds,
- fps: sourceItem.fps,
- height: sourceItem.height,
- name: sourceItem.name,
- width: sourceItem.width,
- }),
+ sourceVideo: { ...rebuiltClip, endFrame, startFrame },
};
recalledMedia = true;
}
@@ -173,6 +186,42 @@ export const executeVideoRecall = async ({
if (!recalledMedia) {
result.fields = result.fields.filter((field) => field !== 'media');
}
+
+ // What survived hydration can imply a mode the effective model rejects
+ // — a deleted first frame leaves an interpolate recall holding only its
+ // last frame (no Wan mode), and an uninstalled recorded model leaves
+ // i2v media on whatever main the panel kept. Reconcile with the same
+ // rules the model-selection transition applies, so the recall never
+ // assembles an un-generatable panel behind a success toast.
+ const effectiveModel = result.values.model;
+
+ if (effectiveModel) {
+ const modes = getVideoModelPolicy(effectiveModel, result.values).modes;
+ let { firstFrameImage, lastFrameImage, sourceVideo } = result.values;
+
+ if (sourceVideo && !modes.includes('extend')) {
+ sourceVideo = null;
+ }
+ if (firstFrameImage && !modes.includes('first-frame') && !modes.includes('first-last')) {
+ firstFrameImage = null;
+ }
+ if (lastFrameImage) {
+ const lastFrameSupported =
+ firstFrameImage || sourceVideo ? modes.includes('first-last') : modes.includes('last-frame');
+
+ if (!lastFrameSupported) {
+ lastFrameImage = null;
+ }
+ }
+
+ if (
+ firstFrameImage !== result.values.firstFrameImage ||
+ lastFrameImage !== result.values.lastFrameImage ||
+ sourceVideo !== result.values.sourceVideo
+ ) {
+ result.values = { ...result.values, firstFrameImage, lastFrameImage, sourceVideo };
+ }
+ }
}
if (result.fields.length === 0) {
@@ -189,8 +238,10 @@ export const executeVideoRecall = async ({
commands.generation.patchPromptDraft(result.promptPatch, 'video', projectId);
}
// A prompts-only recall changes no widget values — skip the whole-values
- // write (and the lost-update window it would widen).
- if (result.values !== currentValues || result.fields.some((field) => field !== 'prompts')) {
+ // write (and the lost-update window it would widen). The builder always
+ // returns a fresh copy, so the fields list, not object identity, is the
+ // signal.
+ if (result.fields.some((field) => field !== 'prompts')) {
commands.widgets.patchValues('video', { ...result.values }, projectId);
}
commands.notifications.add({
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts
index c967e21f82..4b120b4a85 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts
@@ -255,10 +255,43 @@ describe('buildVideoRecallSettings', () => {
const result = buildVideoRecallSettings({ currentValues, kind: 'all', metadata, models: catalog });
expect(result?.fields).toContain('media');
- expect(result?.mediaNames).toEqual({ firstFrameName: 'first.png', lastFrameName: null, sourceVideoName: null });
+ expect(result?.mediaNames).toEqual({
+ firstFrameName: 'first.png',
+ lastFrameName: null,
+ sourceVideoName: null,
+ sourceVideoTrim: null,
+ });
expect(result?.values.firstFrameImage).toBeNull();
});
+ it('recalls the recorded Wan fps and carries the source-clip trim bounds for the executor', () => {
+ const withFps = buildVideoRecallSettings({
+ currentValues,
+ kind: 'all',
+ metadata: wanMetadata({ fps: 24 }),
+ models: catalog,
+ });
+
+ expect(withFps?.fields).toContain('fps');
+ expect(withFps?.values.fps).toBe(24);
+
+ const extend = buildVideoRecallSettings({
+ currentValues,
+ kind: 'all',
+ metadata: wanMetadata({
+ generation_mode: 'wan_extend_video',
+ model: { key: WAN_I2V.key },
+ source_video: { video_name: 'clip.mp4' },
+ source_video_end_frame: 50,
+ source_video_start_frame: 10,
+ }),
+ models: catalog,
+ });
+
+ expect(extend?.mediaNames.sourceVideoName).toBe('clip.mp4');
+ expect(extend?.mediaNames.sourceVideoTrim).toEqual({ endFrame: 50, startFrame: 10 });
+ });
+
it('restores reuse-primary semantics when the low-noise CFG key is absent', () => {
const withLow = { ...createDefaultVideoWidgetValues([WAN_T2V]), cfgScaleLowNoise: 2 };
// wan_t2v metadata without guidance_scale_low_noise: the run reused the
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
index 146d67b46e..14a503eb95 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
@@ -66,6 +66,7 @@ export type VideoRecalledField =
| 'seed'
| 'size'
| 'frames'
+ | 'fps'
| 'steps'
| 'cfg'
| 'loras'
@@ -335,6 +336,12 @@ export interface VideoRecallMediaNames {
firstFrameName: string | null;
lastFrameName: string | null;
sourceVideoName: string | null;
+ /**
+ * The recorded trim bounds (metadata extras), so the executor can restore
+ * the clip's actual trim instead of `createVideoSourceClip`'s default —
+ * without them a recalled extension would start from the wrong frame.
+ */
+ sourceVideoTrim: { endFrame: number; startFrame: number } | null;
}
export const buildVideoRecallSettings = ({
@@ -355,7 +362,12 @@ export const buildVideoRecallSettings = ({
const fields: VideoRecalledField[] = [];
let values: VideoWidgetValues = { ...currentValues };
let promptPatch: ProjectPromptDraftPatch | null = null;
- const mediaNames: VideoRecallMediaNames = { firstFrameName: null, lastFrameName: null, sourceVideoName: null };
+ const mediaNames: VideoRecallMediaNames = {
+ firstFrameName: null,
+ lastFrameName: null,
+ sourceVideoName: null,
+ sourceVideoTrim: null,
+ };
if (kind === 'all' || kind === 'prompts' || kind === 'remix') {
const { negativePrompt, positivePrompt } = getMetadataPrompts(metadata);
@@ -450,6 +462,18 @@ export const buildVideoRecallSettings = ({
fields.push('cfg');
}
+ const fps = getInteger(metadata, 'fps');
+
+ // Wan records the delivered frame rate (H3 is fixed at 24 and records
+ // none). Recalling it into an extend-mode panel is harmless: the fps field
+ // is display-only there and the compiled graph re-inherits the clip's rate.
+ if (policy.fps.editable && fps !== null && fps >= 1 && fps <= 120) {
+ if (fps !== values.fps) {
+ values = { ...values, fps };
+ }
+ fields.push('fps');
+ }
+
const sizeRecall = getVideoSizeRecall(model, getInteger(metadata, 'width'), getInteger(metadata, 'height'));
if (sizeRecall) {
@@ -516,6 +540,12 @@ export const buildVideoRecallSettings = ({
mediaNames.firstFrameName = media.firstFrameName;
mediaNames.lastFrameName = media.lastFrameName;
mediaNames.sourceVideoName = media.sourceVideoName;
+ if (media.sourceVideoName) {
+ const startFrame = getInteger(metadata, 'source_video_start_frame');
+ const endFrame = getInteger(metadata, 'source_video_end_frame');
+
+ mediaNames.sourceVideoTrim = startFrame !== null && endFrame !== null ? { endFrame, startFrame } : null;
+ }
fields.push('media');
} else if (hadMedia) {
fields.push('media');
@@ -537,6 +567,7 @@ const VIDEO_FIELD_LABELS: Record<VideoRecalledField, string> = {
cfg: 'CFG',
steps: 'steps',
components: 'components',
+ fps: 'FPS',
frames: 'frames',
loras: 'concepts',
media: 'conditioning media',