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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(minimax-h3): migrate stored integer frame counts to the choice value
Lincoln Steinf5f4c1edb163
diff --git a/invokeai/app/invocations/minimax_h3_denoise.py b/invokeai/app/invocations/minimax_h3_denoise.pyindex 4c89aac8da..570fc5555f 100644--- a/invokeai/app/invocations/minimax_h3_denoise.py+++ b/invokeai/app/invocations/minimax_h3_denoise.py@@ -105,7 +105,7 @@ assert set(get_args(MiniMaxH3NumFrames)) == {}, "MiniMaxH3NumFrames is out of sync with the 17n+5 frame grid."MINIMAX_H3_NUM_FRAMES_LABELS: dict[str, str] = {- str(MINIMAX_H3_STILL_NUM_FRAMES): f"{MINIMAX_H3_STILL_NUM_FRAMES} - still image only",+ str(MINIMAX_H3_STILL_NUM_FRAMES): f"{MINIMAX_H3_STILL_NUM_FRAMES} frames - still image only",**{str(n): f"{n} frames - {n / MINIMAX_H3_FPS:.2f} s" for n in MINIMAX_H3_VIDEO_FRAME_CHOICES},}diff --git a/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.json b/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.jsonindex b375cb5516..2dc156942e 100644--- a/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.json+++ b/invokeai/app/services/workflow_records/default_workflows/First Frame to Video - MiniMax H3.json@@ -607,12 +607,7 @@"nodeId": "9d3b9faf-405b-7e6f-bf4d-5c6a7f8e9d04","fieldName": "num_frames"},- "showDescription": true,- "settings": {- "type": "integer-field-config",- "showShuffle": false,- "component": "number-input"- }+ "showDescription": true}},"node-field-h3-steps": {diff --git a/invokeai/app/services/workflow_records/default_workflows/Text to Video - MiniMax H3.json b/invokeai/app/services/workflow_records/default_workflows/Text to Video - MiniMax H3.jsonindex 6bf05ec844..4870d4f639 100644--- a/invokeai/app/services/workflow_records/default_workflows/Text to Video - MiniMax H3.json+++ b/invokeai/app/services/workflow_records/default_workflows/Text to Video - MiniMax H3.json@@ -428,12 +428,7 @@"nodeId": "9d3b9faf-405b-7e6f-bf4d-5c6a7f8e9d04","fieldName": "num_frames"},- "showDescription": true,- "settings": {- "type": "integer-field-config",- "showShuffle": false,- "component": "number-input"- }+ "showDescription": true}},"node-field-h3-steps": {diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex f2768826a9..35d35c5aa0 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -66075,7 +66075,7 @@"311": "311 frames - 12.96 s","328": "328 frames - 13.67 s","345": "345 frames - 14.38 s",- "5": "5 - still image only",+ "5": "5 frames - still image only","90": "90 frames - 3.75 s"}},diff --git a/invokeai/frontend/web/src/features/controlLayers/components/CanvasWorkflowIntegration/WorkflowFieldRenderer.tsx b/invokeai/frontend/web/src/features/controlLayers/components/CanvasWorkflowIntegration/WorkflowFieldRenderer.tsxindex 2d91be13bf..25509aaf58 100644--- a/invokeai/frontend/web/src/features/controlLayers/components/CanvasWorkflowIntegration/WorkflowFieldRenderer.tsx+++ b/invokeai/frontend/web/src/features/controlLayers/components/CanvasWorkflowIntegration/WorkflowFieldRenderer.tsx@@ -363,6 +363,8 @@ export const WorkflowFieldRenderer = memo(({ el }: WorkflowFieldRendererProps) =// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst options = (fieldTemplate as any)?.options ?? (fieldTemplate as any)?.ui_choice_labels ?? [];const optionsList = Array.isArray(options) ? options : Object.keys(options);+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ const choiceLabels = (fieldTemplate as any)?.ui_choice_labels as Record<string, string> | undefined;return (<FormControl>@@ -370,7 +372,7 @@ export const WorkflowFieldRenderer = memo(({ el }: WorkflowFieldRendererProps) =<Select value={String(currentValue)} onChange={handleSelectChange}>{optionsList.map((option: string) => (<option key={option} value={option}>- {option}+ {choiceLabels?.[option] ?? option}</option>))}</Select>diff --git a/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.test.ts b/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.test.tsindex 07d826c078..59d5f33751 100644--- a/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.test.ts+++ b/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.test.ts@@ -91,6 +91,53 @@ const currentImageCollectionTemplate = {},} satisfies InvocationTemplate;+const oldMiniMaxH3DenoiseTemplate = {+ title: 'Denoise - MiniMax H3',+ type: 'minimax_h3_denoise',+ version: '1.2.0',+ tags: ['latents', 'video', 'audio', 'minimax'],+ description: 'Run the MiniMax H3 joint audio-video denoising loop.',+ outputType: 'minimax_h3_denoise_output',+ inputs: {+ num_frames: {+ name: 'num_frames',+ title: 'Number of Frames',+ required: false,+ description: 'Number of output frames at the fixed 24 fps.',+ fieldKind: 'input',+ input: 'any',+ ui_hidden: false,+ type: { name: 'IntegerField', cardinality: 'SINGLE', batch: false },+ default: 124,+ },+ },+ outputs: {},+ useCache: true,+ nodePack: 'invokeai',+ classification: 'prototype',+ category: 'latents',+} satisfies InvocationTemplate;++const currentMiniMaxH3DenoiseTemplate = {+ ...oldMiniMaxH3DenoiseTemplate,+ version: '1.3.0',+ inputs: {+ num_frames: {+ name: 'num_frames',+ title: 'Number of Frames',+ required: false,+ description: 'Only the video VAE 17n+5 grid points are offered.',+ fieldKind: 'input',+ input: 'any',+ ui_hidden: false,+ type: { name: 'EnumField', cardinality: 'SINGLE', batch: false },+ default: '124',+ options: ['5', '90', '107', '124', '141', '345'],+ ui_choice_labels: { '124': '124 frames - 5.17 s' },+ },+ },+} satisfies InvocationTemplate;+describe('updateNode', () => {it('moves old image_collection direct collection values to the new images field', () => {const node = buildInvocationNode({ x: 0, y: 0 }, oldImageCollectionTemplate);@@ -140,4 +187,48 @@ describe('updateNode', () => {expect(updated.data.inputs.images?.value).toBeUndefined();expect(updated.data.inputs.collection?.value).toEqual(images);});+ it('converts a stored minimax_h3_denoise frame count to the matching choice value', () => {+ const node = buildInvocationNode({ x: 0, y: 0 }, oldMiniMaxH3DenoiseTemplate);+ const numFrames = node.data.inputs.num_frames;+ if (!numFrames) {+ throw new Error('Expected num_frames input');+ }+ numFrames.value = 141;++ const updated = updateNode(node, currentMiniMaxH3DenoiseTemplate, { connectedInputNames: new Set() });++ expect(updated.data.version).toBe('1.3.0');+ // Without the migration the stale number survives the merge and the field renders as nothing.+ expect(updated.data.inputs.num_frames?.value).toBe('141');+ });++ it('falls back to the default when a stored frame count is no longer offered', () => {+ const node = buildInvocationNode({ x: 0, y: 0 }, oldMiniMaxH3DenoiseTemplate);+ const numFrames = node.data.inputs.num_frames;+ if (!numFrames) {+ throw new Error('Expected num_frames input');+ }+ numFrames.value = 22;++ const updated = updateNode(node, currentMiniMaxH3DenoiseTemplate, { connectedInputNames: new Set() });++ expect(updated.data.inputs.num_frames?.value).toBe('124');+ });++ it('leaves an already-migrated choice value alone', () => {+ const node = buildInvocationNode({ x: 0, y: 0 }, currentMiniMaxH3DenoiseTemplate);+ const numFrames = node.data.inputs.num_frames;+ if (!numFrames) {+ throw new Error('Expected num_frames input');+ }+ numFrames.value = '345';++ const updated = updateNode(+ node,+ { ...currentMiniMaxH3DenoiseTemplate, version: '1.4.0' },+ { connectedInputNames: new Set() }+ );++ expect(updated.data.inputs.num_frames?.value).toBe('345');+ });});diff --git a/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.ts b/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.tsindex 8c3e3b5c55..ca1b397a91 100644--- a/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.ts+++ b/invokeai/frontend/web/src/features/nodes/util/node/nodeUpdate.ts@@ -3,6 +3,7 @@ import { compare, satisfies } from 'compare-versions';import { defaultsDeep, keys, pick } from 'es-toolkit/compat';import { NodeUpdateError } from 'features/nodes/types/error';import { nodeAcceptsExtraInputs } from 'features/nodes/types/extraInputs';+import { isEnumFieldInputTemplate } from 'features/nodes/types/field';import type { InvocationNode, InvocationNodeData, InvocationTemplate } from 'features/nodes/types/invocation';import { zParsedSemver } from 'features/nodes/types/semver';@@ -78,6 +79,42 @@ export const migrateImageCollectionInputValues = (collection.value = [];};+/**+ * `minimax_h3_denoise.num_frames` became a grid-aligned choice list in 1.3.0, having been a free+ * integer. The recursive merge below preserves the stored number, which no longer validates+ * against the enum instance schema - the field then renders as nothing at all, leaving the user+ * no way to fix it from the editor. Convert a stored count that is still on the offered grid, and+ * fall back to the template's default for one that is not.+ */+export const migrateMiniMaxH3NumFramesValue = (+ node: InvocationNode,+ template: InvocationTemplate,+ sourceVersion?: string+) => {+ if (node.data.type !== 'minimax_h3_denoise') {+ return;+ }+ if (sourceVersion && compare(sourceVersion, '1.3.0', '>=')) {+ return;+ }++ const field = node.data.inputs.num_frames;+ const fieldTemplate = template.inputs.num_frames;+ if (!field || !fieldTemplate || !isEnumFieldInputTemplate(fieldTemplate)) {+ return;+ }++ // Annotated `unknown` so the typeof check below narrows the local, not `field.value` itself -+ // the assignment that follows has to widen back to a string.+ const storedCount: unknown = field.value;+ if (typeof storedCount !== 'number') {+ return;+ }++ const asChoice = String(storedCount);+ field.value = fieldTemplate.options.includes(asChoice) ? asChoice : fieldTemplate.default;+};+/*** Updates a node to the latest version of its template:* - Create a new node data object with the latest version of the template.@@ -111,6 +148,7 @@ export const updateNode = (clone.data.version = template.version;defaultsDeep(clone, defaults); // mutates!migrateImageCollectionInputValues(clone, { ...options, sourceVersion });+ migrateMiniMaxH3NumFramesValue(clone, template, sourceVersion);// Remove any fields that are not in the template. Nodes that accept extras (pydantic// `extra='allow'`, e.g. `core_metadata`) may carry undeclared inputs that are not in the templatediff --git a/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts b/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.tsindex 2245c0b709..a55e13e094 100644--- a/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts+++ b/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts@@ -7,7 +7,11 @@ import { nodeAcceptsExtraInputs } from 'features/nodes/types/extraInputs';import type { FieldInputInstance, FieldInputTemplate } from 'features/nodes/types/field';import type { WorkflowV3 } from 'features/nodes/types/workflow';import { getDefaultForm, isWorkflowInvocationNode } from 'features/nodes/types/workflow';-import { getConnectedInputNames, migrateImageCollectionInputValues } from 'features/nodes/util/node/nodeUpdate';+import {+ getConnectedInputNames,+ migrateImageCollectionInputValues,+ migrateMiniMaxH3NumFramesValue,+} from 'features/nodes/util/node/nodeUpdate';import { buildFieldInputInstance } from 'features/nodes/util/schema/buildFieldInputInstance';import type { NonNullableGraph } from 'services/api/types';import { v4 as uuidv4 } from 'uuid';@@ -139,6 +143,14 @@ export const graphToWorkflow = (graph: NonNullableGraph, autoLayout = true): WormigrateImageCollectionInputValues(node, {connectedInputNames: getConnectedInputNames(node.id, workflow.edges),});++ // A graph recalled from an older session carries num_frames as a raw integer, and the node is+ // built at the current template version, so nothing else would convert it. No source version+ // is available here; the migration is a no-op unless the stored value really is a number.+ const nodeTemplate = templates[node.data.type];+ if (nodeTemplate) {+ migrateMiniMaxH3NumFramesValue(node, nodeTemplate);+ }});if (autoLayout) {diff --git a/tests/app/invocations/test_minimax_h3_denoise_num_frames.py b/tests/app/invocations/test_minimax_h3_denoise_num_frames.pyindex 1cf3ec2e6e..fecfd18376 100644--- a/tests/app/invocations/test_minimax_h3_denoise_num_frames.py+++ b/tests/app/invocations/test_minimax_h3_denoise_num_frames.py@@ -57,7 +57,9 @@ def test_labels_cover_every_choice_and_name_the_duration():}assert MINIMAX_H3_NUM_FRAMES_LABELS["124"] == "124 frames - 5.17 s"assert MINIMAX_H3_NUM_FRAMES_LABELS["90"] == "90 frames - 3.75 s"- assert "still image" in MINIMAX_H3_NUM_FRAMES_LABELS["5"]+ assert MINIMAX_H3_NUM_FRAMES_LABELS["5"] == "5 frames - still image only"+ # Every label opens with "<count> frames" so the list reads consistently in the dropdown.+ assert all(label.startswith(f"{key} frames") for key, label in MINIMAX_H3_NUM_FRAMES_LABELS.items())def test_choices_appear_in_the_generated_json_schema():