Rescue each flow trigger error so later triggers still run
What does this MR do and why?
One flow trigger error no longer fails PipelineHooksWorker. Later triggers still run. The error goes to Gitlab::ErrorTracking.track_exception.
EE::Ci::Pipelines::HookService#execute delivers webhooks in super, then starts flow triggers. PipelineHooksWorker uses retry: 3 and is not idempotent. Before this change, a raise from one trigger delivered those webhooks again on each retry. The loop stopped at the first raise.
The rescue wraps each trigger in that loop. It follows the per-trigger rescue in CloudEventsFlowTriggerWorker#execute_flow_triggers. A rescue around the whole execute_flow_triggers call would stop the worker retry. Later triggers would still not run. The worker stays without a rescue, so a webhook failure can still retry. An error while triggers are loaded still fails the worker. There is no single trigger to track in that case.
The stuck workflow row is out of scope for this MR. Ci::Pipeline#resource_parent was restored by merged !266177 (merged).
The owning group is DAP Events. Code owners are gitlab-org/maintainers/rails-backend.
The changelog trailer is Changelog: fixed. The feature code is only under ee/, so the other trailer is EE: true.
Verified that the new examples fail when the rescue is removed, and that no doc sentence describes the old retry.
References
- Related to #637932 (closed)
- Pipeline hook fan-out that led to this issue: !266177 (merged)
- Probe note: !266177 (comment 4137548296)
Screenshots or screen recordings
Not applicable. There is no UI change.
How to set up and validate locally
Run these steps in one Rails console, in order. Use a project that already has two active pipeline event triggers. Each trigger needs an empty filter and no foundational flow. FilterEvaluator#allowed? returns true for a blank filter. A foundational flow can add a precondition on top of an empty filter. Exit the console when you finish. The prepend lasts for that process.
-
Confirm the project will not deliver hooks during this check, and that the pipeline user can run a flow trigger.
project = Project.find_by_full_path('<project full path>')Stop if
projectis nil.pipeline = project.ci_pipelines.where(source: :push, status: :success).firstStop if
pipelineis nil. Use a successful push pipeline.HookService#executecallsPipelineFailedWorker.queue_forbefore webhooks and event triggers. A failed pipeline can enqueue that worker, and a separate Sidekiq process does not inherit this console'sRunService.prepend. A successful pipeline returns atqueue_for's first guard, so this check stays on the rescue under test.user = pipeline.user Ability.allowed?(user, :trigger_ai_flow, project) project.has_active_hooks?(:pipeline_hooks) project.has_active_integrations?(:pipeline_hooks)Stop if
Ability.allowed?is false. The service returns before the loop. Stop if either hook check is true.performwould deliver real hooks. -
Confirm two triggers will reach
RunService.triggers = ::Ai::FlowTrigger.applicable_to_project(project, triggered_on: :pipeline_hooks).to_a triggers.sizeStop if
triggers.sizeis under 2. -
Raise on one trigger and record every trigger that reaches
execute. The block keepsranandfailing_id. Adefinside a module would not see those locals. This override skips the real workload.ran = [] failing_id = triggers.first.id override = Module.new do define_method(:execute) do |_params| ran << flow_trigger.id raise StandardError, 'boom' if flow_trigger.id == failing_id nil end end ::Ai::FlowTriggers::RunService.prepend(override) -
Call the service. It returns without an exception.
ranincludes every trigger id from step 2, includingfailing_id.::Ai::FlowTriggers::EventTriggerService.new( project: project, current_user: user, event: :pipeline_hooks, data: { object_attributes: { id: pipeline.id } } ).execute ran -
Clear
ran, then call the worker with the same override still in place. The call returns without an exception.ranagain includes every trigger id from step 2, includingfailing_id. Use the successful pipeline from step 1 soqueue_forreturns before enqueue.ran.clear PipelineHooksWorker.new.perform(pipeline.id) ran -
Open
log/exceptions_json.log. The new lines areStandardErrorwith messageboom, and the extra data includesflow_trigger_idforfailing_id.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.