Skip to content
Closed
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-15073-merge-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Activity Monitor distinguishes awaiting the merge gate, ready, soaking and merging, labels merge-sweep and agent glyphs separately, and shows sweep timing and nested PR soak countdowns ([#15073](https://github.com/hivecommons/hive/issues/15073)).
5 changes: 5 additions & 0 deletions src/cmd/hive/automerge_sweep_wiring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func TestRunAutoMergeSweepIfDue_DueSweepStampsLastRunAndCallsAPI(t *testing.T) {
if lastRun.Before(start) {
t.Fatalf("due sweep must stamp lastRun, got %v", lastRun)
}
clock := ghClient.MergeSweepClock().Snapshot("testorg/widget", 1)
if clock.LastSweepAt == nil || clock.LastSweepAt.Before(start) || clock.NextSweepAt == nil || !clock.NextSweepAt.Equal(lastRun.Add(autoMergeSweepInterval)) {
t.Fatalf("sweep clock did not publish actual pass timing: %+v", clock)
}

}

func TestRunAutoMergeSweepIfDue_NilLastRunStillSweeps(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9314,6 +9314,8 @@ func runAutoMergeSweepIfDue(ctx context.Context, ghClient *github.Client, cfg *c
if lastRun != nil {
*lastRun = now
}
ghClient.MergeSweepClock().Schedule("queued", now.Add(autoMergeSweepInterval))
defer ghClient.MergeSweepClock().Begin("queued")()
ctx = github.WithPacingClass(ctx, github.PacingLow)
// governor.automerge covers the queued, trusted-author and contributor-
// lane sweeps plus the stage-label pass that follows them. The sweep runs
Expand Down
5 changes: 4 additions & 1 deletion src/docs/dashboard-sections.md

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ type StageTrackerItem struct {
// soak window was left as of the last sweep (the lane's
// `soaking(remaining=…)` reason aged by the time since it was recorded);
// 0 when unknown or not soaking.
SoakRemainingSeconds int64 `json:"soak_remaining_seconds,omitempty"`
SoakRemainingSeconds int64 `json:"soak_remaining_seconds,omitempty"`
MergeGate *StageTrackerMergeGate `json:"merge_gate,omitempty"`
// SentinelAlert is true on a PR the suspicious-activity sentinel flagged:
// it wears the configured alert label (sentinel.label, default
// sentinel-alert) or the review evidence bundle for its current head
Expand Down Expand Up @@ -458,16 +459,19 @@ type StageTrackerLinkedIssue struct {

// StageTrackerLinkedPR is one covering PR nested under an issue row.
type StageTrackerLinkedPR struct {
BaseRef string `json:"base_ref,omitempty"`
Number int `json:"number"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
Author string `json:"author,omitempty"`
AuthorKind string `json:"author_kind,omitempty"`
Stage int `json:"stage,omitempty"`
StageSince *time.Time `json:"stage_since,omitempty"`
Caption string `json:"caption,omitempty"`
Modifiers []string `json:"modifiers,omitempty"`
MergeGate *StageTrackerMergeGate `json:"merge_gate,omitempty"`
SoakRemainingSeconds int64 `json:"soak_remaining_seconds,omitempty"`
Reason string `json:"reason,omitempty"`
BaseRef string `json:"base_ref,omitempty"`
Number int `json:"number"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
Author string `json:"author,omitempty"`
AuthorKind string `json:"author_kind,omitempty"`
Stage int `json:"stage,omitempty"`
StageSince *time.Time `json:"stage_since,omitempty"`
Caption string `json:"caption,omitempty"`
Modifiers []string `json:"modifiers,omitempty"`
// DeferredModifiers mirrors the nested PR's own row field: the
// merge-gate pills it is not yet drawing.
DeferredModifiers []string `json:"deferred_modifiers,omitempty"`
Expand Down Expand Up @@ -1777,6 +1781,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
resp.OpenIssues, resp.OpenPRs = stageTrackerOpenCounts(resp.Items)
s.applyOperatorActions(resp.Items, now)
resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items)
s.applyMergeGates(resp.Items, now)
stageTrackerResolveLinkedPRs(resp.Items)
sort.SliceStable(resp.Items, stageTrackerLess(resp.Items))
return resp
Expand Down Expand Up @@ -2500,6 +2505,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) {
if pr := prs[it.Repo+"#"+strconv.Itoa(lp.Number)]; pr != nil {
lp.Title, lp.Author, lp.AuthorKind, lp.Stage = pr.Title, pr.Author, pr.AuthorKind, pr.Stage
lp.StageSince, lp.Caption = pr.StageSince, pr.Caption
lp.MergeGate, lp.SoakRemainingSeconds, lp.Reason = pr.MergeGate, pr.SoakRemainingSeconds, pr.Reason
lp.SentinelAlert, lp.SentinelReason, lp.Head = pr.SentinelAlert, pr.SentinelReason, pr.Head
lp.Adoption = pr.Adoption
lp.HumanApprover, lp.ManualMerge = pr.HumanApprover, pr.ManualMerge
Expand Down
53 changes: 53 additions & 0 deletions src/pkg/dashboard/stage_tracker_merge_gate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dashboard

import (
"time"

"github.com/hivecommons/hive/pkg/github"
)

// StageTrackerMergeGate distinguishes admission, soak and merge execution.
// Clock fields are null until a lane has actually scheduled/completed a pass.
type StageTrackerMergeGate struct {
State string `json:"state"`
Reason string `json:"reason"`
github.MergeSweepTimes
SoakUntil *time.Time `json:"soak_until"`
SoakRemainingSeconds int64 `json:"soak_remaining_seconds"`
}

func stageTrackerMergeGate(it StageTrackerItem, clock github.MergeSweepTimes, now time.Time) *StageTrackerMergeGate {
state := "gate-pending"
switch it.Stage {
case 60:
state = "gate-pending"
case 80:
state = "ready"
case 95:
state = "soaking"
case 100:
state = "merging"
case 110:
state = "merged"
}
gate := &StageTrackerMergeGate{State: state, Reason: it.Reason, MergeSweepTimes: clock, SoakRemainingSeconds: it.SoakRemainingSeconds}
if it.Stage == 95 && it.SoakRemainingSeconds > 0 {
until := now.Add(time.Duration(it.SoakRemainingSeconds) * time.Second)
gate.SoakUntil = &until
}
return gate
}

func (s *Server) applyMergeGates(items []StageTrackerItem, now time.Time) {
for i := range items {
it := &items[i]
if it.Kind != "pr" {
continue
}
clock := github.MergeSweepTimes{}
if s.deps != nil && s.deps.GHClient != nil {
clock = s.deps.GHClient.MergeSweepClock().Snapshot(it.Repo, it.Number)
}
it.MergeGate = stageTrackerMergeGate(*it, clock, now)
}
}
44 changes: 44 additions & 0 deletions src/pkg/dashboard/stage_tracker_merge_gate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dashboard

import (
"encoding/json"
"testing"
"time"

"github.com/hivecommons/hive/pkg/github"
)

func TestStageTrackerMergeGateStatesAndNestedSoak(t *testing.T) {
now := time.Date(2026, 10, 28, 19, 0, 0, 0, time.UTC)
for stage, state := range map[int]string{50: "gate-pending", 60: "gate-pending", 80: "ready", 95: "soaking", 100: "merging", 110: "merged"} {
got := stageTrackerMergeGate(StageTrackerItem{Stage: stage, Reason: "check-pending", SoakRemainingSeconds: 420}, github.MergeSweepTimes{}, now)
if got == nil || got.State != state || got.Reason != "check-pending" {
t.Fatalf("stage %d: %+v", stage, got)
}
if stage == 95 && (got.SoakUntil == nil || !got.SoakUntil.Equal(now.Add(7*time.Minute))) {
t.Fatalf("soak deadline: %+v", got)
}
}
pr := StageTrackerItem{Repo: "org/repo", Kind: "pr", Number: 2, Stage: 95, SoakRemainingSeconds: 420, Reason: "soaking(remaining=7m)"}
pr.MergeGate = stageTrackerMergeGate(pr, github.MergeSweepTimes{SweepRunning: true, NextSweepAt: &now}, now)
items := []StageTrackerItem{{Repo: "org/repo", Kind: "issue", Number: 1, LinkedPR: 2}, pr}
stageTrackerResolveLinkedPRs(items)
nested := items[0].LinkedPRs[0]
if nested.MergeGate != pr.MergeGate || nested.SoakRemainingSeconds != 420 || nested.Reason != pr.Reason {
t.Fatalf("nested PR lost gate context: %+v", nested)
}
data, err := json.Marshal(nested)
if err != nil {
t.Fatal(err)
}
var wire map[string]any
if err := json.Unmarshal(data, &wire); err != nil {
t.Fatal(err)
}
gate := wire["merge_gate"].(map[string]any)
for _, key := range []string{"state", "reason", "sweep_running", "last_sweep_at", "next_sweep_at", "soak_until", "soak_remaining_seconds"} {
if _, ok := gate[key]; !ok {
t.Fatalf("missing wire field %s: %s", key, data)
}
}
}
Loading
Loading