Files
ComfyUI/comfy_execution/asset_enrichment.py
Simon Pinfold d1014a5f92 feat(assets): add --disable-assets flag to turn the assets system off
With --enable-assets removed and the assets system always on, there is no
supported way to run without it. Add an explicit opt-out for the rollout
bake period: cloud multi-tenant sidecars need a guaranteed off-switch, and
QA needs a clean-fallback configuration.

When --disable-assets is passed:
- asset API routes are registered but disabled, returning a structured 503
- database initialization is skipped entirely (no sqlite file is created;
  the database currently has no non-asset users)
- the background seeder is disabled, covering startup, /object_info and
  post-execution enrich scans, and output registration
- workflow output enrichment and /upload/image asset registration are
  skipped
- the assets feature flag reports false, and supports_model_type_tags
  follows it since model_type tags are an assets-API capability

The hidden --enable-assets no-op remains accepted for launcher
compatibility; --disable-assets takes precedence since the former gates
nothing.
2026-07-28 05:44:53 +12:00

67 lines
2.8 KiB
Python

"""Enrich executed-node output entries with asset id."""
import logging
import os
def enrich_output_with_assets(output_ui: dict) -> dict:
"""Register file-type output entries as assets and inject their ``id``.
Runs at output-processing time, once per produced output, unless
--disable-assets is set. Returns a new dict; entries without a resolvable
on-disk file path are left unchanged. Errors are caught per-entry so a
failure never blocks execution or the other entries.
"""
from comfy.cli_args import args
if args.disable_assets:
return output_ui
import folder_paths
from app.assets.services.ingest import register_file_in_place, DependencyMissingError
enriched = {}
for key, entries in output_ui.items():
if not isinstance(entries, list):
enriched[key] = entries
continue
new_entries = []
for entry in entries:
if not isinstance(entry, dict) or "filename" not in entry or "type" not in entry:
new_entries.append(entry)
continue
try:
base = folder_paths.get_directory_by_type(entry["type"])
if base is None:
new_entries.append(entry)
continue
base_abs = os.path.abspath(base)
abs_path = os.path.abspath(os.path.join(base_abs, entry.get("subfolder") or "", entry["filename"]))
try:
if os.path.commonpath([base_abs, abs_path]) != base_abs:
raise ValueError("escapes base")
except ValueError:
logging.warning("Asset enrichment skipped (path escapes base): %s", entry.get("filename"))
new_entries.append(entry)
continue
if not os.path.isfile(abs_path):
new_entries.append(entry)
continue
# Register unconditionally: the file was just produced, and
# register_file_in_place re-hashes so an overwritten path can
# never carry a stale id.
result = register_file_in_place(
abs_path=abs_path,
name=entry["filename"],
tags=[entry["type"]],
)
entry = dict(entry)
entry["id"] = result.ref.id
except DependencyMissingError:
logging.warning("Asset enrichment skipped (blake3 not available): %s", entry.get("filename"))
except Exception:
logging.warning("Failed to enrich output entry with asset id: %s", entry.get("filename"), exc_info=True)
new_entries.append(entry)
enriched[key] = new_entries
return enriched