Skip to content

feat: add get_execution_environment() API#13059

Open
deepme987 wants to merge 3 commits intomasterfrom
deepme987/add-execution-environment-api
Open

feat: add get_execution_environment() API#13059
deepme987 wants to merge 3 commits intomasterfrom
deepme987/add-execution-environment-api

Conversation

@deepme987
Copy link
Copy Markdown
Contributor

@deepme987 deepme987 commented Mar 19, 2026

Summary

Adds api.environment.get() to the public ComfyAPI, returning "local", "cloud", or "remote" based on the COMFY_EXECUTION_ENVIRONMENT env var.

Motivation

ComfyComplete (the curated node distribution) needs a way for custom nodes to detect whether they are running in a local, cloud, or remote environment. For example:

  • Skip model downloads when models are pre-provisioned in managed environments
  • Disable hardware-dependent features (webcam, clipboard) gracefully instead of crashing
  • Use cached paths instead of runtime downloads

Usage

from comfy_api.latest import api

env = await api.environment.get()  # "local" | "cloud" | "remote"

if env == "local":
    model = download_from_huggingface(repo_id)
else:
    model = load_from_cache(model_path)

Or synchronously:

from comfy_api.latest import ComfyAPISync

api = ComfyAPISync()
env = api.environment.get()

How deployments set it

Managed deployments set the env var in their container:

env:
  - name: COMFY_EXECUTION_ENVIRONMENT
    value: "cloud"

When not set, defaults to "local" — existing installations are unaffected.

Design decisions

  • Public API (ComfyAPI_latest.Environment) not comfy.utils — follows the same pattern as Execution, Caching, NodeReplacement
  • Env var, not CLI arg — deployment concern (set by orchestrator), not user concern
  • Environment detection over feature flags — simpler, covers the primary use case
  • Three valueslocal (default), cloud (Comfy Cloud), remote (other managed deployments)
  • Graceful fallback — invalid/missing values default to "local"

Test plan

  • api.environment.get() returns "local" when env var is not set
  • Returns "cloud" when COMFY_EXECUTION_ENVIRONMENT=cloud
  • Returns "remote" when COMFY_EXECUTION_ENVIRONMENT=remote
  • Returns "local" for invalid values
  • Case-insensitive
  • Sync API (ComfyAPISync) works the same

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e3328ee-55f8-4b06-b053-6ea261e03367

📥 Commits

Reviewing files that changed from the base of the PR and between cb1ca33 and 8165160.

📒 Files selected for processing (1)
  • comfy_api/latest/__init__.py

📝 Walkthrough

Walkthrough

The changes add environment configuration support to the ComfyAPI_latest class. A new Environment class is introduced as a proxied singleton that exposes an async get() method. This method reads the COMFY_EXECUTION_ENVIRONMENT variable, normalizes it by converting to lowercase and trimming whitespace, validates it against a set of allowed values (local, cloud, remote), and defaults to "local" if the value is missing or invalid. The ComfyAPI_latest class now includes a self.environment attribute that provides access to this functionality.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding an execution environment detection API to ComfyAPI.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the motivation, usage, design decisions, and test plan.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

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


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

@deepme987 deepme987 force-pushed the deepme987/add-execution-environment-api branch from 8f7e986 to 70340d4 Compare March 19, 2026 03:26
@bigcat88
Copy link
Copy Markdown
Contributor

Should this be added to the public API and not just in the implementation file?

Adds api.environment.get() to the public ComfyAPI — returns
"local" (default), "cloud", or "remote" based on the
COMFY_EXECUTION_ENVIRONMENT env var.

Custom nodes use this to adapt behavior for managed deployments
(e.g. skip model downloads when models are pre-provisioned).
@deepme987 deepme987 force-pushed the deepme987/add-execution-environment-api branch from cb1ca33 to 8165160 Compare March 20, 2026 17:05
@deepme987
Copy link
Copy Markdown
Contributor Author

Should this be added to the public API and not just in the implementation file?

done!

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.

3 participants