Skip to content

Conversation

@pollockjj
Copy link

@pollockjj pollockjj commented Dec 3, 2025

PyIsolate Update: Production-Ready Process Isolation for ComfyUI

Major Features

1. Full ComfyUI Integration with Path Unification

Commits: aee01de, 458d11a, 846e4cc, 8699bfa, 029ae2c
ComfyUI-side: 951a6ba7, a62150a3, 230544ac, 852251a0, 04485daa

  • Module-level sys.path unification prevents import errors in spawned processes
  • Host path preservation for multiprocessing.spawn compatibility
  • Automatic ComfyUI root detection and path ordering (ComfyUI root → isolated venv → host paths)
  • Validation layer ensures utils.json_util accessible in all children
  • Zero Impact: Logic only executes in child processes; host ComfyUI startup path remains untouched.

2. Lazy Loading & Caching System

Commits: b4cdd9a
ComfyUI-side: 1a20f4ac, fe3b402a

  • Zero startup penalty: Nodes cached after first spawn, instant on subsequent loads
  • Load at first use: Child processes spawn only when node appears in execution graph
  • Auto-eject: Processes terminate when node no longer in graph
  • Import time tracking shows isolated nodes: 0.0s (cached)
  • Architecture guarantee: Zero runtime overhead for standard (non-isolated) custom nodes

3. Windows Compatibility

Commits: dbca9bb
ComfyUI-side: 8587e20b

  • Manager-based IPC queues replace POSIX-only Queue implementation
  • Spawn context compatibility fixes for Windows multiprocessing
  • Cross-platform validated on Windows, Linux

Expansions

1. Torch Ecosystem Support

Commits: 99e742e, 8d83a4b, 4baa626, 4027e0c

  • Dynamic discovery of torch ecosystem packages (torchvision, torchaudio, etc.) for CUDA version compatibility
  • .pth-based venv inheritance for zero-copy tensor sharing via share_torch=True
  • Support for torch dev/nightly builds via --index-strategy unsafe-best-match (standard uv pattern for non-release version resolution where strict matching fails)
  • Optimized link mode handling for faster venv creation

2. Stateless RPC Implementation

Commits: cd07469, 846e4cc, d785fa3
ComfyUI-side: 6603f42c, d9a5c36c, 54784f33

  • CLIP Stateless RPC Proxy: Automatic serialization for CLIP models across process boundary
  • RPC Callback Support: Bidirectional async communication with context tracking
  • Global RPC instance management for child processes
  • ⚠️ Note: ModelPatcher serialization infrastructure in progress, not feature-complete

3. Tensor Serialization Safety

Commits: 28e7018, a54aa19

  • Custom dict/sequence subclass handling (TorchDict, etc.)
  • CUDA tensor IPC safety checks
  • Unpicklable object detection with fail-loud behavior
  • Inference mode enforcement for shared tensors

Polish

1. Logging Deduplication

Commits: fcb2489, e0540f8
ComfyUI-side: 2d1bb755, fe3b402a, c80c1dbb

  • Child process log filter suppresses messages already shown by host
  • Prevents N×spam from N isolated children
  • Deduplicated patterns: VRAM info, CUDA device, pytorch version, etc.
  • pynvml deprecation warning suppression

2. Documentation

Commits: 029ae2c, f045210

  • Module-level docstrings explaining initialization order
  • Environment variable reference (PYISOLATE_CHILD, PYISOLATE_HOST_SNAPSHOT, PYISOLATE_PATH_DEBUG, PYISOLATE_MODULE_PATH)
  • Path unification timing comments (why module-level execution is critical)
  • Cross-references between client.py and path_helpers.py

3. Unit Tests

Commits: 465c72b, 58ba87d

  • Client snapshot handling tests
  • Extension safety tests
  • Path helpers validation
  • Singleton shared state tests
  • Integration test improvements

Testing

Baseline test: 3 isolated nodes loading in 0.0s (cached), workflow execution in 0.15s

Command: /home/johnj/mysolate/debug/run_debug.sh

Result: ✅ PASS


Statistics

Commit range: 16ddb98..029ae2c (27 commits)
Lines changed: 59 files, +9194/-194 lines
Authors: John Pollock (pyisolate), ComfyUI-side integration

