Skip to content

PSMDB-2141: automate the upstream-merge loop (periodic merge + merge gate + AI merge-pick)#1963

Open
plebioda wants to merge 6 commits into
masterfrom
PSMDB-2141-periodic-merge-standalone
Open

PSMDB-2141: automate the upstream-merge loop (periodic merge + merge gate + AI merge-pick)#1963
plebioda wants to merge 6 commits into
masterfrom
PSMDB-2141-periodic-merge-standalone

Conversation

@plebioda

Copy link
Copy Markdown

What

Makes the mergai upstream-merge loop self-driving instead of hand-triggered. Adds a
scheduled periodic-merge workflow that decides when to merge, and extends
trigger-merge to decide which commit to merge (deterministic gate or AI) - all
driven by opt-in repository variables that are inert by default.

Changes

  • New periodic-merge.yml - evaluates the merge gate token-free and dispatches
    mergai.yml when it's open and no merge is in progress.
  • trigger-merge pick 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_REF selects the mergai CLI ref for both workflows.
  • Merge gate + AI pick config in .mergai/config.yml and .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). Enable MERGAI_PERIODIC_MERGE_ENABLED
with MERGAI_MERGE_PICK_MODE=gate first, then switch to ai once validated.

Details

See .github/MERGAI.md for the full workflow description, the
repository variables, and the merge-pick-mode table.

mergai PR: Percona-Lab/mergai#27

plebioda added 2 commits June 24, 2026 10:03
…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yml to evaluate a token-free merge gate and dispatch mergai.yml when it’s time to merge.
  • Extended mergai.yml trigger-merge to pick commits based on MERGAI_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.

Comment thread .github/workflows/periodic-merge.yml Outdated
@plebioda plebioda force-pushed the PSMDB-2141-periodic-merge-standalone branch from 818ec3e to f2b5491 Compare June 24, 2026 12:14
@@ -0,0 +1,31 @@
# PSMDB merge-pick rules

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@plebioda plebioda force-pushed the PSMDB-2141-periodic-merge-standalone branch from f2b5491 to ca0b374 Compare June 24, 2026 13:33
plebioda added 4 commits June 24, 2026 20:53
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.
@plebioda plebioda force-pushed the PSMDB-2141-periodic-merge-standalone branch from ca0b374 to 69ae616 Compare June 24, 2026 18:56
@plebioda plebioda requested review from igorsol and ktrushin June 24, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants