From ab579aac5b55215fb8f448e2a348d472ea044ffd Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 10:20:51 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(dashboard):=20name=20the?= =?UTF-8?q?=20blocking=20PR=20on=20tracker=20rows=20and=20keep=20webhook?= =?UTF-8?q?=20unblocks=20from=20being=20overwritten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com> --- changelog.d/fixed-14952.md | 1 + src/cmd/hive/eval_cycle_source.go | 99 ++++++++-- src/cmd/hive/main.go | 5 +- .../reconcile_webhook_replay_14952_test.go | 119 ++++++++++++ src/cmd/hive/repos_rescan.go | 4 +- src/pkg/dashboard/stage_tracker.go | 15 +- .../dashboard/stage_tracker_blocked_on_pr.go | 66 +++++++ .../stage_tracker_blocked_on_pr_14952_test.go | 178 ++++++++++++++++++ src/pkg/dashboard/static/index.html | 48 ++++- src/pkg/github/client.go | 7 + src/pkg/github/issue_blocked.go | 19 ++ src/pkg/github/webhook_item_patch.go | 15 +- 12 files changed, 544 insertions(+), 32 deletions(-) create mode 100644 changelog.d/fixed-14952.md create mode 100644 src/cmd/hive/reconcile_webhook_replay_14952_test.go create mode 100644 src/pkg/dashboard/stage_tracker_blocked_on_pr.go create mode 100644 src/pkg/dashboard/stage_tracker_blocked_on_pr_14952_test.go diff --git a/changelog.d/fixed-14952.md b/changelog.d/fixed-14952.md new file mode 100644 index 0000000000..fecab4a718 --- /dev/null +++ b/changelog.d/fixed-14952.md @@ -0,0 +1 @@ +- The Activity Monitor's `blocked` pill now names and links the PR an issue is waiting on ("blocked on #N"), and an issue the hive unblocks no longer reverts to `blocked` when a reconcile pass that started before the unblock finishes after it. diff --git a/src/cmd/hive/eval_cycle_source.go b/src/cmd/hive/eval_cycle_source.go index 077a4a79bb..86b2ec7c23 100644 --- a/src/cmd/hive/eval_cycle_source.go +++ b/src/cmd/hive/eval_cycle_source.go @@ -86,37 +86,96 @@ type snapshotPatcher struct { // apply upserts each snapshot into the stored result and returns how many // changed it. No stored result (before the first enumeration) is a no-op: -// the first cycle lists everything anyway. +// the first cycle lists everything anyway. Each applied read is remembered +// on the published snapshot (WebhookReads) so a reconcile pass already in +// flight can replay it (publishReconciledSnapshot). The swap is a +// compare-and-swap: a reconcile result published meanwhile is patched +// rather than overwritten. func (p *snapshotPatcher) apply(snaps []github.WebhookItemSnapshot) int { if p == nil || p.target == nil || len(snaps) == 0 { return 0 } p.mu.Lock() defer p.mu.Unlock() - cur := p.target.Load() - if cur == nil { - return 0 - } - next := cur.Clone() - applied := 0 - for _, snap := range snaps { - if next.ApplyWebhookItem(snap) { - applied++ + for { + cur := p.target.Load() + if cur == nil { + return 0 + } + next := cur.Clone() + now := time.Now() + applied := 0 + for _, snap := range snaps { + if next.ApplyWebhookItem(snap) { + applied++ + if snap.FetchedAt.IsZero() { + snap.FetchedAt = now + } + next.WebhookReads = append(next.WebhookReads, snap) + } + } + if applied == 0 { + return 0 } + next.WebhookReads = pruneWebhookReads(next.WebhookReads, now.Add(-webhookReadReplayWindow)) + if !p.target.CompareAndSwap(cur, next) { + continue + } + if p.logger != nil { + p.logger.Info("webhook re-read patched the cached actionable snapshot", + "items", applied, "issues", next.Issues.Count, "prs", next.PRs.Count, "hold", next.Hold.Total, + "snapshot_age", time.Since(next.GeneratedAt).Round(time.Second).String()) + } + if p.onPatch != nil { + p.onPatch(applied) + } + return applied } - if applied == 0 { - return 0 +} + +// webhookReadReplayWindow bounds how long an applied webhook re-read is +// remembered for replay: far longer than any reconcile pass runs. +const webhookReadReplayWindow = 2 * time.Hour + +// pruneWebhookReads drops reads fetched before cutoff, into a fresh slice. +func pruneWebhookReads(reads []github.WebhookItemSnapshot, cutoff time.Time) []github.WebhookItemSnapshot { + var out []github.WebhookItemSnapshot + for _, r := range reads { + if !r.FetchedAt.Before(cutoff) { + out = append(out, r) + } } - p.target.Store(next) - if p.logger != nil { - p.logger.Info("webhook re-read patched the cached actionable snapshot", - "items", applied, "issues", next.Issues.Count, "prs", next.PRs.Count, "hold", next.Hold.Total, - "snapshot_age", time.Since(next.GeneratedAt).Round(time.Second).String()) + return out +} + +// publishReconciledSnapshot stores a reconcile pass's result. Webhook +// re-reads fetched after the pass started (passStart) describe a newer +// GitHub state than the pass may have listed — the hive's own `blocked` +// removal at 12:41 under a pass that listed at 12:38 — so they are replayed +// onto the result first (ApplyWebhookItem drops any the pass already saw a +// newer copy of) and kept on it for the next pass. Compare-and-swap, so a +// patch landing meanwhile is replayed too rather than lost +// (hivecommons/hive#14952). +func publishReconciledSnapshot(last *atomic.Pointer[github.ActionableResult], actionable *github.ActionableResult, passStart time.Time) { + if last == nil || actionable == nil { + return } - if p.onPatch != nil { - p.onPatch(applied) + for { + prev := last.Load() + var reads []github.WebhookItemSnapshot + if prev != nil { + for _, r := range prev.WebhookReads { + if r.FetchedAt.After(passStart) { + actionable.ApplyWebhookItem(r) + reads = append(reads, r) + } + } + } + actionable.WebhookReads = reads + if last.CompareAndSwap(prev, actionable) { + return + } } - return applied } // applyWebhookItemsFunc is the dashboard.Dependencies.ApplyWebhookItems hook. diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index a7b1a13aa7..a34bf2f3ad 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -7077,6 +7077,9 @@ func runEvalCycle( return } + // A reconcile pass replays webhook re-reads fetched after this instant + // onto its result before publishing it (publishReconciledSnapshot). + cycleStart := time.Now() budgetMode, _ := ghClient.APIBudgetMode() budgetDecision := decideEvalBudgetWork(budgetMode, cfg.Governor.OptionalSweepEveryNCycles, evalAPIBudgetCycle.Add(1)) @@ -7211,7 +7214,7 @@ func runEvalCycle( // on a copy, and storing it back would overwrite a webhook patch that // landed while the cycle ran. if cachedSnapshot == nil { - lastActionable.Store(actionable) + publishReconciledSnapshot(lastActionable, actionable, cycleStart) if data, err := json.Marshal(actionable); err == nil { atomicWrite(lastActionablePath, data) } diff --git a/src/cmd/hive/reconcile_webhook_replay_14952_test.go b/src/cmd/hive/reconcile_webhook_replay_14952_test.go new file mode 100644 index 0000000000..08be548101 --- /dev/null +++ b/src/cmd/hive/reconcile_webhook_replay_14952_test.go @@ -0,0 +1,119 @@ +package main + +import ( + "sync/atomic" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" +) + +// blockedIssueSnapshot is a reconcile pass's copy of org/repo#1 still +// parked as blocked, listed at listedAt. +func blockedIssueSnapshot(listedAt time.Time) *github.ActionableResult { + return &github.ActionableResult{ + GeneratedAt: listedAt, + TotalByRepo: map[string]github.RepoCounts{"org/repo": {Issues: 1}}, + WorkDetailsByRepo: map[string]github.RepoWorkDetails{"org/repo": {Issues: []github.RepoWorkIssue{{ + Repo: "org/repo", Number: 1, Title: "finding", Labels: []string{github.BlockedLabel}, + Bucket: "filtered", Reason: "blocked on org/repo#9", UpdatedAt: listedAt.Add(-6 * time.Hour), + }}}}, + } +} + +// unblockRead is the webhook re-read after the hive removed `blocked`. +func unblockRead(updatedAt, fetchedAt time.Time) github.WebhookItemSnapshot { + return github.WebhookItemSnapshot{ + Repo: "org/repo", Number: 1, State: "open", UpdatedAt: updatedAt, FetchedAt: fetchedAt, + Patch: github.WebhookItemPatch{Bucket: github.WebhookBucketActionable, Issue: &github.Issue{Repo: "org/repo", Number: 1, Title: "finding", UpdatedAt: updatedAt}}, + } +} + +func issueOneListedActionable(r *github.ActionableResult) bool { + for _, it := range r.Issues.Items { + if it.Repo == "org/repo" && it.Number == 1 { + return true + } + } + return false +} + +func issueOneSidelinedBlocked(r *github.ActionableResult) bool { + for _, it := range r.WorkDetailsByRepo["org/repo"].Issues { + if it.Number == 1 { + return true + } + } + return false +} + +// hivecommons/hive#14952: a reconcile pass that listed the issue before the +// hive's own unblock and finished after the webhook re-read patched the +// snapshot must not publish its pre-unblock copy over the patch. +func TestReconcilePassReplaysWebhookReadsFetchedAfterItStarted(t *testing.T) { + now := time.Now() + passStart := now.Add(-4 * time.Minute) + + var last atomic.Pointer[github.ActionableResult] + last.Store(blockedIssueSnapshot(now.Add(-30 * time.Minute))) + p := &snapshotPatcher{target: &last} + if p.apply([]github.WebhookItemSnapshot{unblockRead(now.Add(-time.Minute), now.Add(-time.Minute))}) != 1 { + t.Fatal("unblock re-read not applied") + } + if !issueOneListedActionable(last.Load()) || len(last.Load().WebhookReads) != 1 { + t.Fatalf("patched snapshot does not carry the unblock: %+v", last.Load().Issues) + } + + // The pass that started before the unblock now publishes its stale copy. + stale := blockedIssueSnapshot(passStart) + publishReconciledSnapshot(&last, stale, passStart) + + got := last.Load() + if !issueOneListedActionable(got) || issueOneSidelinedBlocked(got) { + t.Fatalf("reconcile pass overwrote the webhook unblock: issues=%+v work=%+v", got.Issues, got.WorkDetailsByRepo) + } + if len(got.WebhookReads) != 1 { + t.Fatalf("replayed read not kept for the next pass: %d", len(got.WebhookReads)) + } +} + +// A read fetched before the pass started is already covered by the pass's +// own listing, which stays authoritative. +func TestReconcilePassDoesNotReplayReadsOlderThanItsStart(t *testing.T) { + now := time.Now() + var last atomic.Pointer[github.ActionableResult] + last.Store(blockedIssueSnapshot(now.Add(-time.Hour))) + p := &snapshotPatcher{target: &last} + p.apply([]github.WebhookItemSnapshot{unblockRead(now.Add(-20*time.Minute), now.Add(-20*time.Minute))}) + + passStart := now.Add(-10 * time.Minute) + fresh := blockedIssueSnapshot(passStart) + publishReconciledSnapshot(&last, fresh, passStart) + + got := last.Load() + if got != fresh || !issueOneSidelinedBlocked(got) || issueOneListedActionable(got) { + t.Fatalf("pre-pass read replayed onto the reconcile result: %+v", got.Issues) + } + if len(got.WebhookReads) != 0 { + t.Fatalf("pre-pass reads must be dropped: %d", len(got.WebhookReads)) + } +} + +// A read whose updated_at is older than the pass's own copy is dropped by +// the monotonic guard even when fetched after the pass started. +func TestReconcilePassReplayKeepsNewerListedCopy(t *testing.T) { + now := time.Now() + passStart := now.Add(-4 * time.Minute) + var last atomic.Pointer[github.ActionableResult] + last.Store(&github.ActionableResult{GeneratedAt: now.Add(-time.Hour), TotalByRepo: map[string]github.RepoCounts{"org/repo": {}}}) + p := &snapshotPatcher{target: &last} + if p.apply([]github.WebhookItemSnapshot{unblockRead(now.Add(-8*time.Hour), now.Add(-time.Minute))}) != 1 { + t.Fatal("read not applied to a snapshot that never listed the item") + } + + fresh := blockedIssueSnapshot(passStart) + publishReconciledSnapshot(&last, fresh, passStart) + if got := last.Load(); !issueOneSidelinedBlocked(got) || issueOneListedActionable(got) { + t.Fatalf("older read replaced the pass's newer copy: %+v", got.Issues) + } +} diff --git a/src/cmd/hive/repos_rescan.go b/src/cmd/hive/repos_rescan.go index bf4bc3772a..e344fa66b6 100644 --- a/src/cmd/hive/repos_rescan.go +++ b/src/cmd/hive/repos_rescan.go @@ -6,6 +6,7 @@ import ( "errors" "log/slog" "sync/atomic" + "time" "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/github" @@ -53,6 +54,7 @@ func rescanRepos( return nil, errNoForgeCredentials } + passStart := time.Now() actionable, err := ghClient.EnumerateActionable(ctx) if err != nil { // Same tolerance as the eval cycle: on a hive whose issues come from a @@ -77,7 +79,7 @@ func rescanRepos( ghClient.EnrichLinkedIssueTitles(ctx, actionable.WorkDetailsByRepo, actionable.PRs.Items, actionable.PRs.Held, actionable.PRs.StaleDrafts) applyDuplicatePRGuard(ctx, cfg, ghClient, actionable, logger) - lastActionable.Store(actionable) + publishReconciledSnapshot(lastActionable, actionable, passStart) publishStageSharedCIIncidents(actionable) if data, marshalErr := json.Marshal(actionable); marshalErr == nil { atomicWrite(lastActionablePath, data) diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index c07319a62b..7cbc6f4152 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -340,10 +340,15 @@ type StageTrackerItem struct { // (scheduler.partitionBlockedIssues). Without it a sequenced sub-issue // read as plain Actionable nobody was picking up (hivecommons/hive#14765); // the row wears the `blocked` modifier and the caption names the wait. - BlockedOn []string `json:"blocked_on,omitempty"` - NudgeCount int `json:"nudge_count,omitempty"` - LastNudgeAt *time.Time `json:"last_nudge_at,omitempty"` - AdoptedBy int `json:"adopted_by,omitempty"` + BlockedOn []string `json:"blocked_on,omitempty"` + // BlockedOnPR names the pull request a `blocked` issue waits on, read + // from the review-backlog marker `` + // (or the enumeration's "blocked on owner/repo#N" reason), so the pill + // and caption say what lifts the block (hivecommons/hive#14952). + BlockedOnPR *StageTrackerBlockedOnPR `json:"blocked_on_pr,omitempty"` + NudgeCount int `json:"nudge_count,omitempty"` + LastNudgeAt *time.Time `json:"last_nudge_at,omitempty"` + AdoptedBy int `json:"adopted_by,omitempty"` // ClaimantKind is the author kind of whoever holds the live claim on a // claimed issue (human / clanker / hive), from the worker-claim ledger. ClaimantKind string `json:"claimant_kind,omitempty"` @@ -1462,6 +1467,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) if it.Stage == trackerNumberClaimed { it.ClaimantKind = s.stageTrackerClaimantKind(repoName, issue.Number) } @@ -1536,6 +1542,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto } } resp.OpenIssues, resp.OpenPRs = stageTrackerOpenCounts(resp.Items) + stageTrackerResolveBlockedOnPRState(resp.Items, resp.RecentlyMerged) stageTrackerResolveLinkedPRs(resp.Items) sort.SliceStable(resp.Items, stageTrackerLess(resp.Items)) return resp diff --git a/src/pkg/dashboard/stage_tracker_blocked_on_pr.go b/src/pkg/dashboard/stage_tracker_blocked_on_pr.go new file mode 100644 index 0000000000..7b661cf258 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_blocked_on_pr.go @@ -0,0 +1,66 @@ +package dashboard + +import ( + "slices" + "strconv" + "strings" + + "github.com/hivecommons/hive/pkg/github" +) + +// StageTrackerBlockedOnPR is the pull request a `blocked` issue waits on +// (hivecommons/hive#14952). State is "open" or "merged" when the hive's own +// caches know it (the status snapshot's open PRs, which the forgestate +// overlay feeds, and the recent-merge ring); "" when they do not. No GitHub +// call is ever made to fill it. +type StageTrackerBlockedOnPR struct { + Repo string `json:"repo"` + Number int `json:"number"` + URL string `json:"url,omitempty"` + State string `json:"state,omitempty"` +} + +// stageTrackerBlockedOnPR names the PR a `blocked` issue waits on, from the +// review-backlog marker in its body when the row carries one, else from the +// enumeration's filtered reason or the stage reason ("blocked on +// owner/repo#N"). The caption then says what lifts the block instead of +// "No stage recorded yet". +func stageTrackerBlockedOnPR(it *StageTrackerItem, body, bucketReason, githubBaseURL string) { + if it == nil || it.Kind != "issue" || !slices.ContainsFunc(it.Labels, func(l string) bool { return strings.EqualFold(strings.TrimSpace(l), github.BlockedLabel) }) { + return + } + repo, number, ok := github.ParseBlockedOnMarker(body) + if !ok { + repo, number, ok = github.ParseBlockedFilterReason(bucketReason) + } + if !ok { + repo, number, ok = github.ParseBlockedFilterReason(it.Reason) + } + if !ok { + return + } + it.BlockedOnPR = &StageTrackerBlockedOnPR{Repo: repo, Number: number, URL: overviewItemURL("", repo, number, "pr", githubBaseURL)} + it.Caption = "Blocked on PR " + stageTrackerBlockerList(it.Repo, []string{repo + "#" + strconv.Itoa(number)}) + " — lifts when it merges" + it.Actor = "its blocking PR" +} + +// stageTrackerResolveBlockedOnPRState fills each BlockedOnPR's state from +// what the response already holds: a PR listed as a row is open, one in the +// recent-merge ring merged. +func stageTrackerResolveBlockedOnPRState(items []StageTrackerItem, merged []StageTrackerMerged) { + key := func(repo string, number int) string { return strings.ToLower(repo) + "#" + strconv.Itoa(number) } + state := map[string]string{} + for _, it := range items { + if it.Kind == "pr" { + state[key(it.Repo, it.Number)] = "open" + } + } + for _, m := range merged { + state[key(m.Repo, m.Number)] = "merged" + } + for i := range items { + if b := items[i].BlockedOnPR; b != nil { + b.State = state[key(b.Repo, b.Number)] + } + } +} diff --git a/src/pkg/dashboard/stage_tracker_blocked_on_pr_14952_test.go b/src/pkg/dashboard/stage_tracker_blocked_on_pr_14952_test.go new file mode 100644 index 0000000000..fc087003c8 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_blocked_on_pr_14952_test.go @@ -0,0 +1,178 @@ +package dashboard + +import ( + "os/exec" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" +) + +// A `blocked` issue parked on an unmerged PR names it: the review-backlog +// marker (or the enumeration's "blocked on owner/repo#N" reason) becomes +// blocked_on_pr, its state comes from what the hive already holds, and the +// caption says what lifts the block instead of "No stage recorded yet" +// (hivecommons/hive#14952). +func TestStageTrackerBlockedOnPRNamesTheBlocker(t *testing.T) { + now := time.Date(2026, 10, 28, 13, 18, 0, 0, time.UTC) + s := newTestServer() + status := minimalPayload() + status.Repos = []FrontendRepo{{ + Name: "hive", Full: "hivecommons/hive", + ActionableIssues: []any{ + github.Issue{Number: 14863, Title: "Review backlog: body marker", Author: "hive-app[bot]", Labels: []string{"blocked"}, + Body: "**Blocked on PR #14862.**\n\n" + github.BlockedOnMarker("hivecommons/hive", 14862)}, + github.Issue{Number: 14870, Title: "Bare blocked label", Author: "pat", AuthorIsHuman: true, Labels: []string{"blocked"}}, + github.Issue{Number: 14871, Title: "Marker without the label", Author: "pat", AuthorIsHuman: true, Labels: []string{"stage/010-actionable"}, + Body: github.BlockedOnMarker("hivecommons/hive", 14862)}, + }, + OpenPrs: []any{ + FrontendPR{PullRequest: github.PullRequest{Number: 14862, Title: "The blocker", Author: "pat", Labels: []string{"stage/050-review-pending"}}}, + }, + NonActionableIssues: []any{ + github.RepoWorkIssue{Repo: "hivecommons/hive", Number: 14867, Title: "Review backlog: filtered reason", Labels: []string{"blocked"}, + Bucket: "filtered", Reason: "blocked on hivecommons/crux#77"}, + }, + }} + s.UpdateStatus(status) + resp := s.buildStageTracker(s.status, s.stageStore, now) + + body := trackerItem(t, resp, "issue", 14863) + if body.BlockedOnPR == nil { + t.Fatalf("#14863 blocked_on_pr missing (mods %v caption %q)", body.Modifiers, body.Caption) + } + if got := *body.BlockedOnPR; got.Repo != "hivecommons/hive" || got.Number != 14862 || got.URL != "https://github.com/hivecommons/hive/pull/14862" || got.State != "open" { + t.Errorf("#14863 blocked_on_pr = %+v, want hivecommons/hive#14862 open with its PR URL", got) + } + if body.Caption != "Blocked on PR #14862 — lifts when it merges" { + t.Errorf("#14863 caption = %q", body.Caption) + } + if !hasMod(body, modBlocked) || len(body.BlockedOn) != 0 { + t.Errorf("#14863 mods %v blocked_on %v: the label pill stays, the dependency list untouched", body.Modifiers, body.BlockedOn) + } + + reason := trackerItem(t, resp, "issue", 14867) + if reason.BlockedOnPR == nil || reason.BlockedOnPR.Repo != "hivecommons/crux" || reason.BlockedOnPR.Number != 77 || reason.BlockedOnPR.State != "" { + t.Errorf("#14867 blocked_on_pr = %+v, want hivecommons/crux#77 with unknown state (no GitHub call)", reason.BlockedOnPR) + } + if reason.Caption != "Blocked on PR hivecommons/crux#77 — lifts when it merges" { + t.Errorf("#14867 caption = %q", reason.Caption) + } + + if bare := trackerItem(t, resp, "issue", 14870); bare.BlockedOnPR != nil { + t.Errorf("#14870 with no marker = %+v, want none", bare.BlockedOnPR) + } + if unlabelled := trackerItem(t, resp, "issue", 14871); unlabelled.BlockedOnPR != nil { + t.Errorf("#14871 without the blocked label = %+v, want none (the sweep already lifted it)", unlabelled.BlockedOnPR) + } +} + +func TestStageTrackerBlockedOnPRStateFromMergeRing(t *testing.T) { + items := []StageTrackerItem{ + {Repo: "o/r", Number: 1, Kind: "issue", BlockedOnPR: &StageTrackerBlockedOnPR{Repo: "o/r", Number: 9}}, + {Repo: "o/r", Number: 2, Kind: "issue", BlockedOnPR: &StageTrackerBlockedOnPR{Repo: "O/R", Number: 10}}, + {Repo: "o/r", Number: 10, Kind: "pr"}, + } + stageTrackerResolveBlockedOnPRState(items, []StageTrackerMerged{{Repo: "o/r", Number: 9}}) + if items[0].BlockedOnPR.State != "merged" || items[1].BlockedOnPR.State != "open" { + t.Errorf("states = %q, %q; want merged, open", items[0].BlockedOnPR.State, items[1].BlockedOnPR.State) + } +} + +func TestParseBlockedFilterReason(t *testing.T) { + for _, c := range []struct { + in string + repo string + n int + ok bool + }{ + {"blocked on hivecommons/hive#14862", "hivecommons/hive", 14862, true}, + {"blocked", "", 0, false}, + {"blocked until 2026-10-28T12:00:00Z", "", 0, false}, + {"blocked on #5", "", 0, false}, + {"blocked on o/r#x", "", 0, false}, + } { + repo, n, ok := github.ParseBlockedFilterReason(c.in) + if repo != c.repo || n != c.n || ok != c.ok { + t.Errorf("ParseBlockedFilterReason(%q) = %q, %d, %v", c.in, repo, n, ok) + } + } +} + +// The pill reads "blocked on #N", links to the PR, and its tooltip, the row +// tooltip and the chevron tip all name the PR and what lifts the block. +func TestStageTrackerBlockedOnPRJS(t *testing.T) { + html := indexHTML(t) + for _, snippet := range []string{ + "function stageTrackerBlockedOnPRRef(item) {", + "function stageTrackerBlockedOnPRTip(item) {", + "' — lifts when it merges; re-triage if closed unmerged'", + `blocked on #14862'), chip); +assert.ok(chip.includes('href="https://github.com/hivecommons/hive/pull/14862"'), chip); +assert.ok(chip.includes('title="' + want + '"') && chip.includes('aria-label="' + want + '"'), chip); +const tip = stageTrackerTooltip(item, Date.now()); +assert.ok(tip.includes('Blocked on PR #14862 — lifts when it merges'), tip); +assert.ok(tip.includes(want), tip); +assert.strictEqual(stageTrackerBlockedTip(item), 'blocked on PR #14862'); + +const foreign = Object.assign({}, item, { blocked_on_pr: { repo: 'hivecommons/crux', number: 77, url: 'https://github.com/hivecommons/crux/pull/77' } }); +assert.ok(stageTrackerChipsHtml(foreign).includes('>blocked on hivecommons/crux#77')); +assert.strictEqual(stageTrackerBlockedOnPRTip(foreign), 'Blocked on PR hivecommons/crux#77 — lifts when it merges; re-triage if closed unmerged'); + +const bare = { kind: 'issue', repo: 'hivecommons/hive', number: 14870, stage: 0, modifiers: ['blocked'], labels: ['blocked'] }; +assert.ok(/^blocked<\/span>$/.test(stageTrackerChipsHtml(bare)), stageTrackerChipsHtml(bare)); +assert.strictEqual(stageTrackerBlockedTip(bare), 'carries the blocked label'); +` + if out, err := exec.Command(node, "-e", script).CombinedOutput(); err != nil { + t.Fatalf("blocked-on-PR pill check failed: %v\n%s", err, out) + } +} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 9b41d09395..0093474729 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1486,6 +1486,9 @@ /* hive:unauthorized — the App lacks a permission for the next step; muted, never red: a person must take the step. */ .ham-badge-mod.ham-mod-unauthorized { color: var(--text-muted); border-color: var(--line-subtle); border-style: dashed; } .ham-badge-mod.ham-mod-possible-dupe { color: var(--purple); border-color: color-mix(in srgb, var(--purple) 45%, transparent); } + /* "blocked on #N": the blocked pill links to the PR it waits on (hivecommons/hive#14952). */ + a.ham-badge-mod.ham-blocked-on-pr { text-decoration: none; } + a.ham-badge-mod.ham-blocked-on-pr:hover { color: var(--text); } /* Sentinel-flagged PR, #13535 follow-up: the chip beside needs rebase / regressed, and the human-decision chevron itself when its word reads "Sentinel alert · needs human". Danger-tinted from the @@ -13998,11 +14001,36 @@