pollockjj and others added 28 commits November 14, 2025 03:50
- Implemented activation scripts for bash, csh, and fish shells.
- Created executable scripts for f2py, normalizer, numpy-config, pip, pip3, and python binaries.
- Added pyvenv.cfg for virtual environment configuration.
- Enhanced client and host modules to support path unification and environment snapshotting.
- Introduced path_helpers for managing sys.path in child processes.
- Added unit tests for path_helpers to ensure functionality and correctness.
- Implements host sys.path snapshot and child reconstruction
- Enables isolated processes to import host modules (e.g., ComfyUI utils)
- Adds build_child_sys_path() with smart filtering:
  * Prepends application root
  * Filters code subdirectories to prevent shadowing
  * Preserves host .venv/site-packages
  * Appends isolated venv packages
- Adds serialize_host_snapshot() for environment capture
- 18 unit tests with 100% coverage for path_helpers.py
- Solves multiprocessing.spawn() import visibility problem

Use case: ComfyUI custom nodes need both host modules (folder_paths,
utils.*) and isolated dependencies (deepdiff) in same process.

Tested with ComfyUI integration - all imports working correctly.
- Add --index-strategy unsafe-best-match for torch dev versions
- Enables PyIsolate to work with torch nightlies (e.g., 2.9.0.dev+cu129)
- Without this, uv fails when exact dev version unavailable on PyPI
- Unblocks 100% of ComfyUI installations using torch nightlies

Fixes issue where exact dev build versions don't exist on any index
and uv refuses to install without fallback strategy enabled.
…client snapshot handling and extension safety
…n; ensure CUDA tensors are handled correctly
…; implement serialization hooks for ModelPatcher
…n; support sharing of PyTorch and optimize link mode handling
… of `logging` python library and those messages being properly transmitted via RPC
Implements CLIPRegistry (ProxiedSingleton) + CLIPProxy for isolated nodes. Handles unpicklable CLIP objects via RPC. Includes ScopedModelRegistry, full test coverage, and automatic CLIP→CLIPRef serialization in execution flow. Deletes rejected logging_proxy.py.
Replace --system-site-packages with site.addsitedir() injection to enable
proper parent→child venv inheritance while blocking system Python packages.

Architecture:
- Child venvs created WITHOUT --system-site-packages (blocks /usr packages)
- Write _pyisolate_parent.pth into child's site-packages on creation
- .pth file invokes site.addsitedir(parent_site) for recursive .pth processing
- Ensures namespace packages and C extensions initialize correctly
…treamline editable and local path handling in dependencies
Problem:
On Windows, multiprocessing.Queue() uses semaphores that cannot be
inherited by child processes when set_executable() changes the Python
interpreter to a different venv. This causes:
  PermissionError: [WinError 5] Access is denied

Solution:
Replace direct Queue() with Manager().Queue() which uses TCP sockets
instead of semaphores, avoiding Windows handle inheritance issues.

Key changes in pyisolate/_internal/host.py:
- Use get_context("spawn") instead of set_start_method() for isolation
- Initialize Manager-based queues for cross-venv IPC compatibility
- Set PYISOLATE_CHILD=1 BEFORE Manager() to prevent ComfyUI re-init
- Add proper Manager.shutdown() cleanup in Extension.stop()
- Add os.name=="nt" checks for Windows-specific paths:
  - Scripts/python.exe vs bin/python
  - Lib/site-packages vs lib/pythonX.Y/site-packages
  - VIRTUAL_ENV environment variable injection

Linux compatibility:
- All changes are additive with proper else branches
- Manager queues work on both platforms (negligible overhead)
- Platform-agnostic env var guards

Tested on: Windows 11,
…ct and sequence subclasses, and add safety checks for unpicklable objects
…pynvml deprecation warnings in child processes
Copilot AI review requested due to automatic review settings December 3, 2025 01:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces PyIsolate v1.0 with production-ready process isolation for ComfyUI. The major changes include full ComfyUI integration with path unification to ensure isolated child processes can access ComfyUI imports, a lazy loading and caching system for zero startup penalty, and Windows compatibility through Manager-based IPC queues. Additional improvements include torch ecosystem support with dynamic package discovery, stateless RPC implementation with callback support, tensor serialization safety features, logging deduplication, comprehensive documentation, and unit tests.

