From 822d4e753ae3f3aa37b95b02a33642460f72df84 Mon Sep 17 00:00:00 2001 From: Federico Volovnik-Jose Date: Mon, 27 Apr 2026 14:43:34 +0200 Subject: [PATCH] fix(loader): force re-run when keep_loaded=False so freed model gets reloaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ComfyUI caches each node's output keyed by its inputs. With keep_loaded=False, the previous run's Generate node freed the model and processor from the cache (model=None, processor=None on the still-cached MOSS_TTS_MODEL handle). Without IS_CHANGED, ComfyUI hands that empty handle to the next run's Generate, which crashes with 'NoneType has no attribute build_user_message'. Add IS_CHANGED that returns a fresh value (time.time()) when keep_loaded is False, forcing ComfyUI to re-execute load() each run. get_or_load then sees an empty cache and reloads the model from the local HuggingFace cache. For keep_loaded=True the return value is stable, so ComfyUI keeps reusing the same loaded model — preserves the original keep-resident behaviour. --- nodes/loader.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nodes/loader.py b/nodes/loader.py index 42099c4..1d20af0 100644 --- a/nodes/loader.py +++ b/nodes/loader.py @@ -1,5 +1,7 @@ """ComfyUI node: MOSSTTSLoader.""" +import time + from ..lib.model_state import get_or_load @@ -27,6 +29,16 @@ class MOSSTTSLoader: FUNCTION = "load" CATEGORY = "MOSS-TTS/loaders" + @classmethod + def IS_CHANGED(cls, model_id, device, dtype, attn_implementation, keep_loaded): + # When keep_loaded is False, the previous run's Generate node freed the + # model from the cache. ComfyUI's per-node output cache would otherwise + # hand the now-empty handle to Generate again. Returning a fresh value + # each call forces ComfyUI to re-execute load() and reload the model. + if not keep_loaded: + return time.time() + return f"{model_id}|{device}|{dtype}|{attn_implementation}|keep" + def load(self, model_id, device, dtype, attn_implementation, keep_loaded): entry = get_or_load( model_id=model_id,