Skip to content
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

Conversation

despairblue
Copy link
Contributor

@despairblue despairblue commented Nov 28, 2024

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

  • 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)

@despairblue despairblue changed the base branch from master to extract-filter-disabled-nodes November 28, 2024 14:08
@despairblue despairblue force-pushed the pay-2166-chat-triggers-dont-work-with-the-new-partial-execution-flow-try-2 branch from cb67955 to fc9a357 Compare November 28, 2024 14:09
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Nov 28, 2024
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/core/src/index.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Base automatically changed from extract-filter-disabled-nodes to master November 29, 2024 11:58
@despairblue despairblue force-pushed the pay-2166-chat-triggers-dont-work-with-the-new-partial-execution-flow-try-2 branch from fc9a357 to 4dbc563 Compare November 29, 2024 13:26
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) {
Copy link
Contributor Author

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.

Comment on lines 222 to 230
async needsWebhook(options: {
userId: string;
workflowEntity: IWorkflowDb;
additionalData: IWorkflowExecuteAdditionalData;
runData?: IRunData;
pushRef?: string;
destinationNode?: string;
preferredTrigger?: WorkflowRequest.ManualRunPayload['preferredTrigger'];
}) {
Copy link
Contributor Author

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.

Comment on lines 340 to 345
// 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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@despairblue despairblue marked this pull request as ready for review November 29, 2024 13:34
Copy link
Contributor

@ivov ivov left a 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!

packages/cli/src/webhooks/test-webhooks.ts Outdated Show resolved Hide resolved
packages/cli/src/webhooks/test-webhooks.ts Outdated Show resolved Hide resolved
packages/cli/src/workflow-runner.ts Show resolved Hide resolved
packages/cli/src/workflow-runner.ts Outdated Show resolved Hide resolved
packages/cli/src/workflow-runner.ts Outdated Show resolved Hide resolved
// that trigger, not the other ones.
if (preferredTrigger) {
webhooks = webhooks.filter((w) => w.node === preferredTrigger.name);
}
Copy link
Contributor

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?

Copy link
Contributor Author

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 🤔 )

Copy link
Contributor

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 :)

Copy link
Contributor Author

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.

cc @cstuncsik @CharlieKolb

Comment on lines 298 to 302
} else if (data.preferredTrigger?.data && data.startNodes && !data.destinationNode) {
this.logger.debug(
`Execution ID ${executionId} had preferredTrigger. Starting from that trigger.`,
{ executionId },
);
Copy link
Contributor

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?

Copy link
Contributor Author

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:

  1. trigger can make up data (schedule trigger)
  2. trigger has pinned data
  3. trigger waits for an external event (any webhook or polling trigger)
  4. 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.

Copy link
Contributor

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.

@@ -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.`,
Copy link
Contributor

@ivov ivov Dec 2, 2024

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

packages/cli/src/workflow-runner.ts Show resolved Hide resolved
ivov
ivov previously approved these changes Dec 4, 2024
Copy link
Contributor

@ivov ivov left a 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 :)

Copy link
Contributor

github-actions bot commented Dec 4, 2024

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link

cypress bot commented Dec 4, 2024

n8n    Run #8207

Run Properties:  status check passed Passed #8207  •  git commit f68c0d753a: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Project n8n
Branch Review pay-2166-chat-triggers-dont-work-with-the-new-partial-execution-flow-try-2
Run status status check passed Passed #8207
Run duration 04m 30s
Commit git commit f68c0d753a: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Committer Danny Martini
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 478
View all changes introduced in this branch ↗︎

Copy link
Contributor

github-actions bot commented Dec 4, 2024

✅ All Cypress E2E specs passed

@despairblue despairblue merged commit 2b6a72f into master Dec 4, 2024
51 checks passed
@despairblue despairblue deleted the pay-2166-chat-triggers-dont-work-with-the-new-partial-execution-flow-try-2 branch December 4, 2024 14:33
@github-actions github-actions bot mentioned this pull request Dec 11, 2024
@janober
Copy link
Member

janober commented Dec 11, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants