PSMDB-2141: automate the upstream-merge loop (periodic merge + merge gate + AI merge-pick)#1963
Open
plebioda wants to merge 6 commits into
Open
PSMDB-2141: automate the upstream-merge loop (periodic merge + merge gate + AI merge-pick)#1963plebioda wants to merge 6 commits into
plebioda wants to merge 6 commits into
Conversation
…lready in progress Before merging, abort the trigger-merge job if any mergai branch (main/conflict/solution/semantic) already exists for the picked commit, meaning another run already started it. This prevents racing a merge that is already underway and covers the window the periodic-merge workflow cannot see (a run dispatched but still awaiting privileged-ops approval, with no PR open yet).
…ster) Source the MergAI tool ref from the MERGAI_REF repository variable (not a secret) in mergai.yml and update-fork-status.yml, falling back to master when unset. mergai.yml's workflow_dispatch 'mergai-ref' input now defaults to empty and resolves input -> MERGAI_REF -> master, so a manually supplied ref still wins. Lets the mergai version be pinned or rolled forward in one place without editing the workflows.
There was a problem hiding this comment.
Pull request overview
Automates the upstream-merge loop for PSMDB by adding a scheduled “periodic merge” driver workflow, extending mergai.yml to support gate/AI/next merge-pick modes, and making the mergai CLI ref configurable via repository variables (inert by default).
Changes:
- Added
periodic-merge.ymlto evaluate a token-free merge gate and dispatchmergai.ymlwhen it’s time to merge. - Extended
mergai.ymltrigger-mergeto pick commits based onMERGAI_MERGE_PICK_MODE(gate/ai/next) and to fail early if a merge for the selected SHA is already underway. - Added merge-gate + AI merge-pick configuration and documentation (
.mergai/config.yml, rules markdown, and.github/MERGAI.md).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.mergai/merge_pick_rules.md |
Adds project-specific heuristics to guide AI merge boundary selection. |
.mergai/config.yml |
Introduces merge-gate thresholds and AI pick configuration (agent, rules file, fallback). |
.github/workflows/update-fork-status.yml |
Allows selecting the mergai CLI ref via MERGAI_REF repo variable. |
.github/workflows/periodic-merge.yml |
New scheduler/follow-up workflow that checks “merge gate” and dispatches merges. |
.github/workflows/mergai.yml |
Implements mode-driven merge-pick (gate/ai/next) and adds in-progress guard by SHA. |
.github/MERGAI.md |
Documents the new periodic workflow, variables, and merge-pick behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
818ec3e to
f2b5491
Compare
plebioda
commented
Jun 24, 2026
| @@ -0,0 +1,31 @@ | |||
| # PSMDB merge-pick rules | |||
Author
There was a problem hiding this comment.
This is a proposal. I would like to encourage you to take a look at this and suggest any changes. I've made this based on the historical merges using the mergai.yml workflow.
These are the stats:
| Metric | Value |
|---|---|
| Total PRs analyzed | 44 |
Batch size (merged_up_to_pick) |
min 1, max 150, mean 48.9, median 47.5 |
| Candidate window | min 51, max 551, mean 292, median 272 |
| Pick in candidates | 44/44 (100%) |
| Pick matched a mergai suggestion | 44/44 (100%) |
| Pick == mergai TOP suggestion | 7/44 (16%) |
| Bucket | Count |
|---|---|
| 1–15 | 5 |
| 16–30 | 5 |
| 31–50 | 15 |
| 51–65 | 10 |
| >65 | 9 |
f2b5491 to
ca0b374
Compare
Add the merge_gate (min_commits, max_age_days, max_commits window, force_strategies) and ai_pick (agent, rules_file, fallback) sections to .mergai/config.yml, plus .mergai/merge_pick_rules.md with the PSMDB batch-size targets and boundary heuristics the AI pick follows.
Add periodic-merge.yml: on a daily cron, on manual dispatch, or when a mergai
main PR (mergai/*/main -> master) is merged, decide whether to merge and
dispatch the mergai bot trigger-merge job. It stops early if a merge is already
in progress (an open mergai PR), then runs the token-free merge gate
('mergai fork merge-pick --plan') and dispatches only if the gate is open.
Gated behind the MERGAI_PERIODIC_MERGE_ENABLED and MERGAI_FOLLOWUP_MERGE_ENABLED
repository variables (off by default); the mergai ref comes from MERGAI_REF.
Only the decision/trigger layer lives here - all merge behavior is reused
unchanged from trigger-merge.
Replace trigger-merge's fixed merge-pick step with a mode switch driven by the
MERGAI_MERGE_PICK_MODE repository variable:
* ai -> the agent picks the boundary within the gate's candidate window;
its reasoning is surfaced to the step log and the run job summary.
* gate -> gate-respecting deterministic pick (honors min_commits /
max_commits / force_strategies).
* next -> raw first-strategy pick (no gate, no window cap).
An explicit merge-pick input still forces a merge. 'ai' and 'gate' honor the
merge gate: an empty pick (gate closed / nothing to merge) skips the merge, so
context-init / early-fail / merge are gated on a non-empty pick.
…s in MERGAI.md Describe the new periodic-merge.yml workflow (schedule/dispatch/follow-up triggers, the token-free gate + privileged pick split) and the reworked trigger-merge pick behavior. Add a Repository Variables section covering MERGAI_REF, MERGAI_MERGE_PICK_MODE, MERGAI_PERIODIC_MERGE_ENABLED, and MERGAI_FOLLOWUP_MERGE_ENABLED, with a table explaining the merge-pick mode values (gate/ai/next), plus a Merge Gate section pointing at the .mergai/config.yml merge_gate / ai_pick settings.
ca0b374 to
69ae616
Compare
ktrushin
approved these changes
Jun 25, 2026
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.
What
Makes the mergai upstream-merge loop self-driving instead of hand-triggered. Adds a
scheduled
periodic-mergeworkflow that decides when to merge, and extendstrigger-mergeto decide which commit to merge (deterministic gate or AI) - alldriven by opt-in repository variables that are inert by default.
Changes
periodic-merge.yml- evaluates the merge gate token-free and dispatchesmergai.ymlwhen it's open and no merge is in progress.trigger-mergepick is mode-driven (MERGAI_MERGE_PICK_MODE:gate/ai/next),honors the gate, and early-fails if a merge for the picked commit already exists.
MERGAI_REFselects the mergai CLI ref for both workflows..mergai/config.ymland.mergai/merge_pick_rules.md.Rollout
Defaults are safe: scheduled/follow-up merges stay off until their toggles are set, and
the pick mode defaults to deterministic (
gate). EnableMERGAI_PERIODIC_MERGE_ENABLEDwith
MERGAI_MERGE_PICK_MODE=gatefirst, then switch toaionce validated.Details
See
.github/MERGAI.mdfor the full workflow description, therepository variables, and the merge-pick-mode table.
mergai PR: Percona-Lab/mergai#27