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): keep a recorded video_audio reference on recall

Lincoln Stein280de2c5e634
diff --git a/invokeai/app/services/video_records/video_records_common.py b/invokeai/app/services/video_records/video_records_common.py
index 153710e2fd..121bd3e671 100644
--- a/invokeai/app/services/video_records/video_records_common.py
+++ b/invokeai/app/services/video_records/video_records_common.py
@@ -63,10 +63,11 @@ def coerce_media_origin(value: Any) -> Optional[str]:
`ValidationError` while *deserializing the row*, which does not merely mislabel the
video: it makes the record, its DTO, and every gallery listing that contains it fail to
build. One odd upload would take out the gallery. An unrecognized marker means the same
- thing as an absent one, so it is dropped here rather than propagated -- including one
- past :data:`MEDIA_ORIGIN_MAX_LENGTH`, which no real marker reaches.
+ thing as an absent one, so it is dropped here rather than propagated -- including the
+ empty string, which the frontend's own mapper also treats as no marker, and one past
+ :data:`MEDIA_ORIGIN_MAX_LENGTH`, which no real marker reaches.
"""
- if not isinstance(value, str) or len(value) > MEDIA_ORIGIN_MAX_LENGTH:
+ if not isinstance(value, str) or not value or len(value) > MEDIA_ORIGIN_MAX_LENGTH:
return None
return value
diff --git a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs
index e46ca4fc5b..f06397959d 100644
--- a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs
+++ b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs
@@ -32,8 +32,6 @@ export const MOCK_BACKEND_PROFILE_COUNTS = Object.freeze({
export const MOCK_BACKEND_FIXED_EPOCH = '2026-01-15T12:00:00.000Z';
export const MOCK_BACKEND_REPRESENTATIVE_VIDEO_NAME = 'fixture-video-001.mp4';
-/** The wrapped-audio upload fixture: a waveform video marked `media_origin: audio_upload`. */
-export const MOCK_BACKEND_WRAPPED_AUDIO_VIDEO_NAME = 'fixture-video-audio.mp4';
const FIXED_EPOCH_MS = Date.parse(MOCK_BACKEND_FIXED_EPOCH);
const range = (length, build) => Array.from({ length }, (_, index) => build(index));
@@ -280,27 +278,6 @@ const createVideos = () => [
width: 64,
workflow: null,
},
- {
- // An uploaded audio file, as the server stores one: a waveform video carrying
- // `media_origin: audio_upload`. Video references made from it start on "Audio only".
- board_id: null,
- created_at: timestampAt(3),
- duration: 1,
- fps: 24,
- graph: null,
- height: 360,
- is_intermediate: false,
- metadata: { media_origin: 'audio_upload' },
- owner_user_id: 'fixture-user',
- starred: false,
- thumbnail_url: `/api/v1/videos/i/${MOCK_BACKEND_WRAPPED_AUDIO_VIDEO_NAME}/thumbnail`,
- video_category: 'user',
- video_name: MOCK_BACKEND_WRAPPED_AUDIO_VIDEO_NAME,
- video_origin: 'external',
- video_url: `/api/v1/videos/i/${MOCK_BACKEND_WRAPPED_AUDIO_VIDEO_NAME}/full`,
- width: 640,
- workflow: null,
- },
];
/**
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
index 2e31b6d2ae..51d28c9837 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
@@ -247,23 +247,6 @@ describe('createVideoSourceClip', () => {
});
});
- it('carries the media-origin marker so a derived reference needs no metadata fetch', () => {
- const wrapped = createVideoSourceClip({
- durationSeconds: 5,
- fps: 24,
- height: 360,
- mediaOrigin: 'audio_upload',
- name: 'song.mp4',
- width: 640,
- });
-
- expect(wrapped.mediaOrigin).toBe('audio_upload');
- // An unmarked clip stays clean rather than carrying an explicit undefined.
- expect(
- 'mediaOrigin' in createVideoSourceClip({ durationSeconds: 5, fps: 24, height: 360, name: 'c.mp4', width: 640 })
- ).toBe(false);
- });
-
it('falls back to 16 fps when the probe recorded none, mirroring extract_video_range', () => {
const clip = createVideoSourceClip({ durationSeconds: 2, height: 480, name: 'clip.mp4', width: 832 });
@@ -753,19 +736,16 @@ describe('reference-extend linkage', () => {
// The panel's default; every choice is on the 17n+5 grid.
const FRAMES = 141;
- it('anchors on video + audio even for a wrapped audio clip -- the role needs visual rows', () => {
+ it('anchors on video + audio -- the role needs visual rows', () => {
const [ordinary] = applyReferenceExtendSourceVideo([], source24, 3, FRAMES);
+ // Deliberately NOT derived from whether the clip is a wrapped audio upload. The anchor
+ // is what the generated frames continue from, an 'audio' reference emits no visual rows
+ // at all, and the all-audio validation does not fire when other references are visual --
+ // so the seam would go silently discontinuous. `anchorReferenceConditioning` promotes in
+ // the other direction. (The clip carries no marker at all, so this cannot regress by
+ // accident.)
expect(ordinary).toMatchObject({ conditioning: 'video_audio', fromSourceVideo: true });
-
- // The marker now rides on the clip, so deriving the anchor's conditioning from it is an
- // easy mistake to make. It would be wrong: the anchor is what the generated frames
- // continue from, an 'audio' reference emits no visual rows at all, and the all-audio
- // validation does not fire when other references are visual -- so the seam would go
- // silently discontinuous. `anchorReferenceConditioning` promotes in the other direction.
- const [wrapped] = applyReferenceExtendSourceVideo([], { ...source24, mediaOrigin: 'audio_upload' }, 3, FRAMES);
-
- expect(wrapped).toMatchObject({ conditioning: 'video_audio', fromSourceVideo: true });
});
it('derives the tail trim: the window ending at the cutpoint, clamped at 0', () => {
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.ts
index 68d6b1a52e..6a5ab14981 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts
@@ -156,6 +156,16 @@ export const resizeReferenceSampleWindow = (clip: VideoSourceClip, rawSampleFram
};
const VIDEO_REFERENCE_CONDITIONINGS = ['video_audio', 'video', 'audio'] as const;
+
+/**
+ * Whether a value is one of the three conditionings a video reference can carry.
+ *
+ * Exported for recall, which must tell "the run recorded this" from "the run recorded
+ * nothing usable" -- the two take different branches, and enumerating the literals at the
+ * call site is how one of them gets forgotten.
+ */
+export const isVideoReferenceConditioning = (value: unknown): value is VideoReferenceConditioning =>
+ VIDEO_REFERENCE_CONDITIONINGS.includes(value as (typeof VIDEO_REFERENCE_CONDITIONINGS)[number]);
const VIDEO_REFERENCE_IMAGE_DETAILS = ['max', 'match'] as const;
export const isVideoReferenceItem = (value: unknown): value is VideoReferenceItem => {
@@ -534,7 +544,6 @@ export const createVideoSourceClip = (item: {
durationSeconds: number;
fps?: number;
height: number;
- mediaOrigin?: string;
name: string;
width: number;
}): VideoSourceClip => {
@@ -546,7 +555,6 @@ export const createVideoSourceClip = (item: {
endFrame: Math.max(1, numFrames - 2),
fps,
height: item.height,
- ...(item.mediaOrigin ? { mediaOrigin: item.mediaOrigin } : {}),
numFrames,
startFrame: 0,
video_name: item.name,
diff --git a/invokeai/frontend/webv2/src/features/video/core/types.ts b/invokeai/frontend/webv2/src/features/video/core/types.ts
index b4afa0fc89..d1793520b5 100644
--- a/invokeai/frontend/webv2/src/features/video/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/types.ts
@@ -22,11 +22,6 @@ export interface VideoSourceClip {
/** Inclusive trim bounds forwarded to `extract_video_range`; negative indices count from the end. */
startFrame: number;
endFrame: number;
- /**
- * The clip's `mediaOrigin` marker, carried so the conditioning a derived reference starts
- * on can be decided without re-fetching the video's metadata. See `GalleryVideoItem`.
- */
- mediaOrigin?: string;
}
/**
diff --git a/invokeai/frontend/webv2/src/features/video/index.ts b/invokeai/frontend/webv2/src/features/video/index.ts
index 17f29d4646..266d7b99b6 100644
--- a/invokeai/frontend/webv2/src/features/video/index.ts
+++ b/invokeai/frontend/webv2/src/features/video/index.ts
@@ -24,6 +24,7 @@ export {
getDefaultReferenceConditioning,
isImageWithDims,
isVideoAspectRatioId,
+ isVideoReferenceConditioning,
isVideoReferenceItem,
isVideoSettings,
isVideoSourceClip,
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
index d1065f946c..05e2c2b5e8 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
@@ -549,8 +549,11 @@ export const VideoReferenceListField = memo(function VideoReferenceListField({
// wrapped audio upload from footage without a second request, so every caller gets the
// right answer synchronously.
(item: GalleryVideoItem) => {
+ // The marker is read here and NOT stored on the clip: a clip outlives the gallery
+ // record it came from (it is persisted in the project and re-uploaded under a fresh
+ // name on import, where the server does not re-derive the marker), so a copy on the
+ // clip would go stale, and nothing downstream should be tempted to trust it.
const conditioning = getDefaultReferenceConditioning(item.mediaOrigin);
- // `createVideoSourceClip` reads `mediaOrigin` off the item too, so the clip carries it.
const clip = createVideoSourceClip(item);
// Built outside the updater so the caller holds the same object the list does: it is
// the only durable handle on this entry once reordering moves it.
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
index 1d8044686b..de197cd281 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
@@ -101,7 +101,6 @@ export const VideoSourceClipField = memo(
durationSeconds: item.durationSeconds,
fps: item.fps,
height: item.height,
- mediaOrigin: item.mediaOrigin,
name: item.name,
width: item.width,
})
@@ -154,7 +153,6 @@ export const VideoSourceClipField = memo(
durationSeconds: uploaded.durationSeconds,
fps: uploaded.fps,
height: uploaded.height,
- mediaOrigin: uploaded.mediaOrigin,
name: uploaded.name,
width: uploaded.width,
})
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx
index 0ea63404dc..9a44965466 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx
@@ -388,7 +388,6 @@ const SingleItemMenuItems = ({
durationSeconds: item.durationSeconds,
fps: item.fps,
height: item.height,
- mediaOrigin: item.mediaOrigin,
name: item.name,
width: item.width,
}),
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.test.ts
index f304280eea..2f226776d1 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.test.ts
@@ -59,6 +59,74 @@ const metadata = {
width: 1280,
};
+const h3Model = {
+ base: 'minimax-h3',
+ format: 'diffusers',
+ key: 'h3-main',
+ name: 'MiniMax H3',
+ path: '/models/h3',
+ type: 'main',
+ variant: 'ref2va',
+} as unknown as ModelConfig;
+
+/** A wrapped audio upload, as the gallery hands one back. */
+const wrappedAudioItem: GalleryVideoItem = {
+ ...item,
+ durationSeconds: 6,
+ fps: 24,
+ mediaOrigin: 'audio_upload',
+ name: 'song.mp4',
+};
+
+const h3ReferenceMetadata = (conditioning: unknown) => ({
+ generation_mode: 'minimax_h3_ref2v',
+ height: 768,
+ minimax_h3_references: [
+ {
+ end_frame: 47,
+ kind: 'video',
+ start_frame: 2,
+ video_name: 'song.mp4',
+ ...(conditioning === undefined ? {} : { conditioning }),
+ },
+ ],
+ model: { base: 'minimax-h3', key: 'h3-main', name: 'MiniMax H3', type: 'main' },
+ num_frames: 124,
+ positive_prompt: 'a red fox',
+ seed: 7,
+ steps: 4,
+ width: 1344,
+});
+
+// `executeVideoRecall` memoizes metadata per video name, so each case recalls a distinct
+// output video rather than re-reading a cached answer.
+let recallSeq = 0;
+
+const recallReferences = async (conditioning: unknown) => {
+ recallSeq += 1;
+ const recalledItem: GalleryVideoItem = { ...item, name: `output-${recallSeq}.mp4` };
+
+ galleryApi.galleryVideos.metadata.mockResolvedValue(h3ReferenceMetadata(conditioning));
+ galleryApi.galleryItems.resolve.mockResolvedValue(wrappedAudioItem);
+ const patchValues = vi.fn();
+ const commands = {
+ notifications: { add: vi.fn(), reportError: vi.fn() } as unknown as WorkbenchCommands['notifications'],
+ widgets: { patchValues } as unknown as WorkbenchCommands['widgets'],
+ };
+
+ await executeVideoRecall({
+ commands,
+ getVideoValues: () => createDefaultVideoWidgetValues([h3Model]) as unknown as Record<string, unknown>,
+ item: recalledItem,
+ kind: 'all',
+ models: [h3Model],
+ });
+
+ const written = patchValues.mock.calls.at(-1)?.[1] as { references?: { conditioning?: string }[] } | undefined;
+
+ return written?.references;
+};
+
const createCommands = () => {
const patchValues = vi.fn();
const commands = {
@@ -125,3 +193,30 @@ describe('executeVideoRecall', () => {
});
});
});
+
+describe('ref2va reference conditioning on recall', () => {
+ beforeEach(() => {
+ accountLifecycle.activate('test-account');
+ galleryApi.galleryVideos.metadata.mockReset();
+ galleryApi.galleryItems.resolve.mockReset();
+ });
+
+ // Recall must reproduce the run. The panel offers all three conditionings, so a recorded
+ // 'video_audio' on a wrapped audio clip is a deliberate user choice -- and it is the one
+ // value an enumerate-the-literals check is most likely to omit, because it used to be the
+ // fall-through default and so cost nothing to forget.
+ it('keeps a recorded video_audio, even on a clip marked as a wrapped audio upload', async () => {
+ expect(await recallReferences('video_audio')).toMatchObject([{ conditioning: 'video_audio' }]);
+ });
+
+ it('keeps a recorded video and a recorded audio', async () => {
+ expect(await recallReferences('video')).toMatchObject([{ conditioning: 'video' }]);
+ expect(await recallReferences('audio')).toMatchObject([{ conditioning: 'audio' }]);
+ });
+
+ it('falls back to the clip default only when nothing usable was recorded', async () => {
+ expect(await recallReferences(undefined)).toMatchObject([{ conditioning: 'audio' }]);
+ expect(await recallReferences(42)).toMatchObject([{ conditioning: 'audio' }]);
+ expect(await recallReferences('nonsense')).toMatchObject([{ conditioning: 'audio' }]);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts
index 3e9d3c917d..5f722da322 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeVideoRecall.ts
@@ -10,6 +10,7 @@ import {
createVideoSourceClip,
getDefaultReferenceConditioning,
getVideoModelPolicy,
+ isVideoReferenceConditioning,
normalizeVideoWidgetValues,
syncVideoWidgetValuesWithModels,
} from '@features/video';
@@ -158,7 +159,6 @@ export const executeVideoRecall = async ({
durationSeconds: sourceItem.durationSeconds,
fps: sourceItem.fps,
height: sourceItem.height,
- mediaOrigin: sourceItem.mediaOrigin,
name: sourceItem.name,
width: sourceItem.width,
});
@@ -224,7 +224,6 @@ export const executeVideoRecall = async ({
durationSeconds: item.durationSeconds,
fps: item.fps,
height: item.height,
- mediaOrigin: item.mediaOrigin,
name: item.name,
width: item.width,
});
@@ -233,15 +232,13 @@ export const executeVideoRecall = async ({
const endFrame = recorded.trim
? Math.min(Math.max(recorded.trim.endFrame, startFrame), clip.numFrames - 1)
: clip.numFrames - 1;
- // A recorded conditioning is what the run actually used, so it wins. Absent one
- // (metadata from a build that did not record it), fall back to the same default
- // the add path would pick rather than a literal -- a wrapped audio upload has
- // its marker in hand here, and defaulting it to video + audio would spend a
- // video reference slot on a picture of its own waveform.
- const conditioning =
- recorded.conditioning === 'video' || recorded.conditioning === 'audio'
- ? recorded.conditioning
- : getDefaultReferenceConditioning(item.mediaOrigin);
+ // A recorded conditioning is what the run actually used, so it wins -- ALL THREE
+ // values of it, tested as a set. Only when the metadata recorded nothing usable
+ // does this fall back to the default the add path would pick, which for a
+ // wrapped audio upload is its soundtrack rather than a picture of its waveform.
+ const conditioning = isVideoReferenceConditioning(recorded.conditioning)
+ ? recorded.conditioning
+ : getDefaultReferenceConditioning(item.mediaOrigin);
references.push({ clip: { ...clip, endFrame, startFrame }, conditioning, kind: 'video' });
} catch {
diff --git a/tests/app/services/video_records/test_video_records_sqlite.py b/tests/app/services/video_records/test_video_records_sqlite.py
index caa06f39c9..8673cb6101 100644
--- a/tests/app/services/video_records/test_video_records_sqlite.py
+++ b/tests/app/services/video_records/test_video_records_sqlite.py
@@ -323,6 +323,7 @@ def test_media_origin_survives_a_listing(store: SqliteVideoRecordStorage) -> Non
pytest.param("1", id="a JSON number"),
pytest.param("true", id="a JSON boolean"),
pytest.param("1.5", id="a JSON float"),
+ pytest.param('""', id="an empty string, which the frontend also reads as no marker"),
],
)
def test_a_non_string_marker_does_not_break_the_record(store: SqliteVideoRecordStorage, raw: str) -> None: