From e90527788c84b0ec2e6c475bb6edff6282d1a64a Mon Sep 17 00:00:00 2001 From: Danathar Date: Mon, 26 Oct 2026 06:16:31 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(sentinel):=20judge=20the=20h?= =?UTF-8?q?ive's=20superseding=20PR=20by=20the=20adopted=20author?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A PR the hive opens to supersede an adopted contributor PR starts at the contributor's head, unchanged, but Sentinel judged it by its author, the App: a blocking alert on the contributor's PR became an "author is trusted (hive agent)" notice on the App's copy of the same commit, and no merge lane was stopped. Since #14306 forks are no longer re-homed, but every supersede path still runs for a same-repo branch of a non-maintainer. The sweep now reads the adopted PR and its author from the supersede line AdoptionPRBody writes and decides trust by that author. A maintainer's clearance of the same head on the adopted PR carries over; later heads are judged afresh. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- ...nel-adopted-pr-judged-by-adopted-author.md | 1 + src/docs/operator-reference.md | 2 +- .../automerge_adoption_sentinel_test.go | 27 ++ src/pkg/github/sentinel_adopted.go | 81 ++++++ src/pkg/github/sentinel_adopted_test.go | 244 ++++++++++++++++++ src/pkg/github/sentinel_sweep.go | 24 +- 6 files changed, 373 insertions(+), 6 deletions(-) create mode 100644 changelog.d/fixed-sentinel-adopted-pr-judged-by-adopted-author.md create mode 100644 src/pkg/github/automerge/automerge_adoption_sentinel_test.go create mode 100644 src/pkg/github/sentinel_adopted.go create mode 100644 src/pkg/github/sentinel_adopted_test.go diff --git a/changelog.d/fixed-sentinel-adopted-pr-judged-by-adopted-author.md b/changelog.d/fixed-sentinel-adopted-pr-judged-by-adopted-author.md new file mode 100644 index 0000000000..45d15b17ff --- /dev/null +++ b/changelog.d/fixed-sentinel-adopted-pr-judged-by-adopted-author.md @@ -0,0 +1 @@ +- Fixed Sentinel posting an "author is trusted (hive agent)" notice instead of a blocking alert on a PR the hive opened to supersede an adopted contributor PR. Such a PR is now judged by the adopted PR's author, since its code is theirs; a maintainer's clearance of the same head on the adopted PR carries over. diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 3fb718e838..8799707a66 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -1088,7 +1088,7 @@ survives a hub restart or a second replica and nothing else needs to be posted. |---|---|---| | `sentinel.enabled` | **on** when unset | `false` disables the sweep entirely. | | `sentinel.label` | `sentinel-alert` | Label added to untrusted flagged PRs (created red if missing). Neutral on purpose: it means "look closely", not "malicious". This configured label is also added to Hive's hold/exclude set and blocks Hive approval plus every auto-merge lane until a human removes it. | -| `sentinel.trusted_authors_block` | `false` | When `false`, trusted author findings are notice-only: comment, audit/dashboard record, no label, no approval/merge block. Set `true` to add the blocking label for trusted authors too. | +| `sentinel.trusted_authors_block` | `false` | When `false`, trusted author findings are notice-only: comment, audit/dashboard record, no label, no approval/merge block. Set `true` to add the blocking label for trusted authors too. A PR the hive opens to supersede an adopted contributor PR (body line `Supersedes #N (…; original commits by @login preserved).`) is judged by the adopted PR's author, not by the App: its code is that author's, so an untrusted author's flagged head gets the label on the App's PR too. A maintainer who removed the label from the adopted PR at the same head is not asked again; any later head is judged afresh. | | `sentinel.sensitive_paths` | shipped defaults (`sentinel.DefaultSensitivePaths`) | Glob list (same syntax as `intent.guardrail_path_patterns`; `**` crosses directories) that **replaces** the defaults when set. Defaults cover OWNERS/CODEOWNERS/MAINTAINERS, SECURITY.md, GOVERNANCE.md, `.github/workflows/**`, actions, dependabot, codeql, rulesets, CI config, Makefile/Justfile, pre-commit hooks, `policies/**`, `hive.yaml*`, `gh-wrapper*`, proxy rules, Dockerfiles, `install.sh`, dependency manifests and lockfiles, release workflows, `.env*`/key material, `deploy/**`, Terraform, Helm/k8s manifests. | | `sentinel.disabled_behaviors` | empty | Rule names from the table above to switch off. Unknown names are rejected. | | `sentinel.exempt_logins` | empty | GitHub logins never flagged (e.g. a release bot). Use sparingly. | diff --git a/src/pkg/github/automerge/automerge_adoption_sentinel_test.go b/src/pkg/github/automerge/automerge_adoption_sentinel_test.go new file mode 100644 index 0000000000..033cd0bb3f --- /dev/null +++ b/src/pkg/github/automerge/automerge_adoption_sentinel_test.go @@ -0,0 +1,27 @@ +package automerge + +import ( + "testing" + + hgithub "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// The Sentinel sweep judges a superseding PR by the adopted PR's author, +// which it reads from this body (hgithub.AdoptedFrom). Every supersede path +// must keep writing a line it can read, or the App's copy of a flagged head +// goes back to a trusted-author notice. +func TestAdoptionPRBodyNamesTheAdoptedAuthorForSentinel(t *testing.T) { + obs := stageObservation{Number: 930, HeadSHA: "44428f31f051", Author: "kylerankin", BaseRef: "main", Display: "o/r", Body: "Closes #918", Reason: "check-failing:unit"} + for _, reason := range []string{AdoptReasonGrace, AdoptReasonOffline, AdoptReasonUnregistered, AdoptReasonDCORehome, AdoptReasonSignoffRehome, AdoptReasonInPlaceStalled} { + for _, fence := range []string{"", contributorLaneReasonWorkflowPath} { + for _, dco := range []bool{false, true} { + body := AdoptionPRBody(obs, stagelabels.Record{AdoptReason: reason, AdoptDiffFence: fence}, dco) + n, author, ok := hgithub.AdoptedFrom(body) + if !ok || n != 930 || author != "kylerankin" { + t.Fatalf("reason=%s fence=%q dco=%v: AdoptedFrom = (%d, %q, %v), want (930, kylerankin):\n%s", reason, fence, dco, n, author, ok, body) + } + } + } + } +} diff --git a/src/pkg/github/sentinel_adopted.go b/src/pkg/github/sentinel_adopted.go new file mode 100644 index 0000000000..7c3a9bd1a1 --- /dev/null +++ b/src/pkg/github/sentinel_adopted.go @@ -0,0 +1,81 @@ +package github + +import ( + "context" + "fmt" + "regexp" + "strconv" + "strings" + + gh "github.com/google/go-github/v72/github" +) + +// A PR the hive opens to supersede an adopted contributor PR +// (automerge.AdoptionPRBody) is authored by the App, but its code is the +// contributor's: the branch starts at the adopted head, unchanged. Judging +// it by the PR author turned a blocking alert on the contributor's PR into +// an "author is trusted (hive agent)" notice on the App's copy of the same +// commit, with nothing left to stop a merge lane (projectbluefin/utah#930 → +// #936). The sweep judges such a PR by the author of the code instead. + +// adoptedFromRE matches the line AdoptionPRBody opens the superseding PR's +// body with: "Supersedes #N (; original commits by @login preserved)." +var adoptedFromRE = regexp.MustCompile(`(?m)^Supersedes #(\d+) \([^\n]*; original commits by @([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\[bot\])?) preserved\)`) + +// AdoptedFrom reads the adopted PR's number and author from a superseding +// PR's body; ok is false when the body has no such line. +func AdoptedFrom(body string) (number int, author string, ok bool) { + m := adoptedFromRE.FindStringSubmatch(body) + if m == nil { + return 0, "", false + } + n, err := strconv.Atoi(m[1]) + if err != nil || n <= 0 { + return 0, "", false + } + return n, m[2], true +} + +// sentinelCodeAuthor returns the login whose trust decides the PR: the +// adopted PR's author when the PR is the App's superseding copy, else the PR +// author. origin is the adopted PR's number, 0 when the PR is not one. +func (c *Client) sentinelCodeAuthor(pr *gh.PullRequest) (login string, origin int) { + author := pr.GetUser().GetLogin() + app := strings.TrimSpace(c.AppBotLogin()) + if app == "" || !strings.EqualFold(author, app) { + return author, 0 + } + n, adopted, ok := AdoptedFrom(pr.GetBody()) + if !ok || n == pr.GetNumber() || strings.EqualFold(adopted, app) { + return author, 0 + } + return adopted, n +} + +// sentinelAdoptedNote is the sentence the marker comment adds on a +// superseding PR, so the alert does not read as a verdict on the App. +func sentinelAdoptedNote(origin int, author string) string { + return fmt.Sprintf("\nThis PR is the hive's adoption of #%d. Its code is @%s's, so Hive judges it by that author, not by the hive account that opened it.\n", origin, author) +} + +// sentinelOriginClearedNote closes the marker comment when a maintainer +// already cleared the alert on the adopted PR at this same head; the +// arguments are the label and the adopted PR's number. +const sentinelOriginClearedNote = "_A maintainer removed the `%s` label from #%d after Hive alerted on this same head there, so Hive treats this head as reviewed and will not re-apply the label unless new commits are pushed._" + +// sentinelOriginCleared reports whether the adopted PR carries the hive's +// own blocking alert for head and no longer carries the label: the same +// proof sentinelClearedByMaintainer reads on the PR itself, so a maintainer +// who reviewed the head before the adoption is not asked again. Any read +// failure counts as not cleared, which keeps the label. +func (c *Client) sentinelOriginCleared(ctx context.Context, owner, repo string, origin int, head, label string) bool { + pr, _, err := c.client.PullRequests.Get(ctx, owner, repo, origin) + if err != nil || pr == nil || prHasLabel(pr, label) { + return false + } + comment, posted, err := c.findOwnMarkerComment(ctx, owner, repo, origin, SentinelMarker+" "+head) + if err != nil { + return false + } + return sentinelClearedByMaintainer(comment, posted) +} diff --git a/src/pkg/github/sentinel_adopted_test.go b/src/pkg/github/sentinel_adopted_test.go new file mode 100644 index 0000000000..c1dc804ffc --- /dev/null +++ b/src/pkg/github/sentinel_adopted_test.go @@ -0,0 +1,244 @@ +package github + +import ( + "context" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/sentinel" +) + +const sentinelTestApp = "hive-app[bot]" + +// sentinelAdoptionBody is the opening of automerge.AdoptionPRBody for a +// superseding PR (TestAdoptionPRBodyNamesTheAdoptedAuthorForSentinel pins +// that the two stay in step). +func sentinelAdoptionBody(origin, author string) string { + return "\n" + + "Supersedes #" + origin + " (adopted after CI went red and the contributor was unavailable; original commits by @" + author + " preserved).\n\nCloses #918\n" +} + +func sentinelAdoptedPR(num int, head, body string, labels ...string) map[string]any { + pr := sentinelPR(num, sentinelTestApp, head, labels...) + pr["body"] = body + return pr +} + +// sentinelTrustApp trusts the App ("hive agent") and nobody else, as a hive +// with no trusted-author policy does. +func sentinelTrustApp(_ string, author string) SentinelAuthorTrust { + if strings.EqualFold(author, sentinelTestApp) { + return SentinelAuthorTrust{Trusted: true, Reason: "hive agent"} + } + return SentinelAuthorTrust{} +} + +func sentinelWorkflowFile() []map[string]any { + return []map[string]any{{"filename": ".github/workflows/ci.yml", "status": "modified", "patch": "+permissions: write-all\n"}} +} + +func sentinelAdoptedOpts() SentinelSweepOptions { + opts := defaultSentinelOpts(nil) + opts.TrustedAuthor = sentinelTrustApp + return opts +} + +func sentinelAlertFor(head, author string) string { + return SentinelComment(DecideSentinelAction("sentinel-alert", SentinelAuthorTrust{}, false), head, author, []sentinel.Finding{{Rule: "sensitive_path", Summary: "workflow", Paths: []string{".github/workflows/ci.yml"}}}) +} + +// The projectbluefin/utah#930 → #936 shape on a same-repo branch, which +// adoption still supersedes after #14306: the contributor's PR carries the +// blocking alert, the App's superseding PR starts at the same head. The +// superseder must get the label and an alert, not a trusted-author notice. +func TestSweepSentinelAdoptedPRJudgedByAdoptedAuthor(t *testing.T) { + for _, tc := range []struct { + name string + existing []string // marker comments already on the superseder + }{ + {name: "first evaluation"}, + {name: "replaces a notice an older hive posted for the head", existing: []string{ + SentinelComment(DecideSentinelAction("sentinel-alert", SentinelAuthorTrust{Trusted: true, Reason: "hive agent"}, false), "h1", sentinelTestApp, nil), + }}, + } { + t.Run(tc.name, func(t *testing.T) { + f := &sentinelFixture{ + prs: []map[string]any{ + sentinelPR(930, "kylerankin", "h1", "sentinel-alert"), + sentinelAdoptedPR(936, "h1", sentinelAdoptionBody("930", "kylerankin")), + }, + files: map[int][]map[string]any{930: sentinelWorkflowFile(), 936: sentinelWorkflowFile()}, + labelExists: true, + comments: map[int][]string{930: {sentinelAlertFor("h1", "kylerankin")}, 936: tc.existing}, + commentUsers: map[int][]string{930: {sentinelTestApp}, 936: {sentinelTestApp}}, + } + srv := newSentinelServer(t, f) + defer srv.Close() + c := newTestClient(t, srv, "o", []string{"o/r"}) + c.SetAppBotLogin(sentinelTestApp) + res, err := c.SweepSentinel(context.Background(), sentinelAdoptedOpts()) + if err != nil { + t.Fatalf("sweep: %v", err) + } + if len(res.Flagged) != 1 || res.Flagged[0].Number != 936 || len(res.Notified) != 0 { + t.Fatalf("superseder must be flagged, not notified: %+v", res) + } + if got := f.labels[936]; len(got) != 1 || got[0] != "sentinel-alert" { + t.Fatalf("superseder labels = %v, want sentinel-alert", got) + } + if len(f.comments[936]) != 1 { + t.Fatalf("want one marker comment on the superseder, got %d: %v", len(f.comments[936]), f.comments[936]) + } + body := f.comments[936][0] + for _, want := range []string{SentinelMarker + " h1", sentinelAlertHeading, "adoption of #930", "@kylerankin's"} { + if !strings.Contains(body, want) { + t.Errorf("alert missing %q:\n%s", want, body) + } + } + if strings.Contains(body, sentinelNoticeHeading) { + t.Errorf("alert still reads as a trusted-author notice:\n%s", body) + } + }) + } +} + +// A maintainer who already cleared the alert on the adopted PR at this head +// is not asked again; a hive commit on top (a new head) is judged afresh. +func TestSweepSentinelAdoptedPRCarriesOriginClearanceForSameHead(t *testing.T) { + f := &sentinelFixture{ + prs: []map[string]any{ + sentinelPR(796, "kylerankin", "h1"), + sentinelAdoptedPR(877, "h1", sentinelAdoptionBody("796", "kylerankin")), + }, + files: map[int][]map[string]any{796: sentinelWorkflowFile(), 877: sentinelWorkflowFile()}, + labelExists: true, + comments: map[int][]string{796: {sentinelAlertFor("h1", "kylerankin")}}, + commentUsers: map[int][]string{796: {sentinelTestApp}, 877: {sentinelTestApp}}, + } + srv := newSentinelServer(t, f) + defer srv.Close() + c := newTestClient(t, srv, "o", []string{"o/r"}) + c.SetAppBotLogin(sentinelTestApp) + res, err := c.SweepSentinel(context.Background(), sentinelAdoptedOpts()) + if err != nil || len(res.Flagged) != 0 { + t.Fatalf("cleared head must not be re-alerted: res=%+v err=%v", res, err) + } + if len(f.labels[877]) != 0 { + t.Fatalf("superseder labelled despite the clearance on #796: %v", f.labels[877]) + } + if len(f.comments[877]) != 1 || !strings.Contains(f.comments[877][0], sentinelAlertHeading) || !strings.Contains(f.comments[877][0], "from #796 after Hive alerted on this same head") { + t.Fatalf("superseder must record the carried clearance: %v", f.comments[877]) + } + + // The record survives a restart: a fresh client stays quiet. + c = newTestClient(t, srv, "o", []string{"o/r"}) + c.SetAppBotLogin(sentinelTestApp) + if res, err := c.SweepSentinel(context.Background(), sentinelAdoptedOpts()); err != nil || len(res.Flagged) != 0 || len(f.labels[877]) != 0 || len(f.comments[877]) != 1 { + t.Fatalf("restart re-alerted a carried clearance: res=%+v err=%v labels=%v comments=%d", res, err, f.labels[877], len(f.comments[877])) + } + + // The hive pushes a fix on top: #796 never saw h2, so h2 is alerted. + f.mu.Lock() + f.prs[1] = sentinelAdoptedPR(877, "h2", sentinelAdoptionBody("796", "kylerankin")) + f.mu.Unlock() + c = newTestClient(t, srv, "o", []string{"o/r"}) + c.SetAppBotLogin(sentinelTestApp) + res, err = c.SweepSentinel(context.Background(), sentinelAdoptedOpts()) + if err != nil || len(res.Flagged) != 1 || len(f.labels[877]) != 1 { + t.Fatalf("new head on the superseder must be alerted: res=%+v err=%v labels=%v", res, err, f.labels[877]) + } + + // The adopted PR still carrying the label is no clearance either. + f.mu.Lock() + f.prs = []map[string]any{ + sentinelPR(796, "kylerankin", "h1", "sentinel-alert"), + sentinelAdoptedPR(878, "h1", sentinelAdoptionBody("796", "kylerankin")), + } + f.files[878] = sentinelWorkflowFile() + f.mu.Unlock() + c = newTestClient(t, srv, "o", []string{"o/r"}) + c.SetAppBotLogin(sentinelTestApp) + if res, err := c.SweepSentinel(context.Background(), sentinelAdoptedOpts()); err != nil || len(res.Flagged) != 1 || len(f.labels[878]) != 1 { + t.Fatalf("an uncleared original must not clear the superseder: res=%+v err=%v labels=%v", res, err, f.labels[878]) + } +} + +// What did not change: a trusted adopted author keeps the notice, the App's +// own PR keeps the notice, and the supersedes line counts only on a PR the +// App opened. +func TestSweepSentinelAdoptedPRUnchangedCases(t *testing.T) { + trusted := func(_ string, author string) SentinelAuthorTrust { + if strings.EqualFold(author, "carol") { + return SentinelAuthorTrust{Trusted: true, Reason: "trusted author"} + } + return sentinelTrustApp("", author) + } + humanCopy := sentinelPR(51, "dave", "h1") + humanCopy["body"] = sentinelAdoptionBody("50", "kylerankin") + for _, tc := range []struct { + name string + pr map[string]any + appLogin string + trust func(string, string) SentinelAuthorTrust + wantBlock bool + wantIn string + wantNote bool + }{ + {name: "trusted adopted author", pr: sentinelAdoptedPR(51, "h1", sentinelAdoptionBody("50", "carol")), appLogin: sentinelTestApp, trust: trusted, wantIn: "author is trusted (trusted author)", wantNote: true}, + {name: "hive's own PR", pr: sentinelAdoptedPR(51, "h1", "Fixes #9\n"), appLogin: sentinelTestApp, trust: sentinelTrustApp, wantIn: "author is trusted (hive agent)"}, + {name: "line in a PR the App did not open", pr: humanCopy, appLogin: sentinelTestApp, trust: func(_ string, a string) SentinelAuthorTrust { + return SentinelAuthorTrust{Trusted: a == "dave", Reason: "owner"} + }, wantIn: "author is trusted (owner)"}, + {name: "App login unknown", pr: sentinelAdoptedPR(51, "h1", sentinelAdoptionBody("50", "kylerankin")), trust: sentinelTrustApp, wantIn: "author is trusted (hive agent)"}, + } { + t.Run(tc.name, func(t *testing.T) { + f := &sentinelFixture{ + prs: []map[string]any{tc.pr}, + files: map[int][]map[string]any{51: sentinelWorkflowFile()}, + labelExists: true, + } + srv := newSentinelServer(t, f) + defer srv.Close() + c := newTestClient(t, srv, "o", []string{"o/r"}) + c.SetAppBotLogin(tc.appLogin) + opts := defaultSentinelOpts(nil) + opts.TrustedAuthor = tc.trust + res, err := c.SweepSentinel(context.Background(), opts) + if err != nil { + t.Fatalf("sweep: %v", err) + } + if blocked := len(f.labels[51]) > 0; blocked != tc.wantBlock || len(res.Flagged) > 0 != tc.wantBlock { + t.Fatalf("blocked=%v, want %v: res=%+v labels=%v", blocked, tc.wantBlock, res, f.labels[51]) + } + if len(f.comments[51]) != 1 || !strings.Contains(f.comments[51][0], tc.wantIn) { + t.Fatalf("comment missing %q: %v", tc.wantIn, f.comments[51]) + } + if got := strings.Contains(f.comments[51][0], "adoption of #50"); got != tc.wantNote { + t.Fatalf("adoption note present=%v, want %v: %s", got, tc.wantNote, f.comments[51][0]) + } + }) + } +} + +func TestAdoptedFrom(t *testing.T) { + for _, tc := range []struct { + name string + body string + number int + author string + }{ + {name: "fence marker first", body: sentinelAdoptionBody("930", "kylerankin"), number: 930, author: "kylerankin"}, + {name: "a line added above it later", body: "**Depends on o/x#276.**\n\n" + sentinelAdoptionBody("912", "hanthor"), number: 912, author: "hanthor"}, + {name: "re-home cause", body: "Supersedes #7 (adopted in place, re-homed for DCO repair; original commits by @renovate[bot] preserved).\n", number: 7, author: "renovate[bot]"}, + {name: "quoted, not at line start", body: "> Supersedes #7 (x; original commits by @eve preserved).\n"}, + {name: "prose mention", body: "This supersedes #7 by @eve.\n"}, + {name: "no author", body: "Supersedes #7. `bot` opened it with the workflow `GITHUB_TOKEN`.\n"}, + } { + t.Run(tc.name, func(t *testing.T) { + n, author, ok := AdoptedFrom(tc.body) + if ok != (tc.number != 0) || n != tc.number || author != tc.author { + t.Fatalf("AdoptedFrom = (%d, %q, %v), want (%d, %q)", n, author, ok, tc.number, tc.author) + } + }) + } +} diff --git a/src/pkg/github/sentinel_sweep.go b/src/pkg/github/sentinel_sweep.go index 82dd964f1b..a3e5d2f2f2 100644 --- a/src/pkg/github/sentinel_sweep.go +++ b/src/pkg/github/sentinel_sweep.go @@ -393,9 +393,10 @@ func (c *Client) trySentinelPR(ctx context.Context, displayRepo, owner, repo str number := pr.GetNumber() head := pr.GetHead().GetSHA() author := pr.GetUser().GetLogin() + codeAuthor, origin := c.sentinelCodeAuthor(pr) trust := SentinelAuthorTrust{} if opts.TrustedAuthor != nil { - trust = opts.TrustedAuthor(displayRepo, author) + trust = opts.TrustedAuthor(displayRepo, codeAuthor) } decision := DecideSentinelAction(label, trust, opts.TrustedAuthorsBlock) hasAlertLabel := prHasLabel(pr, label) @@ -420,6 +421,11 @@ func (c *Client) trySentinelPR(ctx context.Context, displayRepo, owner, repo str } event := SentinelSweepEvent{Number: number, Author: author, Title: pr.GetTitle(), HeadSHA: head, Findings: findings, Blocked: decision.Block, TrustedReason: decision.TrustedReason} digest := sentinelFlaggedDigest(findings, files) + markerBody := SentinelComment(decision, head, author, findings) + if origin > 0 { + markerBody += sentinelAdoptedNote(origin, codeAuthor) + } + markerBody = sentinelWithDigest(markerBody, digest) marker := SentinelMarker + " " + head comment, posted, err := c.findOwnMarkerComment(ctx, owner, repo, number, marker) if err != nil { @@ -435,6 +441,15 @@ func (c *Client) trySentinelPR(ctx context.Context, displayRepo, owner, repo str // where it is durable: the marker comment itself. return SentinelSweepEvent{}, false, nil } + if decision.Block && !hasAlertLabel && origin > 0 && c.sentinelOriginCleared(ctx, owner, repo, origin, head, label) { + // The App's copy of a head a maintainer already cleared on the + // adopted PR: that review covers this head too. It also replaces a + // trusted-author notice an older hive left for this head. + if err := c.recordSentinelClearance(ctx, owner, repo, number, fmt.Sprintf(sentinelOriginClearedNote, label, origin), markerBody); err != nil { + return SentinelSweepEvent{}, false, err + } + return SentinelSweepEvent{}, false, nil + } if decision.Block && !hasAlertLabel && !posted { // No marker for this head: either it is new and owes an alert, or // the head moved (a Renovate rebase, say) between the alert and the @@ -459,15 +474,14 @@ func (c *Client) trySentinelPR(ctx context.Context, displayRepo, owner, repo str note = sentinelCarriedNote } if cleared { - alert := sentinelWithDigest(SentinelComment(decision, head, author, findings), digest) - if err := c.recordSentinelClearance(ctx, owner, repo, number, fmt.Sprintf(note, clearedBy, label), alert); err != nil { + if err := c.recordSentinelClearance(ctx, owner, repo, number, fmt.Sprintf(note, clearedBy, label), markerBody); err != nil { return SentinelSweepEvent{}, false, err } return SentinelSweepEvent{}, false, nil } } if !decision.Block { - body := sentinelWithDigest(SentinelComment(decision, head, author, findings), digest) + body := markerBody if hasAlertLabel { if !posted { return SentinelSweepEvent{}, false, nil @@ -493,7 +507,7 @@ func (c *Client) trySentinelPR(ctx context.Context, displayRepo, owner, repo str if _, _, err := c.client.Issues.AddLabelsToIssue(ctx, owner, repo, number, []string{label}); err != nil { return SentinelSweepEvent{}, false, fmt.Errorf("adding %s label: %w", label, err) } - body := sentinelWithDigest(SentinelComment(decision, head, author, findings), digest) + body := markerBody if posted { if _, _, err := c.client.Issues.EditComment(ctx, owner, repo, comment.GetID(), &gh.IssueComment{Body: gh.Ptr(body)}); err != nil { return SentinelSweepEvent{}, false, fmt.Errorf("updating sentinel alert: %w", err)