Loops/Sub-loop Sometimes don't loop

Sometimes loops don’t loop

2 items (2 titles) → loop, should run twice :white_check_mark: (working as expected) → creates 1 or 2 items (subtitles) → loop over subtitles sometimes works and sometimes it doesn’t

i have replicated the bug in a simple workflow i added bellow
i also attached a recording of the workflow not working as expected

Expected output:

[Node: “Outputs 2 Titles”] ‘titles created: [ title 1, title 2 ]’
[Node: “Outputs 1 or 2 Subtitles”] ‘title 1 looping over subtitles should log 1 subtitles: [ subtitle 1 ]’
[Node: “Log Subtitle”] ‘subtitle 1’
[Node: “Outputs 1 or 2 Subtitles”] ‘title 2 looping over subtitles should log 1 subtitles: [ subtitle 1 ]’
[Node: “Log Subtitle”] ‘subtitle 1’

or // depends if 1 or 2 subtitles was created

[Node: “Outputs 2 Titles”] ‘titles created: [ title 1, title 2 ]’
[Node: “Outputs 1 or 2 Subtitles”] ‘title 1 looping over subtitles should log 2 subtitles: [ subtitle 1, subtitle 2 ]’
[Node: “Log Subtitle”] ‘subtitle 1’
[Node: “Log Subtitle”] ‘subtitle 2’
[Node: “Outputs 1 or 2 Subtitles”] ‘title 2 looping over subtitles should log 1 subtitles: [ subtitle 1 ]’
[Node: “Log Subtitle”] ‘subtitle 1’

Actual Output

[Node: “Outputs 2 Titles”] ‘titles created: [ title 1, title 2 ]’
[Node: “Outputs 1 or 2 Subtitles”] ‘title 1 looping over subtitles should log 1 subtitles: [ subtitle 1 ]’
[Node: “Log Subtitle”] ‘subtitle 1’
[Node: “Outputs 1 or 2 Subtitles”] ‘title 2 looping over subtitles should log 1 subtitles: [ subtitle 1 ]’

In a nutshell The second title almost never gets its subtitles logged

#[details=“instance information”]

Debug info

core

  • n8nVersion: 1.112.4
  • platform: docker (cloud)
  • nodeJsVersion: 22.19.0
  • database: sqlite
  • executionMode: regular
  • concurrency: 20
  • license: community

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 720 hours
  • maxCount: 25000 executions

client

  • userAgent: mozilla/5.0 (macintosh; intel mac os x 10_15_7) applewebkit/537.36 (khtml, like gecko) chrome/139.0.0.0 safari/537.36
  • isTouchDevice: false

Generated at: 2025-09-25T15:37:53.799Z}
[/details]

i spent hours debugging and trying to figure it out, i got nowhere, i am almost certain its a bug, (i reported it on github but the ticket got closed almost immediately and was redirected to this community, its my first post so Hello everyone :waving_hand: , Thank you for your help

as pointed out by Joffcom, this can be solved by adding a reset expression on the second loop

{{ prevNode.name === 'Outputs 1 or 2 Subtitles' }} 

But when i tried implementing this in my original workflow it still didn’t work,
as a new user i cant upload a video here to show the issue but here is the github issue Loops have unexpected behavior, sometimes it does not loop over items · Issue #20083 · n8n-io/n8n · GitHub where the details are available

hello @yammine

Sub-loops won’t work. Use sub-workflows

1 Like

@barn4k hello, thank you for replying. i am using the cloud version and i am stuck at 10k executions a month, sub-workflows are expensive, and the simplest of data structures need nested loops, i think its a bit unfair if i am looping over 1k items to spend 1k workflows 10% of my entire month.

Well… Then you will need to rebuild the workflow :slight_smile:

Sub-loops won’t work at all. You can work only with one level of nesting. However, in most cases, you don’t need the first nesting level, as it’s already working by design. E.g. here

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