-
Notifications
You must be signed in to change notification settings - Fork 178
Description
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
- 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;
}-
Run
npm run devor trigger the workflow graph extraction -
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.