ci: detect queue merges by replaying PR timeline queue membership#5483
Merged
Conversation
Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
Signed-off-by: Madhu Mohan Jaishankar <madhu.mohan.jaishankar@ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issue
Closes #390
📝 Summary
Fixes false-positive Slack notifications from the direct-merge-to-main detector introduced in #5479 / #5480.
The workflow's job is to alert
#contextforge-merge-notificationsonly when a PR is merged tomainwhile bypassing the merge queue. Earlier attempts tried to distinguish queue merges from bypass merges using single boolean-ish fields — none of which are reliable:merged_by.type—merged_byis the human who queued the PR, not the queue bot.auto_merged—nullfor queue merges (it only reflects the "Enable auto-merge" toggle).removed_from_merge_queuevsmerged— fragile; a genuine bypass merge could coincidentally share a timestamp with a queue-removal event.GitHub exposes no single field that says "this PR was merged by the queue." The only authoritative signal is the PR timeline. This PR replays the timeline chronologically, tracking merge-queue membership (
added_to_merge_queue→ in queue,removed_from_merge_queue→ out of queue) and captures that state at the moment themergedevent fires:For queue merges, GitHub emits
mergedbeforeremoved_from_merge_queuein the timeline, so the replay correctly sees the PR still in the queue. This ordering-based check is robust even when a bypass merge shares a timestamp with a queue-removal event. It also correctly handles the "queued → ejected → merged directly" case (a real bypass), which a naive "was it ever queued?" check would misclassify.📏 Reviewability
triage🏷️ Type of Change
🧪 Verification
Detection logic was validated empirically by replaying the timeline of real merged PRs via
gh apiand asserting the classification:merged_in_queuetruemain(bypass)falsemaindirect mergesfalseCommand used per PR:
Timeline event ordering (
added_to_merge_queue→merged→removed_from_merge_queue) was confirmed by inspecting the raw array indices of queue-merged PRs.Standard repo checks:
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes (optional)
merged_byis the human who queued the PR,auto_mergedreflects an unrelated toggle, and the merge committer isweb-flow(GitHub) for both queue and bypass merges — so none of these discriminate. The timeline replay is the only authoritative approach.workflow_dispatchshort-circuits the timeline lookup (no PR context) so the Slack integration can be verified end-to-end from any branch.notify-slack-merge-queue-ejection.yml(merged in Ci/slack merge queue fixes #5480) handles the ejection case; both post to the same channel viaSLACK_MERGE_NOTIFICATION_WEBHOOK_URL.Open the PR at: https://github.com/IBM/mcp-context-forge/compare/main...ci/slack-direct-merge-queue-detection?expand=1&template=bug_fix.mdOpen the PR at: https://github.com/IBM/mcp-context-forge/compare/main...ci/slack-direct-merge-queue-detection?expand=1&template=bug_fix.md