Nested Loops - Inner loop straight to done branch in the second iteration of the outer loop

Hi n8n community,

I’m facing an issue with nested loops in my n8n workflow, and I’d really appreciate your help in troubleshooting and resolving it. I’m using n8n to automate video creation, and my workflow involves iterating over 6 items in an outer loop and 5 items in an inner loop for each outer iteration. However, I’m encountering a problem where the inner loop works correctly in the first iteration of the outer loop but skips directly to the “Done” branch in the second iteration (and beyond) instead of iterating over the 5 items.

What I’m Trying to Achieve

I’m building a workflow to create 6 short videos, each with 5 random clips.

Here’s the structure:
Outer Loop (“Loop Create Video”): Iterates over 6 items (representing 6 titles, each with a videoIndex from 1 to 6).
Inner Loop (“Loop Clips”): For each title, iterates over 5 items (representing 5 random clips) to download the clips, save them to disk, and create a clips_.txt file.
After the inner loop completes, the workflow proceeds to create the final video for that title.

What I’ve Tried

I’ve verified that the “Choose 5 Random Clips” node outputs 5 items in every iteration of the outer loop, so the input to “Loop Clips” is correct.
I’ve checked the “Loop Clips” node settings:
Batch Size: 1 (default).
No additional options are set.
I’ve added logging to confirm that the outer loop is iterating correctly (it processes all 6 titles), but the inner loop skips iterations after the first one.
I’ve tested the inner loop independently (outside the outer loop), and it works fine, iterating over the 5 clips as expected.

My Setup

n8n Version: I’m running n8n on my VPS (self-hosted, latest version as of March 2025).
Environment: Docker container.

Questions

Why is the inner “Loop Clips” node skipping iterations after the first outer loop iteration and going straight to the “Done” branch?
How can I fix this so that the inner loop iterates over the 5 clips in every iteration of the outer loop, ensuring all 6 videos are created?
Is there a better way to structure this workflow to avoid this issue, perhaps by avoiding nested loops altogether?

Additional Information

I’ve attached a screenshot of the “Loop Clips” node’s output during the second iteration, showing that it goes straight to the “Done” branch with the 5 input items.
I’ve also attached the full workflow diagram for context.
I’m open to restructuring the workflow if there’s a more reliable approach (e.g., using sub-workflows or triggers), but I’d prefer to fix the nested loop if possible since it fits my current design.
Thank you in advance for your help! I’m really stuck on this and would appreciate any insights or suggestions from the community.

Best regards,
Mark

Is there anything in the outer loop that depends on the outputs from the inner loop?

Anyway, I would try to connect the inner loop’s Done branch back to the outer loop. You may not need the inner loop’s output as it is apparently about side effects, but for the workflow execution consistency this makes sense. You may “reset” the inner loop’s output to strip all heavy payload before merging it with the rest of the outer loop.

Another strategy would be to indeed put the inner loop logic into a subworkflow. Since it is, again, about side effects you may employ option to not wait for the subworkflow to complete. The “call the subworkflow” node will simply bypass inputs further down. I’d merge it back into outer loop anyway.

One of the benefits of the fire-and-forget subworkflow - better memory management. In your current setup the data from the inner workflow, when properly fixed, will mount up. If you isolate it into a subworkflow there will be individual runner for each iteration of the outer workflow which will be cleared once it’s completed.

Hope the above makes sense to you and helps.

2 Likes

Hi @Olek ,

Thank you for your detailed answer. I was wondering if there is a way to make this work without having subworkflows, but I understand that having a subworkflow might be smarter because of memory not piling up.

Also, is there a way to have this subworkflow still in the same workflow if you know what I mean. I would like to have everything in the same workflow even other subworkflows that have a different trigger. But in this case I would need to trigger a subworkflow with a node that needs a workflow ID, meaning I need to create a totally separate workflow for these 5 nodes?

Best, Mark

You can definitely keep subworkflow on the same canvas with the main workflow. My understanding is that this approach still solves memory issues as it will be a separate execution. Although you may need some scrolling through the executions panel to distingush between main and subworkflow executions for debugging purposes.

1 Like

Understood, thank you very much for your help :slight_smile:

1 Like

Happy n8ning! :slight_smile:

1 Like

Hi,

I have tried this right now, but I cant seem to figure out how to do this in teh same canva. If I want to use Execute Subworkflow node it requieres a subworkflow from a different workflow. Is this even possible?

Your main workflow should be in the list for you to pick.
For e.g. the workflow I used as an example is named _sandbox sub-workflows. I just pick it in Execute Workflow node configuration.

Just to make sure, check your workflow’s settings.

1 Like

Is that only included in the Enterprise plan? I dont see these settings.


Weird. I’m on a Starter cloud plan. I guess the less powerful plan is trial only lol

So, general workflow settings are accessible via ... button somewhere in the upper right corner of the canvas. Not by my laptop now to make a screenshot.

1 Like

No worries, I will just create a separate workflow than. As long as it works I’m good :slight_smile:
Thanks again for your help.

Best, Mark

Alright, here we go.
Here is where you find the general workflow’s settings:

A quick-checklist:

  • This workflow can be called by (on General workflow’s settings) is permissive (created by you or by any workflow)
  • When Executed by Another Workflow trigger node for a sub-workflow is already placed on the canvas and has no issues (make it accept all data for now)
  • Execute Workflow node lists any workflows at all

I wonder what that red triangle gives a hint about about when hovered?
image

Try also use By ID instead of From List. You will find ID in the workflow’s url:
image

1 Like

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