-
Notifications
You must be signed in to change notification settings - Fork 54.3k
feat: Trigger validation service #25037
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
base: master
Are you sure you want to change the base?
Conversation
…trigger-validation-service
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…trigger-validation-service
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.
No issues found across 9 files
|
Found 45 test failures on Blacksmith runners: Failures
|
|
Found 45 test failures on Blacksmith runners: Failures
|
mfsiega
left a comment
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 really like the general approach!
I do worry that there are a lot of tricky corner cases.
Haven't taken a full look line-by-line yet.
| * Parameters that must be unique across all active workflows, keyed by trigger type. | ||
| */ | ||
| export const TRIGGERS_UNIQUE_PARAMETERS: Record<string, string[]> = { | ||
| 'n8n-nodes-base.kafkaTrigger': ['groupId'], |
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.
Strictly speaking we still can't prevent this, because we support expressions, right? But of course it helps if somebody does this accidentally.
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.
true, but I do think that this is unlikely, as it isfor triggers
| // Check whether this workflow is active. | ||
| const workflowIsActive = await this.workflowRepository.isActive(payload.workflowData.id); | ||
|
|
||
| const triggerToStartFrom = |
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 think we probably want to move this lower, down around line 221? Since in between here and there we do some work to potentially choose the relevant trigger (e.g., if it's a partial execution to a destination node, we pick a trigger on the backend).
There's also the question of pinned data - if we have pinned data for the trigger we won't actually end up activating it. So in that case, I think we would want to allow it.
| return false; | ||
| } | ||
|
|
||
| await this.triggerValidation.validateWorkflowActivation(workflow); |
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.
We have some existing validation in the WorkflowService.activateWorkflow, which I think is a slightly better place for this. Should it live there instead? (And maybe we can unify some of the logic a bit?)
Summary
This PR introduces a centralized trigger validation system that enforces constraints on specific trigger types during workflow execution and activation.
Changes
New Trigger Configuration Constants
Added two constants in
trigger-validation.service.ts:TRIGGERS_PREVENT_TEST_WHILE_ACTIVE- ASet<string>defining trigger types that cannot run test/manual executions while the workflow is active. This addresses limitations in certain triggers (e.g., Kafka) where simultaneous production and test listeners cause conflicts.TRIGGERS_UNIQUE_PARAMETERS- ARecord<string, string[]>mapping trigger types to parameter names that must be unique across all active workflows. This prevents resource conflicts (e.g., two active workflows cannot share the same Kafka consumer group ID).Validation Service
The
TriggerValidationServiceprovides two main validation methods:validateManualExecution()- Called before test/manual runs to:validateWorkflowActivation()- Called before workflow activation to:Error Handling
SingleTriggerError- RenamedSingleWebhookTriggerError, thrown when attempting to test a restricted trigger while the workflow is activeTriggerParameterConflictError- Thrown when a parameter value conflicts with an active workflowExample Configuration
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/NODE-4323/trigger-validation-service
Review / Merge checklist
release/backport(if the PR is an urgent fix that needs to be backported)