Loop Node Only Processes the First Item - How to Fix?

Hello, community!

I’m facing an issue with the Loop node in my workflow. The Set Input node correctly sends 4 items to the Loop, but only the first item gets processed, while the other items are sent directly to the “done” output without being iterated over.

I have tried adjusting the Batch Size in the Loop, but the behavior remains the same. Even when the batch size is set to process multiple items at once, the Loop node processes only the first item and skips the others.

Here are a few more details:

  • I am using [n8n version].
  • I’ve set different Batch Sizes (1, 4, 10), but the behavior hasn’t changed.
  • The input data has similar structures, so I don’t think the issue is with inconsistent data.

What I’ve Tried:

  1. Increasing the Batch Size in the Loop.
  2. Reviewing the logic for “loop” and “done” outputs.
  3. Checking the data being passed into the Loop.
  4. Enabling the “Reset” option in the Loop node.

Has anyone else encountered this issue or have suggestions on how I can ensure that all items are iterated over correctly by the Loop?

Thanks in advance for the help!

  • Version 1.54.0
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • n8n selfhosted
  • Windows
3 Likes

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @Gustavo_Borges !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.


No mastery here. You are sending only one item to the Loop node at a time. Hence only one item is processed at a time.

The logic of your workflow does not make much sense to me. You would use the loop to break a set of items as opposed to having only 1 item.

For example, try this instead to see that Loop is working as expected.

1 Like

Hello, Ihorton,
Thank you for your support.

This is a generic flow I used to understand the node’s behavior.
Yes, I am sending one item at a time, and that’s the desired behavior. The point is that the Loop processes only the first item sent, while the following ones go directly to the output “done.”

Notice that I send 3 items to the Loop, but it only processes one.

In the real case, an AI model sends a “requires-action” that contains an array of calls. This array is sent to the Loop node and is processed. But meanwhile, in the same thread, the AI can send another “requires-action” item containing another array of calls… this second item goes straight to “done” without being processed.
And then, my next node after the LOOP picks up a data structure that hasn’t been properly processed.

In your example, it works perfectly. But I receive the items at different times, and I can’t combine them.

This is my real flow.


No, you are still misreading it. You feed 3 items to the Loop separately, not in one set.

See the difference.

Separate items - 3 sets of 1 item
image

Single set of 3 items

That what I meant that your usage of the Loop did not make sense to me. It cannot work the way you want by design. You need a different approach. Here’s a quick demo of what it might be to assemble items together.

Yes. That’s clear.

So the LOOP node doesn’t support multiple items separately?! Do you have any idea what approach I could take?

Look at the flow from a real case… I can receive multiple items coming from the Switch, at different times. The first item coming from the Switch goes through the LOOP and iterates fine. But the second one goes straight to the DONE output of the LOOP without being processed.

Here you can see that all 36 items within the first item sent to the LOOP are iterated. But the second item goes straight to DONE with its other 36 items.

That is correct. You still seems to be struggling with comprehending how the data processed by the Loop is represented in UI. The last one is indeed the sum of all the iterations which comes out of “done” branch - to be more precise, all individual iterations are combined into a set. That is, individual iterations go to the “loop” branch and then all them combined go out via “done” branch. So the UI shows them all together. The last one does no go via “loop”, it shows what comes out of the “done” as the last step of the Loop node processing.

Thx for you patience.

Your explanation is clear to me.

When I mentioned “second item,” I was referring to a second concrete array that goes to the LOOP node, not the second item that appears in the DONE output summing the iterated items from the first array.

Take a look at the example I posted in the image. Initially, I sent an array with 36 items to the loop. The system iterated through all the items, and in the “done” branch, 37 items appear (the 36 items from the array plus the summed item). So far, everything is fine.

However, when I send a second array, this time with 34 items, to the LOOP, these items are not iterated as they should be. Instead, they go directly to the “done” branch. As a result, the 37 items that previously appeared in the “done” branch, containing the 36 iterated items, increase to 38, but these 38 include the 34 items that were not iterated.

Hey @Gustavo_Borges , looks like you are right. I can reproduce the same behaviour (with much simpler workflow for better understanding). Indeed, the 2nd set of items is not getting iterated but rather gets concatenated with the first outcome of the first set of iterations.

I believe this is a limitation of the Loop node. You currently cannot loop the “done” outcome back to the input of the Loop (regardless if it is via other nodes, not directly).

You might need to find some other solution. For example, engage another Loop node for the 2nd set based on $runIndex or the loop part implement as a separate workflow.

1 Like

Hey @Gustavo_Borges,

I have just picked this one up, The loop node can be tricky at times. So in this case the reset option needs to be used to tell the Loop node that it is a new set of data but as you probably noticed while testing if you just enable reset it will run forever as it will reset for every item that comes in from the loop branch.

This brings the new question… How do I reset it for the second run of items? The example workflow that @ihortom gave us is below, In this workflow we will want to run the output of the Debug Helper in the loop twice but without the reset we get the issue you are seeing.

So to change this and reset the data properly we want to make sure that we only reset the data if the node that ran before it is the If node that way when the code node loops back we don’t continue with the first item. To do this we open the Loop node and add the reset option but change it to use an expression, For the value of the expression we use {{ $prevNode.name === 'If' }} so if the previous node name is if we return true which will reset it.

image

So now when we run the workflow we get this…

It has done 14 runs of the loop node (1 for each item and 1 for each done branch) and we have the 12 items being processed correctly.

Let me know if this helps or if you have any other questions on this.

13 Likes

Thank you guys so much. That works perfectly.
I was about to go crazy with this situation for a couple of days

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.