Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ history.

### Changed

- `comfy workflow save --where cloud` prints a link that opens only the saved
workflow (`?workflowId=<workflow id>`) when Cloud's `/api/features` has
`private_saved_file_links_enabled` on. The workflow id is the one record
Cloud made from the saved file. With the setting off, or when that record
is missing, not unique, or the search for it fails, the link opens the
folder as before. The receipt adds `url_opens` (`workflow` or `folder`) and
`folder_link_reason`.
- Release watches poll through `stopping` and report `build_stopped` (exit 1) when a release stops. Log following reads the final lines after `stopped` and exits successfully.

- `comfy deploy status` explains beside its sampled counts that they may lag after workers scale down. The deploy-failure guidance also clarifies that sampled counts cannot establish whether a worker or job is running now.
Expand Down Expand Up @@ -64,7 +71,7 @@ history.
uploads with `--no-upload` and then uploads only the approved files with
`--allow-upload`, and the agent runs
one real job before it saves with `comfy workflow save --where cloud` and
hands back the folder link (or says there is none for a record-only save).
hands back the save's link (or says there is none for a record-only save).
`comfy_cli/skills/comfy-run-on-cloud/PROMPT-TEMPLATE.md` is the prompt local
ComfyUI's Copy prompt button gives the agent. `comfy-build` points a
single-workflow request at the new skill, `comfy-build-failures` says a
Expand Down
113 changes: 87 additions & 26 deletions comfy_cli/command/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ def _local_delete(renderer, target, workflow_id: str) -> None:
# userdata file in a folder of its own instead (Cloud mirrors that file into
# a workflow record by itself) and prints a link that opens the folder. Any
# other answer, or no answer, keeps the record-only save exactly as before.
# Workflow-id links: docs/adr/SIDEBAR-0013-link-a-cloud-save-to-the-workflow-it-made.md.
# The file is written with ``overwrite=false``, so nothing that exists is
# ever replaced: a name already taken moves on to ``<name> (2)``, ``(3)``, ...
# Only a frontend-format workflow goes into a folder, since the sidebar opens
Expand All @@ -1421,6 +1422,7 @@ def _local_delete(renderer, target, workflow_id: str) -> None:
# ---------------------------------------------------------------------------

_CLI_CLOUD_SAVE_FLAG = "cli_cloud_save_enabled"
_WORKFLOW_LINKS_FLAG = "private_saved_file_links_enabled"

# How long the flag read may take before ``save`` keeps the record-only path.
_FEATURES_TIMEOUT_S = 10.0
Expand Down Expand Up @@ -1465,18 +1467,24 @@ def _request_errors() -> tuple[type[BaseException], ...]:
)


def _cli_cloud_save_enabled(target) -> bool:
"""True only when Cloud's ``/api/features`` answers ``cli_cloud_save_enabled: true``.
def _cloud_save_features(target) -> dict[str, Any]:
"""Cloud's ``/api/features`` reply, or ``{}`` when it cannot be read.

A missing key, any other value, or a request that fails in any way reads
as off, so ``save`` keeps its record-only path and ``delete`` its
record-only delete.
A flag counts as on only when its value is a JSON ``true``; a missing
key, any other value, or a request that fails in any way reads as off, so
``save`` keeps its record-only path and ``delete`` its record-only delete.
``save`` reads both of its flags from this one reply.
"""
try:
_, body = _http_request(target.url("features"), target, timeout=_FEATURES_TIMEOUT_S)
except _request_errors():
return False
return isinstance(body, dict) and body.get(_CLI_CLOUD_SAVE_FLAG) is True
return {}
return body if isinstance(body, dict) else {}


def _cli_cloud_save_enabled(target) -> bool:
"""True only when Cloud's ``/api/features`` answers ``cli_cloud_save_enabled: true``."""
return _cloud_save_features(target).get(_CLI_CLOUD_SAVE_FLAG) is True


def _cloud_folder_name(name: str) -> str:
Expand Down Expand Up @@ -1565,13 +1573,36 @@ def _cloud_records_named(target, name: str) -> list[dict] | None:
return None


