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-15758-soak-caption-no-restamp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The stage tracker's "Hive:" note for a soaking PR no longer re-stamps itself every eval pass. The contributor lane records the soak head, start and window once on the stage record and reports the stable reason `contributor-lane:soaking`; the dashboard computes the time left from that deadline at request time (showing `soak complete β€” merges on the next pass` at the deadline instead of `0s left`), sends an explicit `note_changed_at`, and the SPA refreshes the countdown in place rather than opening a new line. `LastSeen` no longer counts as a record change and is persisted at most once per 10 minutes. Records written with the old `contributor-lane:soaking(remaining=…)` reason stay readable (#15758).
8 changes: 5 additions & 3 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ sentinel alert, parked-on-decision), human-merge paths and head-SHA pinning β€”
before `hive-merge` merges it. A refusal is terminal for that request (`.denied`),
names the failing gate in the result the agent sees (for example
`contributor-lane:claim-tier-untrusted (author tier "untrusted", require_tiers
merger, trusted)` or `contributor-lane:soaking(remaining=27m)`), and is audited
merger, trusted)` or `contributor-lane:soaking, 27m0s remaining`), and is audited
as `merge_request_refused`. An agent cannot use the relay to land a contributor
PR the lane would not merge; the lane still merges it on its own tick once the
gates clear. Hive-authored PRs keep the relay's existing checks.
Expand Down Expand Up @@ -561,8 +561,10 @@ A PR merges through this tier only when all of the following hold:
went green β€” the latest `completed_at` over its check runs, read once per
(repo, PR, head) and then pinned in process β€” so a pod restart or upgrade
does not restart it; a new push restarts
the soak and the skip reason reports the time left
(`contributor-lane:soaking(remaining=25m0s)`).
the soak. The skip reason is the stable `contributor-lane:soaking`; the
soak head, start and window are recorded once on the stage record, so the
stage tracker computes "N left" from that deadline at request time instead
of the hive re-stamping its note every pass.

Merges squash through the same effect-claimed `MergePR` path as the other tiers,
log `automerge merged tier=contributor-lane admitted_by=<path>`, record the
Expand Down
18 changes: 14 additions & 4 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ type StageTrackerItem struct {
Reason string `json:"reason,omitempty"`
Caption string `json:"caption"`
Actor string `json:"actor,omitempty"`
// NoteChangedAt is when the caption last changed meaning: the stage
// entry, a new reason class, or a soak that ran out. A caption whose
// text moves while this stands still (a soak countdown) is the same
// note; the SPA refreshes the words in place and ages the note from
// here, not from the sweep that re-read it (hivecommons/hive#15729).
NoteChangedAt *time.Time `json:"note_changed_at,omitempty"`
// Modifiers are the health and control markers in effect and drawn as
// pills: stalled, regressed, hold, needs-human, needs-decision
// (stage/045 on an issue or stage/085 on a PR carried as a park
Expand Down Expand Up @@ -342,9 +348,10 @@ type StageTrackerItem struct {
RegressedAt *time.Time `json:"regressed_at,omitempty"`
RegressedReason string `json:"regressed_reason,omitempty"`
// SoakRemainingSeconds is, at 095 pre-merge-soak, how much of the lane's
// 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.
// soak window is left now (the record's soak deadline; a record written
// before the deadline existed falls back to its `soaking(remaining=…)`
// reason aged by the time since it was recorded); 0 when unknown or
// not soaking.
SoakRemainingSeconds int64 `json:"soak_remaining_seconds,omitempty"`
// MergeGate narrates a PR's position at the merge gate (060 / 080 /
// 095 / 100): state, what holds it, whether hive's merge sweep is on
Expand Down Expand Up @@ -620,7 +627,10 @@ type StageTrackerLinkedPR struct {
Stage int `json:"stage,omitempty"`
StageSince *time.Time `json:"stage_since,omitempty"`
Caption string `json:"caption,omitempty"`
Modifiers []string `json:"modifiers,omitempty"`
// NoteChangedAt mirrors the PR row's: when the caption last changed
// meaning.
NoteChangedAt *time.Time `json:"note_changed_at,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
5 changes: 5 additions & 0 deletions src/pkg/dashboard/stage_tracker_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto
if c := stageTrackerSoakCaption(rec, now); c != "" {
it.Caption = c
}
if hasRec && rec.Stage != stagelabels.None {
if at := stageTrackerNoteChangedAt(rec, now); !at.IsZero() {
it.NoteChangedAt = &at
}
}
if hasAttempt && (attempt.InFlight() || attempt.Merged) {
it.Caption, it.Actor = stageTrackerMergingCaption(attempt), StageActorHive
}
Expand Down
72 changes: 53 additions & 19 deletions src/pkg/dashboard/stage_tracker_caption.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,14 @@ func stageTrackerUntrustedAuthorFix(base, author string) string {
return ""
}

