ComfyUI Node

Queue Next

The node that presses Queue for you — the loop engine of a batch

By hodgemann·Created 6 months ago·Updated 6 months ago· 3
Queue Next
  • image
    text

    The whole trick of hodgemann's ComfyUI-BatchFolderTools is that you click Queue Prompt once. The loader nodes hand you one file at a time, and Queue Next is the piece that makes the graph loop: every time it runs, it quietly submits the workflow again, so the next file gets picked up automatically. It's the closest ComfyUI has to a "repeat until the folder's empty" button, and it has no settings worth worrying about.

    You place it at the very end of the chain, after everything that has to happen per file. It's an output node - it has no outputs and produces nothing visible; its entire job is to fire a re-queue after the rest of the graph has finished.

    How it actually works

    This is the part people find surprising: it isn't a ComfyUI-native loop. The node grabs the full prompt via a hidden input (the PROMPT handle every workflow carries), makes a deep copy, and POSTs it back to the local ComfyUI API at http://127.0.0.1:8188/prompt in a background thread. The workflow runs, finishes, and re-submits itself - effectively you, but scripted.

    Two things make that re-submission actually do something:

    • The loader defeats the cache. ComfyUI aggressively skips nodes whose inputs haven't changed. Both the image and video loaders return IS_CHANGED = NaN in sequential mode, which the engine treats as "always different," so the next run genuinely advances to the next file. That's the always-rerun trick from comfyui-node-plumbing.md, and it's non-negotiable here - without it the loop would just produce the same image forever.
    • It cache-busts the prompt. ComfyUI deduplicates identical prompt submissions. The node bumps the loader's index widget by one (harmless in sequential mode) and randomizes the seed on any QwenVL node in the graph, specifically so the API can't say "I already ran this exact prompt." The seed randomization also stops a VLM's internal caching from returning stale captions for different inputs - that's the "fixed duplicate captions" note in the changelog.

    And the loop stops itself. When the loader runs out of files it raises an error before Queue Next ever executes, so no re-queue fires and the workflow halts cleanly. You'll see ✅ ALL N ... PROCESSED - DONE in the console. One click in, walk away.

    The inputs (both optional - wire whichever fits)

    • image - an IMAGE output. If your chain ends on pixels, wire the final image here.
    • text - a STRING output. If your chain ends on text (say, a caption string), wire that instead.

    You only need one of them, and only so the node sits at the end of the data flow and is guaranteed to run after the work is done. It accepts either; it ignores the actual value. The pack's Save Text File node is output-type, so in the captioning workflow the natural terminal is the save node, not this one - but if your graph has no other output node, Queue Next is what anchors it.

    Installing it

    It ships inside ComfyUI-BatchFolderTools, so install the pack: ComfyUI Manager, search Batch Folder Tools, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/hodgemann/ComfyUI-BatchFolderTools.git
    

    Restart and you'll find it under the 📂 BatchFolder category. No models, no extra dependencies - the re-queue call uses only Python's standard library.

    Where people get burned

    • It "doesn't loop." Almost always the loader is in manual mode, or the loader's IS_CHANGED isn't being honored because of the workflow cache. Set the loader to sequential and re-check that Queue Next actually sits downstream of something that depends on the loader's output - if it's dangling, ComfyUI may not run it at all.
    • It re-queues everything, including previews and saves. Because the whole prompt is re-submitted, every loop iteration is a full workflow run. That's the intended design (each file gets its own complete pass), but if your graph has a slow node it runs every time, a long batch is a long batch - there's no "only the loader re-runs" optimization.
    • It depends on the local API port. The re-queue posts to 127.0.0.1:8188, ComfyUI's default. The node runs on the server, so this works with remote frontends, but if you've changed the --port your server listens on, the re-queue fails (you'll see [BatchFolder] Re-queue failed in the console) even though the rest of the graph is fine.

    The honest take: it's a one-trick node, and the trick is good. If you've ever written a shell loop around a ComfyUI workflow, this is that loop, minus the shell.

    Category📂 BatchFolder

    Inputs (2)

    NameTypeDefaultDescription
    imageoptIMAGEWire an IMAGE output here to trigger after image processing.
    textoptSTRINGWire a STRING output here to trigger after text processing.

    Outputs (0)

    No outputs