def _cloud_saved_record(target, name: str) -> dict | None:
"""The record Cloud mirrored a new file into, or None when it cannot be told."""
# The first half of the ``workflow_record_unknown`` message, by the reason
# ``_cloud_saved_record`` gives.
_RECORD_UNKNOWN_CLAUSES = {
"record_not_found": "Cloud did not show the workflow record it made from it",
"record_ambiguous": "Cloud shows more than one workflow record of its name",
"record_lookup_failed": "the search for the workflow record Cloud made from it failed",
}


def _cloud_saved_record(target, name: str) -> tuple[dict | None, str | None]:
"""The record Cloud mirrored a new file into, or None and why it cannot be told.

The reason is ``record_not_found`` (no live record has the name: Cloud's
copy into its workflow records is best-effort), ``record_ambiguous``
(more than one has it) or ``record_lookup_failed`` (the search failed,
ran past its page cap, or sent a row with no usable id).
"""
try:
rows = _cloud_records_named(target, name)
except _request_errors():
return None
return rows[0] if rows and len(rows) == 1 else None
return None, "record_lookup_failed"
if rows is None:
return None, "record_lookup_failed"
if not rows:
return None, "record_not_found"
if len(rows) > 1:
return None, "record_ambiguous"
if not isinstance(rows[0].get("id"), str) or not rows[0]["id"]:
return None, "record_lookup_failed"
return rows[0], None


def _cloud_link_id(value: Any) -> str | None:
Expand All @@ -1587,9 +1618,13 @@ def _cloud_workspace_id(target) -> str | None:
return _cloud_link_id(body.get("id")) if isinstance(body, dict) else None


def _cloud_folder_link(target, *, workspace_id: str | None, folder: str, deployment: str) -> str | None:
"""The Cloud editor link that opens ``folder``, or None for an unusable base URL.
def _cloud_save_link(
target, *, workspace_id: str | None, folder: str, deployment: str, workflow_id: str | None = None
) -> str | None:
"""The Cloud editor link for a sidebar save, or None for an unusable base URL.

With ``workflow_id`` the link opens that one workflow record
(``workflowId=<id>``); without it, every workflow in ``folder``.
``deployment`` is a deployment id, or ``standard`` for Comfy Cloud itself.
It goes in only with the workspace, since the editor reads it only then.
"""
Expand All @@ -1601,7 +1636,10 @@ def _cloud_folder_link(target, *, workspace_id: str | None, folder: str, deploym
query: dict[str, str] = {}
if workspace_id:
query["workspace"] = workspace_id
query[_WORKFLOWS_DIR] = folder
if workflow_id:
query["workflowId"] = workflow_id
else:
query[_WORKFLOWS_DIR] = folder
if workspace_id:
query["deployment"] = deployment
encoded = urllib.parse.urlencode(query, quote_via=urllib.parse.quote)
Expand All @@ -1617,13 +1655,15 @@ def _cloud_folder_save(
name: str,
description: str | None,
deployment: str | None,
workflow_links: bool,
) -> None:
"""Write the workflow as ``workflows/<new folder>/<name>.json`` and print its link.

