Skip to content

feat: server-side missing model downloads for remote web UI - #14472

Closed
djmango wants to merge 3 commits into
Comfy-Org:masterfrom
djmango:pr/remote-server-model-download
Closed

djmango wants to merge 3 commits into
Comfy-Org:masterfrom
djmango:pr/remote-server-model-download

Conversation

@djmango

@djmango djmango commented Jun 14, 2026 •

Copy link
Copy Markdown

Summary

  • Adds POST /download_model so the ComfyUI host fetches missing models (HuggingFace, Civitai, GitHub) into the correct models/<folder>/ path instead of the client browser downloading them locally.
  • Adds GET /download_model/progress with byte-level progress for long downloads.
  • Gated by Comfy.ModelDownloadEnabled (defaults to enabled).

Fixes #13282

Related: #8826 — users hitting missing checkpoint validation when the model never lands on the server (e.g. remote UI sent the download to the laptop).

Test plan

  • Open ComfyUI in a browser against a remote host (Tailscale/LAN, not localhost).
  • Load a workflow with a missing model and click Download / Download All.
  • Confirm the file appears under ComfyUI/models/<save_dir>/ on the server and not in the client Downloads folder.
  • Confirm /download_model/progress reports increasing bytes for multi-GB files.
  • Confirm disallowed URLs and path traversal attempts return HTTP 400.
  • Confirm local Comfy Desktop sessions still use the desktop download path when appropriate.

Companion frontend PR: Comfy-Org/ComfyUI_frontend#12844

djmango added 3 commits June 14, 2026 12:32
Expose POST /download_model so browser clients fetch models onto the host
instead of the user's laptop. Enabled by default via Comfy.ModelDownloadEnabled.
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

ModelFileManager gains two new HTTP endpoints for server-side model downloading. The constructor now accepts an is_download_model_enabled callable and initializes a _download_progress dictionary and a threading.Lock. Internal helpers manage progress keys, atomic progress updates, and a synchronous streamed download that writes to a .tmp file before renaming to the final path. POST /download_model validates enablement, sanitizes inputs, enforces a URL allowlist, performs realpath containment checks, runs the download in a thread executor, and tracks running/completed/failed states. GET /download_model/progress returns in-memory state or infers it from file existence. PromptServer now passes a callback that reads Comfy.ModelDownloadEnabled from comfy.settings.json, defaulting to True.

🚥 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 accurately and concisely describes the main feature: server-side model downloads for remote web UI scenarios, which is the core objective of the PR.
Description check ✅ Passed The description clearly relates to the changeset, detailing the new POST and GET endpoints, configuration gating, security measures, and test scenarios that align with the code changes.
Linked Issues check ✅ Passed The PR successfully addresses issue #13282 by implementing server-side model downloading via POST /download_model endpoint with progress tracking (GET /download_model/progress), preventing unwanted client-side downloads on remote/headless hosts.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the server-side model download feature: ModelFileManager enhancements for downloading and progress tracking, plus PromptServer configuration integration for the feature gate.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
server.py (1)

216-218: ⚡ Quick win

Consider logging exceptions when reading settings.

The broad except Exception: silently swallows all errors (JSON decode errors, permission errors, etc.), which could make it difficult for users to diagnose configuration problems. Consider adding a warning log to aid debugging while maintaining the safe default behavior.

📋 Suggested improvement
             except Exception:
-                pass
+                logging.warning(f"Failed to read model download setting from {settings_path}, defaulting to enabled", exc_info=True)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.py` around lines 216 - 218, The bare `except Exception:` block in the
settings reading code silently ignores all errors including JSON decode errors
and permission errors without any logging, making it difficult to diagnose
configuration issues. Replace the `pass` statement with a warning log call that
captures and records the exception details before returning True, so users can
see what configuration problems occurred while still maintaining the safe
default behavior.
app/model_manager.py (1)

9-9: 💤 Low value

Unused import: tqdm is imported but never used.

The tqdm library is imported but not utilized anywhere in this file. This may be a leftover from development or intended for future progress bar functionality that was removed.

🧹 Proposed fix
-from tqdm.auto import tqdm
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/model_manager.py` at line 9, Remove the unused import statement `from
tqdm.auto import tqdm` at line 9 in app/model_manager.py since tqdm is never
used anywhere in the file and is just cluttering the imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server.py`:
- Line 213: The open() call that reads the settings file is missing an explicit
UTF-8 encoding parameter. Since JSON files should use UTF-8 encoding per RFC
8259 and Python's default encoding is platform-dependent, add the
encoding='utf-8' parameter to the open() function call to ensure consistent
UTF-8 decoding across all platforms and prevent issues with non-ASCII characters
in the settings file.

---

Nitpick comments:
In `@app/model_manager.py`:
- Line 9: Remove the unused import statement `from tqdm.auto import tqdm` at
line 9 in app/model_manager.py since tqdm is never used anywhere in the file and
is just cluttering the imports.

In `@server.py`:
- Around line 216-218: The bare `except Exception:` block in the settings
reading code silently ignores all errors including JSON decode errors and
permission errors without any logging, making it difficult to diagnose
configuration issues. Replace the `pass` statement with a warning log call that
captures and records the exception details before returning True, so users can
see what configuration problems occurred while still maintaining the safe
default behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cab4b1b9-ecee-4012-a8f2-75d3fd86ace8

📥 Commits

Reviewing files that changed from the base of the PR and between e1b9366 and bbfb237.

📒 Files selected for processing (2)
  • app/model_manager.py
  • server.py

Comment thread server.py
settings_path = os.path.join(folder_paths.get_user_directory(), "default", "comfy.settings.json")
try:
if os.path.isfile(settings_path):
with open(settings_path) as f:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Specify UTF-8 encoding when opening JSON file.

The file is opened without an explicit encoding parameter. JSON files should use UTF-8 encoding per RFC 8259, and Python's default encoding is platform-dependent (e.g., cp1252 on Windows). This could cause decoding issues if the settings file contains non-ASCII characters.

📝 Proposed fix
-                    with open(settings_path) as f:
+                    with open(settings_path, encoding='utf-8') as f:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
with open(settings_path) as f:
with open(settings_path, encoding='utf-8') as f:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.py` at line 213, The open() call that reads the settings file is
missing an explicit UTF-8 encoding parameter. Since JSON files should use UTF-8
encoding per RFC 8259 and Python's default encoding is platform-dependent, add
the encoding='utf-8' parameter to the open() function call to ensure consistent
UTF-8 decoding across all platforms and prevent issues with non-ASCII characters
in the settings file.

@alexisrolland

Copy link
Copy Markdown
Member

Thank you for your contribution @djmango but we have an internal initiative to manage this. The topic is more complex than it looks because we also need to ensure compatibility with our cloud and desktop applications.

Thanks again.

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.

[V2 UI] Missing model links trigger local browser download instead of server-side fetch on remote/headless hosts

2 participants