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
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:
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:
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:
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
Design workflows carefully
Plan the workflow hierarchy before building
Use descriptive names
Makes it easier to spot potential loops
Document dependencies
Keep track of which workflows call which others
Test incrementally
Test nested workflows before combining them
Valid Patterns
Sequential Calls
A → B → C
✅ Valid - no loops
Parallel Calls
A → B
A → C
✅ Valid - both B and C are called from A, but don't call each other
Conditional Calls
A → (if condition) → B
A → (else) → C
✅ Valid - only one path executes
Debugging
If you encounter an infinite loop error:
- Check the call chain in the error message
- Review your workflow structure
- Look for circular dependencies
- Consider refactoring to break the cycle
Tendrl