Where to get help

// The Open · blocked chevron's reason: the blocker when the payload names // one (`blocked_on`: "owner/repo#N" or a list of them), else the label. function stageTrackerBlockedTip(item) { + const pr = typeof stageTrackerBlockedOnPRRef === 'function' ? stageTrackerBlockedOnPRRef(item) : ''; + if (pr) return 'blocked on PR ' + pr; const on = item && item.blocked_on; const refs = (Array.isArray(on) ? on : (on ? [on] : [])).map(r => String(r || '').trim()).filter(Boolean); return refs.length ? 'blocked on ' + refs.join(', ') : 'carries the blocked label'; } + // The PR a `blocked` issue waits on (`blocked_on_pr`, from the + // review-backlog marker; hivecommons/hive#14952): "#N" in the row's own + // repo, else "owner/repo#N"; '' when the payload names none. + function stageTrackerBlockedOnPRRef(item) { + const b = item && item.blocked_on_pr; + const n = b ? Number(b.number) || 0 : 0; + if (!n) return ''; + const repo = String(b.repo || '').trim(); + const own = !repo || repo.toLowerCase() === String(item.repo || '').trim().toLowerCase(); + return (own ? '' : repo) + '#' + n; + } + + // Hover / aria text for that PR: what blocks the row, the PR's state + // when the hive knows it, and what lifts the block. + function stageTrackerBlockedOnPRTip(item) { + const b = item && item.blocked_on_pr; + const n = b ? Number(b.number) || 0 : 0; + if (!n) return ''; + const repo = String(b.repo || '').trim(); + const state = String(b.state || '').trim(); + return 'Blocked on PR ' + repo + '#' + n + (state ? ' (' + state + ')' : '') + ' — lifts when it merges; re-triage if closed unmerged'; + } + // "Sentinel flagged security-relevant changes at : // " — the sentinel wording for an item's tooltips and aria // labels; '' when the item carries no alert. Without a reason or a @@ -14307,6 +14335,8 @@

