Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-merge-train-readiness-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Merge trains now order their members by readiness first: PRs the lane knows are merge-ready (080 admitted, soaking, merge queue) lead, members it has not evaluated follow, and members still in CI/Review trail β€” re-sorted every pass, so a PR going green moves up and one going red moves back. A PR still in CI/Review renders in its real column with a "train Β· joins behind #N when green" chip instead of a Merge-queue chip, and a train with no ready member says its front is provisional ([#15761](https://github.com/hivecommons/hive/issues/15761)).
1 change: 1 addition & 0 deletions changelog.d/fixed-odometer-rolls-after-bee-lands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The Activity Monitor's Merged odometer no longer rolls before the bee lands: a merge the merge-gate hold still masks as "Merging" is held back from the count like a flight to come, so the number waits through the hold and the flight and rolls once when the glyph reaches the chip. Successive merges queue their rolls and the display ends on the server's value; a reload still shows the server's number at once ([#15762](https://github.com/hivecommons/hive/issues/15762)).
32 changes: 32 additions & 0 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,38 @@ gate, saying it will wait for a human. The rule exists because a ⚠️-titled
PR was auto-merged by the trusted-author lane while its owner was still
deciding whether to ship it.

### Merge train: ready PRs lead

Every lane groups its candidates on one base whose changed files overlap
into a **merge train** (`auto_merge.merge_train.*`, [#15117](https://github.com/hivecommons/hive/issues/15117))
and merges one front at a time; the siblings park at stage/080 with lane
reason `merge-train:queued-behind#<front>:<pos>/<size>:…` and, the moment
the front merges, are update-branched (`behind`) or handed to the rebase
resolver (`dirty`) so the next front is evaluated on a current base. Hive's
own repo also runs the current-base gate (`require_current_base`), which
holds a behind head until the update lands; the two cooperate β€” the train
refreshes, the gate waits for the refresh.

The train's order is **readiness first**. Each pass the lane sorts the
members by what it last saw of their heads: a head at the merge gate β€”
green, approved, soaking or waiting on a sweep β€” leads; a head the lane has
not evaluated since it was pushed comes next (so it is evaluated and
sorted); a head still at CI / Review trails; a blocked head (red required
check, terminal hold) trails everything and never fronts. Within a tier the
old tiebreak holds (clean-mergeable first, then oldest, then number). The
order is recomputed every pass, so a member that turns green moves up and
one that turns red moves back. The front of a train is therefore always a
ready member when the train has one; a train whose every member is still
short of the gate has a *provisional* front, and the Activity Monitor says
so rather than reading "1st in the merge queue".

This replaced the age-first order after hive's own #15741, still at CI /
Review, led #15748 and #15755 β€” both green and queued at 080 β€” and nothing
merged until its checks finished. In the Activity Monitor only members at
080 and beyond ride a train chip in the *Merge queue* column; a member still
at CI / Review keeps its chevron in its own column with a muted
"train Β· joins behind #N when green" note.

### Trusted-author auto-merge

`auto_merge.trusted_authors` is a third, default-off sweep tier for
Expand Down
2 changes: 1 addition & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ advanced into the merge path.
| `auto_merge.require_current_base_default` | `false` | Hive-wide default of the current-base gate for repos in neither `require_current_base` nor `skip_current_base` (Settings β†’ Features β†’ Auto-merge β†’ "Merge only on current base"). **Off** by default: the merge train already update-branches overlapping siblings, so the gate is being soaked per repo (hive's own hive first, via `require_current_base`) before any hive turns it on everywhere. When `true`, a behind head the App cannot update merges as it was tested, with one WARN per PR (`automerge current-base gate: … merging as tested`), so fork-heavy repos are not parked wholesale. |
| `auto_merge.skip_current_base` | unset | Repo list (`owner/repo`) with an explicit **off** override for the current-base gate (Settings β†’ Repos β†’ "Merge only on current base" unchecked): a green head there merges even if the base has moved, whatever `require_current_base_default` says. An explicit `require_current_base` entry wins over this list. |
| `auto_merge.merge_forward_trusted_human` | unset (off) | Repo list (`owner/repo`) where a `role/trusted` + `author/human` PR on a same-repo branch that GitHub reports as conflicting (`dirty`) gets the base merged into its head as one App-authored, signed-off merge commit via the GitHub merges API (no human commit is rewritten), then merges once CI is green on the new head. A real conflict pushes nothing and posts one `<!-- hive:merge-forward-conflict head=… -->` note naming the files both sides changed. Fork heads are never written. Attempted once per head (#13636). |
| `auto_merge.merge_train.enabled` | `true` | Conflict-aware merge train in every automerge lane (hive, trusted-author, contributor) ([#15117](https://github.com/hivecommons/hive/issues/15117)). Each sweep groups the open approved / mergeable-pending PRs of one repo+base by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and lets ONE front per group merge β€” the clean-mergeable PR approved earliest β€” while the others wait at stage/080 with lane reason `merge-train:queued-behind#<front>:<pos>/<size>:…` (tracker pill "In merge queue Β· 3 of 4 Β· ~4m", never a human stage, never `needs-rebase` as a human flag). The moment the front merges, every sibling whose branch is merely `behind` gets `PUT /pulls/{n}/update-branch`; a `dirty` one is handed to the fixer's rebase-resolve episode (`requested_by: merge-train`, the shared two-attempt guard of [#15104](https://github.com/hivecommons/hive/pull/15104); the fixer router still requires a head the hive can push to, so a fork without maintainer edits stays on the plain `conflicting` path for a person). A head the lane last saw blocked on its own (red required check, terminal hold, permanent merge refusal) never fronts, and a group whose best member is blocked imposes no ordering (fail-open) β€” nobody waits behind a PR that is not moving. One INFO line `merge train` per order change, not per cycle. The queue carries one PR per issue: when two open PRs declare the same `Fixes #N`, the sweep keeps one (green first, then the earlier-opened) and holds the other with lane reason `merge-train:duplicate-of#<winner>:<issue>/0:0/0:` (tracker pill "Duplicate of #15402 Β· needs a pick"; *Let hive decide* supersedes, [#15395](https://github.com/hivecommons/hive/issues/15395)). `false` restores independent per-PR evaluation. A PR GitHub reports conflicting on its own, or one at stage/072 returned-to-contributor (label or stage record), is never a member nor counted in the train's size and draws no train idle comment; a conflicting PR rides only while the train itself is repairing it (its rebase requested behind a merged front, loop guard not spent) ([#15395](https://github.com/hivecommons/hive/issues/15395)). |
| `auto_merge.merge_train.enabled` | `true` | Conflict-aware merge train in every automerge lane (hive, trusted-author, contributor) ([#15117](https://github.com/hivecommons/hive/issues/15117)). Each sweep groups the open approved / mergeable-pending PRs of one repo+base by overlapping changed files (`GET /pulls/{n}/files`, cached per head SHA) and lets ONE front per group merge β€” ordered readiness first: a head the lane last saw at the merge gate (green, approved, soaking or waiting on a sweep) leads, one it has not evaluated since its push comes next, one still at CI / Review trails, then clean-mergeable before behind, then oldest; recomputed every pass, so a member that turns green moves up and one that turns red moves back β€” while the others wait at stage/080 with lane reason `merge-train:queued-behind#<front>:<pos>/<size>:…` (tracker pill "In merge queue Β· 3 of 4 Β· ~4m", never a human stage, never `needs-rebase` as a human flag). The moment the front merges, every sibling whose branch is merely `behind` gets `PUT /pulls/{n}/update-branch`; a `dirty` one is handed to the fixer's rebase-resolve episode (`requested_by: merge-train`, the shared two-attempt guard of [#15104](https://github.com/hivecommons/hive/pull/15104); the fixer router still requires a head the hive can push to, so a fork without maintainer edits stays on the plain `conflicting` path for a person). A head the lane last saw blocked on its own (red required check, terminal hold, permanent merge refusal) never fronts, and a group whose best member is blocked imposes no ordering (fail-open) β€” nobody waits behind a PR that is not moving. One INFO line `merge train` per order change, not per cycle. The queue carries one PR per issue: when two open PRs declare the same `Fixes #N`, the sweep keeps one (green first, then the earlier-opened) and holds the other with lane reason `merge-train:duplicate-of#<winner>:<issue>/0:0/0:` (tracker pill "Duplicate of #15402 Β· needs a pick"; *Let hive decide* supersedes, [#15395](https://github.com/hivecommons/hive/issues/15395)). `false` restores independent per-PR evaluation. A PR GitHub reports conflicting on its own, or one at stage/072 returned-to-contributor (label or stage record), is never a member nor counted in the train's size and draws no train idle comment; a conflicting PR rides only while the train itself is repairing it (its rebase requested behind a merged front, loop guard not spent) ([#15395](https://github.com/hivecommons/hive/issues/15395)). |
| `auto_merge.merge_train.max_rebase_attempts` | `2` | Loop guard: how many rebase-resolve requests the train makes for one PR behind one front. Past it the PR moves to stage/085 with the pill "Needs human decision Β· rebase failed twice" and the decision option "Rebase, then merge as maintainer". |
| `auto_merge.native_merge_queue.enabled` | `false` | Opt-in: once the lane's gates pass, enqueue the PR into GitHub's native merge queue (App auth only) instead of merging directly, and withdraw only Hive's own entries when the PR loses eligibility ([#15198](https://github.com/hivecommons/hive/issues/15198)). Off keeps the pre-queue behaviour everywhere, including the `merge-queue-required` park. See [native-merge-queue.md](native-merge-queue.md). |
| `auto_merge.native_merge_queue.repos` | unset (every watched repo once enabled) | `owner/repo` allow-list for the hand-off, matched case-insensitively. |
Expand Down
113 changes: 112 additions & 1 deletion src/pkg/dashboard/stage_tracker_cues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ let renders = 0; function renderStageTracker() { renders++; }
const srcs = new Map(); function stageTrackerRowSrcOf(node) { return srcs.get(node); }
let _stageTrackerEvents = {};
const STAGE_TRACKER_TERMINAL = 110;
var _stageTrackerPRHost = {}; var _stageTrackerPRTitle = {}; var _stageTrackerMergeState = null, _stageTrackerZapped = {}, _stageTrackerMerged = { server: null, local: {} }, _stageTrackerMergedShown = 0, _stageTrackerCelebrating = {}, _stageTrackerCelebratePending = {}, _stageTrackerFlights = 0, _stageTrackerReleaseTimer = 0;
var _stageTrackerPRHost = {}; var _stageTrackerPRTitle = {}; var _stageTrackerMergeState = null, _stageTrackerZapped = {}, _stageTrackerMerged = { server: null, local: {} }, _stageTrackerMergedShown = 0, _stageTrackerCelebrating = {}, _stageTrackerCelebratePending = {}, _stageTrackerMergedHeld = {}, _stageTrackerFlights = 0, _stageTrackerReleaseTimer = 0;
let settingsClosed = 0; function closeStageTrackerSettings() { settingsClosed++; }
const odoText = e => e.getAttribute('data-odo-value');
const flights = () => body.children.filter(c => c.classList.contains('cue-flight'));
Expand Down Expand Up @@ -855,6 +855,117 @@ console.log('ok');
`)
}

// TestStageTrackerOdometerWaitsForMergingHoldNode (owner: "the odometer
// still updates before the bee animation lands on it"): the merge gate's
// hold (#15245) masks a landed merge as still open for the banner's
// lifetime, and the poll that brought it also brings the server's raised
// ledger total. The drum used to roll on that poll β€” the hold kept the
// bee grounded while nothing kept the number β€” so the landing, a full
// hold later, found nothing left to roll. The chip now holds the masked
// merges back like flights to come: the number waits through the hold,
// through the flight, and rolls once on the landing. Runs the real hold
// functions (the other celebration tests stub them off).
func TestStageTrackerOdometerWaitsForMergingHoldNode(t *testing.T) {
html := indexHTML(t)
for _, want := range []string{
"_stageTrackerMergedHeld = {};",
"masked.held.forEach(k => { _stageTrackerMergedHeld[k] = true; });",
"stageTrackerMergedHoldback(_stageTrackerMerged, _stageTrackerCelebratePending, _stageTrackerMergedHeld)",
} {
if !strings.Contains(html, want) {
t.Errorf("index.html missing %q", want)
}
}
holdOn := strings.Join([]string{
jsConstLine(t, html, "STAGE_TRACKER_MERGING_HOLD_MS"),
jsConstLine(t, html, "STAGE_TRACKER_MERGE_QUEUE"),
"var _stageTrackerMergingHold = {}; var _stageTrackerPRItems = {}; var _stageTrackerMergingHoldTimer = 0; var _stageTracker = null;",
jsFunc(t, html, "stageTrackerPRItemsOf"),
jsFunc(t, html, "stageTrackerMergingHoldLive"),
jsFunc(t, html, "stageTrackerMergingHoldNext"),
jsFunc(t, html, "stageTrackerMergingHoldMask"),
jsFunc(t, html, "stageTrackerMergingHoldSchedule"),
jsFunc(t, html, "stageTrackerMergingHoldRelease"),
}, "\n")
js := strings.Replace(stageTrackerCelebrateJS(t, html), stageTrackerMergingHoldOffJS, holdOn, 1)
if js == stageTrackerCelebrateJS(t, html) {
t.Fatal("the hold stub was not swapped for the real functions")
}
runStageTrackerRowActionsScript(t, js+stageTrackerCelebrateFixture+`
const rolling = e => e.children[0].children.filter(c => c.classList.contains('ham-odo-roll'));
const iso = ms => new Date(ms).toISOString();
const rec = (...nums) => nums.map(x => ({ repo: 'o/r', number: x, title: 'fix ' + x, merged_at: iso(clock), merged_by: 'hive', lane: 'hive' }));
const srv = (all, today, recent) => ({ all_time: all, today, total_7d: today, total_30d: today, recent, tz: 'UTC', day_start: iso(stageTrackerLocalMidnight(clock)) });
const pr = (num, stage, mg) => Object.assign({ repo: 'o/r', kind: 'pr', number: num, stage, title: 'fix ' + num }, mg ? { merge_gate: mg } : {});
// The poll handler: remember the payload (the hold's release re-reads it) and note it.
const poll = d => { _stageTracker = d; stageTrackerNoteMerges(d); };
panel.appendChild(row('o/r/pr#1'));
poll({ items: [pr(1, 90)], merged: srv(40, 2, rec(31, 30)) });
assert.strictEqual(odoText(n), '40', 'hydrated'); assert.strictEqual(odoText(sub), '2 today Β· 2 this week');
// The sweep is merging #1: the gate says so.
tick(5000);
const T = clock;
poll({ items: [pr(1, 95, { state: 'merging', merging_since: iso(T) })], merged: srv(40, 2, rec(31, 30)) });
assert.strictEqual(odoText(n), '40');
// Next poll: #1 landed β€” the items dropped it, the ledger counts it (41),
// recently_merged settles it. The hold masks the merge for the banner's
// lifetime, so no bee launches yet; the number must wait with it.
tick(5000);
poll({ items: [], recently_merged: [{ repo: 'o/r', number: 1, merged_at: iso(clock) }], merged: srv(41, 3, rec(1, 31, 30)) });
tick(0);
assert.strictEqual(flights().length, 0, 'the hold keeps the bee grounded');
assert.strictEqual(odoText(n), '40', 'the total waits for the bee (it used to roll here, a full hold early)'); assert.strictEqual(rolling(n).length, 0);
assert.strictEqual(odoText(sub), '2 today Β· 2 this week', 'so does the day line');
assert.ok(!chip.classList.contains('cue-tick'), 'no pop');
assert.deepStrictEqual(zaps, []);
// A further poll inside the hold with the same numbers: still waiting.
tick(10000);
poll({ items: [], recently_merged: [{ repo: 'o/r', number: 1, merged_at: iso(T) }], merged: srv(41, 3, rec(1, 31, 30)) });
assert.strictEqual(odoText(n), '40', 'a repeat poll does not leak the number either');
// The hold ends: the merge is re-read as fresh, the bee launches, the number still waits.
tick(T + STAGE_TRACKER_MERGING_HOLD_MS - clock + 60);
tick(0);
assert.strictEqual(flights().length, 1, 'the bee launches when the hold ends');
assert.strictEqual(odoText(n), '40', 'held under the flight'); assert.strictEqual(rolling(n).length, 0);
// The bee lands: one roll, to the server's number.
flights()[0]._ev.animationend();
assert.strictEqual(flights().length, 0);
assert.strictEqual(odoText(n), '41', 'the landing rolls it'); assert.strictEqual(rolling(n).length, 1, 'rolled, not set');
assert.strictEqual(odoText(sub), '3 today Β· 3 this week');
assert.ok(chip.classList.contains('cue-tick'), 'pop with the roll'); assert.deepStrictEqual(zaps, [1], 'zap with the roll');
assert.ok(chip.title.startsWith('Merged: 41 all time'), chip.title);
tick(STAGE_TRACKER_ODOMETER_MS + 100);
// Steady afterwards: the same ledger does not move it again.
poll({ items: [], merged: srv(41, 3, rec(1, 31, 30)) });
assert.strictEqual(odoText(n), '41'); assert.strictEqual(rolling(n).length, 0);
// Two merges in quick succession, each through its own hold: nothing is lost β€” the display ends on the server's value.
zaps.length = 0; chip.classList.remove('cue-tick');
panel.appendChild(row('o/r/pr#2')); panel.appendChild(row('o/r/pr#3'));
poll({ items: [pr(2, 90), pr(3, 90)], merged: srv(41, 3, rec(1, 31, 30)) });
tick(1000); const T2 = clock;
poll({ items: [pr(2, 95, { state: 'merging', merging_since: iso(T2) }), pr(3, 90)], merged: srv(41, 3, rec(1, 31, 30)) });
tick(3000); const T3 = clock;
poll({ items: [pr(3, 95, { state: 'merging', merging_since: iso(T3) })], recently_merged: [{ repo: 'o/r', number: 2 }], merged: srv(42, 4, rec(2, 1, 31, 30)) });
assert.strictEqual(odoText(n), '41', '#2 held');
tick(3000);
poll({ items: [], recently_merged: [{ repo: 'o/r', number: 2 }, { repo: 'o/r', number: 3 }], merged: srv(43, 5, rec(3, 2, 1, 31, 30)) });
assert.strictEqual(odoText(n), '41', '#2 and #3 held');
// #2's hold ends first: its bee flies and lands; the number still waits for #3, whose hold is live.
tick(T2 + STAGE_TRACKER_MERGING_HOLD_MS - clock + 60); tick(0);
assert.strictEqual(flights().length, 1, '#2 flies');
flights()[0]._ev.animationend();
assert.strictEqual(odoText(n), '41', 'still held: #3 is masked (its bee is to come), and a landing never leaves a merge uncounted');
// #3's hold ends: its bee flies and lands; the display reaches the server's value.
tick(T3 + STAGE_TRACKER_MERGING_HOLD_MS - clock + 60); tick(0);
assert.strictEqual(flights().length, 1, '#3 flies');
assert.strictEqual(odoText(n), '41', 'held under its flight');
flights()[0]._ev.animationend();
assert.strictEqual(odoText(n), '43', 'final displayed value == server value');
assert.strictEqual(odoText(sub), '5 today Β· 5 this week');
console.log('ok');
`)
}

// TestStageTrackerFlightTargetNode: the operator's spec for the flight β€”
// from the βœ“ cell to the Merged chip when the chip is inside the viewport,
// otherwise up and out through the top edge; the glyph is configurable;
Expand Down
Loading
Loading