Keep policy timeout from skipping while head pipeline runs

What does this MR do and why?

The approval policy evaluation timeout no longer skips violations while the merge request's head pipeline is still running.

Details

Any pipeline completing on a SHA schedules UnblockPendingMergeRequestViolationsWorker 150 seconds later, including a branch pipeline with no security jobs. The worker then skipped the running violations of every open merge request at that SHA and required approvals, even when the merge request's head pipeline was a different pipeline still running its scanners. The merge request stayed blocked until the head pipeline finished and its own evaluation cleared it.

The worker now skips merge requests whose diff head pipeline is a different, active pipeline. The head pipeline's own completion schedules its own timeout, so nothing is left without one.

  • Behind the gitlab_com_derisk flag policy_timeout_waits_for_running_head_pipeline (default off), actor: the merge request's target project.
  • No changelog: default-off flag.

Reviewable LOC: 20 (plus 34 in tests)

References

Screenshots or screen recordings

Not applicable, backend only.

How to set up and validate locally

  1. In rails console, enable the feature flag:
    Feature.enable(:policy_timeout_waits_for_running_head_pipeline)
  2. Create a merge request approval policy with a scan_finding rule.
  3. Push to a branch with an open MR, so a branch pipeline without security jobs and an MR pipeline with scanners both run. Make the MR pipeline's scanners take more than 150 seconds after the branch pipeline finishes.
  4. With the flag on, the MR shows no Policy evaluation timed out skip while its pipeline runs. With the flag off, it does.

Specs:

$ bin/rspec ee/spec/workers/security/scan_result_policies/unblock_pending_merge_request_violations_worker_spec.rb
36 examples, 0 failures

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.

Context for LLM agents
  • Rejected: checking scans of other pipelines at the SHA inside the timeout window. Deferring to the head pipeline is simpler, and its completion already schedules a timeout through UnenforceablePolicyRulesPipelineNotificationWorker.
  • active? deliberately excludes created and scheduled: a head pipeline that has not started yet keeps the old fail-closed skip, so a pipeline stuck before starting cannot hold violations in running indefinitely.
  • The guard only applies when the head pipeline differs from the triggering one. When the timeout comes from the head pipeline itself (for example scheduled at MR creation), behaviour is unchanged.

Merge request reports

Loading
Loading