From b1ff271e117d150d0b1dcd037b32aeec513369d3 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 09:10:27 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20advisory=20checklists?= =?UTF-8?q?=20resolve=20themselves=20and=20never=20park=20on=20a=20person?= 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> --- ...xed-15754-advisory-checklists-autoclose.md | 1 + .../close_on_merge_advisory_autoclose_test.go | 27 +++ src/cmd/hive/close_on_merge_sweep.go | 2 + .../dashboard-sections/activity-monitor.md | 2 + .../labels-and-control-signals/reference.md | 2 + src/docs/operator-reference.md | 25 ++ src/pkg/config/config.go | 3 + src/pkg/config/dedupe.go | 17 ++ src/pkg/config/dedupe_test.go | 29 +++ .../config/testdata/agent_runtime_golden.json | 1 + .../api_repo_item_decide_delegated_plan.go | 1 + ...i_repo_item_decide_delegated_plan_issue.go | 22 ++ ...o_item_decide_delegated_plan_issue_test.go | 47 ++++ .../dashboard/settings_parity_allowlist.txt | 1 + src/pkg/dashboard/stage_tracker_advisory.go | 31 ++- .../stage_tracker_advisory_working.go | 43 ++++ .../stage_tracker_advisory_working_test.go | 109 +++++++++ src/pkg/dashboard/stage_tracker_build.go | 1 + src/pkg/dashboard/static/index.html | 4 +- src/pkg/github/close_on_merge.go | 5 + src/pkg/github/dedupe_advisory_close.go | 32 ++- src/pkg/github/dedupe_advisory_close_test.go | 21 +- src/pkg/github/dedupe_advisory_items.go | 226 ++++++++++++++++++ src/pkg/github/dedupe_advisory_items_test.go | 152 ++++++++++++ src/pkg/github/dedupe_checklist_findings.go | 8 +- 25 files changed, 799 insertions(+), 13 deletions(-) create mode 100644 changelog.d/fixed-15754-advisory-checklists-autoclose.md create mode 100644 src/cmd/hive/close_on_merge_advisory_autoclose_test.go create mode 100644 src/pkg/config/dedupe.go create mode 100644 src/pkg/config/dedupe_test.go create mode 100644 src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue.go create mode 100644 src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue_test.go create mode 100644 src/pkg/dashboard/stage_tracker_advisory_working.go create mode 100644 src/pkg/dashboard/stage_tracker_advisory_working_test.go create mode 100644 src/pkg/github/dedupe_advisory_items.go create mode 100644 src/pkg/github/dedupe_advisory_items_test.go diff --git a/changelog.d/fixed-15754-advisory-checklists-autoclose.md b/changelog.d/fixed-15754-advisory-checklists-autoclose.md new file mode 100644 index 0000000000..4a412a924d --- /dev/null +++ b/changelog.d/fixed-15754-advisory-checklists-autoclose.md @@ -0,0 +1 @@ +- Hive-authored dedupe advisory checklists now tick each item once it is closed or merged and close themselves when all are resolved (`dedupe.advisory_autoclose`, default on); their tracker row reads "Advisory · hive is working the items (k/N resolved)" instead of parking on a person, and "Let hive decide" on an issue now says "Approve the direction of #N and let the hive pick it up." diff --git a/src/cmd/hive/close_on_merge_advisory_autoclose_test.go b/src/cmd/hive/close_on_merge_advisory_autoclose_test.go new file mode 100644 index 0000000000..fb40e83558 --- /dev/null +++ b/src/cmd/hive/close_on_merge_advisory_autoclose_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "testing" + + "github.com/hivecommons/hive/pkg/config" +) + +// dedupe.advisory_autoclose reaches the close-on-merge backfill +// (hivecommons/hive#15754): unset is on, false turns the item pass off. +func TestCloseOnMergeOptionsAdvisoryAutoclose(t *testing.T) { + off := false + for _, tc := range []struct { + name string + cfg config.Config + wantDisable bool + }{ + {"unset", config.Config{}, false}, + {"off", config.Config{Dedupe: config.DedupeConfig{AdvisoryAutoclose: &off}}, true}, + } { + t.Run(tc.name, func(t *testing.T) { + if got := closeOnMergeOptionsFor(&tc.cfg, nil, nil).DisableAdvisoryAutoclose; got != tc.wantDisable { + t.Fatalf("DisableAdvisoryAutoclose = %v, want %v", got, tc.wantDisable) + } + }) + } +} diff --git a/src/cmd/hive/close_on_merge_sweep.go b/src/cmd/hive/close_on_merge_sweep.go index 0ddeded022..858e30ddbf 100644 --- a/src/cmd/hive/close_on_merge_sweep.go +++ b/src/cmd/hive/close_on_merge_sweep.go @@ -110,6 +110,8 @@ func closeOnMergeOptionsFor(cfg *config.Config, logger *slog.Logger, now func() Now: now, LabelDriven: cfg.RepoLabelDriven, RepoOnGitHub: cfg.RepoOnGitHub, + + DisableAdvisoryAutoclose: !cfg.Dedupe.AdvisoryAutocloseEnabled(), } } diff --git a/src/docs/dashboard-sections/activity-monitor.md b/src/docs/dashboard-sections/activity-monitor.md index c82943212d..aac97e9c74 100644 --- a/src/docs/dashboard-sections/activity-monitor.md +++ b/src/docs/dashboard-sections/activity-monitor.md @@ -320,6 +320,8 @@ A row that already wears a hold, `blocked`, a draft marker or any stage record i An issue that is a note for maintainers rather than work — one wearing `triage/advisory`, a dedupe-agent checklist (body opens with ``) or any body whose verdict line reads `Decision required: no` — is an **advisory** ([#15381](https://github.com/hivecommons/hive/issues/15381) sat for hours as a plain *Open · since 3h*, indistinguishable from stalled work). Its row keeps `kind: issue` and carries `advisory{kind: "advisory", source (label|dedupe-checklist|decision-no), empty, chip, caption}`; the Open chevron reads the chip — **Advisory · read & close**, or **Advisory · nothing found · safe to close** when the checklist's own counts are all zero — muted (`ham-open-advisory`, ⓘ), with no *· since Nh* suffix and never the stale tint. The caption is *Advisory for maintainers · read, then close* (or *… · nothing found · safe to close*), the actor is a human with nothing waiting on them, the row is never *New*, never *stalled* or *sent back*, and it is excluded from **Needs human** and **Needs attention**. The row menu leads with **Close (read)**, which posts the existing `POST /api/repos/{owner}/{repo}/items/{number}/decision` with `decision: close-read`: a "Closed as read (advisory acknowledged) by @you from the Hive dashboard" comment, then the issue closes as *completed* (operator action `close-read` in the row's history). +An advisory is never parked on a person ([#15754](https://github.com/hivecommons/hive/issues/15754)): a dedupe checklist at `stage/045-needs-decision` drops the 045 stage, the *needs-decision* pill and the `decision_needed` / `blocker` blocks. A dedupe checklist with `- [ ]` task lines that the hive resolves itself (`dedupe.advisory_autoclose`, default on — the close-on-merge backfill ticks each item once it is closed or merged and closes the checklist when all are resolved) also carries `advisory.items`, `advisory.resolved`, `working: true` and `lead: "Close now"`: its chip and caption read **Advisory · hive is working the items (k/N resolved)**, the actor is the hive, and the row menu's lead is the optional **Close now** (the same `close-read` decision). + The enumeration computes the body-derived part (`RepoWorkIssue.advisory`) because sidelined `hive_advisory` rows do not carry the body. Upstream, the issue-request relay refuses an agent's `issue-create` whose body is a dedupe checklist with no actionable finding (verdict `no`, zero near-duplicate pairs, zero resolved candidates, zero missing PR↔issue links, no `- [ ]` task lines): the agent's result file says why, the write audit records `agent_issue_empty_advisory_refused`, and a knowledge bead keeps the summary in the hive's own log — merge-order reminders and cross-links are notes, not issues. #### Hive's own unblock is live diff --git a/src/docs/labels-and-control-signals/reference.md b/src/docs/labels-and-control-signals/reference.md index 430d5af7ed..d89d95ec48 100644 --- a/src/docs/labels-and-control-signals/reference.md +++ b/src/docs/labels-and-control-signals/reference.md @@ -322,6 +322,8 @@ Hive advisory report is never actionable and never appears on the Hold list. Advisory-only dedupe checklist (`Decision required: no`, #11864) is never actionable and never appears on the Hold list; action-required checklists are parked with `needs-decision` instead. The close-on-merge backfill closes it once every `#N` it references is closed or merged, or after 7 days, and swaps it for `needs-decision` plus the "What to reply" notice if line two turns to `Decision required: yes` (#11871). +Every hive-authored dedupe checklist — labelled or not, including one parked at 045 with `Decision required: yes` — also gets an item pass on each backfill (#15754): a `- [ ] #N …` line is ticked to `- [x]` once #N is closed or merged, and once every task-list line is resolved the hive posts one comment ("All N items resolved (#a closed, #b merged …) — closing this advisory.") and closes the checklist as *completed*. A line that does not lead with a reference waits for a person to tick it. Set `dedupe.advisory_autoclose: false` (default on) to turn the item pass off; the `triage/advisory` rules above still apply. + **Who applies it:** Dedupe agent. **Checked by:** Standing meta classifier. **When:** Before holds/exempts. diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 2d3867a641..1ca39b9cb2 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -977,6 +977,31 @@ someone re-runs it. The shared-CI rerun sweep |---|---|---| | `shared_ci_rerun.enabled` | `true` (unset) | Set `false` to stop re-running PRs when a `[shared-ci]` incident closes. | +## Advisory checklist auto-close (`dedupe`) + +The dedupe agent files one checklist per repository (body opens with +``). Its items are usually resolved by +the hive's own merges and supersessions, so a checklist parked on a person +asked for a click nothing needed +([#15754](https://github.com/hivecommons/hive/issues/15754)). On every +close-on-merge backfill, for each open checklist this hive authored: + +- each `- [ ] #N …` line (also `- [ ] PR #N …`, `owner/repo#N`) is ticked to + `- [x]` once #N is closed or merged; a line that does not lead with a + reference waits for a person to tick it; +- once every task-list line is resolved, one comment ("All N items resolved + (#a closed, #b merged …) — closing this advisory.") is posted and the + checklist closes as *completed*. A checklist a person reopened after that + comment is left alone. + +The stage tracker draws such a row as **Advisory · hive is working the items +(k/N resolved)** with an optional **Close now**, never as *Needs human +decision*. + +| Key | Default | Meaning | +|---|---|---| +| `dedupe.advisory_autoclose` | `true` (unset) | Set `false` to leave dedupe checklists for a person; `triage/advisory` checklists still close on their own rules. | + ## Open-PR dispatch guard and duplicate-fix sweep (`scanner`) An issue whose fix is already open must not be dispatched again diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index d6d794683c..f83992b625 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -174,6 +174,9 @@ type Config struct { // `` once incident #n closes // (hivecommons/hive#12253). Default on. SharedCIRerun SharedCIRerunConfig `yaml:"shared_ci_rerun,omitempty" json:"shared_ci_rerun,omitempty"` + // Dedupe tunes what the hive does with the dedupe agent's advisory + // checklists (hivecommons/hive#15754); see DedupeConfig. + Dedupe DedupeConfig `yaml:"dedupe,omitempty" json:"dedupe,omitempty"` // Scanner tunes the pre-dispatch guards every automated claim producer // runs before an issue is handed out (hivecommons/hive#14799). Scanner ScannerConfig `yaml:"scanner,omitempty" json:"scanner,omitempty"` diff --git a/src/pkg/config/dedupe.go b/src/pkg/config/dedupe.go new file mode 100644 index 0000000000..74bef6ba0e --- /dev/null +++ b/src/pkg/config/dedupe.go @@ -0,0 +1,17 @@ +package config + +// DedupeConfig tunes what the hive does with the dedupe agent's advisory +// checklists (hivecommons/hive#15754). +type DedupeConfig struct { + // AdvisoryAutoclose lets the close-on-merge backfill tick each + // `- [ ] #N` item of a hive-authored dedupe checklist once #N is closed + // or merged, and close the checklist as completed once every item is + // resolved. *bool so unset means on; set + // `dedupe.advisory_autoclose: false` to leave checklists for a person. + AdvisoryAutoclose *bool `yaml:"advisory_autoclose,omitempty" json:"advisory_autoclose,omitempty"` +} + +// AdvisoryAutocloseEnabled reports whether the item pass runs; unset means on. +func (c DedupeConfig) AdvisoryAutocloseEnabled() bool { + return c.AdvisoryAutoclose == nil || *c.AdvisoryAutoclose +} diff --git a/src/pkg/config/dedupe_test.go b/src/pkg/config/dedupe_test.go new file mode 100644 index 0000000000..a610f78874 --- /dev/null +++ b/src/pkg/config/dedupe_test.go @@ -0,0 +1,29 @@ +package config + +import ( + "testing" + + "gopkg.in/yaml.v3" +) + +func TestDedupeAdvisoryAutocloseDefaultsOn(t *testing.T) { + for _, tc := range []struct { + name string + yaml string + want bool + }{ + {"unset", "hive_id: h\n", true}, + {"explicit on", "dedupe:\n advisory_autoclose: true\n", true}, + {"explicit off", "dedupe:\n advisory_autoclose: false\n", false}, + } { + t.Run(tc.name, func(t *testing.T) { + var cfg Config + if err := yaml.Unmarshal([]byte(tc.yaml), &cfg); err != nil { + t.Fatal(err) + } + if got := cfg.Dedupe.AdvisoryAutocloseEnabled(); got != tc.want { + t.Fatalf("AdvisoryAutocloseEnabled() = %v, want %v", got, tc.want) + } + }) + } +} diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json index d417b2075f..cf56d42f2f 100644 --- a/src/pkg/config/testdata/agent_runtime_golden.json +++ b/src/pkg/config/testdata/agent_runtime_golden.json @@ -736,6 +736,7 @@ "good_first_issue": {}, "supersession_sweep": {}, "shared_ci_rerun": {}, + "dedupe": {}, "scanner": {}, "upstream_watch": {}, "convergence": {}, diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go index 9a882787b7..c9904128d8 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go @@ -149,6 +149,7 @@ func (s *Server) planDelegatedDecision(ctx context.Context, repoFull string, num plan.Acting = verb.Acting } plan.Summary, plan.Consequences = delegatedPlanWording(in, d) + plan.Summary, plan.Consequences = delegatedPlanIssueWording(in, d, plan.Summary, plan.Consequences) plan.Why = delegatedPlanWhy(in, d) plan.Ladder = d.Ladder plan.MergeableAsIs = delegatedPlanMergeableAsIs(in, d) diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue.go new file mode 100644 index 0000000000..8e6aee1e64 --- /dev/null +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue.go @@ -0,0 +1,22 @@ +package dashboard + +import ( + "strconv" + + "github.com/hivecommons/hive/pkg/delegatedecision" +) + +// delegatedPlanIssueWording rewords an approval on an issue +// (hivecommons/hive#15754). delegatedPlanWording speaks PR: the plan for +// issue #15734 read "Approve #15734 as it is and let the merge queue merge +// it" — but an issue has no head to approve and nothing to merge. Approving +// an issue records the direction and lifts its decision park, so an agent +// can pick it up. Any other decision keeps its wording. +func delegatedPlanIssueWording(in delegatedecision.Input, d delegatedecision.Decision, summary string, consequences []string) (string, []string) { + if in.Kind != delegatedecision.KindIssue || d.Verdict != delegatedecision.VerdictApprove { + return summary, consequences + } + ref := "#" + strconv.Itoa(in.Number) + return "Approve the direction of " + ref + " and let the hive pick it up.", + []string{"Hive records the approval and lifts the decision park on " + ref + ".", "An agent claims " + ref + " and opens a PR for it."} +} diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue_test.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue_test.go new file mode 100644 index 0000000000..f5f37b4237 --- /dev/null +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan_issue_test.go @@ -0,0 +1,47 @@ +package dashboard + +import ( + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/delegatedecision" +) + +// hivecommons/hive#15754: default-approve on an issue said "Approve #15734 +// as it is and let the merge queue merge it." The plan for an issue speaks +// issue; a PR's stays as it was. +func TestDelegatedPlanWordingBranchesOnItemType(t *testing.T) { + approve := delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove, Rule: "default-approve"} + for _, tc := range []struct { + name string + in delegatedecision.Input + d delegatedecision.Decision + summary string + first string + notWords []string + }{ + {"issue approve", delegatedecision.Input{Kind: delegatedecision.KindIssue, Number: 15734}, approve, + "Approve the direction of #15734 and let the hive pick it up.", + "Hive records the approval and lifts the decision park on #15734.", []string{"merge", "commit", "CI"}}, + {"pr approve", delegatedecision.Input{Kind: delegatedecision.KindPR, Number: 8}, approve, + "Approve #8 as it is and let the merge queue merge it.", + "Hive approves the current commit.", nil}, + {"issue close duplicate", delegatedecision.Input{Kind: delegatedecision.KindIssue, Number: 5}, + delegatedecision.Decision{Verdict: delegatedecision.VerdictCloseDuplicate, Actions: []delegatedecision.Action{{Target: 4}}}, + "Close #5 as a duplicate of #4.", "#5 is closed with a comment pointing at #4.", nil}, + } { + t.Run(tc.name, func(t *testing.T) { + summary, consequences := delegatedPlanWording(tc.in, tc.d) + summary, consequences = delegatedPlanIssueWording(tc.in, tc.d, summary, consequences) + if summary != tc.summary || len(consequences) == 0 || consequences[0] != tc.first { + t.Fatalf("summary=%q consequences=%q", summary, consequences) + } + text := summary + " " + strings.Join(consequences, " ") + for _, w := range tc.notWords { + if strings.Contains(text, w) { + t.Errorf("issue plan mentions %q: %s", w, text) + } + } + }) + } +} diff --git a/src/pkg/dashboard/settings_parity_allowlist.txt b/src/pkg/dashboard/settings_parity_allowlist.txt index 6f889a011f..bf014238a3 100644 --- a/src/pkg/dashboard/settings_parity_allowlist.txt +++ b/src/pkg/dashboard/settings_parity_allowlist.txt @@ -179,6 +179,7 @@ contribute.token_max_age # TODO #11854 convergence.mutation.max_writers_per_target # boundary capacity tuning; yaml-only (#14645) debug.pprof_addr # loopback-only pprof bind address, operator/debug knob, not a Settings control (#14681) deployment.runtime # set via HIVE_DEPLOYMENT_RUNTIME env var or auto-detected, not a Settings control (#14072) +dedupe.advisory_autoclose # advisory checklist auto-close (#15754); yaml-only duplicate_sweep.bot_authors[] # TODO #11854 evidence.complexity.enabled # TODO #11854 evidence.complexity.static_analysis # TODO #11854 diff --git a/src/pkg/dashboard/stage_tracker_advisory.go b/src/pkg/dashboard/stage_tracker_advisory.go index d6798d858a..dc6304678c 100644 --- a/src/pkg/dashboard/stage_tracker_advisory.go +++ b/src/pkg/dashboard/stage_tracker_advisory.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" ) // An advisory issue (hivecommons/hive#15381): a `triage/advisory` issue, a @@ -44,6 +45,14 @@ type StageTrackerAdvisory struct { Empty bool `json:"empty,omitempty"` Chip string `json:"chip"` Caption string `json:"caption"` + // Items / Resolved count a dedupe checklist's task-list lines and the + // ticked ones. Working is true while the hive ticks and closes them + // itself (hivecommons/hive#15754); Lead is then the row's optional + // human action, "Close now". + Items int `json:"items,omitempty"` + Resolved int `json:"resolved,omitempty"` + Working bool `json:"working,omitempty"` + Lead string `json:"lead,omitempty"` } // stageTrackerAdvisoryFor classifies an issue from its labels, its body @@ -65,6 +74,9 @@ func stageTrackerAdvisoryFor(labels []string, body string, hint *github.IssueAdv return nil } adv.Empty = hint != nil && hint.Empty + if hint != nil && hint.DedupeChecklist { + adv.Items, adv.Resolved = hint.Items, hint.Resolved + } adv.Chip, adv.Caption = StageTrackerAdvisoryChip, StageTrackerAdvisoryCaption if adv.Empty { adv.Chip, adv.Caption = StageTrackerAdvisoryEmptyChip, StageTrackerAdvisoryEmptyCaption @@ -79,7 +91,11 @@ var stageTrackerAdvisoryMods = []string{modStalled, modRegressed} // applyStageTrackerAdvisory marks it as an advisory: the caption and the // actor say "read, then close", the stall/regression pills come off, the // 000-new block (which would say "waiting for triage") is dropped, and the -// stage actor is a human with nothing blocking on them. +// stage actor is a human with nothing blocking on them. An advisory is +// never parked on a person (hivecommons/hive#15754): a 045 park, its +// needs-decision pill and its decision_needed / blocker blocks come off +// too, so the row reads as the advisory it is. While the hive works the +// checklist's items the actor is the hive. func applyStageTrackerAdvisory(it *StageTrackerItem, adv *StageTrackerAdvisory) { if it == nil || adv == nil { return @@ -87,12 +103,23 @@ func applyStageTrackerAdvisory(it *StageTrackerItem, adv *StageTrackerAdvisory) it.Advisory = adv it.Caption = adv.Caption it.Actor = "maintainer" - it.Modifiers = slices.DeleteFunc(it.Modifiers, func(m string) bool { return slices.Contains(stageTrackerAdvisoryMods, m) }) + it.Modifiers = slices.DeleteFunc(it.Modifiers, func(m string) bool { + return slices.Contains(stageTrackerAdvisoryMods, m) || m == modNeedsDecision + }) if it.New != nil { it.New = nil if it.StageSlug == StageTrackerNewSlug { it.StageSlug = "" } } + if it.Stage == stagelabels.IssueNeedsDecision.Number() { + it.Stage, it.StageSlug, it.StageLabel = 0, "", "" + } + it.DecisionNeeded, it.Blocker = nil, nil + if adv.Working { + it.Actor = StageActorHive + it.StageActor = &StageTrackerActor{Kind: StageActorHive, Why: stageTrackerAdvisoryWorkingWhy, Since: it.StageSince} + return + } it.StageActor = &StageTrackerActor{Kind: StageActorHuman, Why: stageTrackerAdvisoryWhy, Since: it.StageSince} } diff --git a/src/pkg/dashboard/stage_tracker_advisory_working.go b/src/pkg/dashboard/stage_tracker_advisory_working.go new file mode 100644 index 0000000000..014353eb30 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_advisory_working.go @@ -0,0 +1,43 @@ +package dashboard + +import ( + "fmt" + + "github.com/hivecommons/hive/pkg/config" +) + +// A dedupe checklist the hive resolves itself (hivecommons/hive#15754): the +// close-on-merge backfill ticks each `- [ ] #N` item once #N is closed or +// merged and closes the checklist when every item is resolved. Its row says +// the hive is on it — "Advisory · hive is working the items (k/N resolved)" +// — instead of asking a person to read and close it; "Close now" stays as +// the optional human lead. + +const ( + // stageTrackerAdvisoryWorkingFormat is the chip and caption, given the + // resolved and total item counts. + stageTrackerAdvisoryWorkingFormat = "Advisory · hive is working the items (%d/%d resolved)" + // StageTrackerAdvisoryCloseNowLead is the optional human action. + StageTrackerAdvisoryCloseNowLead = "Close now" + // stageTrackerAdvisoryWorkingWhy is the StageActor sentence. + stageTrackerAdvisoryWorkingWhy = "hive ticks each item once it is closed or merged and closes the advisory when all are resolved; nothing waits on a person" +) + +// stageTrackerAdvisoryWorking marks a dedupe checklist with task-list items +// as worked by the hive when the auto-close knob is on. Any other advisory +// is left as it is. +func stageTrackerAdvisoryWorking(adv *StageTrackerAdvisory, autoclose bool) { + if adv == nil || !autoclose || adv.Source == stageTrackerAdvisorySourceVerdict || adv.Items <= 0 { + return + } + adv.Working = true + adv.Chip = fmt.Sprintf(stageTrackerAdvisoryWorkingFormat, adv.Resolved, adv.Items) + adv.Caption = adv.Chip + adv.Lead = StageTrackerAdvisoryCloseNowLead +} + +// stageTrackerAdvisoryAutoclose reads the dedupe knob; unset (or no +// config) means on. +func stageTrackerAdvisoryAutoclose(cfg *config.Config) bool { + return cfg == nil || cfg.Dedupe.AdvisoryAutocloseEnabled() +} diff --git a/src/pkg/dashboard/stage_tracker_advisory_working_test.go b/src/pkg/dashboard/stage_tracker_advisory_working_test.go new file mode 100644 index 0000000000..c4f9e04aab --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_advisory_working_test.go @@ -0,0 +1,109 @@ +package dashboard + +import ( + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/github" +) + +// hivecommons/hive#15734 as the hive filed it: a dedupe checklist parked +// at 045 with "Decision required: yes", one of three items already ticked. +const advisory15734Body = "\nDecision required: yes\n\n" + + "## Summary\n\nFound 3 near-duplicate pairs, 0 same-root-cause clusters, 0 items that appear already resolved, and 0 missing PR↔issue links.\n\n" + + "## Near-duplicates: close one\n\n" + + "- [x] #15312 — close as superseded by #15646\n" + + "- [ ] #15433 — close as superseded by #15649\n" + + "- [ ] #15482 — close as superseded by #15650\n" + +var advisory15734Labels = []string{"help wanted", "agent/dedupe", "stage/045-needs-decision"} + +func TestStageTrackerAdvisoryWorkingWording(t *testing.T) { + adv := stageTrackerAdvisoryFor(advisory15734Labels, advisory15734Body, nil) + if adv == nil || adv.Source != stageTrackerAdvisorySourceChecklist || adv.Items != 3 || adv.Resolved != 1 { + t.Fatalf("#15734 advisory = %+v", adv) + } + stageTrackerAdvisoryWorking(adv, true) + want := "Advisory · hive is working the items (1/3 resolved)" + if !adv.Working || adv.Chip != want || adv.Caption != want || adv.Lead != "Close now" { + t.Errorf("working advisory = %+v", adv) + } + + off := stageTrackerAdvisoryFor(advisory15734Labels, advisory15734Body, nil) + stageTrackerAdvisoryWorking(off, false) + if off.Working || off.Chip != StageTrackerAdvisoryChip || off.Lead != "" { + t.Errorf("auto-close off = %+v, want the read & close advisory", off) + } + // No task list: nothing for the hive to work. + plain := stageTrackerAdvisoryFor([]string{"triage/advisory"}, "", nil) + stageTrackerAdvisoryWorking(plain, true) + if plain.Working || plain.Chip != StageTrackerAdvisoryChip { + t.Errorf("label-only advisory = %+v", plain) + } +} + +func TestStageTrackerAdvisoryAutocloseKnob(t *testing.T) { + off := false + if !stageTrackerAdvisoryAutoclose(nil) || !stageTrackerAdvisoryAutoclose(&config.Config{}) { + t.Error("unset knob must read as on") + } + if stageTrackerAdvisoryAutoclose(&config.Config{Dedupe: config.DedupeConfig{AdvisoryAutoclose: &off}}) { + t.Error("knob set false must read as off") + } +} + +// An advisory is never parked on a person: the 045 park, its pill and the +// decision / blocker blocks come off, and the hive is the actor while it +// works the items. +func TestApplyStageTrackerAdvisoryNeverParks(t *testing.T) { + adv := stageTrackerAdvisoryFor(advisory15734Labels, advisory15734Body, nil) + stageTrackerAdvisoryWorking(adv, true) + it := StageTrackerItem{Kind: "issue", Number: 15734, Stage: 45, StageSlug: "needs-decision", StageLabel: "Needs human decision", + Modifiers: []string{modNeedsDecision, modStalled}, DecisionNeeded: &StageTrackerDecision{}, Blocker: &StageTrackerBlocker{}} + applyStageTrackerAdvisory(&it, adv) + if it.Stage != 0 || it.StageSlug != "" || it.StageLabel != "" { + t.Errorf("stage = %d/%q/%q, want the 045 park dropped", it.Stage, it.StageSlug, it.StageLabel) + } + if it.DecisionNeeded != nil || it.Blocker != nil || hasMod(it, modNeedsDecision) || hasMod(it, modStalled) { + t.Errorf("decision=%+v blocker=%+v mods=%v, want no park on a person", it.DecisionNeeded, it.Blocker, it.Modifiers) + } + if it.Caption != adv.Caption || it.Actor != StageActorHive || it.StageActor == nil || it.StageActor.Kind != StageActorHive { + t.Errorf("caption=%q actor=%q stage_actor=%+v", it.Caption, it.Actor, it.StageActor) + } + if stageTrackerNeedsHuman(it) { + t.Error("advisory counted as needs-human") + } + if kind, _ := stageTrackerWaitKind(it); kind != "" { + t.Errorf("wait kind = %q, want none", kind) + } +} + +// The built row for #15734: the enumeration's hint carries the counts, the +// row reads "hive is working the items" with no decision block. +func TestStageTrackerAdvisoryWorkingRow(t *testing.T) { + now := time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC) + s, store := stageTrackerFixture(t, now) + created := now.Add(-3 * time.Hour) + + s.statusMu.Lock() + repo := &s.status.Repos[0] + repo.NonActionableIssues = []any{ + github.RepoWorkIssue{Repo: "acme/console", Number: 15734, Title: "triage: duplicate and overlapping open issues/PRs to consolidate", Author: "hive-app[bot]", + Labels: advisory15734Labels, Bucket: "needs-decision", Reason: "parked", CreatedAt: created, UpdatedAt: created, + Advisory: github.IssueAdvisoryFromBody(advisory15734Body)}, + } + s.statusMu.Unlock() + + resp := s.buildStageTracker(s.status, store, now) + it := trackerItem(t, resp, "issue", 15734) + if it.Advisory == nil || !it.Advisory.Working || it.Advisory.Lead != "Close now" { + t.Fatalf("#15734 advisory = %+v", it.Advisory) + } + if want := "Advisory · hive is working the items (1/3 resolved)"; it.Caption != want || it.Advisory.Chip != want { + t.Errorf("#15734 caption/chip = %q / %q", it.Caption, it.Advisory.Chip) + } + if it.DecisionNeeded != nil || it.Stage != 0 || it.NeedsHuman || it.WaitingOnYou || hasMod(it, modNeedsDecision) { + t.Errorf("#15734 parked on a person: decision=%+v stage=%d needs_human=%v waiting=%v mods=%v", it.DecisionNeeded, it.Stage, it.NeedsHuman, it.WaitingOnYou, it.Modifiers) + } +} diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index b4c0d11a35..5336b636e5 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -289,6 +289,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto stageTrackerBlockedBy(&it, issue.OpenBlockers()) stageTrackerBlockedOnPR(&it, issue.Body, bucketReason, status.GitHubBaseURL, prState) advisory := stageTrackerAdvisoryFor(issue.Labels, issue.Body, advisoryHint) + stageTrackerAdvisoryWorking(advisory, stageTrackerAdvisoryAutoclose(cfg)) if advisory == nil { applyStageTrackerNew(&it, stageTrackerNewState(it, ok, issueFilter, status.Governor, now)) } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 934d50c71a..7d059850ad 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -19710,7 +19710,9 @@

