Control layer "custom strength": range `end` silently reverts to the preset value on save/reload
Control layer "custom strength": range end silently reverts to the preset value on save/reload
Environment
- AI Image Diffusion 1.53.0, Krita 5.3.3, Windows 11
- ComfyUI as external server (not relevant, no custom nodes involved)
- Base model: SDXL / Illustrious
- Control mode used in the test:
pose(identical behaviour withcanny_edge)
Summary
With custom strength enabled on a control layer, the end of the range is silently
replaced by the value from presets/control.json the next time the document is loaded.
strength and start keep the custom values. No error, no warning, no log entry.
Steps to reproduce
- Add a control layer (mode = Pose, any source layer).
- Enable custom strength and set Strength = 0.40, Range = 0.10 -> 0.50.
- Save the document (Ctrl+S), close it, reopen it.
- Read Strength / Range in the docker.
Expected
0.40, range 0.10 -> 0.50
Actual
0.40, range 0.10 -> 0.80
0.8 is the end of preset index 1 in presets/control.json for pose / canny_edge
({"strength": 1.0, "start": 0.0, "end": 0.8}). With preset_value = 2 and
max_preset_value = 4, ControlPresets.interpolate(pose, arch, 2/4) resolves to exactly
that entry, so the value that appears is clearly the preset's, not a rounding artifact.
Root cause
model/properties.py writes the state with dir(), which is alphabetical:
def serialize(obj: QObject, converter=_default_serializer):
def _serialize(propt: str):
...
return {name: _serialize(name) for name in dir(obj.__class__) if is_persistent(obj, name)}so a control entry is persisted in this order:
end, layer_id, mode, preset_value, start, strength, use_custom_strengthand deserialize() applies the keys in file order, through the property setters:
def deserialize(obj: QObject, data: dict[str, Any], converter=_default_deserializer):
for name, value in data.items(): # file order
...
setattr(obj, name, value)In model/control.py, set_mode() re-derives the numeric values from the preset table
whenever use_custom_strength is not yet set, and _set_values_from_preset() writes
strength, start and end:
def set_mode(self, mode: ControlMode):
if mode != self.mode:
self._mode = mode
...
if not self.use_custom_strength:
self._set_values_from_preset()
def _set_values_from_preset(self):
params = ControlPresets.instance().interpolate(
self.mode, self._model.arch, self.preset_value / self.max_preset_value
)
self.strength = int(params.strength * self.strength_multiplier)
self.start, self.end = params.rangeSo the restore goes:
| # | key applied | value | result |
|---|---|---|---|
| 1 | end |
0.50 (custom) | 0.50 |
| 2 | mode |
pose | use_custom_strength is still False (it is written last) -> preset overwrites strength, start, end -> end = 0.80 |
| 3 | preset_value |
2 | equals current value -> no re-derive |
| 4 | start |
0.10 (custom) | written after mode, overwrites the preset value -> 0.10 (survives) |
| 5 | strength |
20 (custom) | also after mode -> 0.40 (survives) |
| 6 | use_custom_strength |
true | applied last, too late |
Net effect: exactly one field, end, silently reverts, because it is the only one of the
three numeric values that sorts before mode.
Additional observation (not fully pinned down)
We also had a generation run where the control layer's stored end was 1.0, but the
submitted graph used "end_percent": 0.8 in ControlNetApplyAdvanced - i.e. the value was
already the preset's at graph-build time, without any save/reload by the user. It happened
right after using "Generate control layer from image", which creates the new
[Control] <mode> layer and re-points layer_id to it. We did not isolate the trigger for
that in-session case (something re-reads the state after the layer is created); we only
verified the save/reload path described above.
Suggested fix
- Restore order-independently: apply
mode,preset_value,use_custom_strengthfirst (they are the ones with side effects), then the numeric properties. Or - Suppress
_set_values_from_preset()while restoring (e.g. a_restoringflag), so the preset is only ever applied on explicit user interaction. Or - At minimum, make
serialize()emit the orderdeserialize()needs - sort by an explicit priority list instead ofdir()- so a plugin-written file is at least self-consistent.
1 or 2 preferred: 3 alone leaves the order dependence in place for hand-written or third-party files.
Workaround
Pick the preset_value whose preset already holds the wanted numbers. For pose /
canny_edge (3 presets): preset_value = 2 -> 1.0 / 0.0-0.8, preset_value = 4 ->
1.0 / 0.0-1.0. Custom values that differ from the selected preset will lose end on the
next save/reload.
Source: Acly/krita-ai-diffusion