Skip to content

Workflow graph analyzer stack overflow on recursive workflow calls #851

@chrisedington

Description

@chrisedington

Description

The workflow graph analyzer throws a RangeError: Maximum call stack size exceeded when analyzing workflows that contain recursive calls to themselves.

Error Message

Failed to extract workflow graphs from bundle: RangeError: Maximum call stack size exceeded

Steps to Reproduce

  1. Create a workflow that calls itself recursively under certain conditions:
export async function myWorkflow(params: MyParams): Promise<MyResult> {
  "use workflow";
  
  // ... do some work ...
  
  const result = await someStep();
  
  // Recursive call under certain conditions
  if (result.score < threshold && params.canRetry) {
    return myWorkflow({
      ...params,
      canRetry: false,  // Prevent infinite recursion at runtime
    });
  }
  
  return result;
}
  1. Run npm run dev or trigger the workflow graph extraction

  2. The graph analyzer enters infinite recursion trying to trace the workflow

Expected Behavior

The graph analyzer should detect recursive workflow calls and handle them gracefully, either by:

  • Detecting the cycle and stopping traversal
  • Emitting a warning about recursive workflows
  • Documenting that recursive workflows are not supported

Actual Behavior

Stack overflow crash during graph analysis, blocking the dev server from starting properly.

Workaround

Replace recursive workflow calls with an internal loop structure that achieves the same logic without self-reference.

Environment

  • workflow: 4.0.1-beta.50
  • next: 16.1.3
  • Node.js: v22.x

Additional Context

The recursive pattern is useful for "quality guarantee" features where a workflow retries with different parameters (e.g., escalating to a premium tier) if initial results don't meet a threshold. While the workaround works, native support for recursive workflows or clear documentation about this limitation would be helpful.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions