Nodes/ComfyUI-ZMongo/99 Record Loop Manager
ComfyUI Node

99 Record Loop Manager

A self-advancing loop for batch processing

By CentralFloridaAttorney·Created 5 months ago·Updated 2 months ago· 1
99 Record Loop Manager
  • items_list
  • item
  • document_id_link
  • done
  • index
  • item_count
  • remaining_count
  • reviewed_timestamp
  • selected_items
  • state_json
  • status
  • next_index
  • visible_index
  • visible_next_index
  • progress_text
index0
wrapfalse
advance_on_executetrue
state_namedefault_record_loop
reset_statefalse
timestamp_formatiso_utc
refresh_token

ComfyUI has never had a proper loop primitive, so every serious batch workflow ends up reinventing one. Record Loop Manager is ZMongo's version, and it's the least "database" node in the pack: you feed it a list of items (document IDs, strings, whatever), and each time the workflow executes it hands you the next item - remembering where it left off between runs, on disk, keyed by a name you choose.

The trick that makes it useful in ComfyUI: it's AlwaysDirty, so it re-executes on every queue, and it persists next_index to a state file under your state_name. Run the workflow, it processes item 0 and stores "next: 1". Run it again, you get item 1. That's a manual-but-reliable batch loop - hit Queue, do work, hit Queue again, until done flips true. It's not a single-queue "do all N in one go" node; it's a "feed me one record at a time, I'll keep the place" node.

How it works

On each execution it loads the prior state for state_name, determines the current index, and serves cleaned[effective_index]. If advance_on_execute is on (it is by default), it saves the next index so the following run moves forward. wrap makes it circle back to 0 when it hits the end instead of flipping done. reset_state clears the persisted position and starts from the index widget. timestamp_format lets you pick iso_utc, unix, or local_iso for the reviewed_timestamp.

The outputs cover every angle: the current item, a done flag, index/next_index, item_count/remaining_count, a selected_items list, the full state_json, and a human-readable progress_text - which is what you'll wire into a display node while you iterate.

Inputs and outputs that matter

  • items_list - the list to loop over (accepts any type via the wildcard socket).
  • index - starting position when there's no saved state (default 0).
  • wrap - wrap around at the end (default false).
  • advance_on_execute - persist the next index after each run (default true).
  • state_name - the key for persisted loop state (default default_record_loop).
  • reset_state - clear saved state and restart (default false).

Outputs worth knowing: item, done, index, next_index, selected_items, state_json, progress_text.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/CentralFloridaAttorney/ComfyUI-ZMongo

Restart ComfyUI, or use ComfyUI Manager ("ComfyUI-ZMongo"). Heavy requirements.txt install regardless (pymongo, langchain, sentence-transformers, transformers).

Common issues

  • It keeps returning the same item - advance_on_execute got turned off, or the state file isn't being persisted. Check state_json for the stored next_index.
  • It's always "done" - you hit the end of the list. Set reset_state to true for one run (or flip wrap on) to loop back.
  • Stale state across workflows - state is keyed by state_name and stored on disk, so reusing a name across different graphs reuses the position. Use distinct state_name values per loop.
  • Not a true for loop - you still have to hit Queue N times (or drive it from an external scheduler). It's a stateful iterator, not a parallel batch runner; don't expect one queue to drain the list.
CategoryZMongo/99 Helpers

Inputs (8)

NameTypeDefaultDescription
items_list*
indexINT00–1000000
wrapBOOLEANfalse
advance_on_executeBOOLEANtrue
state_nameSTRINGdefault_record_loop
reset_stateBOOLEANfalse
timestamp_formatCOMBOiso_utc3 options: iso_utc, unix, local_iso
refresh_tokenoptSTRING

Outputs (14)

NameTypeDescription
itemSTRING
document_id_linkSTRING
doneBOOLEAN
indexINT
item_countINT
remaining_countINT
reviewed_timestampSTRING
selected_items*
state_jsonSTRING
statusSTRING
next_indexINT
visible_indexSTRING
visible_next_indexSTRING
progress_textSTRING