Nodes/ComfyForEach/Get TaskID
ComfyUI Node

Get TaskID

The task_id that holds the whole batch together

By pupba·Created about a year ago·Updated about a year ago· 4
Get TaskID
    • task_id
    task_idtask-1234

    If you ever look at a ComfyForEach workflow and wonder what holds it together, it's this: a single string called the task_id, and this node is where it enters the graph. TaskIDStorageNode (display name "Get TaskID") takes a string, stores it in a module-level global that the rest of the pack can read, and outputs it. Everything else in the pack - the folder loader, the saver, the EventBridge trigger - uses that id to build paths like root/abc123/... or to tag the events it sends. It's the identity of one batch job.

    Why bother with a global at all? Because the pack was built for distributed processing on AWS EC2. The README's deeper story is that it patches ComfyUI's execution.py so that errors get tagged with this same id and shipped off to EventBridge - so when one of a thousand EC2 workers fails on a task, the person watching from the other end can tell which task it was. That's the whole point of storing it in a global: it has to be reachable from deep inside ComfyUI's execution loop, not just from nodes that explicitly receive it as a wire.

    How it works

    Mechanically it's two things. It writes task_id into a shared context object (context.py holds a CURRENT_TASK_ID global that get_task_id() reads), and it returns the same string as its output. Put it early in the workflow - the pack's own loader even has a comment noting the TaskID node needs to run first - and every node that builds a path from task_id will see the value you set.

    Inputs and outputs

    • task_id - STRING, default task-1234. Set this to your job's identifier; you can leave the default if you're just testing.

    Output: task_id (STRING). Wire it into FolderImageLoaderNode, SaveExactNameImageNode, and EventBridgeTriggerNode - they all take it, and they all need the same value.

    Install

    Same pack, same routine:

    cd ComfyUI/custom_nodes
    git clone https://github.com/pupba/Comfy_ForEach
    cd Comfy_ForEach
    pip install -r requirements.txt
    

    Or ComfyUI Manager → search ComfyForEach → install. Restart. Dependencies: pillow, boto3, opencv-python-headless, numpy, torch. No models.

    Where people get burned

    • If you skip the execution.py patch, the "global" half does very little. The node still outputs the string and the path-building nodes still work. But the error-tagging feature - the part that makes the global interesting - requires you to hand-edit ComfyUI's core execution.py as shown in the README. That's invasive and will need re-applying on every ComfyUI update, so most people who use the pack for local batch work just don't bother.
    • Global state means it persists across runs. Whatever the last workflow set is what a reader sees until another node sets it. In practice that's fine because you set it every run, but it's worth knowing it's not scoped to the execution.
    • It's not magic validation. Any string goes in; the pack won't check that your folder of that name exists. That's the loader's job, and it will tell you loudly.

    This is the node that reveals what the pack is actually for: scripted, headless, many-workers batch processing where every output and every failure needs to trace back to one job id. Run ComfyForEach locally as a folder-batch tool and this is just a handy string source. Run it on EC2 with the patches in place, and it's the spine of the whole operation.

    CategoryComfyForEach/TaskID

    Inputs (1)

    NameTypeDefaultDescription
    task_idSTRINGtask-1234

    Outputs (1)

    NameTypeDescription
    task_idSTRING