diff --git a/changelog.d/fixed-tracker-000-new.md b/changelog.d/fixed-tracker-000-new.md new file mode 100644 index 0000000000..6f922cf2ad --- /dev/null +++ b/changelog.d/fixed-tracker-000-new.md @@ -0,0 +1 @@ +- The Hive activity monitor now lists every open issue and pull request from its `opened` webhook (with replay and poll fallback) instead of waiting for the governor's next publish, and renders a not-yet-staged item as a `000-new` row in the Open column that says who moves it next — a maintainer's triage label or the hive's stage-label pass — and when the next pass is due (#15094). diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index de829790a3..c2377c5aa1 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -684,6 +684,8 @@ Fed by `GET /api/stage-tracker`. Every issue and pull request follows the same p **Blocked pill.** An issue wearing `blocked` because the hive parked it on a pull request — its body carries `` (the review backlog's spin-off issues, `hive-open-issue comment --blocked-on-pr`) — names that PR: the payload carries `blocked_on_pr: {repo, number, url, state}`, the pill reads `blocked on #N` and links to the PR, its tooltip says `Blocked on PR owner/repo#N (open) — lifts when it merges; re-triage if closed unmerged`, the caption reads `Blocked on PR #N — lifts when it merges` instead of `No stage recorded yet`, and the row's title and chevron tooltip carry the blocker too ([#14952](https://github.com/hivecommons/hive/issues/14952): #14863 showed a bare grey pill and "blocked · since 7h" with nothing to say what it waited on). The state (`open`, `merged`, `closed`, or absent when nothing knows) comes only from what the hive already holds — the status snapshot's open PRs, the ForgeState cache, the recent-merge ring — never a GitHub call from the tracker build; a merged or closed-unmerged blocker says so (`merged; the blocked sweep lifts the label next` / `closed unmerged; the blocked sweep re-triages it next`). The server reads the marker from the issue body when it has one, else from the enumeration's `blocked on owner/repo#N` reason, so sidelined rows (which carry only the reason) name it too. A `blocked` issue with neither (a human-applied label) keeps the bare pill. This is distinct from `blocked_on`, the open GitHub "blocked by" dependencies of a sequenced sub-issue ([#14765](https://github.com/hivecommons/hive/issues/14765)); when a row has both, the chevron tooltip lists them together. +**New row (`000-new`, the pre-stage state).** Every open issue and pull request in `project.repos` is on the list from the moment GitHub reports it — there is no gap between "opened" and "the hive has an opinion about it" ([#15094](https://github.com/hivecommons/hive/issues/15094)). The `issues.opened` / `pull_request.opened` webhook re-read inserts the item into the status payload straight away (`insertFrontendRepoItem`; the governor side keeps the same row in its cached snapshot so a republish does not drop it), the per-item replay re-applies that insert after a governor republish, and the enumeration poll is the fallback for a missed delivery. Until something places the item — a stage record, a `stage/*` label, a hold, a blocked marker, a bucket other than *reporter triage* / *unclassified* — the row is anchored in the **Open** column with the lit chevron reading **New** (`ham-open-new`, blue ✦ rather than amber) and a caption that names who moves it next and when: `New · waiting for the stage-label pass (→ 010 actionable), then the scanner (next pass in 7m)` for an issue the reporter gate has already admitted, `New · waiting for a maintainer's triage (add `triage/accepted`); the hive's next pass in 7m` for a human contributor's issue the reporter-trust gate is still holding (the label names come from `issues.filter.reporter_trust.untrusted_require_labels`), and `New · waiting for the stage-label pass (→ 050 review pending)` for a pull request. The *since* time is the item's `created_at`; "next pass" is the governor's next kick (`governor.nextKickAt`, so it counts down with the Governor tile and reads *due now* once it has passed). The payload carries it all as `new{since, next_mover (maintainer|hive), next_mover_text, next_pass_at, next_pass_in_seconds, gates[], text}`; the chevron tooltip lists the gates ahead — **triage** (the reporter gate: done when admitted, next when a triage label is still needed), **actionable** (the stage-label pass marks it 010), **claimed** (the scanner claims it, 020) — each marked ✓ done, → next or · later, and the row's actor icon reads *human* while the next mover is a maintainer and *hive* otherwise. A row that already wears a hold, `blocked`, a draft marker or any stage record is never *New*; neither is an issue at `015` once the stage-label pass has written it. + **Hive's own unblock is live.** When the blocked sweep or the review-backlog block reconciler lifts `blocked` itself (the tracked PR merged or closed; the `` note), it takes the same path as an inbound label webhook: the tracker cache is dropped and the issue is queued for the targeted re-read (`ItemPatches` delivery `self:edit`), which patches the status row and the governor's cached snapshot at once. A reconcile enumeration that was already listing when the unblock happened used to overwrite that patch with its pre-unblock copy, and the rows reverted to `blocked` until the next pass (~an hour on the hive's hive); the governor now replays re-reads newer than the listing's start onto the pass's result before publishing it, so a row never moves backwards behind a read it has already made. **Closed issue, open PR.** A pull request whose `Fixes #N` issue has already closed (auto-closed by a bot, or closed by hand) while the PR is still open is live work, not a stale line: the row is anchored on the PR ([#14655](https://github.com/hivecommons/hive/issues/14655)). The PR's own icon, number and title lead the row at full width, its stage drives the strip and its timestamps sort it — closing the issue is not a regression of the PR — and the closed issue shrinks to a muted `closes #N · closed` chip linking to it. An issue closed as *not planned* adds an `issue closed (not planned)` chip so the reader can tell the PR may be moot. At 090 such a row still counts under *Needs attention*: the human has a merge to click. When the PR closes or merges too, the row leaves the list as before (a merged PR shows in *Recently merged* for its retention window). diff --git a/src/docs/labels-and-control-signals.md b/src/docs/labels-and-control-signals.md index b257624457..8ba52d5ce5 100644 --- a/src/docs/labels-and-control-signals.md +++ b/src/docs/labels-and-control-signals.md @@ -442,6 +442,28 @@ not read as the issue regressing. > [operator-reference.md](operator-reference.md#central-stage-engine-rollout) > and the plan in [stage-engine-plan.md](stage-engine-plan.md). +### Before any stage: `000-new` in the activity monitor + +A freshly opened issue or pull request carries no `stage/*` label and no +stage record until the stage-label pass of the next enumeration cycle +looks at it (and, for a human contributor's issue, until a maintainer +adds a reporter-trust label — `triage/accepted` by default, +`issues.filter.reporter_trust.untrusted_require_labels`). That gap is not a +label: nothing is written on GitHub for it. It *is* a state the dashboard +shows ([#15094](https://github.com/hivecommons/hive/issues/15094)): the +`opened` webhook re-read inserts the item into the activity monitor at once, +and until something places it the row reads `000-new` in the **Open** column +with a caption naming the next mover — a maintainer (the triage gate is the +next hop; the caption says which label to add) or the hive (the stage-label +pass marks it `010-actionable`, then the scanner claims it, `020`) — and the +governor's next-pass countdown. The gates ahead are always the same three, +in order: **triage** (reporter gate, skipped for admitted reporters and the +hive's own filings) → **actionable** (`010`, written by the stage-label pass) +→ **claimed** (`020`, the scanner). `triage/accepted` plus `help wanted` on +a human-filed issue is actionable work at every level: once the label lands +the next pass writes `010` and the scanner may claim it. The dashboard +legend is in [dashboard-sections.md](dashboard-sections.md#hive-activity-monitor). + ### How a PR's stage is decided The automerge sweep already computes one reason per PR per lane each cycle diff --git a/src/pkg/dashboard/open_items.go b/src/pkg/dashboard/open_items.go index 667f4b3636..27b56d7661 100644 --- a/src/pkg/dashboard/open_items.go +++ b/src/pkg/dashboard/open_items.go @@ -192,19 +192,26 @@ func reconcileRepoOpenItems(r *FrontendRepo) openItemCounts { r.UnlistedPRs = max(0, r.PRs-counts.PRs) r.Issues = counts.Issues r.PRs = counts.PRs - if r.WorkBreakdown != nil { - wb := *r.WorkBreakdown - if wb.Issues.Total() != counts.Issues { - wb.Issues = rebuildIssueBreakdown(wb.Issues, items) - } - if wb.PRs.Total() != counts.PRs { - wb.PRs = rebuildPRBreakdown(items) - } - r.WorkBreakdown = &wb - } + refitRepoWorkBreakdown(r, items, counts) return counts } +// refitRepoWorkBreakdown rebuilds the coarse work buckets from the items +// when the breakdown's totals no longer match the item lists. +func refitRepoWorkBreakdown(r *FrontendRepo, items []openItemRef, counts openItemCounts) { + if r.WorkBreakdown == nil { + return + } + wb := *r.WorkBreakdown + if wb.Issues.Total() != counts.Issues { + wb.Issues = rebuildIssueBreakdown(wb.Issues, items) + } + if wb.PRs.Total() != counts.PRs { + wb.PRs = rebuildPRBreakdown(items) + } + r.WorkBreakdown = &wb +} + // rebuildIssueBreakdown recounts the coarse issue buckets from the items. // The named sub-buckets inside Filtered (needs-human, needs-decision, // needs-spec, reporter-confirmation, exempt, blocked) come from labels the diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index c3d87fdd34..ba8fc1e82d 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -442,7 +442,11 @@ type StageTrackerItem struct { // row's ✓ badge and its hover read these (operator_actions.go). LastOperatorAction *StageTrackerOperatorAction `json:"last_operator_action,omitempty"` OperatorActionCount int `json:"operator_action_count,omitempty"` - History []StageTrackerHop `json:"history"` + // New is set on a 000-new item — open, unplaced, nothing holding it — + // with who moves it next and the gates ahead; the Open column renders + // it as "New · waiting for …" (hivecommons/hive#15094). + New *StageTrackerNew `json:"new,omitempty"` + History []StageTrackerHop `json:"history"` } // StageTrackerLinkedIssue is one issue a PR closes, as its row's issue @@ -1682,6 +1686,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto resp.Items = append(resp.Items, it) } prState := s.stageTrackerPRStateResolver(status, resp.RecentlyMerged) + issueFilter := s.issueFilterConfig() addIssue := func(repoName string, issue github.Issue, bucket, bucketReason string, progress *github.IssueChildren) { // A closed issue has no stage; a stage label it closed wearing is // the closed-issue sweep's to remove, not a row to render @@ -1732,6 +1737,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto finish(&it, issue.Labels, stage, rec, ok, false) stageTrackerBlockedBy(&it, issue.OpenBlockers()) stageTrackerBlockedOnPR(&it, issue.Body, bucketReason, status.GitHubBaseURL, prState) + applyStageTrackerNew(&it, stageTrackerNewState(it, ok, issueFilter, status.Governor, now)) if it.Stage == trackerNumberClaimed { it.ClaimantKind = s.stageTrackerClaimantKind(repoName, issue.Number) } @@ -1770,6 +1776,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto it.Lane = laneHive } finish(&it, pr.Labels, labelStage(pr.Labels), rec, ok, pr.Draft) + applyStageTrackerNew(&it, stageTrackerNewState(it, ok, issueFilter, status.Governor, now)) it.SentinelAlert, it.SentinelFindings, it.SentinelReason = s.stageTrackerSentinel(evidenceVerifier, repoName, pr.Number, pr.HeadSHA, pr.Labels) // The sentinel chip is a merge-gate pill too (the trusted-author // notice and the real alert alike): sentinel_alert stays truthful diff --git a/src/pkg/dashboard/stage_tracker_new.go b/src/pkg/dashboard/stage_tracker_new.go new file mode 100644 index 0000000000..193ad5146c --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_new.go @@ -0,0 +1,183 @@ +package dashboard + +import ( + "fmt" + "slices" + "strings" + "time" + + "github.com/hivecommons/hive/pkg/config" +) + +// StageTrackerNewSlug is the pre-stage slug a brand-new open item wears in +// the Open column before any stage pass has placed it: it has no stage/* +// label and no store record, nothing holds or blocks it, and the only +// thing between it and 010/050 is the next pass of whoever moves it +// (hivecommons/hive#15094). Stage stays 0 so the column keys are unchanged. +const StageTrackerNewSlug = "000-new" + +// Next movers of a 000-new item. +const ( + // StageTrackerMoverMaintainer: a human must accept triage first (the + // reporter-trust gate holds an un-admitted reporter's issue). + StageTrackerMoverMaintainer = "maintainer" + // StageTrackerMoverHive: the hive's own stage-label pass places it on + // its next governor cycle. + StageTrackerMoverHive = "hive" +) + +// Gate states on a 000-new item. +const ( + StageTrackerGateDone = "done" + StageTrackerGateNext = "next" + StageTrackerGateLater = "later" +) + +// StageTrackerGate is one gate ahead of a 000-new item. +type StageTrackerGate struct { + Name string `json:"name"` + State string `json:"state"` + Text string `json:"text"` +} + +// StageTrackerNew narrates a 000-new item: who moves it next, when that +// pass is due, and the gates between it and a claim. +type StageTrackerNew struct { + // Since is when the item was opened (the row's since-time). + Since *time.Time `json:"since,omitempty"` + // NextMover is maintainer or hive; NextMoverText the plain words. + NextMover string `json:"next_mover"` + NextMoverText string `json:"next_mover_text"` + // NextPassAt / NextPassInSeconds: the governor's next cycle, when the + // hive is the mover and the governor has published one. + NextPassAt *time.Time `json:"next_pass_at,omitempty"` + NextPassInSeconds int64 `json:"next_pass_in_s,omitempty"` + Gates []StageTrackerGate `json:"gates"` + // Text is the row caption: "New · waiting for (next pass in Nm)". + Text string `json:"text"` +} + +// stageTrackerIsNew reports whether a finished row is a 000-new item: no +// stage, no record, nothing holding or blocking it, not a draft, and in a +// bucket that means "not placed yet" rather than "placed outside the +// actionable set" (filtered, hive_advisory, claimed, …). +func stageTrackerIsNew(it StageTrackerItem, hasRec bool) bool { + if it.Stage != 0 || hasRec || it.Hold != nil || len(it.BlockedOn) > 0 || it.BlockedOnPR != nil { + return false + } + for _, m := range it.Modifiers { + if m != modNeedsTriage { + return false + } + } + switch it.Bucket { + case "", stageengineReporterTriageBucket: + return true + case "other": + return it.BucketReason == forgeUnclassifiedReason || it.BucketReason == webhookUnclassifiedReason + } + return false +} + +// stageengineReporterTriageBucket mirrors github's workBucketReporterTriage. +const stageengineReporterTriageBucket = "reporter_triage" + +// stageTrackerNewState builds the 000-new narration for it, or nil when +// the row is not new. filter is the project's issue filter (nil-safe); +// governor carries the next cycle when published. +func stageTrackerNewState(it StageTrackerItem, hasRec bool, filter *config.IssueFilterConfig, governor FrontendGovernor, now time.Time) *StageTrackerNew { + if !stageTrackerIsNew(it, hasRec) { + return nil + } + n := &StageTrackerNew{Since: it.CreatedAt} + if n.Since == nil { + n.Since = it.UpdatedAt + } + triagePending := it.Kind == "issue" && (it.Bucket == stageengineReporterTriageBucket || slices.Contains(it.Modifiers, modNeedsTriage)) + if t, ok := parseGovernorNextKick(governor.NextKickAt); ok { + n.NextPassAt = &t + if left := t.Sub(now); left > 0 { + n.NextPassInSeconds = int64(left / time.Second) + } + } + var pass string + switch { + case n.NextPassAt != nil && n.NextPassInSeconds > 0: + pass = "next pass in " + formatETA(time.Duration(n.NextPassInSeconds)*time.Second) + case n.NextPassAt != nil: + pass = "next pass due now" + } + switch { + case triagePending: + n.NextMover = StageTrackerMoverMaintainer + labels := []string{"triage/accepted"} + if filter != nil { + if l := filter.ReporterTrustRequiredLabelsForNotice(); len(l) > 0 { + labels = l + } + } + n.NextMoverText = "a maintainer's triage (add `" + strings.Join(labels, "` or `") + "`)" + n.Gates = []StageTrackerGate{ + {Name: "triage", State: StageTrackerGateNext, Text: "a maintainer accepts triage (" + strings.Join(labels, " / ") + ")"}, + {Name: "actionable", State: StageTrackerGateLater, Text: "the stage-label pass marks it 010 actionable"}, + {Name: "claimed", State: StageTrackerGateLater, Text: "the scanner claims it (020)"}, + } + case it.Kind == "pr": + n.NextMover = StageTrackerMoverHive + n.NextMoverText = "the stage-label pass (→ 050 review pending)" + n.Gates = []StageTrackerGate{ + {Name: "review", State: StageTrackerGateNext, Text: "the stage-label pass places it at 050 review pending"}, + {Name: "merge-gate", State: StageTrackerGateLater, Text: "reviews and checks admit it to the merge gate"}, + } + default: + n.NextMover = StageTrackerMoverHive + n.NextMoverText = "the stage-label pass (→ 010 actionable), then the scanner" + n.Gates = []StageTrackerGate{ + {Name: "triage", State: StageTrackerGateDone, Text: "reporter admitted; no triage label needed"}, + {Name: "actionable", State: StageTrackerGateNext, Text: "the stage-label pass marks it 010 actionable"}, + {Name: "claimed", State: StageTrackerGateLater, Text: "the scanner claims it (020)"}, + } + } + n.Text = "New · waiting for " + n.NextMoverText + if pass != "" && n.NextMover == StageTrackerMoverHive { + n.Text += " (" + pass + ")" + } else if pass != "" { + n.Text += fmt.Sprintf("; the hive's %s", pass) + } + return n +} + +// parseGovernorNextKick reads FrontendGovernor.NextKickAt (RFC3339). +func parseGovernorNextKick(s string) (time.Time, bool) { + if s == "" { + return time.Time{}, false + } + t, err := time.Parse(time.RFC3339, s) + if err != nil { + return time.Time{}, false + } + return t, true +} + +// applyStageTrackerNew stamps the 000-new state on a finished row: slug, +// caption, actor and since-time all read from it. +func applyStageTrackerNew(it *StageTrackerItem, n *StageTrackerNew) { + if n == nil { + return + } + it.New = n + it.StageSlug = StageTrackerNewSlug + it.Caption = n.Text + it.Actor = n.NextMover + if n.Since != nil && it.StageSince == nil { + it.StageSince = n.Since + } +} + +// issueFilterConfig is the project's issue filter, or nil without deps. +func (s *Server) issueFilterConfig() *config.IssueFilterConfig { + if s == nil || s.deps == nil || s.deps.Config == nil { + return nil + } + return &s.deps.Config.Project.IssueFilter +} diff --git a/src/pkg/dashboard/stage_tracker_new_test.go b/src/pkg/dashboard/stage_tracker_new_test.go new file mode 100644 index 0000000000..af2f521f61 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_new_test.go @@ -0,0 +1,316 @@ +package dashboard + +import ( + "os/exec" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#15094: hive's hive did not show hivecommons/hive#15092 +// (a human contributor's issue, opened 20:38Z) in the Activity Monitor +// until the governor republished at 20:45Z — the `opened` re-read only +// rewrote rows the status already listed. An open read for an item no +// list carries must now insert it, and the row must read as 000-new. +func TestWebhookOpenedItemInsertedIntoTracker(t *testing.T) { + now := time.Date(2026, 10, 20, 12, 0, 0, 0, time.UTC) + t.Cleanup(github.ResetWebhookTrackerForTestWithClock(func() time.Time { return now })) + s, store := stageTrackerFixture(t, now) + s.statusMu.Lock() + s.status.Governor.NextKickAt = now.Add(7 * time.Minute).UTC().Format(time.RFC3339) + if s.status.Repos[0].WorkBreakdown == nil { + s.status.Repos[0].WorkBreakdown = &github.RepoWorkBreakdown{} + } + s.statusMu.Unlock() + opened := now.Add(-90 * time.Second) + + triage := github.RepoWorkIssue{Repo: "acme/console", Number: 15092, Title: "Add a thing", Author: "kanrenibm", Labels: []string{"enhancement", "help wanted"}, CreatedAt: opened, UpdatedAt: opened, Bucket: "reporter_triage", Reason: "Awaiting maintainer triage label"} + n := s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{ + // A contributor's issue the reporter gate has not admitted: the + // classifier offers the reporter_triage row. + {Repo: "acme/console", Number: 15092, State: "open", Title: "Add a thing", Author: "kanrenibm", Labels: []string{"enhancement", "help wanted"}, UpdatedAt: opened, + Patch: github.WebhookItemPatch{Bucket: github.WebhookBucketUnknown, WorkIssue: &triage}}, + // A maintainer's issue the classifier admitted outright. + {Repo: "acme/console", Number: 15095, State: "open", Title: "Maintainer ask", Author: "pat", UpdatedAt: opened, + Patch: github.WebhookItemPatch{Bucket: github.WebhookBucketActionable, Issue: &github.Issue{Repo: "acme/console", Number: 15095, Title: "Maintainer ask", Author: "pat", AuthorIsHuman: true, CreatedAt: opened, UpdatedAt: opened}}}, + // A PR with no classification at all (the read carried no patch). + {Repo: "acme/console", Number: 15096, IsPR: true, State: "open", Title: "Fresh PR", Author: "sam", UpdatedAt: opened}, + }) + if n != 3 { + t.Fatalf("applyWebhookItemSnapshots inserted %d rows, want 3", n) + } + s.statusMu.RLock() + repo := s.status.Repos[0] + s.statusMu.RUnlock() + if repo.WorkBreakdown == nil || repo.WorkBreakdown.Issues.ReporterTriage != 1 { + t.Fatalf("issue breakdown after insert = %+v, want reporter_triage 1", repo.WorkBreakdown) + } + + resp := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, resp, "issue", 15092) + if it.Stage != 0 || it.StageSlug != StageTrackerNewSlug || it.New == nil { + t.Fatalf("#15092 = stage %d slug %q new %+v, want 000-new", it.Stage, it.StageSlug, it.New) + } + if it.New.NextMover != StageTrackerMoverMaintainer || !strings.Contains(it.Caption, "New · waiting for a maintainer's triage (add `triage/accepted`)") || it.Actor != StageTrackerMoverMaintainer { + t.Fatalf("#15092 caption %q actor %q new %+v, want the maintainer's triage as next mover", it.Caption, it.Actor, it.New) + } + if it.StageSince == nil || !it.StageSince.Equal(opened) { + t.Fatalf("#15092 since = %v, want the opened time %v", it.StageSince, opened) + } + if len(it.New.Gates) != 3 || it.New.Gates[0].Name != "triage" || it.New.Gates[0].State != StageTrackerGateNext || it.New.Gates[1].Name != "actionable" || it.New.Gates[2].Name != "claimed" { + t.Fatalf("#15092 gates = %+v, want triage (next) → actionable → claimed", it.New.Gates) + } + if it.New.NextPassAt == nil || it.New.NextPassInSeconds != 7*60 || !strings.Contains(it.Caption, "next pass in 7m") { + t.Fatalf("#15092 next pass = %v / %ds caption %q, want the governor's kick in 7m", it.New.NextPassAt, it.New.NextPassInSeconds, it.Caption) + } + + it = trackerItem(t, resp, "issue", 15095) + if it.New == nil || it.New.NextMover != StageTrackerMoverHive || it.Caption != "New · waiting for the stage-label pass (→ 010 actionable), then the scanner (next pass in 7m)" { + t.Fatalf("#15095 = %+v caption %q, want the stage-label pass as next mover", it.New, it.Caption) + } + if it.New.Gates[0].Name != "triage" || it.New.Gates[0].State != StageTrackerGateDone { + t.Fatalf("#15095 gates = %+v, want triage already done", it.New.Gates) + } + + it = trackerItem(t, resp, "pr", 15096) + if it.New == nil || it.New.NextMover != StageTrackerMoverHive || !strings.Contains(it.Caption, "→ 050 review pending") || it.Bucket != "other" || it.BucketReason != webhookUnclassifiedReason { + t.Fatalf("#15096 = %+v bucket %q/%q caption %q", it.New, it.Bucket, it.BucketReason, it.Caption) + } + + // Rows that are placed stay as they were: a held issue, a stalled PR, + // a claimed issue, a filtered sidelined row are not "new". + for _, probe := range []struct { + kind string + number int + }{{"issue", 7}, {"issue", 8}, {"issue", 13}, {"pr", 101}, {"pr", 102}, {"pr", 103}} { + if got := trackerItem(t, resp, probe.kind, probe.number); got.New != nil || got.StageSlug == StageTrackerNewSlug { + t.Fatalf("%s #%d read as new: %+v", probe.kind, probe.number, got) + } + } + + // The governor's next publish, built from an enumeration that began + // before the deliveries, does not list the three; the replay keeps them. + fresh, _ := stageTrackerFixture(t, now) + fresh.statusMu.RLock() + republished := *fresh.status + fresh.statusMu.RUnlock() + s.UpdateStatus(&republished) + again := s.buildStageTracker(s.status, store, now) + for _, probe := range []struct { + kind string + number int + }{{"issue", 15092}, {"issue", 15095}, {"pr", 15096}} { + if got := trackerItem(t, again, probe.kind, probe.number); got.New == nil { + t.Fatalf("%s #%d lost on republish: %+v", probe.kind, probe.number, got) + } + } +} + +// An out-of-order open read behind a remembered close does not re-list +// the item (the `unlabeled` read after the `closed` one), and a stale open +// read is not an insert either. +func TestWebhookOpenedInsertRespectsRememberedClose(t *testing.T) { + now := time.Date(2026, 10, 20, 12, 0, 0, 0, time.UTC) + t.Cleanup(github.ResetWebhookTrackerForTestWithClock(func() time.Time { return now })) + s, _ := stageTrackerFixture(t, now) + closedAt := now.Add(-time.Minute) + if n := s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{{Repo: "acme/console", Number: 8, State: "closed", UpdatedAt: closedAt}}); n == 0 { + t.Fatal("close did not evict #8") + } + if n := s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{{Repo: "acme/console", Number: 8, State: "open", Title: "stale", UpdatedAt: closedAt.Add(-time.Minute)}}); n != 0 { + t.Fatalf("stale open read behind the close inserted %d rows", n) + } + if n := s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{{Repo: "acme/console", Number: 8, State: "open", Title: "no timestamp"}}); n != 0 { + t.Fatalf("untimed open read behind the close inserted %d rows", n) + } + if n := s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{{Repo: "acme/console", Number: 8, State: "open", Title: "reopened", UpdatedAt: closedAt.Add(time.Minute)}}); n != 1 { + t.Fatalf("a reopen newer than the close must re-list: %d", n) + } +} + +// The 000-new derivation on its own: who moves next, the caption, and what +// is not new (hold, blocked, draft, a stage record, a placed bucket). +func TestStageTrackerNewState(t *testing.T) { + now := time.Date(2026, 10, 20, 12, 0, 0, 0, time.UTC) + opened := now.Add(-3 * time.Minute) + gov := FrontendGovernor{NextKickAt: now.Add(5 * time.Minute).UTC().Format(time.RFC3339)} + filter := &config.IssueFilterConfig{ReporterTrust: config.ReporterTrustConfig{UntrustedRequireLabels: []string{"triage/accepted", "kind/approved"}}} + base := StageTrackerItem{Kind: "issue", Stage: 0, CreatedAt: &opened} + + n := stageTrackerNewState(base, false, filter, gov, now) + if n == nil || n.NextMover != StageTrackerMoverHive || n.Text != "New · waiting for the stage-label pass (→ 010 actionable), then the scanner (next pass in 5m)" { + t.Fatalf("plain actionable-list issue = %+v", n) + } + triage := base + triage.Bucket = "reporter_triage" + n = stageTrackerNewState(triage, false, filter, gov, now) + if n == nil || n.NextMover != StageTrackerMoverMaintainer || n.Text != "New · waiting for a maintainer's triage (add `triage/accepted` or `kind/approved`); the hive's next pass in 5m" { + t.Fatalf("reporter_triage issue = %+v", n) + } + labelled := base + labelled.Modifiers = []string{modNeedsTriage} + if n = stageTrackerNewState(labelled, false, nil, FrontendGovernor{}, now); n == nil || n.NextMover != StageTrackerMoverMaintainer || n.Text != "New · waiting for a maintainer's triage (add `triage/accepted`)" || n.NextPassAt != nil { + t.Fatalf("needs-triage issue without a governor kick = %+v", n) + } + pr := StageTrackerItem{Kind: "pr", Stage: 0, CreatedAt: &opened} + if n = stageTrackerNewState(pr, false, filter, gov, now); n == nil || n.Text != "New · waiting for the stage-label pass (→ 050 review pending) (next pass in 5m)" { + t.Fatalf("plain PR = %+v", n) + } + due := FrontendGovernor{NextKickAt: now.Add(-time.Second).UTC().Format(time.RFC3339)} + if n = stageTrackerNewState(pr, false, filter, due, now); n == nil || !strings.HasSuffix(n.Text, "(next pass due now)") || n.NextPassInSeconds != 0 { + t.Fatalf("overdue kick = %+v", n) + } + + notNew := map[string]StageTrackerItem{ + "stage": {Kind: "issue", Stage: 10}, + "hold": {Kind: "issue", Stage: 0, Hold: &StageTrackerHold{By: "pat"}, Modifiers: []string{modHold}}, + "blocked": {Kind: "issue", Stage: 0, BlockedOn: []string{"#1"}, Modifiers: []string{modBlocked}}, + "draft": {Kind: "pr", Stage: 0, Modifiers: []string{modDraft}}, + "filtered": {Kind: "issue", Stage: 0, Bucket: "filtered"}, + "advisory": {Kind: "issue", Stage: 0, Bucket: "hive_advisory"}, + "other": {Kind: "issue", Stage: 0, Bucket: "other", BucketReason: "something the scanner said"}, + } + for name, it := range notNew { + if got := stageTrackerNewState(it, false, filter, gov, now); got != nil { + t.Errorf("%s read as new: %+v", name, got) + } + } + if got := stageTrackerNewState(base, true, filter, gov, now); got != nil { + t.Errorf("a row with a store record read as new: %+v", got) + } + forge := base + forge.Bucket, forge.BucketReason = "other", forgeUnclassifiedReason + if got := stageTrackerNewState(forge, false, filter, gov, now); got == nil { + t.Error("a forge-cache seeded row the scanner has not classified is new") + } + _ = stagelabels.None +} + +// The Open column renders a 000-new row as "New · since Nm" in its own +// colour, with the next mover and the gates on hover. +func TestStageTrackerNewRowRendering(t *testing.T) { + html := indexHTML(t) + for _, fn := range []string{"stageTrackerNewState", "stageTrackerNewLines"} { + if _, ok := jsFuncOptional(html, fn); !ok { + t.Fatalf("%s missing from the SPA", fn) + } + } + if !strings.Contains(html, ".ham-seg.active.ham-open-new {") { + t.Fatal("no .ham-open-new rule in the stylesheet") + } + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node not on PATH — the 000-new rendering was NOT executed by this run") + } + script := strings.Join([]string{ + "const assert = require('assert');", + "function esc(s) { return String(s).replace(/&/g, '&').replace(/New · since 8m'), strip); +const chevronTip = /title="([^"]*)"/.exec(strip)[1]; +assert.ok(chevronTip.startsWith('New — Next: a maintainer's triage') || chevronTip.startsWith('New — Next: a maintainer\'s triage'), chevronTip); +assert.ok(chevronTip.includes('next hive pass in 7m'), chevronTip); +assert.ok(chevronTip.includes('Gates ahead: triage (next) → actionable → claimed'), chevronTip); +assert.ok(chevronTip.includes('Next move: human'), chevronTip); +const tip = stageTrackerTooltip(fresh, now); +const lines = tip.split('\n'); +assert.strictEqual(lines[0], 'New'); +assert.ok(lines.some(l => l.startsWith('Next: a maintainer') && l.endsWith('next hive pass in 7m')), tip); +assert.ok(lines.includes('Gates ahead: triage (next) → actionable → claimed'), tip); +assert.ok(lines.includes(' claimed: the scanner claims it (020)'), tip); +assert.ok(lines.some(l => l.startsWith('Since T')), tip); + +// A hive-moved new PR: the hive is the next mover, the triage gate already done reads with a tick. +const pr = { repo: 'hivecommons/hive', number: 15096, kind: 'pr', title: 'Fresh PR', stage: 0, stage_slug: '000-new', created_at: '2026-10-20T11:58:30Z', + new: { next_mover: 'hive', next_mover_text: 'the stage-label pass (→ 050 review pending)', next_pass_at: '2026-10-20T11:59:00Z', gates: [{ name: 'review', state: 'next' }, { name: 'merge-gate', state: 'later' }], text: 'New · waiting for the stage-label pass (→ 050 review pending) (next pass due now)' } }; +assert.strictEqual(stageTrackerActorKind(pr), 'hive'); +assert.ok(stageTrackerNewLines(pr, now)[0].endsWith('next hive pass due now'), stageTrackerNewLines(pr, now)); +assert.strictEqual(stageTrackerNewLines({ stage: 0, new: { next_mover: 'hive', gates: [{ name: 'triage', state: 'done' }, { name: 'actionable', state: 'next' }] } }, now)[1], 'Gates ahead: triage ✓ → actionable (next)'); + +// Not new: a plain Open row, a held row, a draft PR, a staged row — the word and the class stay as they were. +for (const it of [ + { kind: 'issue', stage: 0, caption: 'No stage recorded yet', labels: ['needs-triage'], modifiers: ['needs-triage'] }, + { kind: 'pr', stage: 0, modifiers: ['hold'], labels: ['hold'], new: { next_mover: 'hive' } }, + { kind: 'pr', stage: 0, modifiers: ['draft'], new: { next_mover: 'hive' } }, + { kind: 'issue', stage: 10, new: { next_mover: 'hive' } }, +]) { + const s = stageTrackerStripItems(it, stages, null, now, {}); + assert.ok(!s.includes('ham-open-new'), JSON.stringify(it) + ' → ' + s); + assert.ok(!s.includes('>New'), JSON.stringify(it) + ' → ' + s); + assert.notStrictEqual(stageTrackerHeadline(it), 'New'); +} +assert.strictEqual(stageTrackerHeadline({ kind: 'issue', stage: 0, caption: 'No stage recorded yet', labels: ['needs-triage'], modifiers: ['needs-triage'] }), 'Open'); +assert.deepStrictEqual(stageTrackerNewLines({ stage: 0 }, now), []); +` + cmd := exec.Command(node, "-") + cmd.Stdin = strings.NewReader(script) + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("node: %v\n%s", err, out) + } +} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 33140c3241..34c45c655f 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1551,6 +1551,10 @@ .ham-seg.active.ham-open-blocked .ham-seg-t::before { content: '⛔'; margin-right: var(--sp-1); } .ham-seg.active.ham-open-draft { background: var(--band-draft); color: var(--surface-0); } .ham-seg.active.ham-open-draft .ham-seg-t::before { content: '✎'; margin-right: var(--sp-1); } + /* 000-new: open, nothing placed it yet; blue says "fresh, nobody owes + it a move but the next pass" (hivecommons/hive#15094). */ + .ham-seg.active.ham-open-new { background: var(--blue); color: var(--surface-0); } + .ham-seg.active.ham-open-new .ham-seg-t::before { content: '✦'; margin-right: var(--sp-1); } .ham-seg.active.ham-open-stale { background: color-mix(in srgb, var(--amber) 65%, var(--red)); } .ham-detour { white-space: normal; overflow-wrap: anywhere; } .ham-current-stage { display: none; margin: 0; font-size: var(--fs-xs); color: var(--muted); overflow-wrap: anywhere; } @@ -14137,6 +14141,8 @@

Where to get help

if (n === 0 && mods.indexOf('hold') >= 0) return 'Open · on hold' + (holdLabels.length ? ' (' + holdLabels.join(', ') + ')' : ''); if (n === 0 && mods.indexOf('blocked') >= 0) return 'Open · blocked'; if (n === 0 && mods.indexOf('draft') >= 0) return 'Open · draft'; + // Guarded: test harnesses lift this function by name without the 000-new helpers. + if (n === 0 && typeof stageTrackerNewState === 'function' && stageTrackerNewState(item)) return 'New'; // An issue parked on a person (045, or a pre-045 085 with no covering // PR) is parked itself, so no "(its PR)" suffix. const viaPR = item.kind === 'issue' && n >= 50 && (n !== 85 || item.via_pr) ? ' (its PR)' : ''; @@ -14428,9 +14434,13 @@

Where to get help

// A draft PR with no stage is the author's, not the hive's: the // Open word says so, muted, and it never tints stale (#14572). const openDraft = n === 0 && state === 'active' && !openHold && !openBlocked && mods.indexOf('draft') >= 0; + // 000-new: the payload says nothing has placed the item yet and + // names who moves it next (hivecommons/hive#15094). + const openNew = n === 0 && state === 'active' && !openHold && !openBlocked && !openDraft && typeof stageTrackerNewState === 'function' && !!stageTrackerNewState(item); if (openHold) word = 'Open · hold'; else if (openBlocked) word = 'Open · blocked'; else if (openDraft) word = 'Draft'; + else if (openNew) word = 'New'; // A plain, blocked or draft Open step (no stage label, not held) // says how long it has sat there, from the same instant the since // column shows — a stale blocked item is exactly what should stand out. @@ -14439,7 +14449,7 @@

Where to get help

const os = stageTrackerOpenSince(item); if (os.ms) { word += ' · since ' + stageTrackerShortAgo(nowMs - os.ms); openSince = Object.assign({ stale: !openDraft && nowMs - os.ms > STAGE_TRACKER_OPEN_STALE_DAYS * 86400000 }, os); } } - return { number: n, code: n ? String(n).padStart(3, '0') : '', short: word, label: tipStage.label || st.label || String(n), description: tipStage.description || st.description || '', state, terminal: false, detour: n === anchor ? detour : null, hold: openHold, blocked: openBlocked, draft: openDraft, openSince }; + return { number: n, code: n ? String(n).padStart(3, '0') : '', short: word, label: tipStage.label || st.label || String(n), description: tipStage.description || st.description || '', state, terminal: false, detour: n === anchor ? detour : null, hold: openHold, blocked: openBlocked, draft: openDraft, isNew: openNew, openSince }; }); segs.push({ number: STAGE_TRACKER_TERMINAL, code: '', short: 'Merged', label: 'Merged', description: 'Merged — the pipeline is complete', state: terminal ? 'active' : 'todo', terminal, cap: true, detour: null }); return segs; @@ -14489,6 +14499,9 @@

