refactor: process isolation support for node replacement API

- Move REGISTERED_NODE_REPLACEMENTS global to NodeReplaceManager instance state
- Add NodeReplacement class to ComfyAPI_latest with async register() method
- Deprecate module-level register_node_replacement() function
- Call register_replacements() from comfy_entrypoint()

This enables pyisolate compatibility where extensions run in separate
processes and communicate via RPC. The async API allows registration
calls to cross process boundaries.

Refs: TDD-002
Amp-Thread-ID: https://ampcode.com/threads/T-019c2b33-ac55-76a9-9c6b-0246a8625f21
This commit is contained in:
bymyself
2026-02-04 19:44:02 -08:00
parent d5b3da823d
commit 3f18652588
4 changed files with 90 additions and 38 deletions

View File

@@ -22,6 +22,23 @@ class ComfyAPI_latest(ComfyAPIBase):
VERSION = "latest"
STABLE = False
class NodeReplacement(ProxiedSingleton):
async def register(self, node_replace: 'node_replace.NodeReplace') -> None:
"""
Register a node replacement mapping.
This async method supports process isolation via pyisolate, where
extensions run in separate processes. The call is RPC'd to the host
process where PromptServer and NodeReplaceManager live.
Args:
node_replace: A NodeReplace object defining the old->new mapping
"""
from server import PromptServer
PromptServer.instance.node_replace_manager.register(node_replace)
node_replacement: NodeReplacement
class Execution(ProxiedSingleton):
async def set_progress(
self,

View File

@@ -1,13 +1,25 @@
from __future__ import annotations
import warnings
from typing import Any
import app.node_replace_manager
def register_node_replacement(node_replace: NodeReplace):
"""
Register node replacement.
.. deprecated::
Use ``ComfyAPI.node_replacement.register()`` instead.
This synchronous function does not work with process isolation (pyisolate).
"""
app.node_replace_manager.register_node_replacement(node_replace)
warnings.warn(
"register_node_replacement() is deprecated. "
"Use 'await ComfyAPI.node_replacement.register()' instead for pyisolate compatibility.",
DeprecationWarning,
stacklevel=2
)
from server import PromptServer
PromptServer.instance.node_replace_manager.register(node_replace)
class NodeReplace: