diff --git a/changelog.d/fixed-dupsweep-bot-series-same-job.md b/changelog.d/fixed-dupsweep-bot-series-same-job.md new file mode 100644 index 0000000000..6611b9b139 --- /dev/null +++ b/changelog.d/fixed-dupsweep-bot-series-same-job.md @@ -0,0 +1 @@ +- The duplicate-PR sweep no longer calls one dependency bot's separate bumps a "Superseded regeneration series". Renovate or Dependabot PRs for different dependencies all edit `package.json`, and the sweep used to call the older ones "superseded by construction" because they shared an author and a file. A bot series now needs the same job: titles that match once versions, dates and hashes are set aside, or byte-identical patches. One bot's different jobs form no cluster and get no comment. Real regeneration series, human and mixed-author clusters, and identical-diff and finding-identity clusters are unchanged. diff --git a/src/docs/duplicate-sweep.md b/src/docs/duplicate-sweep.md index 46e996248d..13742cc693 100644 --- a/src/docs/duplicate-sweep.md +++ b/src/docs/duplicate-sweep.md @@ -52,11 +52,17 @@ not check" must never render as "we checked and they agree". a change should not be asked to stand down for someone who arrived later. Suggestions are posted on the **later** PRs. - **Bot regeneration series** (every member authored by the same `[bot]` - account, or a login listed in `bot_authors`) — the **newest** survives, since - each run supersedes the last by construction, and a **single summary** is - posted on that newest PR rather than one comment on each. A bot re-opening - the same PR daily would otherwise turn this sweep into the noise source it is - meant to reduce. + account, or a login listed in `bot_authors`, running the **same job**: the + titles match once versions, dates and hashes are set aside, or the patches + are byte-identical) — the **newest** survives, since each run supersedes the + last by construction, and a **single summary** is posted on that newest PR + rather than one comment on each. A bot re-opening the same PR daily would + otherwise turn this sweep into the noise source it is meant to reduce. +- **One bot's different jobs** — a dependency bot's separate bumps that all + edit `package.json` and its lockfile, say "update dependency vue-tsc to + v3.3.14" and "update dependency js-yaml to v5" — are **not clustered at + all** and get no comment. They are separate updates, not duplicates. A + shared finding identity still clusters them as an ordinary cluster. Drafts are excluded entirely: a draft is not competing for the queue slot the sweep exists to free. diff --git a/src/pkg/dupsweep/dupsweep.go b/src/pkg/dupsweep/dupsweep.go index 802319e199..f0c579db0c 100644 --- a/src/pkg/dupsweep/dupsweep.go +++ b/src/pkg/dupsweep/dupsweep.go @@ -29,6 +29,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "regexp" "sort" "strings" "time" @@ -95,7 +96,10 @@ type Cluster struct { FindingKey string Confidence Confidence // BotSeries marks a cluster whose members are all the same bot account - // regenerating the same artifact. Those are superseded BY CONSTRUCTION — + // running the same job again: the same title once versions, dates and + // hashes are set aside, or a byte-identical patch (see sameJob). Sharing + // a file is not enough — renovate bumping two different dependencies in + // one package.json is two jobs. Those are superseded BY CONSTRUCTION — // the newest regeneration is the survivor — and they get one summary // comment rather than one comment per PR, because a bot re-opening the // same PR daily would otherwise turn this sweep into the noise source it @@ -256,7 +260,10 @@ func Find(prs []PR, opts Options) []Cluster { if len(b.members) < 2 { continue } - c := buildCluster(b, opts.BotAuthors, false) + c, ok := buildCluster(b, opts.BotAuthors, false) + if !ok { + continue + } clusterByMembers[memberKey(c.Members())] = len(clusters) clusters = append(clusters, c) } @@ -265,7 +272,10 @@ func Find(prs []PR, opts Options) []Cluster { if len(b.members) < 2 { continue } - c := buildCluster(b, opts.BotAuthors, true) + c, ok := buildCluster(b, opts.BotAuthors, true) + if !ok { + continue + } mkey := memberKey(c.Members()) if i, ok := clusterByMembers[mkey]; ok { clusters[i] = c @@ -287,11 +297,22 @@ func Find(prs []PR, opts Options) []Cluster { return clusters } -func buildCluster(b *clusterBucket, botAuthors []string, identity bool) Cluster { +// buildCluster turns a bucket into a cluster. ok is false when the bucket is +// one bot's independent jobs that merely share a file — renovate bumping +// different dependencies in one package.json, the false positive #7469 names +// — which are not duplicates of each other at all. A finding identity or a +// byte-identical patch is evidence beyond the shared file, so those still +// cluster. +func buildCluster(b *clusterBucket, botAuthors []string, identity bool) (Cluster, bool) { members := append([]PR(nil), b.members...) sort.Slice(members, func(i, j int) bool { return members[i].Number < members[j].Number }) - botSeries := isBotSeries(members, botAuthors) + confidence := gradeConfidence(members, identity) + sameBot := sameBotAuthor(members, botAuthors) + botSeries := sameBot && (confidence == ConfidenceIdenticalDiff || sameJob(members)) + if sameBot && !botSeries && confidence != ConfidenceFindingIdentity { + return Cluster{}, false + } survivor := pickSurvivor(members, botSeries) superseded := make([]PR, 0, len(members)-1) for _, m := range members { @@ -303,11 +324,11 @@ func buildCluster(b *clusterBucket, botAuthors []string, identity bool) Cluster Repo: b.repo, Files: b.files, FindingKey: b.findingKey, - Confidence: gradeConfidence(members, identity), + Confidence: confidence, BotSeries: botSeries, Survivor: survivor, Superseded: superseded, - } + }, true } func memberKey(members []PR) string { @@ -355,11 +376,12 @@ func newer(a, b PR) bool { return a.CreatedAt.After(b.CreatedAt) } -// isBotSeries reports whether every member is the same bot account. All three -// conditions matter: same author (two different bots are not a series), a bot -// account (a human resubmitting is NOT superseded by construction and must -// get the ordinary earliest-survives treatment), and more than one member. -func isBotSeries(members []PR, extra []string) bool { +// sameBotAuthor reports whether every member is the same bot account. All +// three conditions matter: same author (two different bots are not a series), +// a bot account (a human resubmitting is NOT superseded by construction and +// must get the ordinary earliest-survives treatment), and more than one member. +// It is necessary for a series, not sufficient: see sameJob. +func sameBotAuthor(members []PR, extra []string) bool { if len(members) < 2 { return false } @@ -375,6 +397,46 @@ func isBotSeries(members []PR, extra []string) bool { return true } +// sameJob reports whether every member's title names the same job once the +// tokens a rerun changes are set aside. A regeneration bot titles every run +// alike ("chore: update churn", "regenerate X (2026-11-16)"); a dependency +// bot names the dependency, so "update dependency vue-tsc to v3.3.14" and +// "update dependency js-yaml to v5" are two jobs even though both edit +// package.json. The head branch cannot tell these apart: two open PRs never +// share one, whether they are reruns or separate bumps. +func sameJob(members []PR) bool { + job := jobTitle(members[0].Title) + for _, m := range members[1:] { + if jobTitle(m.Title) != job { + return false + } + } + return true +} + +var ( + // jobTitleHash matches a commit or digest hash: 7+ hex characters as one + // word. Words without a digit ("deadbeef", "facade") are left alone. + jobTitleHash = regexp.MustCompile(`\b[0-9a-f]{7,64}\b`) + // jobTitleNumber matches a version, date or counter that starts a token + // ("v3.3.14", "2026-11-16", "#42"), but not digits inside a name such as + // "web3" or "python3", which identify the dependency. + jobTitleNumber = regexp.MustCompile(`(^|[^a-z0-9])v?[0-9]+(?:[.\-_:+/][0-9]+)*`) +) + +// jobTitle normalises a title to the job it names: lower-cased, whitespace +// collapsed, hashes and versions/dates/counters replaced by "#". +func jobTitle(title string) string { + t := strings.ToLower(strings.Join(strings.Fields(title), " ")) + t = jobTitleHash.ReplaceAllStringFunc(t, func(s string) string { + if strings.IndexAny(s, "0123456789") < 0 { + return s + } + return "#" + }) + return jobTitleNumber.ReplaceAllString(t, "${1}#") +} + func looksLikeBot(author string, extra []string) bool { a := strings.TrimSpace(author) if a == "" { diff --git a/src/pkg/dupsweep/dupsweep_test.go b/src/pkg/dupsweep/dupsweep_test.go index 7c019bbb4b..9120413bb6 100644 --- a/src/pkg/dupsweep/dupsweep_test.go +++ b/src/pkg/dupsweep/dupsweep_test.go @@ -198,6 +198,110 @@ func TestBotAuthorsOptionExtendsDetection(t *testing.T) { } } +// projectbluefin/website#1023: one dependency bot (renovate running as an +// App) opens one PR per dependency, and every one edits package.json and its +// lockfile. Those are separate updates, not a regeneration series and not +// duplicates of each other, so the sweep must say nothing — not "superseded +// by construction", and not "Possible duplicate" either. +func TestDependencyBotBumpsSharingAManifestAreNotClustered(t *testing.T) { + manifest := []string{"package.json", "package-lock.json"} + prs := []PR{ + {Repo: "o/website", Number: 1009, Title: "chore(deps): update tailwindcss monorepo to v5 (major)", Author: "mergeraptor[bot]", CreatedAt: at(1), Files: manifest, DiffHash: "tw"}, + {Repo: "o/website", Number: 1019, Title: "chore(deps): update dependency vue-tsc to v3.3.14", Author: "mergeraptor[bot]", CreatedAt: at(2), Files: manifest, DiffHash: "vt"}, + {Repo: "o/website", Number: 1023, Title: "chore(deps): update dependency @antfu/eslint-config to v10", Author: "mergeraptor[bot]", CreatedAt: at(3), Files: manifest, DiffHash: "ae"}, + {Repo: "o/website", Number: 1037, Title: "chore(deps): update dependency js-yaml to v5", Author: "mergeraptor[bot]", CreatedAt: at(4), Files: manifest, DiffHash: "jy"}, + } + if got := Find(prs, Options{}); len(got) != 0 { + t.Fatalf("independent dependency bumps clustered: %+v", got) + } + // Unknown diff hashes do not change that: the titles already show two jobs. + for i := range prs { + prs[i].DiffHash = "" + } + if got := Find(prs, Options{}); len(got) != 0 { + t.Fatalf("independent bumps with unknown diffs clustered: %+v", got) + } +} + +// A regeneration bot dates or numbers each run; that is still the same job, +// so #7469's newest-survives series behaviour is unchanged. +func TestRegenerationTitlesDifferingOnlyByDateOrVersionAreASeries(t *testing.T) { + const out = "static/data/update-churn.json" + prs := []PR{ + {Repo: "o/docs", Number: 1264, Title: "chore: regenerate churn (2026-11-15)", Author: "churn[bot]", CreatedAt: at(1), Files: []string{out}, DiffHash: "d1"}, + {Repo: "o/docs", Number: 1272, Title: "chore: regenerate churn (2026-11-16)", Author: "churn[bot]", CreatedAt: at(2), Files: []string{out}, DiffHash: "d2"}, + {Repo: "o/docs", Number: 1275, Title: "Chore: regenerate churn (2026-11-17)", Author: "churn[bot]", CreatedAt: at(3), Files: []string{out}, DiffHash: "d3"}, + } + got := Find(prs, Options{}) + if len(got) != 1 || !got[0].BotSeries { + t.Fatalf("dated regenerations are not one series: %+v", got) + } + if got[0].Survivor.Number != 1275 { + t.Errorf("survivor = #%d, want the newest #1275", got[0].Survivor.Number) + } +} + +// A byte-identical patch is the same job whatever the titles say, so one bot's +// identical PRs still cluster as a series; a shared finding identity is +// evidence beyond the shared file too, so it still clusters (as an ordinary +// cluster, since the titles name different jobs). +func TestSameBotWithStrongerEvidenceStillClusters(t *testing.T) { + identical := []PR{ + {Repo: "o/r", Number: 1, Title: "chore: sync labels", Author: "sync[bot]", CreatedAt: at(1), Files: []string{"labels.yml"}, DiffHash: "same"}, + {Repo: "o/r", Number: 2, Title: "chore: apply label set", Author: "sync[bot]", CreatedAt: at(2), Files: []string{"labels.yml"}, DiffHash: "same"}, + } + got := Find(identical, Options{}) + if len(got) != 1 || got[0].Confidence != ConfidenceIdenticalDiff || !got[0].BotSeries { + t.Fatalf("identical bot patches: %+v, want one identical-diff series", got) + } + + finding := []PR{ + {Repo: "o/r", Number: 3, Title: "fix: pin action in ci.yml", Author: "scanner[bot]", CreatedAt: at(1), Files: []string{".github/workflows/ci.yml"}, FindingKey: "k1"}, + {Repo: "o/r", Number: 4, Title: "fix: unpinned uses: in workflow", Author: "scanner[bot]", CreatedAt: at(2), Files: []string{".github/workflows/ci.yml"}, FindingKey: "k1"}, + } + got = Find(finding, Options{FindingKey: func(p PR) string { return p.FindingKey }}) + if len(got) != 1 || got[0].Confidence != ConfidenceFindingIdentity || got[0].BotSeries { + t.Fatalf("same-finding bot PRs: %+v, want one ordinary finding-identity cluster", got) + } +} + +// Only a cluster made entirely of one bot's different jobs is dropped. A +// person's PR against the same file as a bot's is still a candidate. +func TestMixedAuthorClusterIsUnchanged(t *testing.T) { + prs := []PR{ + {Repo: "o/r", Number: 1, Title: "chore(deps): update dependency vite to v8", Author: "renovate[bot]", CreatedAt: at(1), Files: []string{"package.json"}, DiffHash: "a"}, + {Repo: "o/r", Number: 2, Title: "bump vite", Author: "dave", CreatedAt: at(2), Files: []string{"package.json"}, DiffHash: "b"}, + } + got := Find(prs, Options{}) + if len(got) != 1 || got[0].BotSeries || got[0].Survivor.Number != 1 { + t.Fatalf("mixed-author cluster changed: %+v", got) + } +} + +func TestJobTitleSetsAsideVersionsDatesAndHashes(t *testing.T) { + same := [][2]string{ + {"chore: regenerate X (2026-11-16)", "chore: regenerate X (2026-11-17)"}, + {"update churn data v1.2.3", "Update churn data v1.2.4"}, + {"chore: update docker digest to 1a2b3c4", "chore: update docker digest to 9f8e7d6c5b"}, + } + for _, p := range same { + if jobTitle(p[0]) != jobTitle(p[1]) { + t.Errorf("%q and %q should name one job: %q vs %q", p[0], p[1], jobTitle(p[0]), jobTitle(p[1])) + } + } + different := [][2]string{ + {"update dependency vue-tsc to v3.3.14", "update dependency js-yaml to v5"}, + {"update ghcr.io/o/foo docker digest to 1a2b3c4", "update ghcr.io/o/bar docker digest to 1a2b3c4"}, + {"update dependency web3 to v4", "update dependency web2 to v4"}, + {"Bump actions/checkout from 4.1.0 to 4.2.0", "Bump actions/setup-node from 4.0.0 to 4.1.0"}, + } + for _, p := range different { + if jobTitle(p[0]) == jobTitle(p[1]) { + t.Errorf("%q and %q name different jobs but both normalise to %q", p[0], p[1], jobTitle(p[0])) + } + } +} + // Ordinary clusters must notify the LATER authors, not the first proposer. func TestTargetsAreTheLaterPRs(t *testing.T) { c := Find(utahPackages(), Options{})[0] diff --git a/src/pkg/github/duplicate_sweep_test.go b/src/pkg/github/duplicate_sweep_test.go index b82302856c..534c44ce1c 100644 --- a/src/pkg/github/duplicate_sweep_test.go +++ b/src/pkg/github/duplicate_sweep_test.go @@ -433,3 +433,34 @@ func TestSweepDuplicatePRs_PostedBodyHasNoLiveMention(t *testing.T) { t.Errorf("posted body carries a live @mention:\n%s", rec.posted[2][0]) } } + +// projectbluefin/website#1023/#1037/#1044: one dependency bot's separate bumps +// all edit package.json and its lockfile. With posting on, the sweep must +// neither call them a superseded regeneration series nor post anything else. +func TestSweepDuplicatePRs_DependencyBotBumpsGetNoComment(t *testing.T) { + resetDupCache() + bump := func(number int, title, patch, created string) dupWirePR { + return dupPR(number, "mergeraptor[bot]", title, fmt.Sprintf("sha%d", number), created, + dupWireFile{Filename: "package.json", Patch: patch}, + dupWireFile{Filename: "package-lock.json", Patch: patch + " lock"}) + } + srv, rec := newDupSweepServer(t, "projectbluefin", "website", []dupWirePR{ + bump(1019, "chore(deps): update dependency vue-tsc to v3.3.14", "@@ vue-tsc @@", "2026-11-14T00:00:00Z"), + bump(1023, "chore(deps): update dependency @antfu/eslint-config to v10", "@@ eslint-config @@", "2026-11-16T00:00:00Z"), + bump(1037, "chore(deps): update dependency js-yaml to v5", "@@ js-yaml @@", "2026-11-17T00:00:00Z"), + }) + c := newTestClient(t, srv, "projectbluefin", []string{"projectbluefin/website"}) + + result, err := c.SweepDuplicatePRs(context.Background(), DuplicateSweepOptions{PostComments: true}) + if err != nil { + t.Fatalf("sweep: %v", err) + } + if len(result.Clusters) != 0 || result.Commented != 0 { + t.Fatalf("independent bumps produced clusters %+v and %d comments", result.Clusters, result.Commented) + } + rec.mu.Lock() + defer rec.mu.Unlock() + if len(rec.writes) != 0 { + t.Errorf("sweep wrote to GitHub for independent bumps: %v", rec.writes) + } +}