Where to get help

// Author kind of whoever must move on the item's current stage ('' = none). function stageTrackerActorKind(item) { + // Guarded: test harnesses lift this function by name without the 000-new helpers. + const fresh = typeof stageTrackerNewState === 'function' ? stageTrackerNewState(item) : null; + if (fresh) return fresh.next_mover === 'maintainer' ? 'human' : 'hive'; const role = STAGE_TRACKER_ACTOR[Number(item.stage) || 0] || ''; if (role === 'claimant') return item.claimant_kind || ''; if (role === 'author') { @@ -14499,6 +14512,34 @@

Where to get help

return role; } + // 000-new (hivecommons/hive#15094): a payload `new` block on a stage-0 + // row means nothing has placed the item yet. These are pure so the + // fixture tests can lift them by name. + const STAGE_TRACKER_NEW_GATE_MARK = { done: ' ✓', next: ' (next)' }; + function stageTrackerNewState(item) { + if (!item || (Number(item.stage) || 0) !== 0 || !item.new || typeof item.new !== 'object') return null; + return item.new; + } + // "Next: …" and "Gates ahead: triage ✓ → actionable → claimed" for the + // row tooltip and the lit chevron. nowMs refreshes the next-pass countdown. + function stageTrackerNewLines(item, nowMs) { + const fresh = stageTrackerNewState(item); + if (!fresh) return []; + let next = 'Next: ' + (fresh.next_mover_text || fresh.next_mover || 'the next pass'); + const passMs = Date.parse(fresh.next_pass_at || ''); + if (passMs && nowMs) { + const left = passMs - nowMs; + next += left > 0 ? ' · next hive pass in ' + stageTrackerShortAgo(left) : ' · next hive pass due now'; + } + const lines = [next]; + const gates = Array.isArray(fresh.gates) ? fresh.gates : []; + if (gates.length) { + lines.push('Gates ahead: ' + gates.map(g => (g.name || '') + (STAGE_TRACKER_NEW_GATE_MARK[g.state] || '')).join(' → ')); + gates.forEach(g => { if (g.text) lines.push(' ' + (g.name || '') + ': ' + g.text); }); + } + return lines; + } + // An Open item is tinted stale once it has sat unlabelled this long. const STAGE_TRACKER_OPEN_STALE_DAYS = 2; // When an item entered its current (Open) state: the payload's @@ -14557,13 +14598,14 @@

