Docs / Strand / advanced/infinite-loops

Infinite Loop Prevention

Strand automatically prevents infinite loops when workflows call each other.

How It Works

The system tracks a call chain - a list of workflow IDs in the current execution path. Before executing a nested workflow, it checks if that workflow is already in the chain.

Example

code

Workflow A calls Workflow B
  Call chain: [A]
  
Workflow B calls Workflow A
  Call chain: [A, B]
  
System detects: A is already in chain → ERROR

Error Message

When an infinite loop is detected, you'll see:

code

Infinite loop detected: workflow 'workflow-id' is calling itself 
(directly or indirectly). Call chain: workflow-a -> workflow-b -> workflow-a

Direct Loops

A workflow calling itself directly:

code

Workflow A → Flow Call → Workflow A

This is detected immediately when the Flow Call node tries to execute.

Indirect Loops

A workflow calling itself through other workflows:

code

Workflow A → Workflow B → Workflow C → Workflow A

This is detected when Workflow C tries to call Workflow A, which is already in the chain.

Prevention Tips

1

Design workflows carefully

Plan the workflow hierarchy before building

2

Use descriptive names

Makes it easier to spot potential loops

3

Document dependencies

Keep track of which workflows call which others

4

Test incrementally

Test nested workflows before combining them

Valid Patterns

Sequential Calls

code

A → B → C

✅ Valid - no loops

Parallel Calls

code

A → B
A → C

✅ Valid - both B and C are called from A, but don't call each other

Conditional Calls

code

A → (if condition) → B
A → (else) → C

✅ Valid - only one path executes

Debugging

If you encounter an infinite loop error:

  1. Check the call chain in the error message
  2. Review your workflow structure
  3. Look for circular dependencies
  4. Consider refactoring to break the cycle