99 Record Loop Manager
A self-advancing loop for batch processing
- 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
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 (defaultdefault_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_executegot turned off, or the state file isn't being persisted. Checkstate_jsonfor the storednext_index. - It's always "done" - you hit the end of the list. Set
reset_stateto true for one run (or flipwrapon) to loop back. - Stale state across workflows - state is keyed by
state_nameand stored on disk, so reusing a name across different graphs reuses the position. Use distinctstate_namevalues per loop. - Not a true
forloop - 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.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| items_list | * | — | |
| index | INT | 00–1000000 | — |
| wrap | BOOLEAN | false | — |
| advance_on_execute | BOOLEAN | true | — |
| state_name | STRING | default_record_loop | — |
| reset_state | BOOLEAN | false | — |
| timestamp_format | COMBO | iso_utc | 3 options: iso_utc, unix, local_iso |
| refresh_tokenopt | STRING | — |
Outputs (14)
| Name | Type | Description |
|---|---|---|
| item | STRING | — |
| document_id_link | STRING | — |
| done | BOOLEAN | — |
| index | INT | — |
| item_count | INT | — |
| remaining_count | INT | — |
| reviewed_timestamp | STRING | — |
| selected_items | * | — |
| state_json | STRING | — |
| status | STRING | — |
| next_index | INT | — |
| visible_index | STRING | — |
| visible_next_index | STRING | — |
| progress_text | STRING | — |