-
Notifications
You must be signed in to change notification settings - Fork 451
Description
Problem Description
When loading workflows, widget values can appear in the wrong positions if the backend returns node inputs in a different order than when the workflow was saved. This occurs because JSON object key ordering is not guaranteed to be preserved (especially in languages like Go), and the frontend doesn't handle this variation correctly.
For example, a KSampler node might have its seed, steps, and cfg values swapped around when loading a workflow, resulting in a seed value appearing where cfg should be, etc.
Example
Here's how the same KSampler node's inputs can be returned in different orders from different backends:
Backend A (alphabetical order):
{
"cfg": ["FLOAT", { "default": 8, "max": 100, "min": 0, "round": 0.01, "step": 0.1 }],
"denoise": ["FLOAT", { "default": 1, "max": 1, "min": 0, "step": 0.01 }],
"latent_image": ["LATENT", {}],
"model": ["MODEL", {}],
"negative": ["CONDITIONING", {}],
"positive": ["CONDITIONING", {}],
"sampler_name": [["euler", "euler_cfg_pp", "..."], {}],
"scheduler": [["simple", "sgm_uniform", "..."], {}],
"seed": ["INT", { "default": 0, "max": 18446744073709552000, "min": 0 }],
"steps": ["INT", { "default": 20, "max": 10000, "min": 1 }]
}Backend B (different order):
{
"model": ["MODEL", {}],
"seed": ["INT", { "default": 0, "min": 0, "max": 18446744073709551615 }],
"steps": ["INT", { "default": 20, "min": 1, "max": 10000 }],
"cfg": ["FLOAT", { "default": 8.0, "min": 0.0, "max": 100.0, "step": 0.1, "round": 0.01 }],
"sampler_name": [["euler", "euler_cfg_pp", "..."], {}],
"scheduler": [["simple", "sgm_uniform", "..."], {}],
"positive": ["CONDITIONING", {}],
"negative": ["CONDITIONING", {}],
"latent_image": ["LATENT", {}],
"denoise": ["FLOAT", { "default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01 }]
}The widget values in a workflow are stored as an array like this:
{
"3": {
"class_type": "KSampler",
"inputs": { ... },
"widgets_values": [156680208700286, 1234, "euler", "normal", 20, 8, 1]
}
}If the widget order changes between save and load, these values get misaligned - the seed value might end up where steps should be, etc.
Technical Context
- Widget values are serialized as an array indexed by widget position
- The backend provides an
input_orderfield in node definitions that specifies the correct order - The issue relates to how the frontend transforms node definitions and creates widgets from inputs
- This affects the workflow serialization/deserialization process
Key Areas to Investigate
- How node definitions are transformed when received from the backend
- The widget creation process during node registration
- How widget values are serialized to and deserialized from workflow JSON
- Where and how the
input_orderfield could be utilized
Expected Behavior
- Widget values should maintain their correct associations regardless of JSON key ordering from the backend
- The solution should gracefully handle cases where
input_ordermight not exist (backwards compatibility) - Workflows should be portable between different ComfyUI backends without value corruption
┆Issue is synchronized with this Notion page by Unito