fix(core): Make sub-workflows with waits return correct data to parents
Summary
Executing sub workflows with Execute Sub Workflows in options.waitForSubWorkflow mode containing Wait nodes or "Human in the Loop" sendAndWait nodes would make them return wrong data to the parent workflow once execution resumed after the sub workflow resumed from waiting state.
This affected at least:
"Wait" nodes using resume modes
-
webhook -
form -
specificTime, if the chosen time is more than 65 seconds away -
timeInterval, if the chosen interval is longer than 65 seconds
"Human in the loop" nodes in sendAndWait operation mode
- Discord
- Gmail
- Google Chat
- Microsoft Outlook
- Microsoft Teams
- Send Email
- Slack
- Telegram
- Whatsapp Business Cloud
or any other nodes that would call putExecutionToWait. When parent workflow execution resumed it never received the final output from the sub workflow, and the input to Execute Sub Workflow node was be "returned" from the execution instead (like when options.waitForSubWorkflow mode is disabled).
This PR fixes this by copying the output from last node of sub workflow into the input of its parent workflow's waiting node, which should be the Execute Sub Workflow node. This works well in Run once with all items mode but I now realized that the Run once with each item mode behaves differently here and this fix doesn't work for it yet.
The issue can be reproduced with these workflows
Simple_parent.json Simple_Wait_Webhook_child.json
Note that the wait has to be longer than 65 seconds, but webhook, form and one of the many sendAndWait nodes can be used instead.
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/ADO-3297/community-issue-calling-a-sub-workflow-with-a-wait-by-webhook-node Fixes #13135
Review / Merge checklist
- [ ] PR title and summary are descriptive. (conventions)
- [ ] Docs updated or follow-up ticket created.
- [ ] Tests included.
- [ ] PR Labeled with
release/backport(if the PR is an urgent fix that needs to be backported)
Codecov Report
Attention: Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| packages/cli/src/wait-tracker.ts | 70.58% | 4 Missing and 1 partial :warning: |
:loudspeaker: Thoughts on this report? Let us know!
Please merge.
Closing this PR as the solution proposed here wasn't a feasible one to properly fix the issue. 😞 We're looking into a better solution.
Hello all, do you know if a solution was it found for this problem ?
This has been implemented in v2 now, which should be released next week. But you can check the RC releases already, just be aware that they are beta.
Thanks @Cadiac for the original implementation ❤️
Hello, I confirm it works perfectly well ! Well done n8nTeam