Compare commits

..

3 commits

Author SHA1 Message Date
Matt Miller
c7e4ddfb59 ci: scope the dispatch App to cloud only
An App private key is not scoped: it can mint tokens for every repo its
App is installed on, with the App's full entitlement. The owner and
repositories inputs are step arguments, not a boundary.

cloud-code-bot is entitled to cloud's production release and migration
workflows, so storing its key in this public repo would join the two
repos' trust boundaries at the weaker one. Use a single-purpose App
holding only contents:write on Comfy-Org/cloud instead -- the same
minimal scope the outgoing PAT had, without the silent expiry.
2026-07-28 14:53:22 -07:00
Matt Miller
fefe6420a7 ci: use cloud-code-bot for the dispatch token
FEN_RELEASE_* are environment secrets on the 'backport release'
environment, which is gated on required reviewers. A tag dispatch must
not wait on a human approval, so that environment is not usable here.

cloud-code-bot already authors the bump PRs on the cloud side, so its
write access to Comfy-Org/cloud is established.
2026-07-28 14:47:08 -07:00
Matt Miller
2c40b09059 ci: dispatch to cloud with an App token instead of a PAT
The PAT behind CLOUD_REPO_DISPATCH_TOKEN was regenerated without the
Actions secret being updated, so the stored copy went stale. Every tag
from v0.25.0 through v0.29.0 returned 401 and opened no cloud bump PR,
which went unnoticed for six weeks because the bumps were filed by hand.

Mint an installation token per run instead, scoped to Comfy-Org/cloud,
so there is no stored credential left to drift or expire.
2026-07-28 14:43:54 -07:00
8 changed files with 52 additions and 122 deletions

View file

@ -8,16 +8,44 @@ on:
jobs:
dispatch-cloud:
runs-on: ubuntu-latest
# No checkout and no use of GITHUB_TOKEN; the dispatch goes out on the App
# token generated below, which is scoped to Comfy-Org/cloud only.
permissions:
contents: read
steps:
# A PAT was used here previously. It was silently regenerated upstream
# without the Actions secret being updated, so every tag from v0.25.0
# (2026-06-16) through v0.29.0 dispatched a 401 and no cloud bump PR was
# opened for six weeks. App installation tokens are minted per run and
# cannot drift out of sync with a stored copy.
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1
with:
# A single-purpose App: installed only on Comfy-Org/cloud, holding
# only contents:write. Deliberately NOT cloud-code-bot, which is also
# entitled to cloud's production release and migration workflows --
# an App private key is not scoped, so any key stored here can mint a
# token for everything its App is entitled to, on every repo it is
# installed on. The owner/repositories inputs below are arguments,
# not a security boundary. Keeping this App minimal is what makes it
# safe to hold in a public repository.
app-id: ${{ vars.CORE_TO_CLOUD_DISPATCH_APP_ID }}
private-key: ${{ secrets.CORE_TO_CLOUD_DISPATCH_PRIVATE_KEY }}
# create-github-app-token scopes to the current repository by
# default; this dispatch targets another repo.
owner: Comfy-Org
repositories: cloud
- name: Send repository dispatch to cloud
env:
DISPATCH_TOKEN: ${{ secrets.CLOUD_REPO_DISPATCH_TOKEN }}
DISPATCH_TOKEN: ${{ steps.app-token.outputs.token }}
RELEASE_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
if [ -z "${DISPATCH_TOKEN:-}" ]; then
echo "::error::CLOUD_REPO_DISPATCH_TOKEN is required but not set."
echo "::error::App token generation produced an empty token."
exit 1
fi

View file

