diff --git a/changelog.d/fixed-dedupe-checklist-fold-same-file.md b/changelog.d/fixed-dedupe-checklist-fold-same-file.md new file mode 100644 index 0000000000..3ac2b989bb --- /dev/null +++ b/changelog.d/fixed-dedupe-checklist-fold-same-file.md @@ -0,0 +1 @@ +- A dedupe-agent checklist is no longer folded into an existing finding that shares a path with it. projectbluefin/actions#543, a data-loss bug, received the repository's whole checklist as a "Folded finding"; checklists now skip the path folds like DAG children do. The review backlog's "Same file as #N" cross-link also names the path the two items share: on projectbluefin/utah-packages#868 it named the finding's own `config/factory-build-backlog.toml`, which #852 never cited (the shared file was `docs/skills/factory-build-backlog.md`). diff --git a/src/docs/hive-open-issue.md b/src/docs/hive-open-issue.md index f09c582fe3..87de167c13 100644 --- a/src/docs/hive-open-issue.md +++ b/src/docs/hive-open-issue.md @@ -794,6 +794,15 @@ canonical title match on a human-filed issue), `file_set` (an exact file-set twin) or `component:` (a same-component fold on ``), so the agent can tell a true twin from a shared-path fold. +### Dedupe checklists never take a fold + +A dedupe-agent checklist (body carrying ``) +cites every path its pairs touch, so a path fold would bury the whole repo +checklist in whichever finding shares one: projectbluefin/actions#543, a +data-loss bug, received the repository's checklist as a "Folded finding". A +checklist skips the same folds as a DAG child (below); an open issue with the +exact same title is still reused. + ### DAG children never take a fold A request that declares `--parent` or `--blocked-by` is an explicit statement diff --git a/src/docs/review-swarm.md b/src/docs/review-swarm.md index 041a97d79c..b9f9e3a12c 100644 --- a/src/docs/review-swarm.md +++ b/src/docs/review-swarm.md @@ -108,7 +108,7 @@ The default human threshold is `high`. Review-triggered fix cycles use the same ### Out-of-scope backlog filing -When the relay accepts a review verdict, cited out-of-scope findings (`review_scope: "out-of-scope"` with `file` and positive `line`) are filed as follow-up issues labeled `agent/reviewer` (the reviewer lane provenance/routing label — see [labels-and-control-signals.md](labels-and-control-signals/reference.md#label-axes); the retired `from-review`, `origin/review`, and `origin/reviewer` names are accepted in config and migrated on open items). Each issue is titled `[reviewer] Review backlog (): ` — like every issue the hive files, the title starts with the filing agent in square brackets (`issueshape.AgentIssueTitle`, the one function every hive issue-creation path runs its title through — `CreateIssue`, the raw advisory/recommendations/upstream-watch creates and the egress proxy — so no filer can forget it; it puts the tag first, never doubles it, and title dedupe ignores it so items filed before the tag still match). Each issue body links back to the reviewed PR and records the perspective, severity, evidence location, and finding summary. The relay deduplicates against open issues through the normal issue-create path and also persists a finding key in `/data/review-backlog-issues.json`, so re-reviewing a new commit does not file the same backlog issue or summary comment again. +When the relay accepts a review verdict, cited out-of-scope findings (`review_scope: "out-of-scope"` with `file` and positive `line`) are filed as follow-up issues labeled `agent/reviewer` (the reviewer lane provenance/routing label — see [labels-and-control-signals.md](labels-and-control-signals/reference.md#label-axes); the retired `from-review`, `origin/review`, and `origin/reviewer` names are accepted in config and migrated on open items). Each issue is titled `[reviewer] Review backlog (): ` — like every issue the hive files, the title starts with the filing agent in square brackets (`issueshape.AgentIssueTitle`, the one function every hive issue-creation path runs its title through — `CreateIssue`, the raw advisory/recommendations/upstream-watch creates and the egress proxy — so no filer can forget it; it puts the tag first, never doubles it, and title dedupe ignores it so items filed before the tag still match). Each issue body links back to the reviewed PR and records the perspective, severity, evidence location, and finding summary. The relay deduplicates against open issues through the normal issue-create path and also persists a finding key in `/data/review-backlog-issues.json`, so re-reviewing a new commit does not file the same backlog issue or summary comment again. When an open issue cites a path this finding also cites but is a different finding, the new item gets a "Same file as #N" cross-link naming the path the two share (not necessarily the finding's own evidence file). The PR receives one summary comment listing the backlog issues filed from that review. Filing is enabled by default and bounded by `review.max_out_of_scope_backlog_issues` (default `3`) per PR; set `review.out_of_scope_backlog_disabled: true` to opt out. diff --git a/src/pkg/github/dedupe_checklist_no_fold_test.go b/src/pkg/github/dedupe_checklist_no_fold_test.go new file mode 100644 index 0000000000..18358da3cc --- /dev/null +++ b/src/pkg/github/dedupe_checklist_no_fold_test.go @@ -0,0 +1,50 @@ +package github + +import "testing" + +// projectbluefin/actions#543 (a data-loss bug in reusable-sync-branches.yml) +// received the repo's dedupe checklist as a "Folded finding" on 10-24: the +// checklist cited the same workflow, and three open bot issues on it put the +// request over the same-component fold. A dedupe checklist is filed on its +// own, like projectbluefin/utah#1085. +func TestDedupeChecklistIsNeverPathFolded(t *testing.T) { + siblings := []openTwin{ + {number: 543, author: testBot, title: "[ci-maintainer] reusable-sync-branches.yml force-resets target_branch", body: "github/workflows/reusable-sync-branches.yml"}, + {number: 593, author: testBot, title: "[reviewer] inline inputs interpolation", body: "github/workflows/reusable-sync-branches.yml line 40"}, + {number: 678, author: testBot, title: "[scanner] sync step lacks a lock", body: "github/workflows/reusable-sync-branches.yml line 77"}, + } + checklist := "\nDecision required: no\n\n- [ ] PR #544 and PR #675 both rewrite github/workflows/reusable-sync-branches.yml" + + m := &consolidationMock{} + srv := consolidationMockServer(t, siblings, m) + defer srv.Close() + c := issueTestClient(t, srv.URL) + c.appBotLogin = testBot + _, res := fileRequest(t, c, withIssueDir(t), IssueRequest{ + Repo: "o/r", Agent: "dedupe", + Title: "[dedupe] triage: duplicate and overlapping open issues/PRs to consolidate", + Body: checklist, + }) + if m.created != 1 || len(m.commentedOn) != 0 { + t.Fatalf("created=%d comments=%v, want the checklist filed on its own", m.created, m.commentedOn) + } + if !res.OK || res.Consolidated { + t.Fatalf("result = %+v, want a plain create", res) + } + + // Control: the same body without the marker folds, so the marker is what + // keeps it out. + m = &consolidationMock{} + srv2 := consolidationMockServer(t, siblings, m) + defer srv2.Close() + c = issueTestClient(t, srv2.URL) + c.appBotLogin = testBot + _, res = fileRequest(t, c, withIssueDir(t), IssueRequest{ + Repo: "o/r", Agent: "dedupe", + Title: "[dedupe] triage: duplicate and overlapping open issues/PRs to consolidate", + Body: "Decision required: no\n\n- [ ] PR #544 and PR #675 both rewrite github/workflows/reusable-sync-branches.yml", + }) + if m.created != 0 || !res.Consolidated { + t.Fatalf("control: created=%d result=%+v, want a fold without the marker", m.created, res) + } +} diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index 874ac4349f..8045d7fa24 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -1422,6 +1422,10 @@ type CreateIssueResult struct { // fold into: it cites the same files but not the same finding, so a new // issue was created instead (#13906). 0 otherwise. SameFileAs int + // SameFilePath is the path SameFileAs shares with this request when the + // match was on one component path; "" for an equal file set, where every + // cited path is shared. + SameFilePath string } // CreateIssueRequest is what every hive issue-create path hands the central @@ -1444,7 +1448,7 @@ type CreateIssueRequest struct { // SkipSharedPathFold suppresses the file-set, same-component and // canonical-subject folds (#16065) for a request that declares DAG // placement (--parent or --blocked-by): sibling children routinely share - // a path and a title stem. The create's idempotency claim keys on the + // a path and a title stem. createIssue sets it for a dedupe checklist too. The create's idempotency claim keys on the // exact title rather than the canonical stem for the same reason. The // exact-title and rejected-twin gates still apply. SkipSharedPathFold bool @@ -1524,6 +1528,14 @@ func (c *Client) CreateIssue(ctx context.Context, req CreateIssueRequest) (Creat // dashboard's ACMM gap issues) also turn it on. func (c *Client) createIssue(ctx context.Context, req CreateIssueRequest) (CreateIssueResult, error) { repo, title, body, consolidateOpen := req.Repo, req.Title, req.Body, req.ConsolidateOpen + // A dedupe checklist cites every path its pairs touch, so a path fold + // would bury the whole repo checklist in whichever finding shares one: + // projectbluefin/actions#543, a data-loss bug, received the repo's + // checklist as a "Folded finding" (10-24). It is filed on its own, like a + // declared DAG node; an exact-title twin is still reused. + if strings.Contains(body, dedupeChecklistMarkerPrefix) { + req.SkipSharedPathFold = true + } originLabel := req.OriginLabel() if originLabel == "" { return CreateIssueResult{}, ErrOriginRequired @@ -1661,6 +1673,7 @@ func (c *Client) createIssue(ctx context.Context, req CreateIssueRequest) (Creat // whichever merges first forces the other to rebase. Fold the finding into // the existing issue so one PR handles both. var sameFileAs int + var sameFilePath string if fileSetTwin != nil && req.FoldMatch != nil && !req.FoldMatch(fileSetTwin.GetTitle(), fileSetTwin.GetBody()) { sameFileAs, fileSetTwin = fileSetTwin.GetNumber(), nil } @@ -1712,7 +1725,7 @@ func (c *Client) createIssue(ctx context.Context, req CreateIssueRequest) (Creat } if componentTwin != nil && req.FoldMatch != nil && !req.FoldMatch(componentTwin.GetTitle(), componentTwin.GetBody()) { if sameFileAs == 0 { - sameFileAs = componentTwin.GetNumber() + sameFileAs, sameFilePath = componentTwin.GetNumber(), componentPath } componentTwin = nil } @@ -1804,11 +1817,11 @@ func (c *Client) createIssue(ctx context.Context, req CreateIssueRequest) (Creat } c.logger.Info("CreateIssue: create replayed as already applied, reusing the journaled issue", slog.String("repo", repoName), slog.Int("number", number)) - return CreateIssueResult{Number: number, URL: res.Provenance, AlreadyExisted: true, SameFileAs: sameFileAs}, nil + return CreateIssueResult{Number: number, URL: res.Provenance, AlreadyExisted: true, SameFileAs: sameFileAs, SameFilePath: sameFilePath}, nil } c.logger.Info("CreateIssue: issue created as the App bot", slog.String("repo", repoName), slog.Int("number", issue.GetNumber())) - return CreateIssueResult{Number: issue.GetNumber(), URL: issue.GetHTMLURL(), ID: issue.GetID(), SameFileAs: sameFileAs}, nil + return CreateIssueResult{Number: issue.GetNumber(), URL: issue.GetHTMLURL(), ID: issue.GetID(), SameFileAs: sameFileAs, SameFilePath: sameFilePath}, nil } // issueCreateUnknownTTL bounds how long an issue-create operation may sit diff --git a/src/pkg/github/review_backlog.go b/src/pkg/github/review_backlog.go index 50778b1f37..d57356ebd0 100644 --- a/src/pkg/github/review_backlog.go +++ b/src/pkg/github/review_backlog.go @@ -424,7 +424,7 @@ func (c *Client) fileReviewBacklog(ctx context.Context, req ReviewRequest, now t if !ref.Reused && ref.SameFileAs > 0 && createErr == nil { // hivecommons/hive#13906: the item exists, so a failed // cross-link must not fail the pass and re-file it. - if err := sink.AppendToItem(ctx, req.Repo, ref, reviewBacklogSameFileComment(finding, ref.SameFileAs)); err != nil { + if err := sink.AppendToItem(ctx, req.Repo, ref, reviewBacklogSameFileComment(finding, ref.SameFileAs, ref.SameFilePath)); err != nil { c.logger.Warn("review backlog: same-file cross-link comment failed", slog.String("repo", req.Repo), slog.String("item", ref.Key), slog.Int("same_file_as", ref.SameFileAs), slog.String("error", err.Error())) diff --git a/src/pkg/github/review_backlog_routing.go b/src/pkg/github/review_backlog_routing.go index da4914e014..b2ccccef48 100644 --- a/src/pkg/github/review_backlog_routing.go +++ b/src/pkg/github/review_backlog_routing.go @@ -75,6 +75,9 @@ type ReviewBacklogRef struct { // same file but was not folded into because it describes a different // finding (#13906); 0 when there is none. SameFileAs int + // SameFilePath is the path the two share; "" when every cited path is + // (CreateIssueResult.SameFilePath). + SameFilePath string } // ReviewBacklogSink is a backlog destination. The GitHub issue sink lives @@ -148,12 +151,13 @@ func (s githubIssueBacklogSink) CreateItem(ctx context.Context, item ReviewBackl } } return ReviewBacklogRef{ - ID: strconv.Itoa(res.Number), - Key: fmt.Sprintf("#%d", res.Number), - Number: res.Number, - URL: res.URL, - Reused: res.AlreadyExisted, - SameFileAs: res.SameFileAs, + ID: strconv.Itoa(res.Number), + Key: fmt.Sprintf("#%d", res.Number), + Number: res.Number, + URL: res.URL, + Reused: res.AlreadyExisted, + SameFileAs: res.SameFileAs, + SameFilePath: res.SameFilePath, }, nil } @@ -588,9 +592,16 @@ func (c *Client) reviewBacklogFoldedComment(req ReviewRequest, p review.Perspect // reviewBacklogSameFileComment cross-links a newly filed item to the open // issue that cites the same file but was not folded into because it is a // different finding (#13906). GitHub backlinks the reference on that issue. -func reviewBacklogSameFileComment(f outputschema.Finding, sameFileAs int) string { +// It names the path the two share: projectbluefin/utah-packages#868 said both +// cite its own evidence file, config/factory-build-backlog.toml, which #852 +// never mentions; the shared path was docs/skills/factory-build-backlog.md. +func reviewBacklogSameFileComment(f outputschema.Finding, sameFileAs int, sharedPath string) string { + shared := strings.TrimSpace(sharedPath) + if shared == "" { + shared = strings.TrimSpace(f.File) + } var b strings.Builder fmt.Fprintf(&b, "%s%d -->\n", reviewBacklogSameFileMarker, sameFileAs) - fmt.Fprintf(&b, "Same file as #%d: both cite `%s`, but this finding does not match that issue's symbol, line range or category, so it was filed separately instead of folded in.\n\n%s\n", sameFileAs, strings.TrimSpace(f.File), reviewBacklogFooter) + fmt.Fprintf(&b, "Same file as #%d: both cite `%s`, but this finding does not match that issue's symbol, line range or category, so it was filed separately instead of folded in.\n\n%s\n", sameFileAs, shared, reviewBacklogFooter) return b.String() } diff --git a/src/pkg/github/review_backlog_same_file_path_test.go b/src/pkg/github/review_backlog_same_file_path_test.go new file mode 100644 index 0000000000..a981e20084 --- /dev/null +++ b/src/pkg/github/review_backlog_same_file_path_test.go @@ -0,0 +1,97 @@ +package github + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/outputschema" +) + +// projectbluefin/utah-packages#868 cites config/factory-build-backlog.toml +// (its evidence) and docs/skills/factory-build-backlog.md; #852 cites the +// docs file but never the TOML. The cross-link said "both cite +// `config/factory-build-backlog.toml`". It names the shared path now. +func TestReviewBacklogSameFileNamesSharedPath(t *testing.T) { + withReviewBacklogState(t) + twins := []map[string]any{} + for i, n := range []int{852, 840, 831} { + twins = append(twins, map[string]any{ + "number": n, "state": "open", "html_url": fmt.Sprintf("https://github.example/o/r/issues/%d", n), + "title": fmt.Sprintf("[reviewer] Review backlog (docs-currency): skill doc %d drifts", i), + "body": fmt.Sprintf("Perspective: docs-currency\nEvidence: `docs/skills/font-package-recipes.md:%d`\n\ndocs/skills/factory-build-backlog.md now points at the new recipe.", 100+i), + "user": map[string]any{"login": testBot}, + }) + } + raw, err := json.Marshal(twins) + if err != nil { + t.Fatal(err) + } + comments := map[int][]string{} + created := 0 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch { + case r.Method == http.MethodGet && r.URL.Path == "/repos/o/r/issues": + if r.URL.Query().Get("state") != "open" { + _, _ = io.WriteString(w, `[]`) + return + } + _, _ = w.Write(raw) + case r.Method == http.MethodGet && strings.HasPrefix(r.URL.Path, "/repos/o/r/labels/"): + _, _ = io.WriteString(w, `{"name":"x"}`) + case r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/comments"): + var n int + _, _ = fmt.Sscanf(r.URL.Path, "/repos/o/r/issues/%d/comments", &n) + var payload struct { + Body string `json:"body"` + } + _ = json.NewDecoder(r.Body).Decode(&payload) + comments[n] = append(comments[n], payload.Body) + _, _ = io.WriteString(w, `{"id":1}`) + case r.Method == http.MethodPost && r.URL.Path == "/repos/o/r/issues": + created++ + _, _ = io.WriteString(w, `{"number":868,"html_url":"https://github.example/o/r/issues/868"}`) + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer srv.Close() + c := reviewTestClient(t, srv.URL) + c.appBotLogin = testBot + c.SetReviewBacklogRouting(func() ReviewBacklogRouting { + return ReviewBacklogRouting{ + Severity: config.ReviewSeverityConfig{BlockAt: "P2"}, + Backlog: config.ReviewBacklogConfig{Destination: config.ReviewBacklogGitHubIssue, Labels: []string{"nit"}}, + } + }) + finding := nit("Tracking issue #490 already closed despite five outputs still pending", "low", "config/factory-build-backlog.toml", 12, + "docs/skills/factory-build-backlog.md says the batch stays open until every output builds.") + if err := c.fileOutOfScopeReviewBacklog(context.Background(), ReviewRequest{Repo: "o/r", Number: 867, Agent: "reviewer", Report: routingReport(t, 867, "abc", finding)}, time.Now()); err != nil { + t.Fatal(err) + } + if created != 1 || len(comments[868]) != 1 { + t.Fatalf("created=%d comments on #868=%q, want one new issue with one cross-link", created, comments[868]) + } + note := comments[868][0] + if !strings.Contains(note, "both cite `docs/skills/factory-build-backlog.md`") || strings.Contains(note, "config/factory-build-backlog.toml") { + t.Fatalf("cross-link must name the shared path, not the finding's own file:\n%s", note) + } +} + +func TestReviewBacklogSameFileCommentFallsBackToFindingFile(t *testing.T) { + finding := outputschema.Finding{Title: "x", Severity: outputschema.SeverityLow, File: "pkg/a.go", Line: 3, Summary: "y"} + if got := reviewBacklogSameFileComment(finding, 41, ""); !strings.Contains(got, "both cite `pkg/a.go`") { + t.Fatalf("equal file set keeps the finding's file:\n%s", got) + } + if got := reviewBacklogSameFileComment(finding, 41, " docs/x.md "); !strings.Contains(got, "both cite `docs/x.md`") { + t.Fatalf("shared path wins:\n%s", got) + } +}