Where to get help

if (item.origin) lines.push('Origin: origin/' + item.origin); if (item.kind === 'issue' && Array.isArray(item.linked_prs) && item.linked_prs.length) lines.push('Covering PR: ' + item.linked_prs.map(lp => Number(lp.number) || 0).sort((x, y) => x - y).map(n => '#' + n).join(', ')); else if (item.kind === 'issue' && item.linked_pr) lines.push('Covering PR: #' + item.linked_pr); + const blockedOnPR = typeof stageTrackerBlockedOnPRTip === 'function' ? stageTrackerBlockedOnPRTip(item) : ''; + if (blockedOnPR) lines.push(blockedOnPR); const actorKind = stageTrackerActorKind(item); if (actorKind) lines.push('Next move: ' + actorKind); if (mods.length) lines.push('Flags: ' + mods.map(m => STAGE_TRACKER_MOD_TEXT[m] || m).join(', ')); @@ -14342,6 +14372,11 @@

Where to get help

let text = handled && mods[0] === 'regressed' ? STAGE_TRACKER_HANDLED_TEXT : (STAGE_TRACKER_MOD_TEXT[mods[0]] || mods[0].replace(/-/g, ' ')); // A row the scheduler withholds for open GitHub "blocked by" dependencies names them (hivecommons/hive#14765). if (mods[0] === 'blocked' && Array.isArray(item.blocked_on) && item.blocked_on.length) text = stageTrackerBlockedTip(item); + // A row parked on an unmerged PR (the review-backlog marker) names it and links to it (hivecommons/hive#14952). + const blockedPR = mods[0] === 'blocked' && typeof stageTrackerBlockedOnPRRef === 'function' ? stageTrackerBlockedOnPRRef(item) : ''; + const blockedPRTip = blockedPR ? stageTrackerBlockedOnPRTip(item) : ''; + const blockedPRURL = blockedPR ? String((item.blocked_on_pr && item.blocked_on_pr.url) || '') : ''; + if (blockedPR) text = 'blocked on ' + blockedPR; // A blocked row with a hive:recheck-after deadline ("blocked until ") names when the sweep re-checks it. const recheck = mods[0] === 'blocked' ? /^blocked until (\S+)/i.exec(String(item.bucket_reason || '')) : null; const recheckMs = recheck ? Date.parse(recheck[1]) : NaN; @@ -14349,14 +14384,17 @@