All labels

// read it, then close it. "Close (read)" leads; it is the existing // decision close path with the verdict `close-read`. const advisory = typeof stageTrackerAdvisoryOf === 'function' ? stageTrackerAdvisoryOf(item) : null; - if (advisory) out.push(Object.assign({ id: 'decide:close-read', label: STAGE_TRACKER_ACTION_LABELS['decide:close-read'], hint: advisory.empty ? 'nothing found · closes as completed' : 'advisory acknowledged · closes as completed', lead: true }, stageTrackerActionAllowed('decide:close-read', ctx))); + // While the hive works the checklist's items (hivecommons/hive#15754) + // the same close is the optional "Close now". + if (advisory) out.push(Object.assign({ id: 'decide:close-read', label: advisory.lead || STAGE_TRACKER_ACTION_LABELS['decide:close-read'], hint: advisory.working ? 'optional · hive closes it once every item is resolved' : advisory.empty ? 'nothing found · closes as completed' : 'advisory acknowledged · closes as completed', lead: true }, stageTrackerActionAllowed('decide:close-read', ctx))); for (const a of lead) out.push(a); if (target) { const on = target === item ? '' : ' PR #' + (Number(target.number) || 0); diff --git a/src/pkg/github/close_on_merge.go b/src/pkg/github/close_on_merge.go index 9147dab6ee..81316f1bc7 100644 --- a/src/pkg/github/close_on_merge.go +++ b/src/pkg/github/close_on_merge.go @@ -70,6 +70,10 @@ type CloseOnMergeOptions struct { // GitHub under its slug (hivecommons/hive#14150). nil means every repo is // on GitHub. RepoOnGitHub func(repo string) bool + // DisableAdvisoryAutoclose turns off the item pass over hive-authored + // advisory checklists (dedupe.advisory_autoclose: false, + // hivecommons/hive#15754); the triage/advisory rules still run. + DisableAdvisoryAutoclose bool } func (o CloseOnMergeOptions) now() time.Time { @@ -159,6 +163,7 @@ var closeOnMergeTransientReasons = map[string]bool{ "awaiting_comment_failed": true, "close_comment_failed": true, "close_failed": true, + "advisory_tick_failed": true, } // Settles reports whether the result is a final verdict for its PR/issue diff --git a/src/pkg/github/dedupe_advisory_close.go b/src/pkg/github/dedupe_advisory_close.go index fd833cca2f..40249777c1 100644 --- a/src/pkg/github/dedupe_advisory_close.go +++ b/src/pkg/github/dedupe_advisory_close.go @@ -107,15 +107,26 @@ func dedupeChecklistRefs(body, defaultRepo, selfRepo string, self int) []Claimed } // sweepDedupeAdvisoryChecklist handles one open issue for the close-on-merge -// backfill. It reports handled=false for anything that is not an open -// triage/advisory dedupe checklist, so the backfill's own checks still run. +// backfill. It reports handled=false for anything that is neither an open +// triage/advisory dedupe checklist nor a hive-authored checklist with +// task-list items, so the backfill's own checks still run. // Otherwise it reclassifies a checklist whose verdict turned to "Decision // required: yes", or closes it once it is older than DedupeAdvisoryMaxAge or // every item it references is closed or merged. func (c *Client) sweepDedupeAdvisoryChecklist(ctx context.Context, repo string, issue *gh.Issue, opts CloseOnMergeOptions) (CloseOnMergeResult, bool) { res := CloseOnMergeResult{Repo: repo, Issue: issue.GetNumber()} labels := issueLabelNames(issue.Labels) - if !labelPresent(labels, dedupeAdvisoryLabelName) { + advisory := labelPresent(labels, dedupeAdvisoryLabelName) + // Every hive-authored checklist first gets the item pass + // (hivecommons/hive#15754). A triage/advisory one whose items are still + // open falls through to the rules below. + if items, ok := c.sweepAdvisoryChecklistItems(ctx, repo, issue, opts); ok { + pending := items.Action == CloseOnMergeNoop && (items.Reason == advisoryItemsOpenReason || items.Reason == advisoryItemsTickedReason) + if !advisory || !pending { + return items, true + } + } + if !advisory { return res, false } refRepo, verdict, ok := parseDedupeChecklist(issue.GetBody()) @@ -163,21 +174,26 @@ func (c *Client) sweepDedupeAdvisoryChecklist(ctx context.Context, repo string, } comment, reason = dedupeAdvisoryRefsClosedComment, "dedupe_advisory_refs_closed" } + return c.closeDedupeAdvisory(ctx, res, repo, owner, repoName, number, comment, reason), true +} +// closeDedupeAdvisory posts comment and closes the checklist as completed, +// unless the hive closed it once before and a person reopened it. +func (c *Client) closeDedupeAdvisory(ctx context.Context, res CloseOnMergeResult, repo, owner, repoName string, number int, comment, reason string) CloseOnMergeResult { comments, err := c.listIssueComments(ctx, owner, repoName, number) if err != nil { res.Action, res.Reason = CloseOnMergeNoop, "issue_read_failed" - return res, true + return res } for _, cm := range comments { if cm != nil && strings.Contains(cm.GetBody(), dedupeAdvisoryCloseMarker) { res.Action, res.Reason = CloseOnMergeSkipped, "reopened_after_close" - return res, true + return res } } if _, _, err := c.client.Issues.CreateComment(ctx, owner, repoName, number, &gh.IssueComment{Body: gh.Ptr(comment)}); err != nil { res.Action, res.Reason = CloseOnMergeNoop, "close_comment_failed" - return res, true + return res } if err := c.CloseIssue(ctx, repo, number, IssueCloseOptions{ OverrideReason: "advisory dedupe checklist", @@ -187,10 +203,10 @@ func (c *Client) sweepDedupeAdvisoryChecklist(ctx context.Context, repo string, StateReason: IssueStateReasonCompleted, }); err != nil { res.Action, res.Reason = CloseOnMergeNoop, "close_failed" - return res, true + return res } res.Action, res.Reason = CloseOnMergeClosed, reason - return res, true + return res } // dedupeRefOpen reports whether a referenced issue or PR is still open; the diff --git a/src/pkg/github/dedupe_advisory_close_test.go b/src/pkg/github/dedupe_advisory_close_test.go index a51addd9d1..36c4b8d038 100644 --- a/src/pkg/github/dedupe_advisory_close_test.go +++ b/src/pkg/github/dedupe_advisory_close_test.go @@ -30,6 +30,7 @@ type dedupeFixture struct { labels []string createdAt time.Time refStates map[int]string + refMerged map[int]bool comments []string failRefs bool failPost bool @@ -38,6 +39,7 @@ type dedupeFixture struct { refGets int posted []string patched bool + edits []string added []string removed []string unexpect []string @@ -95,6 +97,19 @@ func (f *dedupeFixture) server() *httptest.Server { f.comments = append(f.comments, c.Body) _ = json.NewEncoder(w).Encode(map[string]any{"id": len(f.comments)}) case r.Method == http.MethodPatch && path == checklist: + var edit struct { + Body *string `json:"body"` + State *string `json:"state"` + } + _ = json.NewDecoder(r.Body).Decode(&edit) + if edit.Body != nil { + f.body = *edit.Body + f.edits = append(f.edits, *edit.Body) + } + if edit.State == nil && edit.Body != nil { + _ = json.NewEncoder(w).Encode(f.issueJSON()) + return + } f.patched = true _ = json.NewEncoder(w).Encode(map[string]any{"number": dedupeTestChecklist, "state": "closed"}) case r.Method == http.MethodDelete && strings.HasPrefix(path, checklist+"/labels/"): @@ -133,7 +148,11 @@ func (f *dedupeFixture) server() *httptest.Server { return } f.refGets++ - _ = json.NewEncoder(w).Encode(map[string]any{"number": n, "state": state}) + ref := map[string]any{"number": n, "state": state} + if f.refMerged[n] { + ref["pull_request"] = map[string]any{"merged_at": dedupeTestNow.Add(-time.Hour).Format(time.RFC3339)} + } + _ = json.NewEncoder(w).Encode(ref) default: f.unexpect = append(f.unexpect, r.Method+" "+path) w.WriteHeader(http.StatusNotFound) diff --git a/src/pkg/github/dedupe_advisory_items.go b/src/pkg/github/dedupe_advisory_items.go new file mode 100644 index 0000000000..2c72e567d7 --- /dev/null +++ b/src/pkg/github/dedupe_advisory_items.go @@ -0,0 +1,226 @@ +package github + +import ( + "context" + "fmt" + "regexp" + "strconv" + "strings" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/pkg/writeback" +) + +// A hive-authored advisory checklist resolves itself (hivecommons/hive#15754). +// hivecommons/hive#15734 was a dedupe checklist parked at 045 "Decision +// required: yes"; by the time the owner looked, the hive had already closed +// or merged most of its items, yet the row still asked a person to click. +// Each close-on-merge backfill now ticks `- [ ] #N …` to `- [x]` once #N is +// closed or merged and, when every item is resolved, posts one short comment +// and closes the checklist as completed — for every hive-authored dedupe +// checklist, not only the triage/advisory-labelled ones. The +// dedupe.advisory_autoclose knob (default on) turns it off. + +// advisoryChecklistItemPattern is one task-list line: the box and the text +// after it. +var advisoryChecklistItemPattern = regexp.MustCompile(`(?m)^([ \t]*[-*+][ \t]+\[)([ xX])(\][ \t]*)(.*)$`) + +// advisoryChecklistLeadRefPattern is the item a line is about: the first +// reference, optionally after "PR" / "issue". +var advisoryChecklistLeadRefPattern = regexp.MustCompile(`^(?i:(?:pr|issue)[ \t]+)?(?:([\w.-]+/[\w.-]+))?#(\d+)\b`) + +// Result reasons of the item pass; a backfill pass that only ticked boxes +// or found items still open leaves a triage/advisory checklist to the +// label path's own refs/expiry rules. +const ( + advisoryItemsResolvedReason = "advisory_items_resolved" + advisoryItemsOpenReason = "advisory_items_open" + advisoryItemsTickedReason = "advisory_items_ticked" +) + +// advisoryChecklistItem is one task-list line of a checklist. Ref is the +// zero value for a line that does not lead with an item: nothing can +// resolve it but a person ticking it. +type advisoryChecklistItem struct { + Ref ClaimedRef + Done bool + // boxAt is the byte offset of the box character in the body. + boxAt int +} + +// advisoryChecklistItems lists the task-list lines of body, resolving bare +// numbers against defaultRepo. +func advisoryChecklistItems(body, defaultRepo string) []advisoryChecklistItem { + var out []advisoryChecklistItem + for _, m := range advisoryChecklistItemPattern.FindAllStringSubmatchIndex(body, -1) { + it := advisoryChecklistItem{Done: body[m[4]:m[5]] != " ", boxAt: m[4]} + if ref := advisoryChecklistLeadRefPattern.FindStringSubmatch(strings.TrimSpace(body[m[8]:m[9]])); ref != nil { + if n, err := strconv.Atoi(ref[2]); err == nil && n > 0 { + it.Ref = ClaimedRef{Repo: defaultRepo, Issue: n} + if ref[1] != "" { + it.Ref.Repo = ref[1] + } + } + } + out = append(out, it) + } + return out +} + +// AdvisoryChecklistProgress counts a checklist body's task-list items and +// how many are ticked; the stage tracker reads "k/N resolved" from it. +func AdvisoryChecklistProgress(body string) (items, resolved int) { + for _, it := range advisoryChecklistItems(strings.ReplaceAll(body, "\r\n", "\n"), "") { + items++ + if it.Done { + resolved++ + } + } + return items, resolved +} + +// advisoryRefOutcome is how a referenced item was resolved. +type advisoryRefOutcome string + +const ( + advisoryRefOpen advisoryRefOutcome = "open" + advisoryRefClosed advisoryRefOutcome = "closed" + advisoryRefMerged advisoryRefOutcome = "merged" +) + +// dedupeRefOutcome reads a referenced issue or PR through the issues API; +// a PR's merged_at tells merged from closed. +func (c *Client) dedupeRefOutcome(ctx context.Context, ref ClaimedRef) (advisoryRefOutcome, error) { + owner, repoName := c.splitRepo(ref.Repo) + item, _, err := c.client.Issues.Get(ctx, owner, repoName, ref.Issue) + if err != nil { + return "", err + } + switch { + case !strings.EqualFold(item.GetState(), "closed"): + return advisoryRefOpen, nil + case item.GetPullRequestLinks().GetMergedAt().Time.IsZero(): + return advisoryRefClosed, nil + } + return advisoryRefMerged, nil +} + +// advisoryItemsResolvedComment is the one closing comment: "All 3 items +// resolved (#1 closed, #2 merged, #3 ticked) — closing this advisory." +func advisoryItemsResolvedComment(defaultRepo string, items []advisoryChecklistItem, outcomes []advisoryRefOutcome) string { + parts := make([]string, 0, len(items)) + for i, it := range items { + word := string(outcomes[i]) + if outcomes[i] == "" { + word = "resolved" + } + if it.Ref.Issue <= 0 { + parts = append(parts, "item "+strconv.Itoa(i+1)+" "+word) + continue + } + ref := "#" + strconv.Itoa(it.Ref.Issue) + if !strings.EqualFold(it.Ref.Repo, defaultRepo) { + ref = it.Ref.Repo + ref + } + parts = append(parts, ref+" "+word) + } + noun := "items" + if len(items) == 1 { + noun = "item" + } + return fmt.Sprintf("%s\nAll %d %s resolved (%s) — closing this advisory.", dedupeAdvisoryCloseMarker, len(items), noun, strings.Join(parts, ", ")) +} + +// sweepAdvisoryChecklistItems is the item pass over one open issue. It +// reports handled=false for anything that is not a hive-authored dedupe +// checklist with task-list items, or when dedupe.advisory_autoclose is off. +// Otherwise it ticks the items whose reference is closed or merged and, +// once every item is resolved, closes the checklist as completed. +func (c *Client) sweepAdvisoryChecklistItems(ctx context.Context, repo string, issue *gh.Issue, opts CloseOnMergeOptions) (CloseOnMergeResult, bool) { + res := CloseOnMergeResult{Repo: repo, Issue: issue.GetNumber()} + if opts.DisableAdvisoryAutoclose { + return res, false + } + body := strings.ReplaceAll(issue.GetBody(), "\r\n", "\n") + refRepo, _, ok := parseDedupeChecklist(body) + if !ok { + return res, false + } + author := safeGetLogin(issue.GetUser()) + if !opts.Identity.IsZero() && !opts.Identity.Matches(author) { + return res, false + } + owner, repoName := c.splitRepo(repo) + fullRepo := owner + "/" + repoName + if refRepo == "" { + refRepo = fullRepo + } + items := advisoryChecklistItems(body, refRepo) + if len(items) == 0 || len(items) > dedupeAdvisoryMaxRefs { + return res, false + } + ctx = WithRESTCaller(ctx, "hive:close_on_merge") + number := issue.GetNumber() + + outcomes := make([]advisoryRefOutcome, len(items)) + ticked := []byte(body) + changed, open := false, 0 + for i, it := range items { + if it.Done { + continue + } + if it.Ref.Issue <= 0 || (it.Ref.Issue == number && strings.EqualFold(it.Ref.Repo, fullRepo)) { + open++ + continue + } + outcome, err := c.dedupeRefOutcome(ctx, it.Ref) + if err != nil { + res.Action, res.Reason = CloseOnMergeNoop, "issue_read_failed" + if opts.Logger != nil { + opts.Logger.Warn("advisory checklist: reading referenced item failed", "repo", repo, "issue", number, "ref", fmt.Sprintf("%s#%d", it.Ref.Repo, it.Ref.Issue), "error", err) + } + return res, true + } + if outcome == advisoryRefOpen { + open++ + continue + } + outcomes[i] = outcome + ticked[it.boxAt] = 'x' + changed = true + } + + item := writeback.Item{Number: number, Author: author, Labels: issueLabelNames(issue.Labels), CreatedAt: issue.GetCreatedAt().Time, HiveAuthored: true} + if changed { + if d := c.WritebackAllowed(repo, item, writeback.KindIssueClose, "tick resolved advisory checklist items"); !d.Allowed { + res.Action, res.Reason = CloseOnMergeSkipped, "writeback_gated" + return res, true + } + if _, _, err := c.client.Issues.Edit(ctx, owner, repoName, number, &gh.IssueRequest{Body: gh.Ptr(string(ticked))}); err != nil { // writeback:gated + res.Action, res.Reason = CloseOnMergeNoop, "advisory_tick_failed" + return res, true + } + } + if open > 0 { + res.Action, res.Reason = CloseOnMergeNoop, advisoryItemsOpenReason + if changed { + res.Reason = advisoryItemsTickedReason + } + return res, true + } + if d := c.WritebackAllowed(repo, item, writeback.KindIssueClose, "close resolved advisory checklist"); !d.Allowed { + res.Action, res.Reason = CloseOnMergeSkipped, "writeback_gated" + return res, true + } + // Items an earlier sweep ticked are read once more for the comment's + // "closed" / "merged"; a failed read just says "resolved". + for i, it := range items { + if it.Done && it.Ref.Issue > 0 { + if outcome, err := c.dedupeRefOutcome(ctx, it.Ref); err == nil && outcome != advisoryRefOpen { + outcomes[i] = outcome + } + } + } + return c.closeDedupeAdvisory(ctx, res, repo, owner, repoName, number, advisoryItemsResolvedComment(refRepo, items, outcomes), advisoryItemsResolvedReason), true +} diff --git a/src/pkg/github/dedupe_advisory_items_test.go b/src/pkg/github/dedupe_advisory_items_test.go new file mode 100644 index 0000000000..628f7c5edf --- /dev/null +++ b/src/pkg/github/dedupe_advisory_items_test.go @@ -0,0 +1,152 @@ +package github + +import ( + "strings" + "testing" +) + +// A dedupe checklist shaped like hivecommons/hive#15734: parked at 045 with +// "Decision required: yes", no triage/advisory label, its items led by the +// reference they are about. +func advisoryItemsBody() string { + return "\nDecision required: yes\n\n## Near-duplicates: close one\n\n" + + "| Keep | Merge into it |\n|---|---|\n| PR #9 | PR #1 |\n\n" + + "- [ ] #1 — close as superseded by #9\n" + + "- [ ] PR #2 — add `Fixes #3` to its body\n" +} + +func newAdvisoryItemsFixture(t *testing.T) *dedupeFixture { + f := newDedupeFixture(t, "yes") + f.body = advisoryItemsBody() + f.labels = []string{"agent/dedupe", issueNeedsDecisionLabel} + f.refStates = map[int]string{1: "closed", 2: "closed", 9: "open"} + f.refMerged = map[int]bool{2: true} + return f +} + +func TestAdvisoryChecklistClosesOnceEveryItemResolved(t *testing.T) { + f := newAdvisoryItemsFixture(t) + results := f.run(CloseOnMergeOptions{}) + assertDedupeResult(t, results, CloseOnMergeClosed, advisoryItemsResolvedReason) + if len(f.edits) != 1 || !strings.Contains(f.edits[0], "- [x] #1 — close") || !strings.Contains(f.edits[0], "- [x] PR #2 — add") { + t.Fatalf("edits = %q, want both items ticked in one edit", f.edits) + } + want := dedupeAdvisoryCloseMarker + "\nAll 2 items resolved (#1 closed, #2 merged) — closing this advisory." + if len(f.posted) != 1 || f.posted[0] != want { + t.Fatalf("posted = %q, want %q", f.posted, want) + } + if !f.patched { + t.Fatal("checklist was not closed") + } + if f.refGets != 2 { + t.Fatalf("ref reads = %d, want 2 (the table's #9 is not an item)", f.refGets) + } +} + +func TestAdvisoryChecklistTicksResolvedItemsAndWaitsForTheRest(t *testing.T) { + f := newAdvisoryItemsFixture(t) + f.refStates[2] = "open" + f.refMerged = nil + assertDedupeResult(t, f.run(CloseOnMergeOptions{}), CloseOnMergeNoop, advisoryItemsTickedReason) + if len(f.edits) != 1 || !strings.Contains(f.edits[0], "- [x] #1 — close") || !strings.Contains(f.edits[0], "- [ ] PR #2") { + t.Fatalf("edits = %q, want only #1 ticked", f.edits) + } + if f.patched || len(f.posted) != 0 { + t.Fatalf("patched=%v posted=%q, want the checklist left open", f.patched, f.posted) + } + + // Nothing new: no edit, no comment. + assertDedupeResult(t, f.run(CloseOnMergeOptions{}), CloseOnMergeNoop, advisoryItemsOpenReason) + if len(f.edits) != 1 || f.patched { + t.Fatalf("edits=%d patched=%v, want no write while #2 is open", len(f.edits), f.patched) + } + + // #2 closes: the last item is ticked and the checklist closes; the + // earlier-ticked #1 is read again for the comment. + f.refStates[2] = "closed" + assertDedupeResult(t, f.run(CloseOnMergeOptions{}), CloseOnMergeClosed, advisoryItemsResolvedReason) + if !strings.Contains(f.body, "- [x] PR #2") || len(f.posted) != 1 || !strings.Contains(f.posted[0], "All 2 items resolved (#1 closed, #2 closed)") { + t.Fatalf("body=%q posted=%q", f.body, f.posted) + } +} + +func TestAdvisoryChecklistItemWithoutLeadingRefWaitsForAPerson(t *testing.T) { + f := newAdvisoryItemsFixture(t) + f.body += "- [ ] Add `Fixes #3` to PR #2's body\n" + assertDedupeResult(t, f.run(CloseOnMergeOptions{}), CloseOnMergeNoop, advisoryItemsTickedReason) + if f.patched || len(f.posted) != 0 { + t.Fatalf("patched=%v posted=%q, want the checklist left open", f.patched, f.posted) + } + // A person ticks it; the next sweep closes the checklist. + f.body = strings.Replace(f.body, "- [ ] Add", "- [x] Add", 1) + assertDedupeResult(t, f.run(CloseOnMergeOptions{}), CloseOnMergeClosed, advisoryItemsResolvedReason) + if len(f.posted) != 1 || !strings.Contains(f.posted[0], "All 3 items resolved (#1 closed, #2 merged, item 3 resolved)") { + t.Fatalf("posted = %q", f.posted) + } +} + +func TestAdvisoryChecklistItemPassLeavesAlone(t *testing.T) { + for _, tc := range []struct { + name string + opts CloseOnMergeOptions + }{ + {"dedupe.advisory_autoclose off", CloseOnMergeOptions{DisableAdvisoryAutoclose: true}}, + {"not authored by this hive", CloseOnMergeOptions{Identity: HiveIdentity{AppLogin: "other-hive[bot]"}}}, + } { + t.Run(tc.name, func(t *testing.T) { + f := newAdvisoryItemsFixture(t) + if results := f.run(tc.opts); len(results) != 0 { + t.Fatalf("results = %+v, want none", results) + } + if len(f.edits) != 0 || f.patched || len(f.posted) != 0 || f.refGets != 0 { + t.Fatalf("edits=%q patched=%v posted=%q refGets=%d, want untouched", f.edits, f.patched, f.posted, f.refGets) + } + }) + } + t.Run("authored by this hive", func(t *testing.T) { + f := newAdvisoryItemsFixture(t) + assertDedupeResult(t, f.run(CloseOnMergeOptions{Identity: HiveIdentity{AppLogin: "hive[bot]"}}), CloseOnMergeClosed, advisoryItemsResolvedReason) + }) +} + +// A triage/advisory checklist whose items are still open keeps the label +// path's own rules (refs, expiry) after the item pass ticked what it could. +func TestAdvisoryChecklistLabelledFallsThroughWhileItemsOpen(t *testing.T) { + f := newAdvisoryItemsFixture(t) + f.body = strings.Replace(advisoryItemsBody(), "Decision required: yes", "Decision required: no", 1) + f.labels = []string{dedupeAdvisoryLabelName} + f.refStates[2] = "open" + assertDedupeResult(t, f.run(CloseOnMergeOptions{}), CloseOnMergeNoop, "dedupe_advisory_refs_open") + if len(f.edits) != 1 || !strings.Contains(f.edits[0], "- [x] #1") { + t.Fatalf("edits = %q, want #1 ticked", f.edits) + } +} + +func TestAdvisoryChecklistProgress(t *testing.T) { + for _, tc := range []struct { + body string + items, resolved int + }{ + {advisoryItemsBody(), 2, 0}, + {"- [x] #1 done\n- [X] PR #2 done\n- [ ] #3 open\n* [ ] o/x#4 elsewhere\n", 4, 2}, + {"no task list; #1 and #2 in prose\n", 0, 0}, + } { + items, resolved := AdvisoryChecklistProgress(tc.body) + if items != tc.items || resolved != tc.resolved { + t.Errorf("AdvisoryChecklistProgress(%q) = %d/%d, want %d/%d", tc.body, resolved, items, tc.resolved, tc.items) + } + } +} + +func TestAdvisoryChecklistItemsRefs(t *testing.T) { + items := advisoryChecklistItems("- [ ] #1 a\n- [ ] PR #2 b\n- [ ] issue o/x#3 c\n- [ ] Add Fixes #4\n", "o/r") + want := []ClaimedRef{{Repo: "o/r", Issue: 1}, {Repo: "o/r", Issue: 2}, {Repo: "o/x", Issue: 3}, {}} + if len(items) != len(want) { + t.Fatalf("items = %+v", items) + } + for i, it := range items { + if it.Ref != want[i] { + t.Errorf("item %d ref = %+v, want %+v", i, it.Ref, want[i]) + } + } +} diff --git a/src/pkg/github/dedupe_checklist_findings.go b/src/pkg/github/dedupe_checklist_findings.go index 5421bd7eb9..e2c677dc32 100644 --- a/src/pkg/github/dedupe_checklist_findings.go +++ b/src/pkg/github/dedupe_checklist_findings.go @@ -94,6 +94,11 @@ type IssueAdvisory struct { // Empty is true when the body is a dedupe checklist with nothing // actionable in it (DedupeChecklistFindings.Actionable is false). Empty bool `json:"empty,omitempty"` + // Items / Resolved count a dedupe checklist's task-list lines and the + // ticked ones (hivecommons/hive#15754): the tracker reads "k/N + // resolved" while the hive works them. + Items int `json:"items,omitempty"` + Resolved int `json:"resolved,omitempty"` } // dedupeDecisionNoLinePattern finds a "Decision required: no" line anywhere @@ -108,7 +113,8 @@ func IssueAdvisoryFromBody(body string) *IssueAdvisory { return nil } if f, ok := ParseDedupeChecklistFindings(body); ok { - return &IssueAdvisory{DedupeChecklist: true, DecisionNo: !f.DecisionRequired, Empty: !f.Actionable()} + items, resolved := AdvisoryChecklistProgress(body) + return &IssueAdvisory{DedupeChecklist: true, DecisionNo: !f.DecisionRequired, Empty: !f.Actionable(), Items: items, Resolved: resolved} } if dedupeDecisionNoLinePattern.MatchString(stripFencedCode(body)) { return &IssueAdvisory{DecisionNo: true} From 26b513c2ee5d1f93fe92bf68a205fb78415a947d Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 09:40:48 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20rename=20config.Dedup?= =?UTF-8?q?eConfig=20to=20avoid=20writeback=20name=20collision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit settingsparity resolves bare identifiers by name across every collected package, so config.DedupeConfig resolved to writeback.DedupeConfig and TestSettingsDialogReferencesEveryHiveYAMLLeaf reported the writeback dedupe leaves as unallowlisted. Rename to DedupeAdvisoryConfig. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/cmd/hive/close_on_merge_advisory_autoclose_test.go | 2 +- src/pkg/config/config.go | 4 ++-- src/pkg/config/dedupe.go | 6 +++--- src/pkg/dashboard/stage_tracker_advisory_working_test.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/hive/close_on_merge_advisory_autoclose_test.go b/src/cmd/hive/close_on_merge_advisory_autoclose_test.go index fb40e83558..d14fc3b9ef 100644 --- a/src/cmd/hive/close_on_merge_advisory_autoclose_test.go +++ b/src/cmd/hive/close_on_merge_advisory_autoclose_test.go @@ -16,7 +16,7 @@ func TestCloseOnMergeOptionsAdvisoryAutoclose(t *testing.T) { wantDisable bool }{ {"unset", config.Config{}, false}, - {"off", config.Config{Dedupe: config.DedupeConfig{AdvisoryAutoclose: &off}}, true}, + {"off", config.Config{Dedupe: config.DedupeAdvisoryConfig{AdvisoryAutoclose: &off}}, true}, } { t.Run(tc.name, func(t *testing.T) { if got := closeOnMergeOptionsFor(&tc.cfg, nil, nil).DisableAdvisoryAutoclose; got != tc.wantDisable { diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index f83992b625..f9fb3701ad 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -175,8 +175,8 @@ type Config struct { // (hivecommons/hive#12253). Default on. SharedCIRerun SharedCIRerunConfig `yaml:"shared_ci_rerun,omitempty" json:"shared_ci_rerun,omitempty"` // Dedupe tunes what the hive does with the dedupe agent's advisory - // checklists (hivecommons/hive#15754); see DedupeConfig. - Dedupe DedupeConfig `yaml:"dedupe,omitempty" json:"dedupe,omitempty"` + // checklists (hivecommons/hive#15754); see DedupeAdvisoryConfig. + Dedupe DedupeAdvisoryConfig `yaml:"dedupe,omitempty" json:"dedupe,omitempty"` // Scanner tunes the pre-dispatch guards every automated claim producer // runs before an issue is handed out (hivecommons/hive#14799). Scanner ScannerConfig `yaml:"scanner,omitempty" json:"scanner,omitempty"` diff --git a/src/pkg/config/dedupe.go b/src/pkg/config/dedupe.go index 74bef6ba0e..275a73c412 100644 --- a/src/pkg/config/dedupe.go +++ b/src/pkg/config/dedupe.go @@ -1,8 +1,8 @@ package config -// DedupeConfig tunes what the hive does with the dedupe agent's advisory +// DedupeAdvisoryConfig tunes what the hive does with the dedupe agent's advisory // checklists (hivecommons/hive#15754). -type DedupeConfig struct { +type DedupeAdvisoryConfig struct { // AdvisoryAutoclose lets the close-on-merge backfill tick each // `- [ ] #N` item of a hive-authored dedupe checklist once #N is closed // or merged, and close the checklist as completed once every item is @@ -12,6 +12,6 @@ type DedupeConfig struct { } // AdvisoryAutocloseEnabled reports whether the item pass runs; unset means on. -func (c DedupeConfig) AdvisoryAutocloseEnabled() bool { +func (c DedupeAdvisoryConfig) AdvisoryAutocloseEnabled() bool { return c.AdvisoryAutoclose == nil || *c.AdvisoryAutoclose } diff --git a/src/pkg/dashboard/stage_tracker_advisory_working_test.go b/src/pkg/dashboard/stage_tracker_advisory_working_test.go index c4f9e04aab..b266b193e4 100644 --- a/src/pkg/dashboard/stage_tracker_advisory_working_test.go +++ b/src/pkg/dashboard/stage_tracker_advisory_working_test.go @@ -48,7 +48,7 @@ func TestStageTrackerAdvisoryAutocloseKnob(t *testing.T) { if !stageTrackerAdvisoryAutoclose(nil) || !stageTrackerAdvisoryAutoclose(&config.Config{}) { t.Error("unset knob must read as on") } - if stageTrackerAdvisoryAutoclose(&config.Config{Dedupe: config.DedupeConfig{AdvisoryAutoclose: &off}}) { + if stageTrackerAdvisoryAutoclose(&config.Config{Dedupe: config.DedupeAdvisoryConfig{AdvisoryAutoclose: &off}}) { t.Error("knob set false must read as off") } }