// trackerSoakRemainingRE pulls the time left out of the lane's
// `contributor-lane:soaking(remaining=12m0s)` reason.
// trackerSoakRemainingRE pulls the time left out of the
// `contributor-lane:soaking(remaining=12m0s)` reason the lane wrote before
// the soak deadline lived on the record (hivecommons/hive#15729). Records
// of that shape may still be on disk; nothing writes it any more.
var trackerSoakRemainingRE = regexp.MustCompile(`remaining=([0-9hms.]+)`)

// soakRemainingFromReason parses the soak time left from a soaking reason.
// soakRemainingFromReason parses the soak time left from a soaking reason
// of the pre-deadline shape; false for the bare `contributor-lane:soaking`.
func soakRemainingFromReason(reason string) (time.Duration, bool) {
m := trackerSoakRemainingRE.FindStringSubmatch(reason)
if m == nil {
Expand All @@ -591,41 +594,72 @@ func soakRemainingFromReason(reason string) (time.Duration, bool) {
}

// stageTrackerSoakCaption is the 095 sentence for a record carrying the
// lane's soak clock: "soaking β€” 12m left" while the window runs, aged from
// the lane's last read so a soak that has run out never says "0s left";
// past it, "soak complete β€” merges on the next pass". "" when the record
// is not at 095 or carries no clock (the generic caption stands).
// lane's soak clock: "soaking β€” 12m left" while the window runs, computed
// at request time from the record's deadline so a soak that has run out
// never says "0s left"; past it, "soak complete β€” merges on the next
// pass". "" when the record is not at 095 or carries no clock (the
// generic caption stands). The words move each minute, but the note's
// age (NoteChangedAt) does not: the SPA refreshes them in place.
func stageTrackerSoakCaption(rec stagelabels.Record, now time.Time) string {
const admitted = "Admitted by the automerge lane; "
if rec.Stage != stagelabels.PreMergeSoak {
return ""
}
if _, ok := soakRemainingFromReason(rec.Reason); !ok {
until, ok := stageTrackerSoakUntil(rec)
if !ok {
return ""
}
if left := stageTrackerSoakRemaining(rec, now); left > 0 {
if left := until.Sub(now); left > 0 {
return admitted + "soaking β€” " + shortDuration(left) + " left"
}
return admitted + "soak complete β€” merges on the next pass"
}

// stageTrackerSoakRemaining is the soak time left now for a record at 095:
// the lane's recorded remaining, aged by the time since the sweep wrote it.
func stageTrackerSoakRemaining(rec stagelabels.Record, now time.Time) time.Duration {
// stageTrackerSoakUntil is the soak deadline a 095 record carries: the
// recorded soak's start plus its window (NoteSoak), else β€” for a record
// written before the deadline existed β€” the lane's `soaking(remaining=…)`
// reason aged from the sweep that wrote it. ok is false when the record
// is not at 095 or carries no clock.
func stageTrackerSoakUntil(rec stagelabels.Record) (time.Time, bool) {
if rec.Stage != stagelabels.PreMergeSoak {
return 0
return time.Time{}, false
}
if _, startedAt, window, ok := rec.Soak(); ok {
return startedAt.Add(window), true
}
left, ok := soakRemainingFromReason(rec.Reason)
if !ok || rec.LastSeen.IsZero() {
return time.Time{}, false
}
return rec.LastSeen.Add(left), true
}

// stageTrackerSoakRemaining is the soak time left now for a record at 095,
// 0 once the deadline has passed or when the record carries no clock.
func stageTrackerSoakRemaining(rec stagelabels.Record, now time.Time) time.Duration {
until, ok := stageTrackerSoakUntil(rec)
if !ok {
return 0
}
if !rec.LastSeen.IsZero() {
left -= now.Sub(rec.LastSeen)
}
if left < 0 {
return 0
if left := until.Sub(now); left > 0 {
return left
}
return left
return 0
}

// stageTrackerNoteChangedAt is when the row's hive note last changed
// meaning: the record's reason-class change (or stage entry), or β€” for a
// 095 row whose soak has run out β€” the deadline, since "soak complete"
// is a different note from "soaking". Never later than now.
func stageTrackerNoteChangedAt(rec stagelabels.Record, now time.Time) time.Time {
at := rec.NoteChangedAt()
if until, ok := stageTrackerSoakUntil(rec); ok && !until.After(now) && until.After(at) {
at = until
}
if at.After(now) {
at = now
}
return at
}

// adoptedWorkCaption names what the hive is doing on a PR it adopted in
Expand Down
32 changes: 32 additions & 0 deletions src/pkg/dashboard/stage_tracker_cues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func stageTrackerCuesJS(t *testing.T, html string) string {
jsConstLine(t, html, "STAGE_TRACKER_EVENT_COVERED_BY_PR"),
jsFunc(t, html, "stageTrackerEventText"),
jsFunc(t, html, "stageTrackerEventsNext"),
jsFunc(t, html, "stageTrackerEventShownAt"),
jsFunc(t, html, "stageTrackerSameNote"),
jsFunc(t, html, "stageTrackerNewEvent"),
jsFunc(t, html, "stageTrackerNoteOwnerEvent"),
jsFunc(t, html, "stageTrackerEventHtml"),
jsFunc(t, html, "stageTrackerLocalMidnight"),
Expand Down Expand Up @@ -207,6 +210,34 @@ assert.strictEqual(events['hivecommons/hive/pr#14947'].text, 'moved to Needs dec
assert.deepStrictEqual(stageTrackerEventsNext({}, null, next, stages, now), {}, 'the first payload never writes a line for everything');
events = stageTrackerEventsNext(events, next, next, stages, now + STAGE_TRACKER_EVENT_MS + 1);
assert.deepStrictEqual(events, {}, 'lines expire');
// A soaking row (hivecommons/hive#15729): the caption counts down each
// poll but note_changed_at stands still, so the line is one note β€” its
// words refresh in place, its age counts from the server's stamp and the
// line neither re-opens nor is re-written when it has expired.
const soakStages = [{ number: 80, label: 'Merge gate' }, { number: 95, label: 'Pre-merge soak' }];
const soakAt = new Date(now - 120000).toISOString();
const soakRow = (caption, noteAt) => ({ repo: 'hivecommons/hive', kind: 'pr', number: 15730, stage: 95, caption, note_changed_at: noteAt });
const gate = stageTrackerStateMap([Object.assign(soakRow('Awaiting merge admission', new Date(now - 600000).toISOString()), { stage: 80 })]);
const soak10 = stageTrackerStateMap([soakRow('Admitted by the automerge lane; soaking β€” 10m left', soakAt)]);
const soak9 = stageTrackerStateMap([soakRow('Admitted by the automerge lane; soaking β€” 9m left', soakAt)]);
const soakKey = 'hivecommons/hive/pr#15730';
let soakEv = stageTrackerEventsNext({}, gate, soak10, soakStages, now);
assert.strictEqual(soakEv[soakKey].text, 'moved to Pre-merge soak');
assert.strictEqual(soakEv[soakKey].at, now - 120000, 'the age counts from when the note changed on the server');
assert.strictEqual(soakEv[soakKey].openAt, now, 'but the 30 s open window starts when this tab first shows it');
soakEv = stageTrackerEventsNext(soakEv, soak10, soak9, soakStages, now + 60000);
assert.strictEqual(soakEv[soakKey].text, 'Admitted by the automerge lane; soaking β€” 9m left', 'the words move in place');
assert.strictEqual(soakEv[soakKey].at, now - 120000, 'the age does not reset');
assert.strictEqual(soakEv[soakKey].openAt, now, 'the line does not re-open');
assert.deepStrictEqual(stageTrackerEventsNext({}, soak10, soak9, soakStages, now + STAGE_TRACKER_EVENT_MS * 2), {}, 'an expired line is not re-written by the countdown');
const soakDone = stageTrackerStateMap([soakRow('Admitted by the automerge lane; soak complete β€” merges on the next pass', new Date(now + 480000).toISOString())]);
soakEv = stageTrackerEventsNext(soakEv, soak9, soakDone, soakStages, now + 500000);
assert.strictEqual(soakEv[soakKey].text, 'Admitted by the automerge lane; soak complete β€” merges on the next pass', 'a new note_changed_at is a new note');
assert.strictEqual(soakEv[soakKey].at, now + 480000);
const legacy9 = stageTrackerStateMap([soakRow('soaking β€” 9m left', '')]);
const legacy8 = stageTrackerStateMap([soakRow('soaking β€” 8m left', '')]);
assert.strictEqual(stageTrackerEventsNext({}, legacy9, legacy8, soakStages, now)[soakKey].at, now, 'without the stamp (an older payload) a caption change is a new line as before');
assert.strictEqual(stageTrackerNewEvent('x', new Date(now + 5000).toISOString(), now).at, now, 'a stamp in the future is clamped to now');
_stageTrackerEvents = {};
stageTrackerNoteOwnerEvent('k', 'approved', now);
let line = stageTrackerEventHtml('k', { events: _stageTrackerEvents, nowMs: now });
Expand Down Expand Up @@ -329,6 +360,7 @@ func stageTrackerCelebrateJS(t *testing.T, html string) string {
jsFunc(t, html, "hamBannerDismiss"),
jsFunc(t, html, "hamBannerShowRow"),
jsFunc(t, html, "stageTrackerEventLineInject"),
jsFunc(t, html, "stageTrackerEventShownAt"),
jsFunc(t, html, "stageTrackerEventHtml"),
jsFunc(t, html, "stageTrackerNoteOwnerEvent"),
jsFunc(t, html, "stageTrackerCueAgeSync"),
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/stage_tracker_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem, open func(repo strin
lp.SoakRemainingSeconds, lp.MergeGate = pr.SoakRemainingSeconds, pr.MergeGate
lp.MergeTrain, lp.LeftTrain, lp.Overlap = pr.MergeTrain, pr.LeftTrain, pr.Overlap
lp.Soak = pr.Soak
lp.NoteChangedAt = pr.NoteChangedAt
lp.LastOperatorAction, lp.OperatorActionCount = pr.LastOperatorAction, pr.OperatorActionCount
lp.Decided, lp.AdoptedFrom = pr.Decided, pr.AdoptedFrom
lp.AdoptedBy, lp.AdoptedByState = pr.AdoptedBy, pr.AdoptedByState
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/dashboard/stage_tracker_note_tuck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func stageTrackerNoteTuckJS(t *testing.T, html string) string {
jsConstLine(t, html, "STAGE_TRACKER_EVENT_COVERED_BY_PR"),
jsFunc(t, html, "stageTrackerEventText"),
jsFunc(t, html, "stageTrackerEventsNext"),
jsFunc(t, html, "stageTrackerEventShownAt"),
jsFunc(t, html, "stageTrackerSameNote"),
jsFunc(t, html, "stageTrackerNewEvent"),
jsFunc(t, html, "stageTrackerNoteEvents"),
jsFunc(t, html, "stageTrackerNoteOwnerEvent"),
jsFunc(t, html, "stageTrackerEventHtml"),
Expand Down
78 changes: 77 additions & 1 deletion src/pkg/dashboard/stage_tracker_soak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ func TestStageTrackerSoakInPayload(t *testing.T) {
s.deps.Config = &config.Config{}
s.deps.Config.AutoMerge.ContributorLane.SoakMinutes = 45

// PR 102 (095) has no NoteSoak yet: the reason fallback with the 45m window.
// A 095 record written before NoteSoak existed (the countdown in its
// reason, no clock): the reason fallback with the 45m window.
store.ClearSoak(stagelabels.Key("acme/console", 102))
store.Observe(stagelabels.Key("acme/console", 102), stagelabels.PreMergeSoak, "contributor-lane:soaking(remaining=7m0s)")
pr := trackerItem(t, s.buildStageTracker(s.status, store, now), "pr", 102)
if pr.Soak == nil || pr.Soak.WindowSeconds != 45*60 || !pr.Soak.Until.Equal(now.Add(7*time.Minute)) {
t.Fatalf("PR 102 soak from reason: %+v", pr.Soak)
}
// The pass records the soak: the record's clock wins.
started := now.Add(-20 * time.Minute)
store.Observe(stagelabels.Key("acme/console", 102), stagelabels.PreMergeSoak, "contributor-lane:soaking")
store.NoteSoak(stagelabels.Key("acme/console", 102), "abc1234def", started, 30*time.Minute)
resp := s.buildStageTracker(s.status, store, now)
pr = trackerItem(t, resp, "pr", 102)
Expand Down Expand Up @@ -259,3 +263,75 @@ assert.deepStrictEqual([stageTrackerSoakLeftText(45000), stageTrackerSoakLeftTex
console.log('soak clock ok');
`)
}

// TestStageTrackerSoakCaptionFromDeadline (hivecommons/hive#15729): the
// 095 caption counts down from the record's soak deadline at request
// time β€” a sweep that re-reads the same reason moves nothing β€” never says
// "0s left", and the note's age is the stage entry while soaking and the
// deadline once the soak is complete. A record written before the
// deadline existed still reads its `soaking(remaining=…)` reason aged
// from the sweep that wrote it.
func TestStageTrackerSoakCaptionFromDeadline(t *testing.T) {
now := time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC)
entered := now.Add(-40 * time.Minute)
rec := stagelabels.Record{Stage: stagelabels.PreMergeSoak, Reason: "contributor-lane:soaking", EnteredAt: entered, ReasonChangedAt: entered, LastSeen: now.Add(-30 * time.Second),
SoakHead: "abc", SoakStartedAt: now.Add(-20 * time.Minute), SoakWindowSeconds: 1800}
if got := stageTrackerSoakCaption(rec, now); got != "Admitted by the automerge lane; soaking β€” 10m left" {
t.Fatalf("caption = %q", got)
}
if left := stageTrackerSoakRemaining(rec, now); left != 10*time.Minute {
t.Fatalf("remaining = %v", left)
}
if at := stageTrackerNoteChangedAt(rec, now); !at.Equal(entered) {
t.Fatalf("note changed at %v, want stage entry %v", at, entered)
}
// A later sweep re-reads the reason: LastSeen moves, nothing else does.
later := rec
later.LastSeen = now
if a, b := stageTrackerNoteChangedAt(rec, now), stageTrackerNoteChangedAt(later, now); !a.Equal(b) {
t.Fatalf("a re-read moved the note's age: %v β†’ %v", a, b)
}
if got := stageTrackerSoakCaption(later, now.Add(time.Minute)); got != "Admitted by the automerge lane; soaking β€” 9m left" {
t.Fatalf("a minute later: %q", got)
}
// At and past the deadline: never "0s left"; the note changed at the deadline.
deadline := rec.SoakStartedAt.Add(30 * time.Minute)
for _, at := range []time.Time{deadline, deadline.Add(90 * time.Second)} {
if got := stageTrackerSoakCaption(rec, at); got != "Admitted by the automerge lane; soak complete β€” merges on the next pass" {
t.Fatalf("at %v: %q", at, got)
}
if left := stageTrackerSoakRemaining(rec, at); left != 0 {
t.Fatalf("at %v: remaining = %v", at, left)
}
if got := stageTrackerNoteChangedAt(rec, at); !got.Equal(deadline) {
t.Fatalf("at %v: note changed at %v, want the deadline %v", at, got, deadline)
}
}
// A new reason class at the same stage dates the note from then.
held := rec
held.Reason, held.ReasonChangedAt = "release-hold", now.Add(-time.Minute)
if at := stageTrackerNoteChangedAt(held, now); !at.Equal(now.Add(-time.Minute)) {
t.Fatalf("note changed at %v", at)
}
// No clock yet (the pass that admitted the head has not written one):
// the generic caption stands.
bare := stagelabels.Record{Stage: stagelabels.PreMergeSoak, Reason: "contributor-lane:soaking", EnteredAt: entered}
if got := stageTrackerSoakCaption(bare, now); got != "" {
t.Fatalf("no clock: %q", got)
}
if at := stageTrackerNoteChangedAt(bare, now); !at.Equal(entered) {
t.Fatalf("no ReasonChangedAt falls back to EnteredAt: %v", at)
}
// Legacy record: the remaining in the reason, aged from the sweep.
legacy := stagelabels.Record{Stage: stagelabels.PreMergeSoak, Reason: "contributor-lane:soaking(remaining=12m0s)", EnteredAt: entered, LastSeen: now.Add(-5 * time.Minute)}
if got := stageTrackerSoakCaption(legacy, now); got != "Admitted by the automerge lane; soaking β€” 7m left" {
t.Fatalf("legacy caption = %q", got)
}
if got := stageTrackerSoakCaption(legacy, now.Add(8*time.Minute)); got != "Admitted by the automerge lane; soak complete β€” merges on the next pass" {
t.Fatalf("legacy past deadline = %q", got)
}
// A note never dates from the future.
if at := stageTrackerNoteChangedAt(stagelabels.Record{Stage: stagelabels.Reviewed, EnteredAt: now.Add(time.Hour)}, now); !at.Equal(now) {
t.Fatalf("future entry clamped: %v", at)
}
}
Loading
Loading