Skip to content

fix(workflows): preserve core_metadata recall fields across workflow roundtrip#9162

Open
Pfannkuchensack wants to merge 1 commit into
invoke-ai:mainfrom
Pfannkuchensack:fix/workflow-metadata-loras-roundtrip
Open

fix(workflows): preserve core_metadata recall fields across workflow roundtrip#9162
Pfannkuchensack wants to merge 1 commit into
invoke-ai:mainfrom
Pfannkuchensack:fix/workflow-metadata-loras-roundtrip

Conversation

@Pfannkuchensack
Copy link
Copy Markdown
Collaborator

@Pfannkuchensack Pfannkuchensack commented May 12, 2026

Summary

The core_metadata node is configured with pydantic extra='allow' and carries recall metadata (loras, controlnets, ipAdapters, t2iAdapters, plus model-specific extras like z_image_seed_variance_*, dype_preset, ref_images). When a generated image's graph was loaded into the workflow editor and saved, those values were being dropped:

  • The four *MetadataField collection types were not registered as StatefulFieldType, so their inputs fell through to zStatelessFieldInputInstance, whose value is z.undefined().catch(undefined) — silently coercing the array away.
  • Extra keys not declared in the OpenAPI schema were dropped earlier still, in graphToWorkflow, because template.inputs[key] was undefined and the field was skipped with a warning.

Result: the regenerated image had no recall metadata and "Recall all parameters" reported no LoRA / no variance settings — even though the backend executed the workflow correctly (lora_selector and the z_image_seed_variance_enhancer node were intact via their edges).

This change:

  • Registers LoRAMetadataField, ControlNetMetadataField, IPAdapterMetadataField, T2IAdapterMetadataField as stateful field types with passthrough zod values.
  • Adds a synthetic MetadataExtraField so undeclared keys on extra='allow' nodes round-trip through the workflow editor.
  • graphToWorkflow synthesizes an extra-field template for keys not in the node template, scoped to nodes that accept extras.
  • buildNodesGraph forwards extra values verbatim when running the workflow.
  • fieldValidators and InputFieldGate no longer treat undeclared inputs on extra-accepting nodes as errors / unexpected fields.

Adds regression tests covering the LoRA roundtrip, the extras roundtrip, and the parseSchema template type for core_metadata.loras.

Related Issues / Discussions

Fixes #9151

QA Instructions

Tested end-to-end against a real Invoke instance (v6.12.0, Z-Image Turbo) with a real LoRA. Reproduction steps for reviewers:

  1. Generate a baseline image in the Generate tab using Z-Image Turbo with at least one LoRA enabled. For extra coverage, enable Seed Variance (strength > 0).
  2. From the gallery, open the image's context menu and choose Load Workflow (or "Edit Workflow"). The workflow editor should open without "Unexpected field" errors and the Invoke button should not be blocked.
  3. Click Invoke to regenerate from the loaded workflow.
  4. Inspect the new image's metadata (Image Info / Metadata panel):
    • loras array is present, with the same model and weight as the original.
    • If Seed Variance was used: z_image_seed_variance_enabled, z_image_seed_variance_strength, z_image_seed_variance_randomize_percent are present.
  5. Click Recall all parameters on the new image — the LoRA and Variance settings should populate the side panel.
  6. Compare the two backend graphs (via the image's "Graph" debug info if available): node set and edges should be identical between the original and the workflow-driven run.

Automated coverage (added in this PR):

  • loraMetadataRoundtrip.test.tszFieldInputInstance preserves values for all four *MetadataField types and accepts null.
  • graphToWorkflow.test.ts — full graph → workflow → parseAndMigrateWorkflow roundtrip preserves both core_metadata.loras and undeclared extras (z_image_seed_variance_*).
  • parseSchemaCoreMetadata.test.tsparseSchema produces a stateful LoRAMetadataField template for core_metadata.loras (not a stateless fallback).

Run with:

cd invokeai/frontend/web
pnpm test:no-watch

Merge Plan

Frontend-only change, no migrations and no backend schema impact. Safe to merge whenever; consider including in a patch release alongside other Z-Image bug fixes since the user-visible symptom (LoRA appears to be ignored on workflow re-runs) is a regression hot spot.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration — N/A (no slice changes; persisted workflow shape is unchanged, only the zod validators are loosened to preserve previously-stripped values)
  • Documentation added / updated (if applicable) — N/A
  • Updated What's New copy (if doing a release after this PR) — defer to release author

…roundtrip

The `core_metadata` node is configured with pydantic `extra='allow'` and
carries recall metadata (`loras`, `controlnets`, `ipAdapters`,
`t2iAdapters`, plus model-specific extras like `z_image_seed_variance_*`,
`dype_preset`, `ref_images`). When a generated image's graph was loaded
into the workflow editor and saved, those values were being dropped:

  * The four `*MetadataField` collection types were not registered as
    StatefulFieldType, so their inputs fell through to
    `zStatelessFieldInputInstance`, whose `value` is
    `z.undefined().catch(undefined)` — silently coercing the array away.
  * Extra keys not declared in the OpenAPI schema were dropped earlier
    still, in `graphToWorkflow`, because `template.inputs[key]` was
    undefined and the field was skipped with a warning.

Result: the regenerated image had no recall metadata and "Recall all
parameters" reported no LoRA / no variance settings — even though the
backend executed the workflow correctly (`lora_selector` and the
`z_image_seed_variance_enhancer` node were intact via their edges).

This change:

  * Registers `LoRAMetadataField`, `ControlNetMetadataField`,
    `IPAdapterMetadataField`, `T2IAdapterMetadataField` as stateful field
    types with passthrough zod values.
  * Adds a synthetic `MetadataExtraField` so undeclared keys on
    `extra='allow'` nodes round-trip through the workflow editor.
  * `graphToWorkflow` synthesizes an extra-field template for keys not in
    the node template, scoped to nodes that accept extras.
  * `buildNodesGraph` forwards extra values verbatim when running the
    workflow.
  * `fieldValidators` and `InputFieldGate` no longer treat undeclared
    inputs on extra-accepting nodes as errors / unexpected fields.

Adds regression tests covering the LoRA roundtrip, the extras roundtrip,
and the parseSchema template type for `core_metadata.loras`.

Fixes invoke-ai#9151
@github-actions github-actions Bot added the frontend PRs that change frontend files label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend PRs that change frontend files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Lora collection not firing during generation on workflow

1 participant