-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Chat triggers don't work with the new partial execution flow #11952
fix: Chat triggers don't work with the new partial execution flow #11952
Conversation
…assing 6 arguments I'll add 2 more arguments to the list
…o send a preferred trigger with or without data
cb67955
to
fc9a357
Compare
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
fc9a357
to
4dbc563
Compare
if ( | ||
startNodeNames.length === 0 && | ||
'destinationNode' in options && | ||
options.destinationNode !== undefined | ||
) { | ||
executedNode = options.destinationNode; | ||
startNodeNames.push(options.destinationNode); | ||
} else if ('triggerNode' in options && 'nodeData' in options) { | ||
} else if (options.triggerNode && options.nodeData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no need to use '...' in object
as a guard and it made the type casting necessary. Changing this get's rid of the type casting below.
async needsWebhook(options: { | ||
userId: string; | ||
workflowEntity: IWorkflowDb; | ||
additionalData: IWorkflowExecuteAdditionalData; | ||
runData?: IRunData; | ||
pushRef?: string; | ||
destinationNode?: string; | ||
preferredTrigger?: WorkflowRequest.ManualRunPayload['preferredTrigger']; | ||
}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of arguments to this function were getting out of hand so I turned it into an object.
packages/cli/src/workflow-runner.ts
Outdated
// TODO: When the old partial execution logic is removed this block can | ||
// be removed and the previous one can be merged into | ||
// `workflowExecute.runPartialWorkflow2`. | ||
// Partial executions then require either a destination node from which | ||
// everything else can be derived, or a preferredTrigger with | ||
// triggerData. Full Execution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is not necessary for the new partial execution flow. As soon as we default to the new flow and remove the old flow we can fold the code for handling preferred triggers into the partial execution function in WorkflowExecute
@@ -203,6 +211,7 @@ export class WorkflowRunner { | |||
} | |||
|
|||
/** Run the workflow in current process */ | |||
// eslint-disable-next-line complexity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary for now. Once we remove the old partial execution logic this function will be much simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll come back later to test it!
// that trigger, not the other ones. | ||
if (preferredTrigger) { | ||
webhooks = webhooks.filter((w) => w.node === preferredTrigger.name); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an else if
with the next check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow.
This check is removing all but one webhook from the list if the preferred trigger was passed.
The next check is checking if the the list contains at least one trigger that is restartable (I think 🤔 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the question is, can it ever happen that a trigger to start triggers the restartable check? What exactly is w.webhookDescription.restartWebhook
?
But if not worth it let's leave it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is w.webhookDescription.restartWebhook?
I don't know either tbh. Jan added this here: 5a179cd#diff-b386248ff00977749c873ed85821c241b773e9740d7e7adf94e05b73b350ed74
Which is a huge commit.
It seems this is for the Form, Wait, Slack and Gmail nodes.
I guess the question is, can it ever happen that a trigger to start triggers the restartable check?
I guess that would be fine still. I'm assuming this is to not listen for webhook for workflows that have been put to into waiting?
Which means you can't actually pick them as a trigger to start from.
At least for the the wait and form nodes this is only interesting for workflows that wait, probably for slack too, e.g. if you render a dialog and wait for the user to click a button. I'm not sure why the gmail node offers this though.
I guess this can be left until the split button is implemented.
packages/cli/src/workflow-runner.ts
Outdated
} else if (data.preferredTrigger?.data && data.startNodes && !data.destinationNode) { | ||
this.logger.debug( | ||
`Execution ID ${executionId} had preferredTrigger. Starting from that trigger.`, | ||
{ executionId }, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This is me having limited context.) What's the significance of the preferred trigger having data? If the preferred trigger has no data, the fact that it's preferred is irrelevant? Or all preferred triggers will always have data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some triggers have the ability to "make up" data. E.g. the schedule trigger must have a function that does that, I didn't check where it it though.
From what I could tell there are these scenarios:
- trigger can make up data (schedule trigger)
- trigger has pinned data
- trigger waits for an external event (any webhook or polling trigger)
- trigger asks everytime for the user to input custom data (probably just the chat trigger?)
The preferred trigger only needs data for 4.
In all other cases you can send the preferred trigger without data, which will be the bases for the split run workflow button that Charlie and Csaba have been working on during the hackmation. This PR is supposed to lay some ground work for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, much clearer now.
packages/cli/src/workflow-runner.ts
Outdated
@@ -286,12 +295,54 @@ export class WorkflowRunner { | |||
data.executionData, | |||
); | |||
workflowExecution = workflowExecute.processRunExecutionData(workflow); | |||
} else if (data.preferredTrigger?.data && data.startNodes && !data.destinationNode) { | |||
this.logger.debug( | |||
`Execution ID ${executionId} had preferredTrigger. Starting from that trigger.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This is mostly me trying to make sense of this.) I see all the other branches specify how much to execute:
- has execution data (e.g. retry) → reuse that data
- has no run data or has no start node → run it fullly
- has run data or has start node → run it partially
But this new branch specifies where to start executing from. Should we stay consistent with the others? What would this branch be in the above terms? A "pseudo full" execution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what think it eventually should be:
let executionData
if (data.executionData) {
executionData = data.executionData
} else if (data.preferredTrigger) {
const triggerData = data.triggerData ?? getTriggerDataFromTrigger(data.preferredTrigger)
executionData = createExecutionDataFromTrigger(data.preferredTrigger, data.triggerData, data.workflowData)
} else if (data.destinationNode) {
executionData = recreateExecutionDataFromPartialExecution(data.destinationNode, data.workflowData, data.runData, data.pinData, ...etc)
}
// run with execution data
So you either start from old execution data, or from a trigger or we have the destination node and try to recreate the execution stack from that.
I don't even know if the block were I added the long TODO comment is used. I just don't want to remove it right now, but when we remove the old partial exec logic which comes with simplifying useRunWorkflow.ts to the point were I can be sure that the "Full Execution" branch is unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, that's clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and working! Nice job :)
|
n8n Run #8207
Run Properties:
|
Project |
n8n
|
Branch Review |
pay-2166-chat-triggers-dont-work-with-the-new-partial-execution-flow-try-2
|
Run status |
Passed #8207
|
Run duration | 04m 30s |
Commit |
f68c0d753a: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
|
Committer | Danny Martini |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
478
|
View all changes introduced in this branch ↗︎ |
✅ All Cypress E2E specs passed |
Got released with |
Summary
This fixes the chat trigger not working with the new execution flow.
Before the chat trigger would always trigger a partial execution, but now a partial execution requires a destination node.
This PR alleviates this by re-using the parts of the new flow that does not require a destination node.
This will be simplified once we can remove the old partial execution flow logic.
before:
pay-2166-before.mp4
after:
pay-2166-after.mp4
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/PAY-2166/chat-triggers-dont-work-with-the-new-partial-execution-flow
Review / Merge checklist
Docs updated or follow-up ticket created.PR Labeled withrelease/backport
(if the PR is an urgent fix that needs to be backported)