Where to get help

// The regressed pill (lead or folded into "+1") explains itself on // hover; failing that, a draft pill (lead or folded) does. const regressed = stageTrackerRegressionText(item, Date.now()); - // An unauthorized pill names the missing App permission and the human step; - // the regressed pill explains itself; a blocked pill names what it waits on; - // failing all three, a draft pill does. - const tip = (mods.indexOf('unauthorized') >= 0 && String(item.unauthorized || '').trim()) || regressed + // A blocked-on-PR pill names the PR and what lifts it; an unauthorized + // pill names the missing App permission and the human step; the + // regressed pill explains itself; a blocked pill names what it waits + // on; failing all of those, a draft pill does. + const tip = blockedPRTip || (mods.indexOf('unauthorized') >= 0 && String(item.unauthorized || '').trim()) || regressed || (mods.indexOf('blocked') >= 0 && Array.isArray(item.blocked_on) && item.blocked_on.length ? 'Withheld from the scanner until ' + item.blocked_on.join(', ') + (item.blocked_on.length > 1 ? ' close' : ' closes') : '') || (mods.indexOf('draft') >= 0 ? STAGE_TRACKER_DRAFT_TIP : ''); const cls = 'ham-mod-' + mods[0] + (handled && mods[0] === 'regressed' ? ' ham-mod-handled' : ''); - return sentinel + `${esc(text)}${mods.length > 1 ? ' +' + (mods.length - 1) : ''}`; + const more = mods.length > 1 ? ' +' + (mods.length - 1) : ''; + if (blockedPRURL) return sentinel + `${esc(text)}${more}`; + return sentinel + `${esc(text)}${more}`; } // Ghost strip for a title line: the lead cell (Open..Claimed) carries diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index eb3f4317ce..a76ae27cce 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -1132,6 +1132,13 @@ type ActionableResult struct { // it, since GeneratedAt then says nothing about an item's age. Keyed by // ItemPatchKey. ItemPatches map[string]ItemPatchMeta `json:"item_patches,omitempty"` + // WebhookReads are the webhook re-reads the governor has patched onto + // this snapshot, each stamped with its FetchedAt. A reconcile pass that + // started before a read and finishes after it replays the newer reads + // onto its own result before publishing, so its pre-read copy of the + // item never overwrites the patch (hivecommons/hive#14952). In-memory + // only; never persisted. + WebhookReads []WebhookItemSnapshot `json:"-"` } // ItemPatchMeta is the audit record of one webhook-driven upsert. diff --git a/src/pkg/github/issue_blocked.go b/src/pkg/github/issue_blocked.go index 86f6fe14ff..25aa187244 100644 --- a/src/pkg/github/issue_blocked.go +++ b/src/pkg/github/issue_blocked.go @@ -124,6 +124,25 @@ func blockedFilterReason(body string) string { return blockedFilterReasonPrefix } +// ParseBlockedFilterReason reads the PR back out of a blocked issue's +// filtered reason ("blocked on owner/repo#N", blockedFilterReason), for a +// reader that holds the enumeration's row but not the issue body. +func ParseBlockedFilterReason(reason string) (repo string, pr int, ok bool) { + rest, found := strings.CutPrefix(strings.TrimSpace(reason), blockedFilterReasonPrefix+" on ") + if !found { + return "", 0, false + } + r, num, found := strings.Cut(strings.TrimSpace(rest), "#") + if !found || !strings.Contains(r, "/") { + return "", 0, false + } + n, err := strconv.Atoi(num) + if err != nil || n <= 0 { + return "", 0, false + } + return r, n, true +} + // blockedRecheck reads a blocked issue's recheck-after deadline (zero when // absent) and whether the body carries the ops-tracking marker. func blockedRecheck(body string) (time.Time, bool) { diff --git a/src/pkg/github/webhook_item_patch.go b/src/pkg/github/webhook_item_patch.go index ff94f0fe55..4b282b6479 100644 --- a/src/pkg/github/webhook_item_patch.go +++ b/src/pkg/github/webhook_item_patch.go @@ -222,6 +222,7 @@ func (r *ActionableResult) Clone() *ActionableResult { out.PRs.Attributed = append([]PullRequest(nil), r.PRs.Attributed...) out.Hold.Items = append([]HoldItem(nil), r.Hold.Items...) out.StaleRepos = append([]string(nil), r.StaleRepos...) + out.WebhookReads = append([]WebhookItemSnapshot(nil), r.WebhookReads...) if r.ItemPatches != nil { out.ItemPatches = make(map[string]ItemPatchMeta, len(r.ItemPatches)) for k, v := range r.ItemPatches { @@ -320,7 +321,9 @@ func (r *ActionableResult) olderThanHeld(snap WebhookItemSnapshot) bool { } // heldUpdatedAt is the updated_at of the listed copy of an item, zero when -// the item is not listed or the list has no timestamp for it. +// the item is not listed or the list has no timestamp for it. A sidelined +// copy (WorkDetailsByRepo: a blocked or filtered issue, a draft PR) counts +// too, so a replayed read never moves it backwards either. func (r *ActionableResult) heldUpdatedAt(repo string, number int, isPR bool) time.Time { if isPR { for _, list := range [][]PullRequest{r.PRs.Items, r.PRs.Held} { @@ -330,6 +333,11 @@ func (r *ActionableResult) heldUpdatedAt(repo string, number int, isPR bool) tim } } } + for _, pr := range r.WorkDetailsByRepo[r.repoKeyFor(repo)].PRs { + if sameItem(pr.Repo, pr.Number, repo, number) { + return pr.UpdatedAt + } + } return time.Time{} } for _, issue := range r.Issues.Items { @@ -337,6 +345,11 @@ func (r *ActionableResult) heldUpdatedAt(repo string, number int, isPR bool) tim return issue.UpdatedAt } } + for _, issue := range r.WorkDetailsByRepo[r.repoKeyFor(repo)].Issues { + if sameItem(issue.Repo, issue.Number, repo, number) { + return issue.UpdatedAt + } + } return time.Time{} } From 2b1f7f8e9e622c06aa15507b7fe1ad55bda9019b Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 10:28:50 -0400 Subject: [PATCH 2/2] docs: refresh scale-envelope citation after client.go shift Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/docs/scale-envelope.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/scale-envelope.md b/src/docs/scale-envelope.md index 18757a3851..95a129e86a 100644 --- a/src/docs/scale-envelope.md +++ b/src/docs/scale-envelope.md @@ -34,7 +34,7 @@ ones to: 2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.** This holds today and is easy to assume backwards: - Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied - (`RankActionableIssues`, `src/pkg/github/client.go:4759-4769`, descending `AgeMinutes`). + (`RankActionableIssues`, `src/pkg/github/client.go:4766-4776`, descending `AgeMinutes`). - PRs are sorted by **review class then oldest-first within class** (`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`; fixes → refactors/docs → tests).