@ -671,9 +671,9 @@ def freqs_cis_matrix(freqs, pad_size, split_mode, num_attention_heads, out_dtype
cos_freq = torch.cat((cos_padding, cos_freq), dim=-1)
sin_freq = torch.cat((sin_padding, sin_freq), dim=-1)
B, T, half_HD = cos_freq.shape
cos_freq = cos_freq.reshape(B, T, num_attention_heads, half_HD // num_attention_heads)
sin_freq = sin_freq.reshape(B, T, num_attention_heads, half_HD // num_attention_heads)
B, T, _ = cos_freq.shape
cos_freq = cos_freq.reshape(B, T, num_attention_heads, -1)
sin_freq = sin_freq.reshape(B, T, num_attention_heads, -1)
rotation_matrix = torch.stack(
(cos_freq, -sin_freq, sin_freq, cos_freq), dim=-1
)

View file

@ -49,12 +49,6 @@ class CausalConv3d(nn.Module):
)
self.temporal_cache_state={}
def _empty_output(self, x):
# empty (0 frame) outputs must still have the conv's output channels and spatial dims
h = (x.shape[3] + 2 * self.conv.padding[1] - self.conv.kernel_size[1]) // self.conv.stride[1] + 1
w = (x.shape[4] + 2 * self.conv.padding[2] - self.conv.kernel_size[2]) // self.conv.stride[2] + 1
return x.new_empty((x.shape[0], self.out_channels, 0, h, w))
def forward(self, x, causal: bool = True):
tid = threading.get_ident()
@ -64,7 +58,7 @@ class CausalConv3d(nn.Module):
if not causal:
padding_length = padding_length // 2
if x.shape[2] == 0:
return self._empty_output(x)
return x
cached = x[:, :, :1, :, :].repeat((1, 1, padding_length, 1, 1))
pieces = [ cached, x ]
if is_end and not causal:
@ -89,7 +83,7 @@ class CausalConv3d(nn.Module):
elif is_end:
self.temporal_cache_state[tid] = (None, True)
return self.conv(x) if x.shape[2] >= self.time_kernel_size else self._empty_output(x)
return self.conv(x) if x.shape[2] >= self.time_kernel_size else x[:, :, :0, :, :]
@property
def weight(self):

View file

@ -390,10 +390,10 @@ class Decoder(nn.Module):
# Compute output channel to be product of all channel-multiplier blocks
output_channel = base_channels
for block_name, block_params in blocks:
for block_name, block_params in list(reversed(blocks)):
block_params = block_params if isinstance(block_params, dict) else {}
if block_name == "res_x_y":
output_channel = block_params.get("in_channels", output_channel * block_params.get("multiplier", 2))
output_channel = output_channel * block_params.get("multiplier", 2)
if block_name == "compress_all":
output_channel = output_channel * block_params.get("multiplier", 1)
if block_name == "compress_space":
@ -432,7 +432,7 @@ class Decoder(nn.Module):
spatial_padding_mode=spatial_padding_mode,
)
elif block_name == "res_x_y":
output_channel = block_params.get("out_channels", output_channel // block_params.get("multiplier", 2))
output_channel = output_channel // block_params.get("multiplier", 2)
block = ResnetBlock3D(
dims=dims,
in_channels=input_channel,

View file

@ -43,98 +43,6 @@ def load_and_process_images(image_files, input_dir):
return output_images
def secure_subfolder_path(base_dir, folder_name):
"""Resolve folder_name inside base_dir, rejecting anything that escapes it.
Blocks '..', absolute paths, drive letters and symlink escapes using the
same realpath containment check as the core file endpoints.
"""
target = os.path.abspath(os.path.join(base_dir, folder_name))
if not folder_paths.is_within_directory(base_dir, target):
raise ValueError(f"Invalid folder name {folder_name!r}: resolves outside of {base_dir}")
return target
def list_dataset_folders():
"""Relative paths of dataset folders found under all dataset roots.
Any subfolder containing a metadata.json or *.safetensors shard counts as
a dataset; the walk doesn't descend into matched folders.
Symlinked directories are followed, but symlink loops are avoided.
"""
found = set()
for root in folder_paths.get_folder_paths("datasets"):
if not os.path.isdir(root):
continue
root = os.path.abspath(root)
seen_dirs = set()
for dirpath, subdirs, filenames in os.walk(root, followlinks=True):
try:
st = os.stat(dirpath) # follows symlinks
except OSError:
subdirs[:] = []
continue
dir_key = (st.st_dev, st.st_ino)
if dir_key in seen_dirs:
subdirs[:] = []
continue
seen_dirs.add(dir_key)
if dirpath != root and (
"metadata.json" in filenames
or any(f.endswith(".safetensors") for f in filenames)
):
found.add(os.path.relpath(dirpath, root).replace(os.sep, "/"))
subdirs[:] = []
continue
kept_subdirs = []
for name in subdirs:
child = os.path.join(dirpath, name)
try:
child_st = os.stat(child) # follows symlinks
except OSError:
continue
child_key = (child_st.st_dev, child_st.st_ino)
if child_key not in seen_dirs:
kept_subdirs.append(name)
subdirs[:] = kept_subdirs
return sorted(found)
def get_dataset_save_dir(folder_name):
"""Resolve the folder to save a new dataset into, inside the default root.
The folder is not created here; callers makedirs after validation.
"""
root = folder_paths.get_folder_paths("datasets")[0]
target = secure_subfolder_path(root, folder_name)
if os.path.realpath(target) == os.path.realpath(root):
raise ValueError("folder_name must name a subfolder of the datasets directory, e.g. 'my_dataset'.")
return target
def get_dataset_dir(folder_name):
"""Find an existing dataset folder by relative name across all dataset roots."""
roots = folder_paths.get_folder_paths("datasets")
for root in roots:
target = secure_subfolder_path(root, folder_name)
if os.path.realpath(target) == os.path.realpath(root):
raise ValueError("folder_name must name a subfolder of the datasets directory, e.g. 'my_dataset'.")
if os.path.isdir(target):
return target
raise ValueError(f"Dataset folder {folder_name!r} not found in: {', '.join(roots)}")
VALID_VIDEO_EXTENSIONS = [".mp4", ".avi", ".mov", ".webm", ".mkv", ".flv"]
@ -487,7 +395,7 @@ class SaveImageDataSetToFolderNode(io.ComfyNode):
filename_prefix = filename_prefix[0]
mode = mode[0]
output_dir = secure_subfolder_path(folder_paths.get_output_directory(), folder_name)
output_dir = os.path.join(folder_paths.get_output_directory(), folder_name)
saved_files = save_images_to_folder(images, output_dir, filename_prefix, mode=='overwrite')
logging.info(f"Saved {len(saved_files)} images to {output_dir}.")
@ -541,7 +449,7 @@ class SaveImageTextDataSetToFolderNode(io.ComfyNode):
filename_prefix = filename_prefix[0]
mode = mode[0]
output_dir = secure_subfolder_path(folder_paths.get_output_directory(), folder_name)
output_dir = os.path.join(folder_paths.get_output_directory(), folder_name)
saved_files = save_images_to_folder(images, output_dir, filename_prefix, mode=='overwrite')
# Save captions
@ -1953,7 +1861,7 @@ class SaveTrainingDataset(io.ComfyNode):
io.String.Input(
"folder_name",
default="training_dataset",
tooltip="Name of folder to save the dataset into, inside the datasets directory. Subfolders like 'project/run1' are allowed.",
tooltip="Name of folder to save dataset (inside output directory).",
),
io.Int.Input(
"shard_size",
@ -1983,8 +1891,8 @@ class SaveTrainingDataset(io.ComfyNode):
f"Something went wrong in dataset preparation."
)
# Create output directory (inside the datasets root, traversal-safe)
output_dir = get_dataset_save_dir(folder_name)
# Create output directory
output_dir = os.path.join(folder_paths.get_output_directory(), folder_name)
os.makedirs(output_dir, exist_ok=True)
# Prepare data pairs
@ -2043,10 +1951,10 @@ class LoadTrainingDataset(io.ComfyNode):
description="Load encoded training dataset (latents + conditioning) from disk for use in training.",
is_experimental=True,
inputs=[
io.Combo.Input(
io.String.Input(
"folder_name",
options=list_dataset_folders(),
tooltip="Saved dataset to load, from the datasets directory.",
default="training_dataset",
tooltip="Name of folder containing the saved dataset (inside output directory).",
),
],
outputs=[
@ -2065,8 +1973,11 @@ class LoadTrainingDataset(io.ComfyNode):
@classmethod
def execute(cls, folder_name):
# Get dataset directory (searched across all dataset roots, traversal-safe)
dataset_dir = get_dataset_dir(folder_name)
# Get dataset directory
dataset_dir = os.path.join(folder_paths.get_output_directory(), folder_name)
if not os.path.exists(dataset_dir):
raise ValueError(f"Dataset directory not found: {dataset_dir}")
# Find all shard files
shard_files = sorted(

View file

@ -29,7 +29,6 @@
# upscale_models: models/upscale_models/
# latent_upscale_models: models/latent_upscale_models/
# custom_nodes: custom_nodes/
# datasets: datasets/
# hypernetworks: models/hypernetworks/
# photomaker: models/photomaker/
# classifiers: models/classifiers/

View file

@ -44,8 +44,6 @@ folder_names_and_paths["latent_upscale_models"] = ([os.path.join(models_dir, "la
folder_names_and_paths["custom_nodes"] = ([os.path.join(base_path, "custom_nodes")], set())
folder_names_and_paths["datasets"] = ([os.path.join(base_path, "datasets")], set())
folder_names_and_paths["hypernetworks"] = ([os.path.join(models_dir, "hypernetworks")], supported_pt_extensions)
folder_names_and_paths["photomaker"] = ([os.path.join(models_dir, "photomaker")], supported_pt_extensions)

View file

@ -22,7 +22,7 @@ alembic
SQLAlchemy>=2.0.0
filelock
av>=16.0.0
comfy-kitchen==0.2.24
comfy-kitchen==0.2.23
comfy-aimdo==0.4.10
requests
simpleeval>=1.0.0