Skip to content

fix: add cycle detection to prevent infinite recursion in graphExecutor#102

Open
g3Bg2 wants to merge 1 commit intomainfrom
openclaw-fix-cycle-detection
Open

fix: add cycle detection to prevent infinite recursion in graphExecutor#102
g3Bg2 wants to merge 1 commit intomainfrom
openclaw-fix-cycle-detection

Conversation

@g3Bg2
Copy link
Contributor

@g3Bg2 g3Bg2 commented Feb 25, 2026

Fixes #79

What was broken

executeGraph() in graphExecutor.ts tracks visited nodes via a Set<string> but never checks it before recursing into a node. If a workflow graph contains a cycle (e.g., Node A → Node B → Node A), the executor would recurse infinitely until the 10,000-iteration guard fired — at which point the automation crashes with a generic error instead of detecting the cycle early.

What was changed

Added a single guard at the top of executeGraph() (before any other logic):

if (visited.has(nodeId)) return;

This causes the executor to skip any node it has already visited, short-circuiting cycles cleanly and immediately — without crashing or burning through the iteration budget.

How to test

  1. Create a workflow with a cycle: e.g., two nodes connected in a loop.
  2. Run the automation.
  3. Before fix: automation hangs until hitting the 10k iteration guard, then crashes.
  4. After fix: automation executes each node once and exits cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent infinite loops

1 participant