A folder is free only when it holds no file at any depth and no live
record already has the name the file would mirror into
(``<folder>/<name>``): Cloud adds a version to a record of that name, so
writing there would change a workflow that already exists.
``workflow_links``: docs/adr/SIDEBAR-0013-link-a-cloud-save-to-the-workflow-it-made.md.
"""
import urllib.error

Expand Down Expand Up @@ -1670,13 +1710,22 @@ def _cloud_folder_save(
except (ValueError, RecursionError):
pass
record_name = key[: -len(".json")]
record = _cloud_saved_record(target, record_name)
workflow_id = record.get("id") if record and isinstance(record.get("id"), str) else None
latest_version = record.get("latest_version") if record and workflow_id else None
record, record_unknown = _cloud_saved_record(target, record_name)
workflow_id = record["id"] if record else None
latest_version = record.get("latest_version") if record else None
workspace_id = _cloud_workspace_id(target)
url = _cloud_folder_link(
target, workspace_id=workspace_id, folder=folder, deployment=deployment or _STANDARD_DEPLOYMENT
link_workflow_id = workflow_id if workflow_links else None
url = _cloud_save_link(
target,
workspace_id=workspace_id,
folder=folder,
deployment=deployment or _STANDARD_DEPLOYMENT,
workflow_id=link_workflow_id,
)
url_opens = None if url is None else ("workflow" if link_workflow_id else "folder")
folder_link_reason = None
if url_opens == "folder":
folder_link_reason = record_unknown if workflow_links else "workflow_links_off"
# ``workflow_id``, ``name``, ``latest_version`` and ``source`` keep their
# record-save meaning: the id is the record Cloud mirrored the file into,
# which `workflow get` and `workflow delete` take.
Expand All @@ -1687,6 +1736,8 @@ def _cloud_folder_save(
"filename": f"{_WORKFLOWS_DIR}/{key}",
"folder": folder,
"url": url,
"url_opens": url_opens,
"folder_link_reason": folder_link_reason,
"workspace_id": workspace_id,
"deployment": deployment or _STANDARD_DEPLOYMENT,
"source": str(path),
Expand All @@ -1706,16 +1757,18 @@ def _cloud_folder_save(
warnings.append(
{
"code": "workspace_unknown",
"message": "Cloud did not say which workspace the save went to, so the link opens the folder in "
"the browser's current workspace",
"message": f"Cloud did not say which workspace the save went to, so the link opens the {url_opens} "
"in the browser's current workspace",
}
)
if workflow_id is None:
why = _RECORD_UNKNOWN_CLAUSES[record_unknown]
warnings.append(
{
"code": "workflow_record_unknown",
"message": "the file is saved, but Cloud did not show the workflow record it made from it, so "
"workflow_id is null; find it with `comfy --json workflow list --name` and the saved name",
"message": f"the file is saved, but {why}, so workflow_id is null"
+ (" and the link opens the folder" if url_opens == "folder" and workflow_links else "")
+ "; find it with `comfy --json workflow list --name` and the saved name",
}
)
if warnings:
Expand Down Expand Up @@ -2043,7 +2096,7 @@ def save_cmd(
"--deployment",
show_default=False,
help="Cloud, when the save goes to a sidebar folder: the deployment id the printed link opens the "
"folder on. Default `standard`, Comfy Cloud itself.",
"workflow or folder on. Default `standard`, Comfy Cloud itself.",
),
] = None,
where: Annotated[str | None, typer.Option("--where", show_default=False)] = None,
Expand Down Expand Up @@ -2092,10 +2145,18 @@ def save_cmd(
# ``nodes[]``; an API-format file there would open empty. So only a
# frontend-format workflow goes into a folder, and an API-format one keeps
# the record-only save with a warning that says why it has no link.
sidebar = _cli_cloud_save_enabled(target)
features = _cloud_save_features(target)
sidebar = features.get(_CLI_CLOUD_SAVE_FLAG) is True
if sidebar and _is_frontend_format(workflow_json):
return _cloud_folder_save(
renderer, target, path=path, text=text, name=name, description=description, deployment=deployment
renderer,
target,
path=path,
text=text,
name=name,
description=description,
deployment=deployment,
workflow_links=features.get(_WORKFLOW_LINKS_FLAG) is True,
)

body: dict[str, Any] = {"name": name, "workflow_json": workflow_json}
Expand Down
12 changes: 8 additions & 4 deletions comfy_cli/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,16 +1034,20 @@ class ErrorCode:
ErrorCode(
"workspace_unknown",
"`comfy workflow save` wrote to a Comfy Cloud Workflows-sidebar folder, but Cloud did not say which "
"workspace it went to, so `data.url` leaves out the workspace and deployment and opens the folder in "
"whatever workspace the browser is on. Surfaced in `data.warnings[]` (not as an error envelope) "
"because the save itself succeeded.",
"workspace it went to, so `data.url` leaves out the workspace and deployment and opens the workflow or "
"folder (`data.url_opens`) in whatever workspace the browser is on. Surfaced in `data.warnings[]` (not "
"as an error envelope) because the save itself succeeded.",
"switch the browser to the workspace `comfy cloud whoami` shows before opening the link",
),
ErrorCode(
"workflow_record_unknown",
"`comfy workflow save` wrote to a Comfy Cloud Workflows-sidebar folder, but Cloud did not show the "
"workflow record it makes from that file, so `data.workflow_id` and `data.latest_version` are null. "
"Surfaced in `data.warnings[]` (not as an error envelope) because the file itself was saved.",
"`data.folder_link_reason` says why when workflow links are on: `record_not_found` (Cloud's copy "
"into its workflow records is best-effort and made none), `record_ambiguous` (more than one record "
"has the name) or `record_lookup_failed` (the search failed). The link then opens the folder instead "
"of the workflow. Surfaced in `data.warnings[]` (not as an error envelope) because the file itself "
"was saved.",
"find the record with `comfy --json workflow list --name <data.name>`",
),
ErrorCode(
Expand Down
26 changes: 21 additions & 5 deletions comfy_cli/skills/comfy-run-on-cloud/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,27 @@ comfy --json workflow save <file> --name '<name>' --where cloud --deployment <id
```

It saves into a new folder in the Cloud Workflows sidebar and never replaces a
file. `data.url` opens that folder in the person's workspace:
`?workspace=<id>&workflows=<folder>&deployment=<id or standard>`. If `data.url`
is missing, the save is a record only: nothing was added to the Workflows
sidebar and there is no link. Say that plainly, give `data.workflow_id`, and do
not point them at a sidebar entry. Then read `data.warnings[]` for the reason:
file. Hand back `data.url` as returned. `data.url_opens` says what it opens in
the person's workspace:

- `workflow`: only the saved workflow,
`?workspace=<id>&workflowId=<data.workflow_id>&deployment=<id or standard>`.
Cloud checks the link against the saved file when it opens.
- `folder`: every workflow in the new folder,
`?workspace=<id>&workflows=<folder>&deployment=<id or standard>`.
`data.folder_link_reason` says why: `workflow_links_off` (the workspace does
Comment thread
vqt123 marked this conversation as resolved.
Resolved
not give workflow links), or `record_not_found`, `record_ambiguous` or
`record_lookup_failed` (the save could not tell which workflow Cloud made
from the file, and `data.warnings[]` carries `workflow_record_unknown`).

Treat a `data.url_opens` or `data.folder_link_reason` value not listed here as
`folder`: later versions may add values.

If `data.url` is missing and `data.filename` is set, the file is in the
sidebar but the CLI could not build a link from the Cloud base URL; give
`data.filename`. If both are missing, the save is a record only: nothing was
added to the Workflows sidebar and there is no link. Say that plainly, give
`data.workflow_id`, and do not point them at a sidebar entry. Then read `data.warnings[]` for the reason:

- `api_format_saved_as_record`: sidebar saving is on, but the file is in API
format, which the sidebar cannot open. Save the editor-format file instead
Expand Down
8 changes: 7 additions & 1 deletion comfy_cli/skills/comfy/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,13 @@ When the cloud workspace has `cli_cloud_save_enabled` on (`GET /api/features`),
file into a new folder in the Cloud Workflows sidebar, named after `--name`
(`<name> (2)` and so on when the folder has files or a workflow of that name
exists; nothing is ever replaced), and `data.url` is a link that opens that
folder. `data.workflow_id` is still the saved workflow's id. The link opens
folder. `data.workflow_id` is still the saved workflow's id. When
`private_saved_file_links_enabled` is also on, the link opens only that
workflow (`workflowId=<data.workflow_id>`) instead; `data.url_opens` is
`workflow` or `folder`, and for a folder link `data.folder_link_reason` says
why (`workflow_links_off`, `record_not_found`, `record_ambiguous`,
`record_lookup_failed`); treat a value not listed here as `folder`. Hand back
`data.url` as returned. The link opens
Comfy Cloud itself unless `--deployment <id>` names a build. `data.warnings[]`
may carry `description_ignored`, `workspace_unknown` or
`workflow_record_unknown`. An API-format workflow keeps the record-only save,
Expand Down
Loading
Loading