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(canvas): resize PiD Fit output once and restore the adapter slot on recall
Josh Corbett9b892f1b62f9
diff --git a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/animaLLLiteCanvasGraphs.json b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/animaLLLiteCanvasGraphs.jsonindex 6341918c2d..8315b8ad6b 100644--- a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/animaLLLiteCanvasGraphs.json+++ b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/animaLLLiteCanvasGraphs.json@@ -1,5 +1,486 @@{"_comment": "Generated by compileCanvasGraph.test.ts; regenerate with `vitest -u`. Consumed by tests/app/invocations/test_frontend_anima_lllite_graphs.py, which validates the graphs against the backend invocations.",+ "inpaint_inpaint_adapter": {+ "edges": [+ {+ "destination": {+ "field": "transformer",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "transformer",+ "node_id": "model_loader"+ }+ },+ {+ "destination": {+ "field": "qwen3_encoder",+ "node_id": "pos_cond"+ },+ "source": {+ "field": "qwen3_encoder",+ "node_id": "model_loader"+ }+ },+ {+ "destination": {+ "field": "vae",+ "node_id": "canvas_l2i"+ },+ "source": {+ "field": "vae",+ "node_id": "model_loader"+ }+ },+ {+ "destination": {+ "field": "prompt",+ "node_id": "pos_cond"+ },+ "source": {+ "field": "value",+ "node_id": "positive_prompt"+ }+ },+ {+ "destination": {+ "field": "item",+ "node_id": "pos_cond_collect"+ },+ "source": {+ "field": "conditioning",+ "node_id": "pos_cond"+ }+ },+ {+ "destination": {+ "field": "positive_conditioning",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "collection",+ "node_id": "pos_cond_collect"+ }+ },+ {+ "destination": {+ "field": "qwen3_encoder",+ "node_id": "neg_cond"+ },+ "source": {+ "field": "qwen3_encoder",+ "node_id": "model_loader"+ }+ },+ {+ "destination": {+ "field": "prompt",+ "node_id": "neg_cond"+ },+ "source": {+ "field": "value",+ "node_id": "negative_prompt"+ }+ },+ {+ "destination": {+ "field": "item",+ "node_id": "neg_cond_collect"+ },+ "source": {+ "field": "conditioning",+ "node_id": "neg_cond"+ }+ },+ {+ "destination": {+ "field": "negative_conditioning",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "collection",+ "node_id": "neg_cond_collect"+ }+ },+ {+ "destination": {+ "field": "seed",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "value",+ "node_id": "seed"+ }+ },+ {+ "destination": {+ "field": "latents",+ "node_id": "canvas_l2i"+ },+ "source": {+ "field": "latents",+ "node_id": "denoise_latents"+ }+ },+ {+ "destination": {+ "field": "seed",+ "node_id": "core_metadata_0_i"+ },+ "source": {+ "field": "value",+ "node_id": "seed"+ }+ },+ {+ "destination": {+ "field": "positive_prompt",+ "node_id": "core_metadata_0_i"+ },+ "source": {+ "field": "value",+ "node_id": "positive_prompt"+ }+ },+ {+ "destination": {+ "field": "negative_prompt",+ "node_id": "core_metadata_0_i"+ },+ "source": {+ "field": "value",+ "node_id": "negative_prompt"+ }+ },+ {+ "destination": {+ "field": "metadata",+ "node_id": "canvas_output"+ },+ "source": {+ "field": "metadata",+ "node_id": "core_metadata_0_i"+ }+ },+ {+ "destination": {+ "field": "vae",+ "node_id": "canvas_i2l"+ },+ "source": {+ "field": "vae",+ "node_id": "model_loader"+ }+ },+ {+ "destination": {+ "field": "latents",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "latents",+ "node_id": "canvas_i2l"+ }+ },+ {+ "destination": {+ "field": "vae",+ "node_id": "create_gradient_mask"+ },+ "source": {+ "field": "vae",+ "node_id": "model_loader"+ }+ },+ {+ "destination": {+ "field": "denoise_mask",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "denoise_mask",+ "node_id": "create_gradient_mask"+ }+ },+ {+ "destination": {+ "field": "mask",+ "node_id": "anima_inpaint_adapter"+ },+ "source": {+ "field": "image",+ "node_id": "invert_anima_inpaint_adapter_mask"+ }+ },+ {+ "destination": {+ "field": "control_lllite",+ "node_id": "denoise_latents"+ },+ "source": {+ "field": "collection",+ "node_id": "control_lllite_collector"+ }+ },+ {+ "destination": {+ "field": "item",+ "node_id": "control_lllite_collector"+ },+ "source": {+ "field": "control",+ "node_id": "anima_inpaint_adapter"+ }+ },+ {+ "destination": {+ "field": "mask",+ "node_id": "expand_mask"+ },+ "source": {+ "field": "expanded_mask_area",+ "node_id": "create_gradient_mask"+ }+ },+ {+ "destination": {+ "field": "layer_upper",+ "node_id": "canvas_output"+ },+ "source": {+ "field": "image",+ "node_id": "canvas_l2i"+ }+ },+ {+ "destination": {+ "field": "mask",+ "node_id": "canvas_output"+ },+ "source": {+ "field": "image",+ "node_id": "expand_mask"+ }+ }+ ],+ "id": "anima_lllite_canvas_inpaint_adapter",+ "nodes": {+ "negative_prompt": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "negative_prompt",+ "type": "string"+ },+ "positive_prompt": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "positive_prompt",+ "type": "string"+ },+ "seed": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "seed",+ "type": "integer"+ },+ "model_loader": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "model_loader",+ "model": {+ "base": "anima",+ "key": "anima-model",+ "name": "Anima",+ "type": "main",+ "hash": "blake3:anima"+ },+ "qwen3_encoder_model": {+ "base": "any",+ "key": "qwen3",+ "name": "Qwen3 Encoder",+ "type": "qwen3_encoder",+ "variant": "qwen3_06b",+ "hash": "blake3:qwen3"+ },+ "type": "anima_model_loader",+ "vae_model": {+ "base": "qwen-image",+ "key": "qwen-vae",+ "name": "Qwen VAE",+ "type": "vae",+ "hash": "blake3:vae"+ }+ },+ "pos_cond": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "pos_cond",+ "type": "anima_text_encoder"+ },+ "pos_cond_collect": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "pos_cond_collect",+ "type": "collect"+ },+ "neg_cond": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "neg_cond",+ "type": "anima_text_encoder"+ },+ "neg_cond_collect": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "neg_cond_collect",+ "type": "collect"+ },+ "denoise_latents": {+ "is_intermediate": true,+ "use_cache": true,+ "denoising_end": 1,+ "denoising_start": 0.4,+ "guidance_scale": 4.5,+ "height": 1024,+ "id": "denoise_latents",+ "scheduler": "euler",+ "steps": 35,+ "type": "anima_denoise",+ "width": 768+ },+ "core_metadata_0_i": {+ "is_intermediate": true,+ "use_cache": true,+ "cfg_scale": 4.5,+ "cfg_rescale_multiplier": 0,+ "generation_mode": "anima_inpaint",+ "height": 1024,+ "id": "core_metadata_0_i",+ "model": {+ "base": "anima",+ "key": "anima-model",+ "name": "Anima",+ "type": "main",+ "hash": "blake3:anima"+ },+ "rand_device": "cpu",+ "scheduler": "euler",+ "seamless_x": false,+ "seamless_y": false,+ "steps": 35,+ "type": "core_metadata",+ "vae": {+ "base": "qwen-image",+ "key": "qwen-vae",+ "name": "Qwen VAE",+ "type": "vae",+ "hash": "blake3:vae"+ },+ "width": 768,+ "qwen3_encoder": {+ "base": "any",+ "key": "qwen3",+ "name": "Qwen3 Encoder",+ "type": "qwen3_encoder",+ "variant": "qwen3_06b",+ "hash": "blake3:qwen3"+ },+ "clip_skip": 0,+ "anima_inpaint_adapter": {+ "base": "anima",+ "cond_in_channels": 4,+ "key": "anima-inpaint",+ "name": "Anima LLLite Inpainting",+ "type": "controlnet",+ "hash": "blake3:inpaint"+ },+ "anima_inpaint_adapter_weight": 0.75,+ "strength": 0.6+ },+ "canvas_i2l": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "canvas_i2l",+ "type": "anima_i2l",+ "image": {+ "image_name": "canvas-composite.png"+ }+ },+ "canvas_l2i": {+ "is_intermediate": true,+ "use_cache": false,+ "id": "canvas_l2i",+ "type": "anima_l2i"+ },+ "create_gradient_mask": {+ "is_intermediate": true,+ "use_cache": true,+ "coherence_mode": "Gaussian Blur",+ "edge_radius": 16,+ "fp32": false,+ "id": "create_gradient_mask",+ "image": {+ "image_name": "canvas-composite.png"+ },+ "minimum_denoise": 0,+ "type": "create_gradient_mask",+ "mask": {+ "image_name": "canvas-mask.png"+ }+ },+ "invert_anima_inpaint_adapter_mask": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "invert_anima_inpaint_adapter_mask",+ "image": {+ "image_name": "canvas-mask.png"+ },+ "max": 0,+ "min": 255,+ "type": "img_lerp"+ },+ "anima_inpaint_adapter": {+ "is_intermediate": true,+ "use_cache": true,+ "control_model": {+ "base": "anima",+ "cond_in_channels": 4,+ "key": "anima-inpaint",+ "name": "Anima LLLite Inpainting",+ "type": "controlnet",+ "hash": "blake3:inpaint"+ },+ "id": "anima_inpaint_adapter",+ "image": {+ "image_name": "canvas-composite.png"+ },+ "type": "anima_lllite",+ "weight": 0.75+ },+ "control_lllite_collector": {+ "is_intermediate": true,+ "use_cache": true,+ "id": "control_lllite_collector",+ "type": "collect"+ },+ "expand_mask": {+ "is_intermediate": true,+ "use_cache": true,+ "fade_size_px": 16,+ "id": "expand_mask",+ "type": "expand_mask_with_fade"+ },+ "canvas_output": {+ "is_intermediate": true,+ "use_cache": false,+ "id": "canvas_output",+ "layer_base": {+ "image_name": "canvas-composite.png"+ },+ "type": "invokeai_img_blend"+ }+ }+ },"inpaint_three_adapters": {"edges": [{@@ -833,7 +1314,7 @@}}],- "id": "anima_lllite_canvas_inpaint_adapter",+ "id": "anima_lllite_canvas_outpaint_adapter","nodes": {"negative_prompt": {"is_intermediate": true,diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.tsindex 5bc142abe3..3b2abc5ea3 100644--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts@@ -1148,6 +1148,7 @@ describe('compileCanvasGraph — Anima ControlNet-LLLite (integration)', () => {};let threeAdapters: BackendGraphContract;let inpaintAdapterGraph: BackendGraphContract;+ let outpaintAdapterGraph: BackendGraphContract;try {// Inpainting exercises the whole denoise wiring the adapters join; one collector serves any adapter count.threeAdapters = compile(hashed(animaModel, 'blake3:anima'), 'inpaint', {@@ -1158,8 +1159,16 @@ describe('compileCanvasGraph — Anima ControlNet-LLLite (integration)', () => {],settings,}).backendGraph;+ // The inpaint adapter alone: it reads the composite and the uploaded mask as fixed image fields.+ inpaintAdapterGraph = compile(hashed(animaModel, 'blake3:anima'), 'inpaint', {+ settings: {+ ...settings,+ animaInpaintAdapterModel: hashed(inpaintAdapter, 'blake3:inpaint'),+ animaInpaintAdapterWeight: 0.75,+ },+ }).backendGraph;// The inpaint adapter beside a control layer: the masked adapter and the unmasked one share the collector.- inpaintAdapterGraph = compile(hashed(animaModel, 'blake3:anima'), 'outpaint', {+ outpaintAdapterGraph = compile(hashed(animaModel, 'blake3:anima'), 'outpaint', {controlLayers: [lliteLayer('sketch-layer', 'sketch', 0.8)],maskImageName: 'canvas-mask.png',settings: {@@ -1175,8 +1184,12 @@ describe('compileCanvasGraph — Anima ControlNet-LLLite (integration)', () => {const fixture = {_comment:'Generated by compileCanvasGraph.test.ts; regenerate with `vitest -u`. Consumed by tests/app/invocations/test_frontend_anima_lllite_graphs.py, which validates the graphs against the backend invocations.',+ inpaint_inpaint_adapter: { ...inpaintAdapterGraph, id: 'anima_lllite_canvas_inpaint_adapter' },inpaint_three_adapters: { ...threeAdapters, id: 'anima_lllite_canvas' },- outpaint_inpaint_adapter_and_control_layer: { ...inpaintAdapterGraph, id: 'anima_lllite_canvas_inpaint_adapter' },+ outpaint_inpaint_adapter_and_control_layer: {+ ...outpaintAdapterGraph,+ id: 'anima_lllite_canvas_outpaint_adapter',+ },};await expect(`${JSON.stringify(fixture, null, 2)}\n`).toMatchFileSnapshot('../__snapshots__/animaLLLiteCanvasGraphs.json'@@ -1238,6 +1251,24 @@ describe('compileCanvasGraph — PiD decode', () => {expect(metadata?.height).toBe(bbox.height);});+ it('txt2img fit with an off-grid bbox: resizes the 4x decode once, straight to the bbox', () => {+ // SDXL snaps 1000x700 to 1000x704 for denoising; legacy resizes the decode once to the final size.+ const { backendGraph } = compile(sdxlModel, 'txt2img', {+ bbox: { height: 700, width: 1000, x: 0, y: 0 },+ settings: pidSettings(sdxlModel, 'fit'),+ });++ expect(backendGraph.nodes.noise).toMatchObject({ height: 704, width: 1000 });+ const resizes = Object.values(backendGraph.nodes).filter((node) => node.type === 'img_resize');+ expect(resizes).toHaveLength(1);+ expect(backendGraph.nodes.canvas_output).toMatchObject({ height: 700, type: 'img_resize', width: 1000 });+ expect(getEdge(backendGraph, 'canvas_output', 'image')?.source.node_id).toBe(pidDecodeNode(backendGraph)?.id);+ expect(backendGraph.nodes.canvas_processing_output).toBeUndefined();+ const metadata = getNodeByType(backendGraph, 'core_metadata');+ expect(metadata).toMatchObject({ height: 700, width: 1000 });+ expect(getEdge(backendGraph, 'canvas_output', 'metadata')?.source.node_id).toBe(metadata?.id);+ });+it('txt2img native: denoises at a quarter of the bbox and the PiD decode owns canvas_output unresized', () => {const { backendGraph } = compile(fluxModel, 'txt2img', { settings: pidSettings(fluxModel, 'native') });@@ -1283,6 +1314,21 @@ describe('compileCanvasGraph — PiD decode', () => {expect(backendGraph.nodes.canvas_processing_output).toBeUndefined();});+ it('img2img native (SDXL): downscales the composite to the quarter size the noise node denoises at', () => {+ const { backendGraph } = compile(sdxlModel, 'img2img', { settings: pidSettings(sdxlModel, 'native') });++ expect(backendGraph.nodes.noise).toMatchObject({ height: bbox.height / 4, width: bbox.width / 4 });+ expect(backendGraph.nodes.canvas_resize_initial_to_processing).toMatchObject({+ height: bbox.height / 4,+ image: { image_name: 'canvas-composite.png' },+ type: 'img_resize',+ width: bbox.width / 4,+ });+ expect(getEdge(backendGraph, 'canvas_i2l', 'image')?.source.node_id).toBe('canvas_resize_initial_to_processing');+ expect(backendGraph.nodes.canvas_output?.type).toBe('sdxl_pid_decode');+ expect(backendGraph.nodes.canvas_processing_output).toBeUndefined();+ });+it.each(PID_BASES)('resolves the encode VAE for a $base native img2img', (model) => {const { backendGraph } = compile(model, 'img2img', {settings: { ...COMPONENT_OVERRIDES[model.base], ...pidSettings(model, 'native') },diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.tsindex 6894505ef0..421d52ec68 100644--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts@@ -12,6 +12,7 @@ import { findVaeSource, GRAPH_BUILDERS } from '@features/generation/core/graph';import { addEdge, addNode, toGraphContract } from '@features/generation/core/graphBuilder';import { addKrea2ConditioningEnhancers } from '@features/generation/core/krea2Conditioning';import { getIsPidActive } from '@features/generation/core/pid';+import { shouldUsePidDecode } from '@features/generation/core/pidGraph';import { MAX_ANIMA_INPAINT_ADAPTER_WEIGHT, MIN_ANIMA_INPAINT_ADAPTER_WEIGHT } from '@features/generation/core/settings';import type {@@ -210,12 +211,23 @@ const resizeCanvasOutputToBbox = (graph: BackendGraphContract,bbox: CompileCanvasGraphInput['bbox'],processingSize: CanvasSize,- destination: CompileCanvasGraphInput['destination']+ destination: CompileCanvasGraphInput['destination'],+ /** PiD Fit ends in an `img_resize` of the 4x decode to the processing size (`addPidDecode`). */+ isPidFit: boolean): void => {if (sizesMatch(bbox, processingSize)) {return;}+ // Retarget PiD Fit's resize so the output is resampled once, straight to the bbox (legacy parity), rather+ // than through the processing size.+ const terminalResize = graph.nodes.canvas_output;+ if (isPidFit && terminalResize?.type === 'img_resize') {+ terminalResize.width = bbox.width;+ terminalResize.height = bbox.height;+ return;+ }+const processingOutput = renameNode(graph, 'canvas_output', 'canvas_processing_output');processingOutput.is_intermediate = true;@@ -807,7 +819,13 @@ export const compileCanvasGraph = (input: CompileCanvasGraphInput): CompiledCanv}if (mode === 'txt2img' || mode === 'img2img') {- resizeCanvasOutputToBbox(backendGraph, bbox, processingSize, destination);+ resizeCanvasOutputToBbox(+ backendGraph,+ bbox,+ processingSize,+ destination,+ shouldUsePidDecode(settings, model.base) && settings.pidMode === 'fit'+ );}setCanvasMetadataDimensions(backendGraph, bbox);diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.tsindex c0a67c156b..4f1eb5be30 100644--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts@@ -103,6 +103,10 @@ export const DEFAULT_ANIMA_INPAINT_ADAPTER_WEIGHT = 1;export const MIN_ANIMA_INPAINT_ADAPTER_WEIGHT = -10;export const MAX_ANIMA_INPAINT_ADAPTER_WEIGHT = 10;+/** Persisted and recalled weights share this clamp, so an out-of-range value never blocks canvas validation. */+export const clampAnimaInpaintAdapterWeight = (weight: number): number =>+ Math.min(Math.max(weight, MIN_ANIMA_INPAINT_ADAPTER_WEIGHT), MAX_ANIMA_INPAINT_ADAPTER_WEIGHT);+export const DEFAULT_LORA_WEIGHT_CONFIG = {coarseStep: 0.05,initial: 0.75,@@ -765,12 +769,10 @@ export const normalizeGenerateSettings = (values: unknown): GenerateSettings | nqwen3VLEncoderModel: getModelIdentifierOrNull(values.qwen3VLEncoderModel),qwen35EncoderModel: getModelIdentifierOrNull(values.qwen35EncoderModel),animaInpaintAdapterModel: getModelIdentifierOrNull(values.animaInpaintAdapterModel),- animaInpaintAdapterWeight: getClampedNumber(- values,- 'animaInpaintAdapterWeight',- MIN_ANIMA_INPAINT_ADAPTER_WEIGHT,- MAX_ANIMA_INPAINT_ADAPTER_WEIGHT,- DEFAULT_ANIMA_INPAINT_ADAPTER_WEIGHT+ animaInpaintAdapterWeight: clampAnimaInpaintAdapterWeight(+ hasFiniteNumber(values, 'animaInpaintAdapterWeight')+ ? (values.animaInpaintAdapterWeight as number)+ : DEFAULT_ANIMA_INPAINT_ADAPTER_WEIGHT),wanT5EncoderModel: getModelIdentifierOrNull(values.wanT5EncoderModel),wanLowNoiseModel: getMainModelOrNull(values.wanLowNoiseModel),diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.tsindex 8561bbc1a9..f79d7daacb 100644--- a/invokeai/frontend/webv2/src/features/generation/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts@@ -2,6 +2,7 @@export {ASPECT_RATIO_MAP,calculateNewSize,+ clampAnimaInpaintAdapterWeight,clampDimension,cloneGenerateWidgetValues,DEFAULT_LORA_WEIGHT_CONFIG,diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.tsindex 45dc748a72..ff88676be2 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts@@ -1260,6 +1260,68 @@ describe('anima inpaint adapter', () => {expect(result?.fields).toContain('animaInpaintAdapterWeight');});+ it('clears a stale adapter from an Anima inpaint record that lacks the key, which the backend persists for none', () => {+ const currentValues = createValues({ animaInpaintAdapterModel: inpaintAdapter, animaInpaintAdapterWeight: 0.5 });+ const {+ anima_inpaint_adapter: _adapter,+ anima_inpaint_adapter_weight: _weight,+ ...withoutAdapter+ } = canvasInpaintMetadata;+ const recall = (metadata: Record<string, unknown>, supportedModels = [animaModel]) =>+ buildImageRecallSettings({+ currentValues,+ image,+ kind: 'all',+ metadata,+ models: [...models, sd1Model],+ supportedModels,+ vaeModels: [qwenImageVae],+ });++ for (const generation_mode of ['anima_inpaint', 'anima_outpaint']) {+ const cleared = recall({ ...withoutAdapter, generation_mode });+ expect(cleared?.values.animaInpaintAdapterModel).toBeNull();+ expect(cleared?.values.animaInpaintAdapterWeight).toBe(0.5);+ expect(cleared?.fields).toContain('components');+ expect(cleared?.fields).not.toContain('animaInpaintAdapterWeight');+ }++ // A record from a mode that never writes the key, or none at all, says nothing about the adapter.+ expect(recall(withoutAdapter)?.values.animaInpaintAdapterModel).toEqual(inpaintAdapter);+ expect(recall({ ...withoutAdapter, generation_mode: 'anima_img2img' })?.values.animaInpaintAdapterModel).toEqual(+ inpaintAdapter+ );+ const notAnima = recall({ generation_mode: 'inpaint', model: { key: sd1Model.key } }, [sd1Model, animaModel]);+ expect(notAnima?.values.model).toBe(sd1Model);+ expect(notAnima?.fields).not.toContain('components');++ // The key present on such a record still sets the adapter.+ const restored = recall({ ...canvasInpaintMetadata, generation_mode: 'anima_inpaint' });+ expect(restored?.values.animaInpaintAdapterModel).toBe(inpaintAdapter);+ expect(restored?.values.animaInpaintAdapterWeight).toBe(0.7);+ });++ it.each([+ [25, 10],+ [-25, -10],+ ])(+ 'clamps a recorded weight of %s to %s instead of applying a value canvas validation rejects',+ (recorded, applied) => {+ const result = buildImageRecallSettings({+ currentValues: createValues(),+ image,+ kind: 'all',+ metadata: { ...canvasInpaintMetadata, anima_inpaint_adapter_weight: recorded },+ models,+ supportedModels: [animaModel],+ vaeModels: [qwenImageVae],+ });++ expect(result?.values.animaInpaintAdapterWeight).toBe(applied);+ expect(result?.fields).toContain('animaInpaintAdapterWeight');+ }+ );+it('skips the adapter and weight when the image is not an Anima image or the adapter is a control adapter', () => {const notAnima = buildImageRecallSettings({currentValues: createValues({ animaInpaintAdapterWeight: 1 }),diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.tsindex e84a954cb3..9d72e8ec60 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts@@ -10,6 +10,7 @@ import type {} from '@features/generation/contracts';import {+ clampAnimaInpaintAdapterWeight,clampDimension,cloneGenerateWidgetValues,deriveAspectRatioId,@@ -420,7 +421,10 @@ const getMetadataKrea2Rebalance = (const hasKrea2Rebalance = (metadata: unknown, model: GenerateModelConfig | undefined): boolean =>Object.keys(getMetadataKrea2Rebalance(metadata, model)).length > 0;-/** The canvas records the adapter's weight beside the adapter; only an Anima image can carry it. */+/**+ * The canvas records the adapter's weight beside the adapter; only an Anima image can carry it. An out-of-range+ * weight is clamped rather than applied, which would block every inpaint until the user edits it.+ */const getMetadataAnimaInpaintAdapterWeight = (metadata: unknown,model: GenerateModelConfig | undefined@@ -431,7 +435,7 @@ const getMetadataAnimaInpaintAdapterWeight = (const weight = getNumber(metadata, 'anima_inpaint_adapter_weight');- return weight === null ? {} : { animaInpaintAdapterWeight: weight };+ return weight === null ? {} : { animaInpaintAdapterWeight: clampAnimaInpaintAdapterWeight(weight) };};const hasAnimaInpaintAdapterWeight = (metadata: unknown, model: GenerateModelConfig | undefined): boolean =>@@ -460,6 +464,12 @@ interface RecalledComponent {setting: RecalledComponentSetting;/** The setting holds a main model (a component source or second transformer), not an encoder. */isMainModel?: true;+ /**+ * The `generation_mode` values whose graphs record the key whenever the component ran. `core_metadata` drops+ * `null` on write, so on these records an absent key means "none" and clears the slot; elsewhere it means+ * "unknown" and keeps the current pick.+ */+ absentMeansNoneIn?: readonly string[];}/**@@ -472,7 +482,11 @@ const RECALLED_COMPONENTS: readonly RecalledComponent[] = [{ isMainModel: true, metadataKey: 'wan_component_source', setting: 'componentSourceModel' },{ isMainModel: true, metadataKey: 'ideogram4_unconditional_model', setting: 'ideogram4UnconditionalModel' },{ isMainModel: true, metadataKey: 'wan_transformer_low_noise', setting: 'wanLowNoiseModel' },- { metadataKey: 'anima_inpaint_adapter', setting: 'animaInpaintAdapterModel' },+ {+ absentMeansNoneIn: ['anima_inpaint', 'anima_outpaint'],+ metadataKey: 'anima_inpaint_adapter',+ setting: 'animaInpaintAdapterModel',+ },{ metadataKey: 'clip_embed_model', setting: 'clipEmbedModel' },{ metadataKey: 'gemma2_encoder', setting: 'gemma2EncoderModel' },{ metadataKey: 'mistral_encoder', setting: 'mistralEncoderModel' },@@ -489,10 +503,17 @@ const getRecalledComponent = (metadata: unknown,component: RecalledComponent,models: readonly ComponentModelConfig[]-): ComponentModelConfig | null | undefined =>- component.isMainModel+): ComponentModelConfig | null | undefined => {+ if (isRecord(metadata) && !(component.metadataKey in metadata) && component.absentMeansNoneIn) {+ const mode = getString(metadata, 'generation_mode');++ return mode !== null && component.absentMeansNoneIn.includes(mode) ? null : undefined;+ }++ return component.isMainModel? getMetadataMainModel(metadata, component.metadataKey, models): getMetadataComponent(metadata, component.metadataKey, models);+};/** Recorded components that resolve to installed models; `null` clears a slot the image left empty. */const getComponentPatch = (diff --git a/tests/app/invocations/test_frontend_anima_lllite_graphs.py b/tests/app/invocations/test_frontend_anima_lllite_graphs.pyindex 92dcaa4ac7..4127cf5d71 100644--- a/tests/app/invocations/test_frontend_anima_lllite_graphs.py+++ b/tests/app/invocations/test_frontend_anima_lllite_graphs.py@@ -2,12 +2,13 @@`animaLLLiteCanvasGraphs.json` is written by webv2's `compileCanvasGraph.test.ts` (regenerate with`vitest -u`) from the real canvas compiler: a complete inpainting submission with three control-layer-adapters, and an outpainting submission that adds the optional 4-channel inpaint adapter beside a control-layer. The frontend routes any number of adapters through one collector, so these graphs cover the edge-types for every count, masked and unmasked. This module checks more than names: pydantic validates every-node against its invocation (bounds such as `anima_lllite.weight` in [-10, 10] included),-`Graph.validate_self` checks every edge type through the collector into `anima_denoise.control_lllite`,-and the denoiser's own normalization runs on the fields the adapter nodes would emit. No model is loaded.+adapters, an inpainting submission with the optional 4-channel inpaint adapter alone, and an outpainting+submission that adds that adapter beside a control layer. The frontend routes any number of adapters through+one collector, so these graphs cover the edge types for every count, masked and unmasked. This module checks+more than names: pydantic validates every node against its invocation (bounds such as `anima_lllite.weight` in+[-10, 10] included), `Graph.validate_self` checks every edge type through the collector into+`anima_denoise.control_lllite`, the denoiser's own normalization runs on the fields the adapter nodes would+emit, and `core_metadata` is serialised the way the gallery persists it. No model is loaded."""import json@@ -20,6 +21,7 @@ from invokeai.app.invocations.anima.anima_denoise import AnimaDenoiseInvocationfrom invokeai.app.invocations.anima.anima_lllite import AnimaLLLiteField, AnimaLLLiteInvocationfrom invokeai.app.invocations.fields import ImageFieldfrom invokeai.app.invocations.image import ImageLerpInvocation+from invokeai.app.invocations.metadata import CoreMetadataInvocationfrom invokeai.app.services.shared.graph import GraphFIXTURE_PATH = (@@ -74,6 +76,7 @@ def test_the_fixtures_combine_several_distinct_adapters() -> None:for name, graph in GRAPHS.items()}assert len(keys["inpaint_three_adapters"]) == 3 and len(set(keys["inpaint_three_adapters"])) == 3+ assert len(keys["inpaint_inpaint_adapter"]) == 1assert len(keys["outpaint_inpaint_adapter_and_control_layer"]) == 2assert len(set(keys["outpaint_inpaint_adapter_and_control_layer"])) == 2@@ -116,7 +119,7 @@ def test_every_adapter_reaches_control_lllite_through_one_collector(graph: Graphdef test_control_layers_send_a_control_image_and_no_inpaint_mask(graph: Graph) -> None:control_layers = _control_layer_nodes(graph)- assert control_layers+ assert len(control_layers) == len(_lllite_nodes(graph)) - (INPAINT_ADAPTER_NODE_ID in graph.nodes)for node in control_layers:assert node.image.image_nameassert node.mask is None@@ -126,14 +129,34 @@ def test_control_layers_send_a_control_image_and_no_inpaint_mask(graph: Graph) -assert not any(e.destination.node_id in control_layer_ids for e in graph.edges)-def test_the_inpaint_adapter_takes_the_infilled_image_and_an_inverted_mask() -> None:- """The adapter wants white = inpaint; the canvas mask is white = keep, so an `img_lerp` 255 -> 0 feeds its mask."""- graph = Graph.model_validate(GRAPHS["outpaint_inpaint_adapter_and_control_layer"])+def _inpaint_adapter(name: str) -> tuple[Graph, AnimaLLLiteInvocation]:+ graph = Graph.model_validate(GRAPHS[name])graph.validate_self()adapter = graph.nodes[INPAINT_ADAPTER_NODE_ID]assert isinstance(adapter, AnimaLLLiteInvocation)assert adapter.weight == 0.75assert adapter.control_model.base.value == "anima"+ return graph, adapter+++def test_the_inpaint_adapter_takes_the_composite_and_the_inverted_uploaded_mask_when_inpainting() -> None:+ """Without Scale Before Processing the canvas uploads are read as fixed image fields, not through resize nodes."""+ graph, adapter = _inpaint_adapter("inpaint_inpaint_adapter")++ assert adapter.image is not None and adapter.image.image_name == "canvas-composite.png"+ inputs = {e.destination.field: e.source for e in graph.edges if e.destination.node_id == adapter.id}+ assert set(inputs) == {"mask"}+ invert = graph.nodes[inputs["mask"].node_id]+ assert isinstance(invert, ImageLerpInvocation)+ assert (invert.min, invert.max) == (255, 0)+ assert invert.image.image_name == "canvas-mask.png"+ assert inputs["mask"].field == "image"+ assert not any(e.destination.node_id == invert.id for e in graph.edges)+++def test_the_inpaint_adapter_takes_the_infilled_image_and_an_inverted_mask_when_outpainting() -> None:+ """The adapter wants white = inpaint; the canvas mask is white = keep, so an `img_lerp` 255 -> 0 feeds its mask."""+ graph, adapter = _inpaint_adapter("outpaint_inpaint_adapter_and_control_layer")inputs = {e.destination.field: e.source for e in graph.edges if e.destination.node_id == adapter.id}assert set(inputs) == {"image", "mask"}@@ -147,6 +170,31 @@ def test_the_inpaint_adapter_takes_the_infilled_image_and_an_inverted_mask() ->assert graph.nodes[mask_source.node_id].get_type() == "mask_combine"+def _persisted_metadata(name: str) -> dict[str, Any]:+ graph = Graph.model_validate(GRAPHS[name])+ metadata = next(node for node in graph.nodes.values() if isinstance(node, CoreMetadataInvocation))+ return metadata.invoke(None).metadata.root # type: ignore[arg-type]+++def test_persisted_metadata_names_the_inpaint_adapter_only_when_one_ran() -> None:+ """`core_metadata` drops `None` on write, so a graph cannot record "no adapter" explicitly. Recall therefore+ reads an absent key on an `anima_inpaint`/`anima_outpaint` record as none, which holds only while the compiler+ writes the key whenever an adapter ran."""+ without_adapter = _persisted_metadata("inpaint_three_adapters")+ assert without_adapter["generation_mode"] == "anima_inpaint"+ assert "anima_inpaint_adapter" not in without_adapter+ assert "anima_inpaint_adapter_weight" not in without_adapter++ for name, mode in (+ ("inpaint_inpaint_adapter", "anima_inpaint"),+ ("outpaint_inpaint_adapter_and_control_layer", "anima_outpaint"),+ ):+ persisted = _persisted_metadata(name)+ assert persisted["generation_mode"] == mode+ assert persisted["anima_inpaint_adapter"]["key"] == "anima-inpaint"+ assert persisted["anima_inpaint_adapter_weight"] == 0.75++def test_the_denoiser_accepts_the_adapters_it_would_receive(graph: Graph) -> None:fields = [_control_field(graph, node) for node in _lllite_nodes(graph)]