Key Changes:

  • Path unification system ensures ComfyUI root is first in sys.path for child processes
  • Lazy process spawning with node caching for instant subsequent loads
  • Windows-compatible IPC using Manager-based queues instead of POSIX-only Queue
  • Dynamic torch ecosystem package discovery for CUDA compatibility
  • RPC callback support for bidirectional async communication

Reviewed changes

Copilot reviewed 25 out of 41 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_singleton_shared.py New test file for singleton and proxied singleton behavior
tests/test_path_helpers.py Tests for sys.path snapshot and reconstruction logic
tests/test_extension_safety.py Tests for extension name normalization and dependency validation
tests/test_client_snapshot.py Tests for client-side snapshot handling and path unification
tests/path_unification/test_path_helpers.py Comprehensive path unification unit tests
tests/conftest.py Added ComfyUI root to sys.path for test compatibility
pyproject.toml Added asyncio_mode configuration for pytest
pyisolate/path_helpers.py New module for host path context sharing and sys.path reconstruction
pyisolate/host.py Lazy loading implementation and improved logging
pyisolate/config.py Dynamic torch ecosystem package discovery
pyisolate/_internal/shared.py RPC callback support and tensor serialization safety
pyisolate/_internal/model_serialization.py Custom serialization for ComfyUI ModelPatcher objects
pyisolate/_internal/host.py Windows Manager-based queues, lazy initialization, torch inheritance
pyisolate/_internal/client.py Module-level path unification and RPC setup
comfy_hello_world/* Example files demonstrating ComfyUI integration
benchmark_results_llamatron_*.txt Benchmark output file
SETUP_GUIDE.md New setup guide for repository
README.md Updated documentation and quick start guide
Comments suppressed due to low confidence (3)

tests/test_client_snapshot.py:1

  • The hardcoded absolute path /home/johnj/ComfyUI is user-specific and will not work on other machines or CI environments. Consider using a relative path, environment variable, or creating a mock ComfyUI structure in tmp_path for portability.
    tests/test_extension_safety.py:1
  • The test expects the environment variable to equal the string "None", but the context manager sets it to None (the Python object). When None is passed to os.environ[key] = str(value), it becomes the string "None". This is inconsistent with the comment on line 70 saying "unsets_when_none". Either the test name is misleading or the behavior should actually remove the key when None is passed.
    tests/conftest.py:1
  • The hardcoded absolute path /home/johnj/ComfyUI is user-specific. This will break tests on other developer machines and CI environments. Consider using an environment variable with a fallback, or detect the path dynamically.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

valid_parents = [p for p in sys.path if "site-packages" in p and p.startswith(host_prefix)]

if not valid_parents:
raise RuntimeError("Could not determine parent site-packages path to inherit")
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message does not provide actionable information for debugging. Consider including details about what paths were checked in valid_parents and what host_prefix was, to help users understand why the detection failed.

Suggested change
raise RuntimeError("Could not determine parent site-packages path to inherit")
raise RuntimeError(
f"Could not determine parent site-packages path to inherit.\n"
f"host_prefix: {host_prefix}\n"
f"parent_sites: {parent_sites}\n"
f"valid_parents: {valid_parents}"
)

Copilot uses AI. Check for mistakes.
include-system-site-packages = false
version = 3.12.3
executable = /usr/bin/python3.12
command = /home/johnj/pyisolate/.venv/bin/python -m venv --copies /home/johnj/pyisolate/comfy_hello_world/node-venvs/simple_text_node
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generated venv configuration file contains hardcoded user-specific paths (/home/johnj/). These files should typically be excluded from version control via .gitignore as they are environment-specific and will not work on other machines.

Copilot uses AI. Check for mistakes.
## 2. Bootstrap the repository

```bash
cd /home/johnj/pyisolate
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup guide uses the hardcoded path /home/johnj/pyisolate which is user-specific. Replace with a generic placeholder like cd /path/to/pyisolate or cd ~/pyisolate to make the guide applicable to all users.

Copilot uses AI. Check for mistakes.
@pollockjj pollockjj changed the title PyIsolate v1.0: Production-Ready Process Isolation for ComfyUI PyIsolate Update: Production-Ready Process Isolation for ComfyUI Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant