diff --git a/changelog.d/fixed-16420-standby-lane-count.md b/changelog.d/fixed-16420-standby-lane-count.md new file mode 100644 index 0000000000..a4afbd2c99 --- /dev/null +++ b/changelog.d/fixed-16420-standby-lane-count.md @@ -0,0 +1 @@ +- Count standby qualification against the same lane-specific dispatchable queue used by standby dispatch. diff --git a/src/docs/design/standby-contributors.md b/src/docs/design/standby-contributors.md index 903baeefbc..6a69644ab8 100644 --- a/src/docs/design/standby-contributors.md +++ b/src/docs/design/standby-contributors.md @@ -723,8 +723,9 @@ meets the list, and it is where the proposal stops: it is carried for logging and decides nothing. The no-writer guard that protects the floor was widened to cover the list's key (`TestStandbyItemTiersHaveNoWriterOutsideConfig`), so no surface may name it, let alone write it. The tile's "M qualify" counts -contributors who could be offered at least one item queued on the lane, from -the same per-lane split `buildLaneQueueDepths` uses for the N beside it. +contributors who could be offered at least one item from the dispatchable +admission queue routed to the lane; it uses that exact lane assignment rather +than the broader lane-depth split. ### S8 — Automatic dispatch, opt-in per lane diff --git a/src/pkg/dashboard/contribute_ws.go b/src/pkg/dashboard/contribute_ws.go index b599f541a1..5661ce2428 100644 --- a/src/pkg/dashboard/contribute_ws.go +++ b/src/pkg/dashboard/contribute_ws.go @@ -3134,22 +3134,21 @@ func standbyProposeItemTier(item standbypkg.Item) standbypkg.Tier { return standbypkg.NormalizeTier(classify.ProposeStandbyItemTierFromLabels(item.Labels).Tier) } -// standbyLaneItems projects the hive's actionable queue into the per-lane item -// lists QualifiedStandbyCounts takes. The lane split mirrors -// buildLaneQueueDepths so the M in "N waiting, M qualify" is counted over the -// same items as the N. -func standbyLaneItems(lanes []string, actionable *ghpkg.ActionableResult) map[string][]standbypkg.Item { - if len(lanes) == 0 || actionable == nil { +// standbyLaneItems projects the dispatchable admission queue into the per-lane +// item lists QualifiedStandbyCounts takes. Its lane and held-item filters match +// standbyDispatchItem so the tile counts only work dispatch can offer. +func standbyLaneItems(lanes []string, queue []ReadyQueueItem) map[string][]standbypkg.Item { + if len(lanes) == 0 || queue == nil { return nil } out := make(map[string][]standbypkg.Item, len(lanes)) for _, lane := range lanes { - items := make([]standbypkg.Item, 0, len(actionable.Issues.Items)) - for _, issue := range actionable.Issues.Items { - if lane != "scanner" && issue.Lane != lane && issue.Lane != "" { + items := make([]standbypkg.Item, 0, len(queue)) + for _, item := range queue { + if item.Held || !strings.EqualFold(strings.TrimSpace(item.Lane), lane) { continue } - items = append(items, standbypkg.Item{Repo: issue.Repo, Labels: issue.Labels}) + items = append(items, standbypkg.Item{Repo: item.Repo, Labels: item.Labels}) } out[lane] = items } diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index 814cbb931d..eb32691b1b 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -2424,16 +2424,12 @@ func (s *Server) UpdateStatusIfFresh(status *StatusPayload, buildEpoch uint64) b status.ContributorPool = s.BuildContributorPoolStatus() status.Inception = s.buildFrontendInception() if s.contributeHub != nil { - // The paused lanes' own queues, so the count honours item tiers - // (RFC #7629 S7). Nil when no enumeration has run yet, which is only - // visible on a hive whose owner has written an item-tier list. - var actionable *github.ActionableResult - if s.deps != nil && s.deps.Scheduler != nil { - actionable = s.deps.Scheduler.GetLastActionable() - } + // Use the admission queue that standby dispatch reads, so qualification + // counts cannot include work assigned to another lane or held from dispatch. + queue := s.contributeHub.admissionQueueSnapshot(readyQueueDefaultLimit, withheldNone).queue status.Governor.QualifiedStandbys = s.contributeHub.QualifiedStandbyCounts( status.Governor.SuppressedLanes, - standbyLaneItems(status.Governor.SuppressedLanes, actionable)) + standbyLaneItems(status.Governor.SuppressedLanes, queue)) status.Governor.SuspendedStandbys = s.contributeHub.SuspendedStandbyCounts(status.Governor.SuppressedLanes) } status.Swarm = s.SwarmSnapshot() diff --git a/src/pkg/dashboard/standby_qualified_test.go b/src/pkg/dashboard/standby_qualified_test.go index dc0bd07ae6..6904544a45 100644 --- a/src/pkg/dashboard/standby_qualified_test.go +++ b/src/pkg/dashboard/standby_qualified_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/hivecommons/hive/pkg/config" - "github.com/hivecommons/hive/pkg/github" standbypkg "github.com/hivecommons/hive/pkg/standby" ) @@ -133,29 +132,29 @@ func TestQualifiedStandbyCountsHonourItemTiers(t *testing.T) { } } -// TestStandbyLaneItemsSplitsTheQueueByLane covers what feeds the count on a -// live hub: each lane's share of the hive's actionable queue, split the same -// way buildLaneQueueDepths splits it, so the M and the N beside it are counted -// over the same items. -func TestStandbyLaneItemsSplitsTheQueueByLane(t *testing.T) { - actionable := &github.ActionableResult{} - actionable.Issues.Items = []github.Issue{ - {Repo: "my-org/repo-a", Lane: "quality", Labels: []string{"dependencies"}}, +// TestStandbyLaneItemsUsesDispatchableQueue verifies the tile counts only +// unheld admission items that standby dispatch can select for each lane. +func TestStandbyLaneItemsUsesDispatchableQueue(t *testing.T) { + queue := []ReadyQueueItem{ {Repo: "my-org/repo-a", Lane: "architect", Labels: []string{"rfc"}}, - {Repo: "my-org/repo-b", Lane: "", Labels: []string{"kind/bug"}}, + {Repo: "my-org/repo-b", Lane: "guide", Labels: []string{"dependencies"}}, + {Repo: "my-org/repo-b", Lane: "scanner", Labels: []string{"kind/security"}, Held: true}, } - items := standbyLaneItems([]string{"quality", "architect"}, actionable) - if len(items["quality"]) != 2 { - t.Errorf("quality items = %v, want its own issue and the unrouted one", items["quality"]) + items := standbyLaneItems([]string{"scanner", "guide", "architect"}, queue) + if len(items["scanner"]) != 0 { + t.Errorf("scanner items = %v, want no dispatchable items", items["scanner"]) } - if len(items["architect"]) != 2 { - t.Errorf("architect items = %v, want its own issue and the unrouted one", items["architect"]) + if len(items["guide"]) != 1 { + t.Errorf("guide items = %v, want only its dispatchable issue", items["guide"]) } - if got := items["quality"][0].Labels; len(got) != 1 || got[0] != "dependencies" { + if len(items["architect"]) != 1 { + t.Errorf("architect items = %v, want only its dispatchable issue", items["architect"]) + } + if got := items["guide"][0].Labels; len(got) != 1 || got[0] != "dependencies" { t.Errorf("labels were not carried: %v", got) } - if standbyLaneItems(nil, actionable) != nil || standbyLaneItems([]string{"quality"}, nil) != nil { - t.Error("standbyLaneItems must be nil when there is no lane or no enumeration to project") + if standbyLaneItems(nil, queue) != nil || standbyLaneItems([]string{"guide"}, nil) != nil { + t.Error("standbyLaneItems must be nil when there are no lanes or no queue") } }