Race condition: MR merged without code suggestion changes when using auto-merge
Summary
When applying a code suggestion to a merge request that has auto-merge enabled, a race condition can occur where the MR is merged immediately without the suggested changes being applied. The new commit with the suggestion is created in the source branch, but the merged code differs from what was displayed in the MR.
Steps to Reproduce
- Create a merge request
- Enable auto-merge on the MR
- Wait for the pipeline to complete and turn green
- Add a code suggestion to the MR
- Approve the MR
- Click "Apply suggestion"
Current Behavior
- The MR gets merged immediately without the suggested changes being applied
- A new commit with the suggestion appears in the source branch
- The code that was actually merged differs from what was shown in the MR before merge
- This creates a discrepancy between what reviewers approved and what was merged
Expected Behavior
- When a code suggestion is applied to an MR with auto-merge enabled, one of the following should occur:
- The auto-merge should be cancelled or postponed until the new commit's pipeline completes
- The suggestion should be applied before the auto-merge is triggered
- The system should prevent applying suggestions while auto-merge is pending
Environment Details
- Feature: Code Suggestions + Auto-merge
- Affected Components: Merge Requests, Code Suggestions, Auto-merge
- Deployment Type: GitLab Self-Managed 18.5.2
Impact
This is a critical issue because:
- Code that was not reviewed gets merged into the codebase
- The audit trail shows approval for different code than what was actually merged
- Pipeline checks may not have run on the final merged code
- This violates the principle of reviewed code being what gets merged
Possible Root Cause
The auto-merge process likely doesn't account for concurrent changes to the source branch (like applying suggestions) and may not wait for the new commit's pipeline to complete before merging.
Related
- Code Suggestions feature
- Auto-merge functionality
- Merge request workflow
Edited by Filip Aleksic