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_deriskflagpolicy_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
- Resolves #633552
- Rollout issue: #634560
- Related: !261836 (merged) (same push scenario, wrong related pipeline)
Screenshots or screen recordings
Not applicable, backend only.
How to set up and validate locally
- In rails console, enable the feature flag:
Feature.enable(:policy_timeout_waits_for_running_head_pipeline) - Create a merge request approval policy with a
scan_findingrule. - 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.
- With the flag on, the MR shows no
Policy evaluation timed outskip 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 failuresMR 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 excludescreatedandscheduled: a head pipeline that has not started yet keeps the old fail-closed skip, so a pipeline stuck before starting cannot hold violations inrunningindefinitely.- 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.