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

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.

  1. 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 project is nil.

    pipeline = project.ci_pipelines.where(source: :push, status: :success).first

    Stop if pipeline is nil. Use a successful push pipeline. HookService#execute calls PipelineFailedWorker.queue_for before webhooks and event triggers. A failed pipeline can enqueue that worker, and a separate Sidekiq process does not inherit this console's RunService.prepend. A successful pipeline returns at queue_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. perform would deliver real hooks.

  2. Confirm two triggers will reach RunService.

    triggers = ::Ai::FlowTrigger.applicable_to_project(project, triggered_on: :pipeline_hooks).to_a
    triggers.size

    Stop if triggers.size is under 2.

  3. Raise on one trigger and record every trigger that reaches execute. The block keeps ran and failing_id. A def inside 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)
  4. Call the service. It returns without an exception. ran includes every trigger id from step 2, including failing_id.

    ::Ai::FlowTriggers::EventTriggerService.new(
      project: project,
      current_user: user,
      event: :pipeline_hooks,
      data: { object_attributes: { id: pipeline.id } }
    ).execute
    ran
  5. Clear ran, then call the worker with the same override still in place. The call returns without an exception. ran again includes every trigger id from step 2, including failing_id. Use the successful pipeline from step 1 so queue_for returns before enqueue.

    ran.clear
    PipelineHooksWorker.new.perform(pipeline.id)
    ran
  6. Open log/exceptions_json.log. The new lines are StandardError with message boom, and the extra data includes flow_trigger_id for failing_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.

Edited by Deepak Reddy Gathpa

Merge request reports

Loading
Loading