Where to get help

return segs.map(sg => { if (sg.number < from || sg.number > to) return ``; const sentinel = !!(sg.detour && sg.detour.sentinel); - const cls = ['ham-seg', sg.state, sg.cap ? 'cap' : '', sg.cap && sg.terminal ? 'merged' : '', sg.detour ? 'detoured' : '', sg.hold ? 'ham-open-hold' : '', sg.blocked ? 'ham-open-blocked' : '', sg.draft ? 'ham-open-draft' : '', sg.openSince && sg.openSince.stale ? 'ham-open-stale' : '', sentinel ? 'ham-sentinel' : ''].filter(Boolean).join(' '); + const cls = ['ham-seg', sg.state, sg.cap ? 'cap' : '', sg.cap && sg.terminal ? 'merged' : '', sg.detour ? 'detoured' : '', sg.hold ? 'ham-open-hold' : '', sg.blocked ? 'ham-open-blocked' : '', sg.draft ? 'ham-open-draft' : '', sg.isNew ? 'ham-open-new' : '', sg.openSince && sg.openSince.stale ? 'ham-open-stale' : '', sentinel ? 'ham-sentinel' : ''].filter(Boolean).join(' '); const active = sg.state === 'active'; let tip = ''; if (active) { tip = sg.label + (sg.description ? ' — ' + sg.description : ''); if (sg.blocked) tip += ' — ' + stageTrackerBlockedTip(item); if (sg.draft) tip += ' — ' + STAGE_TRACKER_DRAFT_TIP; + if (sg.isNew && typeof stageTrackerNewLines === 'function') tip = 'New — ' + stageTrackerNewLines(item, nowMs).join(' — '); if (sg.openSince) tip += ' — open since ' + new Date(sg.openSince.ms).toISOString() + (sg.openSince.fromCreated ? ' (opened)' : ''); // The shared Merge gate word hides 080 vs 095 vs 100; the chevron tooltip carries it. // With merge_gate in the payload the sentence is the gate's own @@ -14703,6 +14745,7 @@

Where to get help

else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr); const actorKind = stageTrackerActorKind(item); if (actorKind) lines.push('Next move: ' + actorKind); + if (typeof stageTrackerNewLines === 'function') lines.push(...stageTrackerNewLines(item, nowMs)); const blockedPR = mods.indexOf('blocked') >= 0 ? stageTrackerBlockedOnPR(item) : null; if (blockedPR) lines.push(blockedPR.tip); // Guarded: the test harnesses load helpers by name, and this one is additive. diff --git a/src/pkg/dashboard/webhook_tracker_refresh.go b/src/pkg/dashboard/webhook_tracker_refresh.go index 29a9ec50ca..62a38d7a05 100644 --- a/src/pkg/dashboard/webhook_tracker_refresh.go +++ b/src/pkg/dashboard/webhook_tracker_refresh.go @@ -360,6 +360,10 @@ func (s *Server) applyWebhookItemSnapshots(snaps []github.WebhookItemSnapshot) i s.statusMu.Unlock() return 0 } + // An open read no list carries is inserted — unless a remembered + // close for the same item is newer: that is the out-of-order + // `unlabeled` read after a `closed` one, not a reopen. + noInsert := s.webhookOpenReadsSupersededLocked(snaps) // Remembered before the lists are patched: a snapshot the governor is // building right now (from the enumeration its cycle began with) still // lists the item as it was, and will have these re-applied on publish. @@ -378,7 +382,11 @@ func (s *Server) applyWebhookItemSnapshots(snaps []github.WebhookItemSnapshot) i if snap.Open() && snapshotOlderThanListed(*repo, snap) { continue } - repoChanged += patchFrontendRepoItem(repo, snap) + n := patchFrontendRepoItem(repo, snap) + if n == 0 && snap.Open() && !noInsert[github.ItemPatchKey(snap.Repo, snap.Number, snap.IsPR)] { + n = insertFrontendRepoItem(repo, snap) + } + repoChanged += n } if repoChanged > 0 { recountRepoOpenItems(repo) @@ -430,6 +438,31 @@ func (s *Server) webhookPatchReplayWindow() time.Duration { // that is older than the remembered one (a `labeled` delivery's read landing // after the `closed` delivery's) cannot un-remember the close; a closed read // always replaces. Entries past the window or over the cap go. +// webhookOpenReadsSupersededLocked lists (statusMu held) the open reads in +// snaps that a remembered close for the same item outranks: a read with no +// timestamp, or one GitHub stamped no later than the close. Such a read +// may not re-list the item. +func (s *Server) webhookOpenReadsSupersededLocked(snaps []github.WebhookItemSnapshot) map[string]bool { + var out map[string]bool + for _, snap := range snaps { + if !snap.Open() || snap.Number <= 0 || snap.Repo == "" { + continue + } + key := github.ItemPatchKey(snap.Repo, snap.Number, snap.IsPR) + prev, ok := s.webhookPatches[key] + if !ok || prev.snap.Open() { + continue + } + if snap.UpdatedAt.IsZero() || !snap.UpdatedAt.After(prev.snap.UpdatedAt) { + if out == nil { + out = map[string]bool{} + } + out[key] = true + } + } + return out +} + func (s *Server) rememberWebhookPatchesLocked(snaps []github.WebhookItemSnapshot, now time.Time) { if s.webhookPatches == nil { s.webhookPatches = map[string]webhookPatchEntry{} @@ -490,7 +523,11 @@ func (s *Server) replayWebhookPatchesLocked(status *StatusPayload, now time.Time if held := frontendRepoItemUpdatedAt(*repo, snap.Number, snap.IsPR); !held.IsZero() && !snap.UpdatedAt.IsZero() && held.After(snap.UpdatedAt) { continue } - repoChanged += patchFrontendRepoItem(repo, snap) + n := patchFrontendRepoItem(repo, snap) + if n == 0 && snap.Open() { + n = insertFrontendRepoItem(repo, snap) + } + repoChanged += n } if repoChanged > 0 { recountRepoOpenItems(repo) @@ -529,8 +566,67 @@ func frontendRepoItemUpdatedAt(repo FrontendRepo, number int, isPR bool) time.Ti // patched item lists. Unlike reconcileRepoOpenItems it leaves the unlisted // remainder alone: an item a webhook took out was listed, not unlisted. func recountRepoOpenItems(r *FrontendRepo) { - counts := countOpenItems(repoOpenItems(*r)) + items := repoOpenItems(*r) + counts := countOpenItems(items) r.Issues, r.PRs = counts.Issues, counts.PRs + refitRepoWorkBreakdown(r, items, counts) +} + +// webhookUnclassifiedReason is the work-detail reason on an open item a +// webhook re-read brought in before any enumeration or classifier placed it. +const webhookUnclassifiedReason = "Opened on GitHub; not yet classified by the scanner" + +// insertFrontendRepoItem adds an open item none of repo's lists carry, so a +// brand-new issue or PR is in the status payload — and the activity +// monitor — from its `opened` delivery rather than from the governor's next +// publish (hivecommons/hive#15094). The governor-side classification rides +// on the snapshot: an actionable row joins the actionable list, a held row +// the held list, and anything sidelined (or unplaced) the sidelined list +// with the classifier's bucket or an "other" placeholder the next +// enumeration settles. Returns the number of entries added (0 or 1). +func insertFrontendRepoItem(repo *FrontendRepo, snap github.WebhookItemSnapshot) int { + if repo == nil || !snap.Open() || snap.Number <= 0 { + return 0 + } + full := overviewRepoName(*repo) + p := snap.Patch + if snap.IsPR { + switch { + case p.Bucket == github.WebhookBucketActionable && p.PR != nil: + repo.OpenPrs = append(append([]any(nil), repo.OpenPrs...), FrontendPR{PullRequest: *p.PR}) + case p.Bucket == github.WebhookBucketHeld && p.PR != nil: + repo.HeldPrs = append(append([]any(nil), repo.HeldPrs...), FrontendPR{PullRequest: *p.PR}) + case p.WorkPR != nil: + repo.NonActionablePrs = append(append([]any(nil), repo.NonActionablePrs...), *p.WorkPR) + default: + bucket := "other" + if snap.Draft { + bucket = "draft" + } + repo.NonActionablePrs = append(append([]any(nil), repo.NonActionablePrs...), github.RepoWorkPR{ + Repo: full, Number: snap.Number, Title: snap.Title, Author: snap.Author, + Labels: append([]string(nil), snap.Labels...), Draft: snap.Draft, + AppAuthored: snap.AppAuthored, HiveAttributed: snap.HiveAttributed, + UpdatedAt: snap.UpdatedAt, URL: snap.URL, Bucket: bucket, Reason: webhookUnclassifiedReason, + }) + } + return 1 + } + switch { + case p.Bucket == github.WebhookBucketActionable && p.Issue != nil: + repo.ActionableIssues = append(append([]any(nil), repo.ActionableIssues...), *p.Issue) + case p.Bucket == github.WebhookBucketHeld && p.Hold != nil: + repo.HeldIssues = append(append([]any(nil), repo.HeldIssues...), *p.Hold) + case p.WorkIssue != nil: + repo.NonActionableIssues = append(append([]any(nil), repo.NonActionableIssues...), *p.WorkIssue) + default: + repo.NonActionableIssues = append(append([]any(nil), repo.NonActionableIssues...), github.RepoWorkIssue{ + Repo: full, Number: snap.Number, Title: snap.Title, Author: snap.Author, + Labels: append([]string(nil), snap.Labels...), UpdatedAt: snap.UpdatedAt, URL: snap.URL, + Bucket: "other", Reason: webhookUnclassifiedReason, + }) + } + return 1 } // patchFrontendRepoItem rewrites every list entry of repo that names the diff --git a/src/pkg/dashboard/webhook_tracker_refresh_test.go b/src/pkg/dashboard/webhook_tracker_refresh_test.go index d50ae74f18..f7c91bc57e 100644 --- a/src/pkg/dashboard/webhook_tracker_refresh_test.go +++ b/src/pkg/dashboard/webhook_tracker_refresh_test.go @@ -187,8 +187,8 @@ func TestWebhookTrackerKeysFromEventResult(t *testing.T) { // TestApplyWebhookItemSnapshotsPatchesRowsAndInvalidatesTracker: the // re-read item's labels, title, draft flag and activity time replace the // snapshot's copy in every list that carries it (actionable, held, -// sidelined; value or pointer), a closed item leaves, an unknown item is -// left for the next cycle, readers of the old snapshot are unaffected, and +// sidelined; value or pointer), a closed item leaves, an unlisted open item +// is inserted as 000-new, readers of the old snapshot are unaffected, and // the tracker cache is dropped so the next GET shows the change. func TestApplyWebhookItemSnapshotsPatchesRowsAndInvalidatesTracker(t *testing.T) { now := time.Date(2026, 10, 20, 12, 0, 0, 0, time.UTC) @@ -252,14 +252,23 @@ func TestApplyWebhookItemSnapshotsPatchesRowsAndInvalidatesTracker(t *testing.T) if got106.Title != "Ready now" || hasMod(got106, modDraft) { t.Fatalf("sidelined draft 106 should now read as ready: %+v", got106) } + brandNew := false for _, it := range after.Items { if (it.Kind == "pr" && it.Number == 107) || (it.Kind == "issue" && it.Number == 21) { t.Fatalf("closed item still listed: %+v", it) } - if it.Number == 999 { - t.Fatal("an item the snapshot never listed must wait for the next cycle") + if it.Kind == "pr" && it.Number == 999 { + // hivecommons/hive#15094: an open item the snapshot never + // listed is inserted as a 000-new row, not left for the cycle. + brandNew = true + if it.StageSlug != StageTrackerNewSlug || it.New == nil { + t.Fatalf("brand-new PR = slug %q new %+v, want 000-new", it.StageSlug, it.New) + } } } + if !brandNew { + t.Fatal("an open item the snapshot never listed must be inserted from its re-read") + } if got20 := trackerItem(t, after, "issue", 20); got20.Title != "Held (renamed)" || len(got20.Labels) != 2 { t.Fatalf("held issue 20 = %+v", got20) } @@ -281,8 +290,11 @@ func TestApplyWebhookItemSnapshotsPatchesRowsAndInvalidatesTracker(t *testing.T) t.Fatalf("tracker_invalidations_1h = %d, want 1", snap.TrackerInvalidations1h) } - // Nothing matched: no publish, no invalidation. - s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{{Repo: "acme/console", Number: 4242, IsPR: true, State: "open"}}) + // Nothing matched (a repo the status does not carry): no publish, no + // invalidation. An open read for an unlisted item of a listed repo is + // no longer a no-op — it is inserted (hivecommons/hive#15094, + // TestWebhookOpenedItemInsertedIntoTracker). + s.applyWebhookItemSnapshots([]github.WebhookItemSnapshot{{Repo: "acme/elsewhere", Number: 4242, IsPR: true, State: "open"}}) s.statusMu.RLock() same := s.status == cur s.statusMu.RUnlock() diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index 9c90f1e21b..ffd79f14d7 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -1845,7 +1845,7 @@ func (c *Client) fetchIssues(ctx context.Context, repo string, now time.Time, re if !ra.AdmitsReporter(labels, safeGetLogin(issue.GetUser()), issue.GetAuthorAssociation()) { c.markReporterTrustAwaiting(ctx, repo, issue, labels, ra, reporterTrustWaitBudget) breakdown.ReporterTriage++ - details = append(details, repoWorkIssue(repo, issue, labels, workBucketReporterTriage, "Awaiting maintainer triage label")) + details = append(details, repoWorkIssue(repo, issue, labels, workBucketReporterTriage, reporterTriageAwaitingReason)) continue } labels = c.clearReporterTrustAwaiting(ctx, repo, issue, labels, ra) diff --git a/src/pkg/github/issue_stage_labels.go b/src/pkg/github/issue_stage_labels.go index 32832f5dd6..339a5ac082 100644 --- a/src/pkg/github/issue_stage_labels.go +++ b/src/pkg/github/issue_stage_labels.go @@ -141,6 +141,9 @@ const ( // trust gate holds until a maintainer adds the triage label // (stageengine.BucketReporterTriage). workBucketReporterTriage = string(stageengine.BucketReporterTriage) + // reporterTriageAwaitingReason is the work-detail note on an issue in + // that bucket, from the full pass and the webhook re-read alike. + reporterTriageAwaitingReason = "Awaiting maintainer triage label" ) // Triage evidence for stage/015-triage-needed (stagelabels.TriageNeeded): diff --git a/src/pkg/github/webhook_item_patch.go b/src/pkg/github/webhook_item_patch.go index cb587b9d0e..4114deff45 100644 --- a/src/pkg/github/webhook_item_patch.go +++ b/src/pkg/github/webhook_item_patch.go @@ -100,8 +100,13 @@ func (c *Client) classifyWebhookIssue(repo string, issue *gh.Issue, labels []str if ra, ok := issueFilter.(ReporterAdmitter); ok && ra.ReporterTrustEnabled() && authorIsHuman { if !ra.AdmitsReporter(labels, author, issue.GetAuthorAssociation()) { // The full pass parks the issue with a label write; a display - // read must not. Leave placement to the reconcile pass. - return WebhookItemPatch{Bucket: WebhookBucketUnknown} + // read must not. Placement of a listed row is left to the + // reconcile pass, but the row the pass would list (the + // reporter_triage bucket) rides along so a brand-new issue + // is visible from its `opened` delivery rather than from the + // next enumeration (hivecommons/hive#15094). + row := repoWorkIssue(repo, issue, labels, workBucketReporterTriage, reporterTriageAwaitingReason) + return WebhookItemPatch{Bucket: WebhookBucketUnknown, WorkIssue: &row} } } if !issueFilter.Admits(labels) { @@ -504,7 +509,23 @@ func (r *ActionableResult) applyWebhookItem(snap WebhookItemSnapshot) bool { } default: if !wasListed { - return false + // Unknown bucket, never listed: an `opened` delivery for an + // item the single read could not place. It is still an open + // item the hive is responsible for, so it enters the sidelined + // set with whatever row the classifier could offer rather than + // staying invisible until the next enumeration + // (hivecommons/hive#15094). + switch { + case !snap.IsPR && p.WorkIssue != nil: + r.addWorkIssue(repoKey, *p.WorkIssue) + case snap.IsPR && p.WorkPR != nil: + r.addWorkPR(repoKey, *p.WorkPR) + default: + return false + } + r.adjustRepoCount(repoKey, snap.IsPR, 1) + r.recount() + return true } // Unknown bucket: keep the row where it was, with fresh fields. return r.restoreUnknown(snap, prev) diff --git a/src/pkg/github/webhook_item_patch_new_test.go b/src/pkg/github/webhook_item_patch_new_test.go new file mode 100644 index 0000000000..6c3b73fa41 --- /dev/null +++ b/src/pkg/github/webhook_item_patch_new_test.go @@ -0,0 +1,64 @@ +package github + +import ( + "net/http" + "net/http/httptest" + "testing" + "time" + + gh "github.com/google/go-github/v72/github" +) + +// hivecommons/hive#15094: a human contributor's `issues.opened` delivery +// for an issue the reporter-trust gate does not yet admit must still carry +// the row the full pass would list (reporter_triage), so the governor's +// snapshot — and the activity monitor — show the issue from its first +// delivery rather than from the next enumeration. +func TestClassifyWebhookIssue_UnadmittedReporterCarriesTriageRow(t *testing.T) { + c := newTestClient(t, httptest.NewServer(http.NotFoundHandler()), "o", []string{"r"}) + c.SetIssueFilter(enabledReporterTrust()) + issue := &gh.Issue{Number: gh.Ptr(15092), State: gh.Ptr("open"), Title: gh.Ptr("Add a thing"), + User: &gh.User{Login: gh.Ptr("kanrenibm")}, AuthorAssociation: gh.Ptr("CONTRIBUTOR"), + Labels: []*gh.Label{{Name: gh.Ptr("enhancement")}, {Name: gh.Ptr("help wanted")}}, + CreatedAt: &gh.Timestamp{Time: time.Now().Add(-time.Minute)}} + p := c.classifyWebhookIssue("o/r", issue, issueLabelNames(issue.Labels), time.Now()) + if p.Bucket != WebhookBucketUnknown { + t.Fatalf("bucket = %q, want unknown (placement stays with the reconcile pass)", p.Bucket) + } + if p.WorkIssue == nil || p.WorkIssue.Bucket != workBucketReporterTriage || p.WorkIssue.Reason != reporterTriageAwaitingReason || p.WorkIssue.Number != 15092 { + t.Fatalf("work row = %+v, want a reporter_triage row for #15092", p.WorkIssue) + } +} + +// An unknown-bucket read for an item no list carries inserts the row the +// classifier offered into the sidelined set and counts it open; a read +// with nothing to offer stays a no-op. +func TestApplyWebhookItem_UnlistedUnknownInsertsOfferedRow(t *testing.T) { + r := patchFixture() + row := RepoWorkIssue{Repo: "org/repo", Number: 15092, Title: "Add a thing", Author: "kanrenibm", Labels: []string{"help wanted"}, Bucket: workBucketReporterTriage, Reason: reporterTriageAwaitingReason} + if !r.ApplyWebhookItem(WebhookItemSnapshot{Repo: "org/repo", Number: 15092, State: "open", Title: "Add a thing", Labels: []string{"help wanted"}, + Patch: WebhookItemPatch{Bucket: WebhookBucketUnknown, WorkIssue: &row}}) { + t.Fatal("an opened issue with an offered row must be inserted") + } + var got *RepoWorkIssue + for i, w := range r.WorkDetailsByRepo["org/repo"].Issues { + if w.Number == 15092 { + got = &r.WorkDetailsByRepo["org/repo"].Issues[i] + } + } + if got == nil || got.Bucket != workBucketReporterTriage { + t.Fatalf("sidelined rows = %+v, want #15092 in reporter_triage", r.WorkDetailsByRepo["org/repo"].Issues) + } + if r.TotalByRepo["org/repo"].Issues != 5 { + t.Fatalf("open count = %d, want 5 (the new issue counted once)", r.TotalByRepo["org/repo"].Issues) + } + if r.Issues.Count != 2 { + t.Fatalf("actionable count moved to %d; a reporter_triage row is not actionable", r.Issues.Count) + } + if r.ApplyWebhookItem(WebhookItemSnapshot{Repo: "org/repo", Number: 15093, State: "open", Title: "nothing offered"}) { + t.Fatal("an unknown read with no row to offer must stay a no-op") + } + if r.TotalByRepo["org/repo"].Issues != 5 { + t.Fatalf("no-op moved the count to %d", r.TotalByRepo["org/repo"].Issues) + } +}