Skip to content

Handle psutil.virtual_memory failures on macOS#14716

Open
yuuki84573 wants to merge 1 commit into
Comfy-Org:masterfrom
yuuki84573:fix-psutil-virtual-memory-fallback
Open

Handle psutil.virtual_memory failures on macOS#14716
yuuki84573 wants to merge 1 commit into
Comfy-Org:masterfrom
yuuki84573:fix-psutil-virtual-memory-fallback

Conversation

@yuuki84573

Copy link
Copy Markdown

Summary

This PR prevents ComfyUI from crashing when psutil.virtual_memory() raises a RuntimeError.

On macOS 27 beta 2, psutil.virtual_memory() can fail with:

RuntimeError: host_statistics64(HOST_VM_INFO64) syscall failed: (ipc/mig) array not large enough

This was reported in #14498.
The crash happens during prompt execution when ComfyUI checks available system memory. This PR wraps ComfyUI's psutil.virtual_memory() usage and falls back to safe/default memory values when that call fails, allowing execution to continue instead of crashing the prompt worker thread.

Fixes #14498

Changes

  • Added a small helper around psutil.virtual_memory().
  • Replaced direct memory-stat calls in execution and memory-management paths.
  • Logs a warning once when fallback memory values are used.
  • Preserves existing behavior when psutil.virtual_memory() works normally.

Testing

  • Reproduced the issue on macOS 27 beta 2.
  • Verified ComfyUI no longer crashes during prompt execution.
  • Confirmed the fallback path is used and logs:
psutil.virtual_memory() failed; using fallback memory values
  • Ran Python syntax checks on the modified files.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 13ef3b71-fdad-4c02-ba84-c955545c8048

📥 Commits

Reviewing files that changed from the base of the PR and between dd17deb and 67d6cca.

📒 Files selected for processing (4)
  • comfy/model_management.py
  • comfy/psutil_utils.py
  • comfy_execution/caching.py
  • execution.py

📝 Walkthrough

Walkthrough

Changes

A new module, comfy/psutil_utils.py, is added to wrap psutil.virtual_memory() calls with a fallback mechanism that handles RuntimeError by computing an approximate total via os.sysconf and logging a one-time warning. comfy/model_management.py, comfy_execution/caching.py, and execution.py are updated to remove direct psutil imports and route their system RAM total/available queries through the new comfy.psutil_utils helpers (virtual_memory_total, virtual_memory_available), including RAM pressure and pin budget calculations.

Sequence Diagram(s)

Included in the hidden review stack artifact above.

Related Issues: None specified in the provided information.

Related PRs: None specified in the provided information.

Suggested labels: memory-management, refactor

Suggested reviewers: comfyanonymous

Poem: A rabbit hopped through psutil's den, found RuntimeErrors now and then. Built a fallback, snug and neat, so memory checks won't skip a beat. Hop, hop, hooray, the RAM's okay!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR's main change: adding fallback handling for psutil.virtual_memory failures on macOS.
Description check ✅ Passed The description is directly about the crash fix and fallback memory handling introduced by this PR.
Linked Issues check ✅ Passed The changes add fallback-aware memory checks in the execution and RAM-management paths, which addresses the crash and free-memory detection goals in #14498.
Out of Scope Changes check ✅ Passed The PR stays focused on psutil fallback handling and related memory-check call sites, with no obvious unrelated changes.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

RuntimeError: host_statistics64(HOST_VM_INFO64) syscall failed: (ipc/mig) array not large enough

1 participant