From e9c87d20e07837dff4a53b61d33f7cbf24f2eaa2 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 17:31:55 +0000 Subject: [PATCH 1/6] Warn and report the agent as unavailable when the served frontend is too old A frontend pin that fails to load falls back to the default frontend. If that frontend predates the agent panel, the page has no Agent button, the only sign is a server log line, and /api/features still says ready. --- app/agent_host.py | 28 +++++++++++ app/frontend_management.py | 13 +++++ server.py | 2 + tests-unit/app_test/agent_host_test.py | 51 ++++++++++++++++++++ tests-unit/app_test/frontend_manager_test.py | 22 +++++++++ 5 files changed, 116 insertions(+) diff --git a/app/agent_host.py b/app/agent_host.py index 9db531b0f69..957389f58de 100644 --- a/app/agent_host.py +++ b/app/agent_host.py @@ -21,12 +21,15 @@ import importlib.metadata import logging import os +import re import folder_paths from comfy_api import feature_flags ENTRY_POINT_GROUP = "comfyui.agent" PROTOCOL = "v1" +# The first frontend that mounts the agent panel from the `agent` feature flag. +MIN_FRONTEND_VERSION = "1.58.1" _host = None # Set when loading or starting the host failed, so the flag reports why rather @@ -34,6 +37,8 @@ _failure = None # feature_flag() can be read on every connection; log a raising status() once. _status_logged = False +# Set when the served frontend predates the agent panel. The host keeps running. +_frontend_outdated = False def emit_event(event, /, **fields) -> None: @@ -74,6 +79,27 @@ def load() -> bool: return _failure is None +def _parse_frontend_version(version: str) -> tuple[int, ...] | None: + match = re.match(r"(\d+)\.(\d+)\.(\d+)", version) + return tuple(int(part) for part in match.groups()) if match else None + + +def check_frontend(served: str | None, requested: str | None) -> None: + """Report a frontend too old to show the agent panel, so a page with no Agent + button isn't the only sign of it. `served` is None when the version is unknown.""" + global _frontend_outdated + served_version = _parse_frontend_version(served) if served else None + if served_version is None or served_version >= _parse_frontend_version(MIN_FRONTEND_VERSION): + return + logging.warning( + f"Frontend {served} is being served (requested: {requested or 'default'}), but the agent panel needs " + f"{MIN_FRONTEND_VERSION} or newer, so it won't appear. If you pinned a newer frontend, check the log above for why it did not load." + ) + _frontend_outdated = True + emit_event("agent_error", reason="frontend_outdated") + _publish_flag() + + def register(app) -> None: """Mount the agent's own API routes onto ComfyUI's aiohttp ``app``. @@ -163,6 +189,8 @@ def feature_flag(): flag = {"state": status["state"]} if status.get("reason"): flag["reason"] = status["reason"] + if _frontend_outdated and flag["state"] != "failed": + return {"state": "failed", "reason": "frontend_outdated"} return flag except SystemExit: # a wheel that exits is broken, not briefly unhealthy, so disable it logging.exception("The local agent's status could not be read; it is disabled.") diff --git a/app/frontend_management.py b/app/frontend_management.py index 5d9b2846cff..46bc2ad7f89 100644 --- a/app/frontend_management.py +++ b/app/frontend_management.py @@ -252,6 +252,19 @@ def default_frontend_path(cls) -> str: ) sys.exit(-1) + @classmethod + def served_version(cls, web_root: str) -> Optional[str]: + """The version of the official frontend at web_root, or None if it isn't one we can identify.""" + path = Path(web_root) + if path.parent == Path(cls.CUSTOM_FRONTENDS_ROOT) / "Comfy-Org_ComfyUI_frontend": + return path.name + if web_root != cls.default_frontend_path(): + return None + try: + return version("comfyui-frontend-package") + except Exception: + return None + @classmethod def template_asset_map(cls) -> Optional[Dict[str, str]]: """Return a mapping of template asset names to their absolute paths.""" diff --git a/server.py b/server.py index 3eb75d925bb..6e3b8158a66 100644 --- a/server.py +++ b/server.py @@ -1326,6 +1326,8 @@ def add_routes(self): # router freezes in start_multi_address(). if args.enable_agent: agent_host.register(self.app) + if args.front_end_root is None: # a custom root has no version to compare + agent_host.check_frontend(FrontendManager.served_version(self.web_root), args.front_end_version) self.user_manager.add_routes(self.routes) self.model_file_manager.add_routes(self.routes) self.custom_node_manager.add_routes(self.routes, self.app, nodes.LOADED_MODULE_DIRS.items()) diff --git a/tests-unit/app_test/agent_host_test.py b/tests-unit/app_test/agent_host_test.py index aa463d8a628..4146359602a 100644 --- a/tests-unit/app_test/agent_host_test.py +++ b/tests-unit/app_test/agent_host_test.py @@ -46,6 +46,7 @@ def _reset(monkeypatch): monkeypatch.setattr(agent_host, "_host", None) monkeypatch.setattr(agent_host, "_failure", None) monkeypatch.setattr(agent_host, "_status_logged", False) + monkeypatch.setattr(agent_host, "_frontend_outdated", False) # The loader publishes the agent flag by mutating this shared dict; keep that # leakage out of other tests. feature_flags.SERVER_FEATURE_FLAGS.pop("agent", None) @@ -297,3 +298,53 @@ def slow_start(**kwargs): loop.run_until_complete(asyncio.wait_for(_until(lambda: agent_host._host.started), 5)) finally: loop.close() + + +def _ready_host(monkeypatch): + host = FakeHost() + host.state["state"] = "ready" + _entry_points(monkeypatch, {"v1": lambda: host}) + assert agent_host.load() is True + return host + + +def test_outdated_frontend_warns_and_reports_unavailable(monkeypatch, caplog): + host = _ready_host(monkeypatch) + with caplog.at_level(logging.INFO): + agent_host.check_frontend("1.57.6", "Comfy-Org/ComfyUI_frontend@1.59.0") + + assert agent_host.feature_flag() == {"state": "failed", "reason": "frontend_outdated"} + assert feature_flags.SERVER_FEATURE_FLAGS["agent"] == {"state": "failed", "reason": "frontend_outdated"} + warning = next(r.getMessage() for r in caplog.records if r.levelno == logging.WARNING) + assert "1.57.6" in warning and "Comfy-Org/ComfyUI_frontend@1.59.0" in warning and agent_host.MIN_FRONTEND_VERSION in warning + assert "[agent-event] agent_error reason=frontend_outdated" in _agent_records(caplog) + assert host.stopped == 0 # the host keeps running: a newer frontend can still use it + + +@pytest.mark.parametrize("served", ["1.58.1", "1.59.0", "1.59.0.dev2", "2.0.0"]) +def test_supported_frontend_keeps_the_host_state(monkeypatch, served): + _ready_host(monkeypatch) + agent_host.check_frontend(served, None) + assert agent_host.feature_flag() == {"state": "ready"} + + +@pytest.mark.parametrize("served", [None, "not-a-version"]) +def test_unknown_frontend_version_is_not_flagged(monkeypatch, served): + # --front-end-root or a fork: nothing to compare, so don't claim it is outdated. + _ready_host(monkeypatch) + agent_host.check_frontend(served, None) + assert agent_host.feature_flag() == {"state": "ready"} + + +def test_host_failure_reason_wins_over_outdated_frontend(monkeypatch): + host = _ready_host(monkeypatch) + host.state.update(state="failed", reason="crashed") + agent_host.check_frontend("1.57.6", None) + assert agent_host.feature_flag() == {"state": "failed", "reason": "crashed"} + + +def test_failed_load_is_not_replaced_by_outdated_frontend(monkeypatch): + _entry_points(monkeypatch, {}) + assert agent_host.load() is False + agent_host.check_frontend("1.57.6", None) + assert agent_host.feature_flag() == {"state": "failed", "reason": "package_missing"} diff --git a/tests-unit/app_test/frontend_manager_test.py b/tests-unit/app_test/frontend_manager_test.py index 6fa245b4ea5..4c1b54a099d 100644 --- a/tests-unit/app_test/frontend_manager_test.py +++ b/tests-unit/app_test/frontend_manager_test.py @@ -373,3 +373,25 @@ def get_asset_path(template_id, filename): asset_map = FrontendManager.template_asset_map() assert asset_map == {"example.json": "/templates/example.json"} + + +def test_served_version_of_a_downloaded_frontend(): + root = FrontendManager.CUSTOM_FRONTENDS_ROOT + assert FrontendManager.served_version(f"{root}/Comfy-Org_ComfyUI_frontend/1.59.0") == "1.59.0" + + +def test_served_version_ignores_other_downloaded_frontends(): + root = FrontendManager.CUSTOM_FRONTENDS_ROOT + assert FrontendManager.served_version(f"{root}/someone_ComfyUI_frontend/1.2.3") is None + + +def test_served_version_of_the_default_frontend(): + with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): + with patch("app.frontend_management.version", return_value="1.57.6") as installed: + assert FrontendManager.served_version("/site/static") == "1.57.6" + installed.assert_called_once_with("comfyui-frontend-package") + + +def test_served_version_of_a_custom_root_is_unknown(): + with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): + assert FrontendManager.served_version("/my/dev/dist") is None From abb5cce27ff144caa8f2872d2f3bb8544aa874e0 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 17:35:56 +0000 Subject: [PATCH 2/6] Keep the host state and add a frontend_outdated note instead state describes the host, and a separately hosted frontend can still use it. Skip the check when the agent already failed, avoid default_frontend_path() exiting when the frontend package is missing, and compare with packaging so pre-release builds of the minimum count as older. --- app/agent_host.py | 34 ++++++++-------- app/frontend_management.py | 7 +++- server.py | 5 ++- tests-unit/app_test/agent_host_test.py | 43 ++++++++++++-------- tests-unit/app_test/frontend_manager_test.py | 15 ++++--- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/app/agent_host.py b/app/agent_host.py index 957389f58de..6a44cf99d2e 100644 --- a/app/agent_host.py +++ b/app/agent_host.py @@ -21,7 +21,6 @@ import importlib.metadata import logging import os -import re import folder_paths from comfy_api import feature_flags @@ -79,24 +78,25 @@ def load() -> bool: return _failure is None -def _parse_frontend_version(version: str) -> tuple[int, ...] | None: - match = re.match(r"(\d+)\.(\d+)\.(\d+)", version) - return tuple(int(part) for part in match.groups()) if match else None - - -def check_frontend(served: str | None, requested: str | None) -> None: +def check_frontend(served: str | None, pinned: str | None) -> None: """Report a frontend too old to show the agent panel, so a page with no Agent - button isn't the only sign of it. `served` is None when the version is unknown.""" + button isn't the only sign of it. `served` is None when the version is unknown; + `pinned` is what --front-end-version asked for, if it asked. The host's state + is left alone: it describes the host, and a newer frontend can still use it.""" + from packaging.version import InvalidVersion, Version + global _frontend_outdated - served_version = _parse_frontend_version(served) if served else None - if served_version is None or served_version >= _parse_frontend_version(MIN_FRONTEND_VERSION): + if _failure is not None or _host is None or served is None: + return + try: + if Version(served) >= Version(MIN_FRONTEND_VERSION): + return + except InvalidVersion: return - logging.warning( - f"Frontend {served} is being served (requested: {requested or 'default'}), but the agent panel needs " - f"{MIN_FRONTEND_VERSION} or newer, so it won't appear. If you pinned a newer frontend, check the log above for why it did not load." - ) + cause = f"check the log above for why {pinned} did not load" if pinned else "update comfyui-frontend-package" + logging.warning(f"Frontend {served} is too old for the agent panel, which needs {MIN_FRONTEND_VERSION} or newer, so it won't appear: {cause}.") _frontend_outdated = True - emit_event("agent_error", reason="frontend_outdated") + emit_event("frontend_outdated", served=served, pinned=pinned) _publish_flag() @@ -189,8 +189,8 @@ def feature_flag(): flag = {"state": status["state"]} if status.get("reason"): flag["reason"] = status["reason"] - if _frontend_outdated and flag["state"] != "failed": - return {"state": "failed", "reason": "frontend_outdated"} + if _frontend_outdated: + flag["frontend_outdated"] = True return flag except SystemExit: # a wheel that exits is broken, not briefly unhealthy, so disable it logging.exception("The local agent's status could not be read; it is disabled.") diff --git a/app/frontend_management.py b/app/frontend_management.py index 46bc2ad7f89..3b03fbd7b8e 100644 --- a/app/frontend_management.py +++ b/app/frontend_management.py @@ -6,6 +6,7 @@ import tempfile import zipfile import importlib +import importlib.util from dataclasses import dataclass from functools import cached_property from pathlib import Path @@ -256,8 +257,10 @@ def default_frontend_path(cls) -> str: def served_version(cls, web_root: str) -> Optional[str]: """The version of the official frontend at web_root, or None if it isn't one we can identify.""" path = Path(web_root) - if path.parent == Path(cls.CUSTOM_FRONTENDS_ROOT) / "Comfy-Org_ComfyUI_frontend": - return path.name + if path.parent.parent == Path(cls.CUSTOM_FRONTENDS_ROOT): + return path.name if path.parent.name.lower() == "comfy-org_comfyui_frontend" else None + if importlib.util.find_spec("comfyui_frontend_package") is None: # default_frontend_path() would exit + return None if web_root != cls.default_frontend_path(): return None try: diff --git a/server.py b/server.py index 6e3b8158a66..5b876395512 100644 --- a/server.py +++ b/server.py @@ -35,7 +35,7 @@ import logging import mimetypes -from comfy.cli_args import args +from comfy.cli_args import args, DEFAULT_VERSION_STRING import comfy.utils import comfy.model_management from comfy_api import feature_flags @@ -1327,7 +1327,8 @@ def add_routes(self): if args.enable_agent: agent_host.register(self.app) if args.front_end_root is None: # a custom root has no version to compare - agent_host.check_frontend(FrontendManager.served_version(self.web_root), args.front_end_version) + pinned = args.front_end_version if args.front_end_version != DEFAULT_VERSION_STRING else None + agent_host.check_frontend(FrontendManager.served_version(self.web_root), pinned) self.user_manager.add_routes(self.routes) self.model_file_manager.add_routes(self.routes) self.custom_node_manager.add_routes(self.routes, self.app, nodes.LOADED_MODULE_DIRS.items()) diff --git a/tests-unit/app_test/agent_host_test.py b/tests-unit/app_test/agent_host_test.py index 4146359602a..ef5509fc649 100644 --- a/tests-unit/app_test/agent_host_test.py +++ b/tests-unit/app_test/agent_host_test.py @@ -308,43 +308,54 @@ def _ready_host(monkeypatch): return host -def test_outdated_frontend_warns_and_reports_unavailable(monkeypatch, caplog): +def test_outdated_frontend_warns_and_is_reported_alongside_the_host_state(monkeypatch, caplog): host = _ready_host(monkeypatch) with caplog.at_level(logging.INFO): agent_host.check_frontend("1.57.6", "Comfy-Org/ComfyUI_frontend@1.59.0") - assert agent_host.feature_flag() == {"state": "failed", "reason": "frontend_outdated"} - assert feature_flags.SERVER_FEATURE_FLAGS["agent"] == {"state": "failed", "reason": "frontend_outdated"} + assert agent_host.feature_flag() == {"state": "ready", "frontend_outdated": True} + assert feature_flags.SERVER_FEATURE_FLAGS["agent"] == {"state": "ready", "frontend_outdated": True} warning = next(r.getMessage() for r in caplog.records if r.levelno == logging.WARNING) assert "1.57.6" in warning and "Comfy-Org/ComfyUI_frontend@1.59.0" in warning and agent_host.MIN_FRONTEND_VERSION in warning - assert "[agent-event] agent_error reason=frontend_outdated" in _agent_records(caplog) - assert host.stopped == 0 # the host keeps running: a newer frontend can still use it + assert "[agent-event] frontend_outdated served=1.57.6 pinned=Comfy-Org/ComfyUI_frontend@1.59.0" in _agent_records(caplog) + + host.state.update(state="failed", reason="crashed") # later host changes keep the note + assert agent_host.feature_flag() == {"state": "failed", "reason": "crashed", "frontend_outdated": True} + + +def test_outdated_default_frontend_says_to_update_the_package(monkeypatch, caplog): + _ready_host(monkeypatch) + with caplog.at_level(logging.WARNING): + agent_host.check_frontend("1.57.6", None) + assert "update comfyui-frontend-package" in caplog.text @pytest.mark.parametrize("served", ["1.58.1", "1.59.0", "1.59.0.dev2", "2.0.0"]) -def test_supported_frontend_keeps_the_host_state(monkeypatch, served): +def test_supported_frontend_is_not_flagged(monkeypatch, served): _ready_host(monkeypatch) agent_host.check_frontend(served, None) assert agent_host.feature_flag() == {"state": "ready"} +@pytest.mark.parametrize("served", ["1.58.0", "1.58.1.dev0", "1.58.1rc1"]) +def test_builds_before_the_minimum_are_flagged(monkeypatch, served): + _ready_host(monkeypatch) + agent_host.check_frontend(served, None) + assert agent_host.feature_flag() == {"state": "ready", "frontend_outdated": True} + + @pytest.mark.parametrize("served", [None, "not-a-version"]) def test_unknown_frontend_version_is_not_flagged(monkeypatch, served): - # --front-end-root or a fork: nothing to compare, so don't claim it is outdated. _ready_host(monkeypatch) agent_host.check_frontend(served, None) assert agent_host.feature_flag() == {"state": "ready"} -def test_host_failure_reason_wins_over_outdated_frontend(monkeypatch): - host = _ready_host(monkeypatch) - host.state.update(state="failed", reason="crashed") - agent_host.check_frontend("1.57.6", None) - assert agent_host.feature_flag() == {"state": "failed", "reason": "crashed"} - - -def test_failed_load_is_not_replaced_by_outdated_frontend(monkeypatch): +def test_no_frontend_warning_when_the_agent_failed_to_load(monkeypatch, caplog): _entry_points(monkeypatch, {}) assert agent_host.load() is False - agent_host.check_frontend("1.57.6", None) + caplog.clear() + with caplog.at_level(logging.INFO): + agent_host.check_frontend("1.57.6", None) assert agent_host.feature_flag() == {"state": "failed", "reason": "package_missing"} + assert "too old" not in caplog.text and not _agent_records(caplog) diff --git a/tests-unit/app_test/frontend_manager_test.py b/tests-unit/app_test/frontend_manager_test.py index 4c1b54a099d..f13fd95dad6 100644 --- a/tests-unit/app_test/frontend_manager_test.py +++ b/tests-unit/app_test/frontend_manager_test.py @@ -1,4 +1,5 @@ import argparse +import sys from types import SimpleNamespace from unittest.mock import Mock, patch, mock_open @@ -378,6 +379,7 @@ def get_asset_path(template_id, filename): def test_served_version_of_a_downloaded_frontend(): root = FrontendManager.CUSTOM_FRONTENDS_ROOT assert FrontendManager.served_version(f"{root}/Comfy-Org_ComfyUI_frontend/1.59.0") == "1.59.0" + assert FrontendManager.served_version(f"{root}/comfy-org_comfyui_frontend/1.57.0") == "1.57.0" def test_served_version_ignores_other_downloaded_frontends(): @@ -386,12 +388,13 @@ def test_served_version_ignores_other_downloaded_frontends(): def test_served_version_of_the_default_frontend(): - with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): - with patch("app.frontend_management.version", return_value="1.57.6") as installed: - assert FrontendManager.served_version("/site/static") == "1.57.6" + with patch.dict(sys.modules, {"comfyui_frontend_package": Mock()}): + with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): + with patch("app.frontend_management.version", return_value="1.57.6") as installed: + assert FrontendManager.served_version("/site/static") == "1.57.6" installed.assert_called_once_with("comfyui-frontend-package") -def test_served_version_of_a_custom_root_is_unknown(): - with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): - assert FrontendManager.served_version("/my/dev/dist") is None +def test_served_version_does_not_exit_without_the_frontend_package(): + with patch.dict(sys.modules, {"comfyui_frontend_package": None}): # import raises ImportError + assert FrontendManager.served_version("/some/other/frontend") is None From 94884da8eaf9c6c53b71eb099d6fb4b32c887a6b Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 17:36:18 +0000 Subject: [PATCH 3/6] Mock find_spec in the served_version tests --- tests-unit/app_test/frontend_manager_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests-unit/app_test/frontend_manager_test.py b/tests-unit/app_test/frontend_manager_test.py index f13fd95dad6..67bc6641347 100644 --- a/tests-unit/app_test/frontend_manager_test.py +++ b/tests-unit/app_test/frontend_manager_test.py @@ -1,5 +1,4 @@ import argparse -import sys from types import SimpleNamespace from unittest.mock import Mock, patch, mock_open @@ -388,7 +387,7 @@ def test_served_version_ignores_other_downloaded_frontends(): def test_served_version_of_the_default_frontend(): - with patch.dict(sys.modules, {"comfyui_frontend_package": Mock()}): + with patch("importlib.util.find_spec", return_value=Mock()): with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): with patch("app.frontend_management.version", return_value="1.57.6") as installed: assert FrontendManager.served_version("/site/static") == "1.57.6" @@ -396,5 +395,6 @@ def test_served_version_of_the_default_frontend(): def test_served_version_does_not_exit_without_the_frontend_package(): - with patch.dict(sys.modules, {"comfyui_frontend_package": None}): # import raises ImportError - assert FrontendManager.served_version("/some/other/frontend") is None + with patch("importlib.util.find_spec", return_value=None): + with patch.object(FrontendManager, "default_frontend_path", side_effect=SystemExit(-1)): + assert FrontendManager.served_version("/some/other/frontend") is None From 9fbf83b6d49161b8648d13d2e71a804195bf4b9d Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 17:47:13 +0000 Subject: [PATCH 4/6] Say what to do when an old pin loaded, and import packaging at module scope --- app/agent_host.py | 11 ++++++++--- tests-unit/app_test/agent_host_test.py | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/agent_host.py b/app/agent_host.py index 6a44cf99d2e..514e4d8b67e 100644 --- a/app/agent_host.py +++ b/app/agent_host.py @@ -22,6 +22,8 @@ import logging import os +from packaging.version import InvalidVersion, Version + import folder_paths from comfy_api import feature_flags @@ -83,8 +85,6 @@ def check_frontend(served: str | None, pinned: str | None) -> None: button isn't the only sign of it. `served` is None when the version is unknown; `pinned` is what --front-end-version asked for, if it asked. The host's state is left alone: it describes the host, and a newer frontend can still use it.""" - from packaging.version import InvalidVersion, Version - global _frontend_outdated if _failure is not None or _host is None or served is None: return @@ -93,7 +93,12 @@ def check_frontend(served: str | None, pinned: str | None) -> None: return except InvalidVersion: return - cause = f"check the log above for why {pinned} did not load" if pinned else "update comfyui-frontend-package" + if not pinned: + cause = "update comfyui-frontend-package" + elif pinned.rpartition("@")[2].lstrip("v") == served: + cause = f"pin a newer version than {pinned}" + else: + cause = f"check the log above for why {pinned} did not load" logging.warning(f"Frontend {served} is too old for the agent panel, which needs {MIN_FRONTEND_VERSION} or newer, so it won't appear: {cause}.") _frontend_outdated = True emit_event("frontend_outdated", served=served, pinned=pinned) diff --git a/tests-unit/app_test/agent_host_test.py b/tests-unit/app_test/agent_host_test.py index ef5509fc649..ad5404dc93f 100644 --- a/tests-unit/app_test/agent_host_test.py +++ b/tests-unit/app_test/agent_host_test.py @@ -323,6 +323,13 @@ def test_outdated_frontend_warns_and_is_reported_alongside_the_host_state(monkey assert agent_host.feature_flag() == {"state": "failed", "reason": "crashed", "frontend_outdated": True} +def test_old_pin_that_loaded_says_to_pin_newer(monkeypatch, caplog): + _ready_host(monkeypatch) + with caplog.at_level(logging.WARNING): + agent_host.check_frontend("1.57.0", "Comfy-Org/ComfyUI_frontend@v1.57.0") + assert "pin a newer version" in caplog.text and "did not load" not in caplog.text + + def test_outdated_default_frontend_says_to_update_the_package(monkeypatch, caplog): _ready_host(monkeypatch) with caplog.at_level(logging.WARNING): From 01e5052a610897754ae89b118ff5d879a85c53b2 Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 2 Nov 2026 05:55:12 +0000 Subject: [PATCH 5/6] Handle the default pin and a custom frontend root inside check_frontend Moves the two argument checks out of server.py into agent_host.check_frontend, where unit tests cover them. server.py now passes the raw arguments. --- app/agent_host.py | 10 +++++++--- server.py | 6 ++---- tests-unit/app_test/agent_host_test.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/agent_host.py b/app/agent_host.py index 514e4d8b67e..2043260e4f1 100644 --- a/app/agent_host.py +++ b/app/agent_host.py @@ -25,6 +25,7 @@ from packaging.version import InvalidVersion, Version import folder_paths +from comfy.cli_args import DEFAULT_VERSION_STRING from comfy_api import feature_flags ENTRY_POINT_GROUP = "comfyui.agent" @@ -80,14 +81,17 @@ def load() -> bool: return _failure is None -def check_frontend(served: str | None, pinned: str | None) -> None: +def check_frontend(served: str | None, pinned: str | None, front_end_root: str | None = None) -> None: """Report a frontend too old to show the agent panel, so a page with no Agent button isn't the only sign of it. `served` is None when the version is unknown; - `pinned` is what --front-end-version asked for, if it asked. The host's state + `pinned` is the --front-end-version argument and `front_end_root` the + --front-end-root one. A custom root has no version to compare. The host's state is left alone: it describes the host, and a newer frontend can still use it.""" global _frontend_outdated - if _failure is not None or _host is None or served is None: + if _failure is not None or _host is None or served is None or front_end_root is not None: return + if pinned == DEFAULT_VERSION_STRING: + pinned = None try: if Version(served) >= Version(MIN_FRONTEND_VERSION): return diff --git a/server.py b/server.py index 5b876395512..46d86cfeacb 100644 --- a/server.py +++ b/server.py @@ -35,7 +35,7 @@ import logging import mimetypes -from comfy.cli_args import args, DEFAULT_VERSION_STRING +from comfy.cli_args import args import comfy.utils import comfy.model_management from comfy_api import feature_flags @@ -1326,9 +1326,7 @@ def add_routes(self): # router freezes in start_multi_address(). if args.enable_agent: agent_host.register(self.app) - if args.front_end_root is None: # a custom root has no version to compare - pinned = args.front_end_version if args.front_end_version != DEFAULT_VERSION_STRING else None - agent_host.check_frontend(FrontendManager.served_version(self.web_root), pinned) + agent_host.check_frontend(FrontendManager.served_version(self.web_root), args.front_end_version, args.front_end_root) self.user_manager.add_routes(self.routes) self.model_file_manager.add_routes(self.routes) self.custom_node_manager.add_routes(self.routes, self.app, nodes.LOADED_MODULE_DIRS.items()) diff --git a/tests-unit/app_test/agent_host_test.py b/tests-unit/app_test/agent_host_test.py index ad5404dc93f..d6974c476fd 100644 --- a/tests-unit/app_test/agent_host_test.py +++ b/tests-unit/app_test/agent_host_test.py @@ -14,6 +14,7 @@ import folder_paths from app import agent_host +from comfy.cli_args import DEFAULT_VERSION_STRING from comfy_api import feature_flags @@ -366,3 +367,19 @@ def test_no_frontend_warning_when_the_agent_failed_to_load(monkeypatch, caplog): agent_host.check_frontend("1.57.6", None) assert agent_host.feature_flag() == {"state": "failed", "reason": "package_missing"} assert "too old" not in caplog.text and not _agent_records(caplog) + + +def test_default_version_argument_counts_as_no_pin(monkeypatch, caplog): + _ready_host(monkeypatch) + with caplog.at_level(logging.WARNING): + agent_host.check_frontend("1.57.6", DEFAULT_VERSION_STRING, None) + assert "update comfyui-frontend-package" in caplog.text + assert DEFAULT_VERSION_STRING not in caplog.text + + +def test_custom_frontend_root_is_not_checked(monkeypatch, caplog): + _ready_host(monkeypatch) + with caplog.at_level(logging.INFO): + agent_host.check_frontend("1.57.6", "Comfy-Org/ComfyUI_frontend@1.59.0", "/srv/my-frontend") + assert agent_host.feature_flag() == {"state": "ready"} + assert "too old" not in caplog.text and not _agent_records(caplog) From e483bfdab8661c0c32caf32b39686cd657917540 Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 2 Nov 2026 06:17:49 +0000 Subject: [PATCH 6/6] Read the served frontend version without risking an exit served_version() called default_frontend_path(), which exits when comfyui-frontend-package is present but fails to import. Both now share _package_frontend_path(), which returns None instead. --- app/frontend_management.py | 18 ++++++++++------- tests-unit/app_test/frontend_manager_test.py | 21 +++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/frontend_management.py b/app/frontend_management.py index bc466e29ccb..9e3cf0a065f 100644 --- a/app/frontend_management.py +++ b/app/frontend_management.py @@ -6,7 +6,6 @@ import tempfile import zipfile import importlib -import importlib.util from dataclasses import dataclass from functools import cached_property from pathlib import Path @@ -242,12 +241,18 @@ def get_comfy_package_versions(cls): return get_comfy_package_versions() @classmethod - def default_frontend_path(cls) -> str: + def _package_frontend_path(cls) -> Optional[str]: + """The frontend bundled in comfyui-frontend-package, or None if the package can't be imported.""" try: import comfyui_frontend_package - - return str(importlib.resources.files(comfyui_frontend_package) / "static") except ImportError: + return None + return str(importlib.resources.files(comfyui_frontend_package) / "static") + + @classmethod + def default_frontend_path(cls) -> str: + path = cls._package_frontend_path() + if path is None: logging.error( f""" ********** ERROR *********** @@ -260,6 +265,7 @@ def default_frontend_path(cls) -> str: """.strip() ) sys.exit(-1) + return path @classmethod def served_version(cls, web_root: str) -> Optional[str]: @@ -267,9 +273,7 @@ def served_version(cls, web_root: str) -> Optional[str]: path = Path(web_root) if path.parent.parent == Path(cls.CUSTOM_FRONTENDS_ROOT): return path.name if path.parent.name.lower() == "comfy-org_comfyui_frontend" else None - if importlib.util.find_spec("comfyui_frontend_package") is None: # default_frontend_path() would exit - return None - if web_root != cls.default_frontend_path(): + if web_root != cls._package_frontend_path(): # not default_frontend_path(), which exits without the package return None try: return version("comfyui-frontend-package") diff --git a/tests-unit/app_test/frontend_manager_test.py b/tests-unit/app_test/frontend_manager_test.py index 6b608c01857..ae788da6b3b 100644 --- a/tests-unit/app_test/frontend_manager_test.py +++ b/tests-unit/app_test/frontend_manager_test.py @@ -482,14 +482,25 @@ def test_served_version_ignores_other_downloaded_frontends(): def test_served_version_of_the_default_frontend(): - with patch("importlib.util.find_spec", return_value=Mock()): - with patch.object(FrontendManager, "default_frontend_path", return_value="/site/static"): - with patch("app.frontend_management.version", return_value="1.57.6") as installed: - assert FrontendManager.served_version("/site/static") == "1.57.6" + with patch.object(FrontendManager, "_package_frontend_path", return_value="/site/static"): + with patch("app.frontend_management.version", return_value="1.57.6") as installed: + assert FrontendManager.served_version("/site/static") == "1.57.6" installed.assert_called_once_with("comfyui-frontend-package") def test_served_version_does_not_exit_without_the_frontend_package(): - with patch("importlib.util.find_spec", return_value=None): + with patch.object(FrontendManager, "_package_frontend_path", return_value=None): with patch.object(FrontendManager, "default_frontend_path", side_effect=SystemExit(-1)): assert FrontendManager.served_version("/some/other/frontend") is None + + +def test_served_version_does_not_exit_when_the_frontend_package_fails_to_import(): + real_import = __import__ + + def broken_import(name, *args, **kwargs): + if name == "comfyui_frontend_package": + raise ImportError("broken install") + return real_import(name, *args, **kwargs) + + with patch("builtins.__import__", side_effect=broken_import): + assert FrontendManager.served_version("/some/other/frontend") is None