Skip to content

Unable to use the nested loops in n8n in a single workflow #25019

Description

Describe the problem/error/question

I am experiencing a critical issue with nested Loop Over Items nodes in n8n. When using one Loop Over Items node inside another, the inner loop's "Done" state persists across iterations of the outer loop, causing it to skip processing items for subsequent outer loop iterations.

Expected Behavior:

  • Outer Loop processes Thread 1 → Inner Loop processes 3 invoices → Inner Loop completes
  • Outer Loop processes Thread 2 → Inner Loop should reset and process 2 new invoices
  • Pattern continues for all threads

Actual Behavior:

  • Outer Loop processes Thread 1 → Inner Loop processes 3 invoices → Inner Loop shows "Done Branch"
  • Outer Loop processes Thread 2 → Inner Loop skips execution because it's still in "Done" state from Thread 1
  • No invoices from Thread 2 onward are processed

Attempted Solutions:

  1. Enabled "Reset" option on the inner Loop Over Items node → Did not resolve the issue; loop still retained "Done" state
  2. Set Batch Size = 1 on both loops → Issue persisted
  3. Added unique identifiers to items → No effect on loop state management

Workflow Structure:

Loop Over Items (Threads) - Batch Size: 1
  ↓
Transaction Splitter Code Node (outputs multiple invoice items per thread)
  ↓
Loop Over Items (Invoices) - Batch Size: 1, Reset: ON
  ↓
  AI Agent Processing
  ↓
  Supabase Update
  ↓
Loop Done (Invoices) ← Gets stuck in "Done" state
  ↓
Loop Done (Threads)

Root Cause Analysis:

The inner Loop Over Items node does not properly reset its execution state when new items arrive from a subsequent iteration of the outer loop. The "Done Branch" status from completing the first thread's invoices persists and prevents the loop from processing items from subsequent threads.

This appears to be a fundamental limitation in how nested Loop Over Items nodes manage their execution state across parent loop iterations.

What is the error message (if any)?

No explicit error message is shown. The workflow executes without errors, but the inner loop silently skips processing after the first outer loop iteration completes.

Please share your workflow/screenshots/recording

Simplified reproduction workflow:

{
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "id": "outer-loop",
      "name": "Loop Over Items (Threads)",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [200, 300],
      "typeVersion": 3
    },
    {
      "parameters": {
        "jsCode": "// Simulate transaction splitter that outputs multiple invoices\nconst threadId = $json.thread_id;\nconst invoices = $json.invoices || [];\n\nreturn invoices.map(inv => ({\n  json: {\n    threadId: threadId,\n    invoiceId: inv.id,\n    data: inv\n  }\n}));"
      },
      "id": "splitter",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [400, 300],
      "typeVersion": 2
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {
          "reset": true
        }
      },
      "id": "inner-loop",
      "name": "Loop Over Items (Invoices)",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [600, 300],
      "typeVersion": 3
    }
  ],
  "connections": {
    "Loop Over Items (Threads)": {
      "main": [
        [{"node": "Code", "type": "main", "index": 0}]
      ]
    },
    "Code": {
      "main": [
        [{"node": "Loop Over Items (Invoices)", "type": "main", "index": 0}]
      ]
    }
  }
}

Screenshot description:

  • Outer loop processes first thread with 3 invoices successfully
  • Inner loop shows "Done Branch" (1 item) after processing all 3 invoices
  • When second thread arrives with 2 invoices, inner loop's "Done Branch" remains and skips execution
  • Loop Branch (expected to receive 2 items) receives 0 items

Share the output returned by the last node

After Thread 1 (3 invoices):

  • Inner Loop "Loop Branch": 3 items processed ✅
  • Inner Loop "Done Branch": 1 item (completion signal) ✅

After Thread 2 (2 invoices) - THE BUG:

  • Inner Loop "Loop Branch": 0 items ❌ (Expected: 2 items)
  • Inner Loop "Done Branch": Still shows 1 item from Thread 1 ❌ (Should process 2 new items first)

The inner loop completely skips execution for Thread 2 because it thinks it's already "done" from Thread 1.

Additional Context

This issue makes it impossible to use nested Loop Over Items for workflows that require:

  • Processing multiple threads, each containing multiple items (emails with multiple invoices)
  • Batch processing where each batch contains sub-items that need iteration
  • Any hierarchical data structure requiring nested iteration

Workaround used:
Removed the inner Loop Over Items entirely and relied on n8n's native behavior of automatically processing multiple items sequentially. However, this removes the ability to use loop control features (loop back, done branch handling, etc.).

Impact:
This is a critical limitation that forces users to restructure workflows significantly or use Execute Workflow nodes (adding complexity and maintenance burden).

Debug info

core

  • n8nVersion: 2.4.6
  • platform: docker (self-hosted)
  • nodeJsVersion: 22.21.1
  • nodeEnv: production
  • database: postgres
  • executionMode: scaling (single-main)
  • concurrency: -1
  • license: enterprise (production)

storage

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

pruning

  • enabled: true
  • maxAge: 168 hours
  • maxCount: 500 executions

client

  • userAgent: mozilla/5.0 (macintosh; intel mac os x 10_15_7) applewebkit/537.36 (khtml, like gecko) chrome/144.0.0.0 safari/537.36
  • isTouchDevice: false
    Generated at: 2026-01-29T08:05:53.818Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs FeedbackWaiting for further input or clarification.StaleIssue was stalestatus:in-linearIssue or PR is now in Lineartriage:pendingWaiting to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions