Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-sentinel-release-memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Sentinel: a dashboard Approve on a flagged PR is now remembered as the release of that head — the sweep reads the hive's own `hive:pr-approval head=<sha>` comment instead of treating the hive-account `unlabeled` event as nobody's clearance, so it no longer re-posts the alert and re-applies `sentinel-alert` to the head the owner just approved (dibs#510, hivecommons/hive#15214); a new push still re-arms. On a Prow repo where the bot is not an approver, a later Approve records the decision without re-posting `/lgtm` + `/approve` and reports `commands_skipped`.
2 changes: 1 addition & 1 deletion src/docs/dashboard-sections.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,13 @@ into blocking them. A maintainer who removes the label keeps the PR clear until
the author pushes again: the sweep reads the clearance back from the alert
comment it left for that head (alert comment present, label absent), so it
survives a hub restart or a second replica and nothing else needs to be posted.
A dashboard **Approve** is the same clearance for the head it names: the hive
takes the label off as its own account, so the `unlabeled` event alone is not
read as a human clearance; the `/lgtm` + `/approve` comments the approval
posted carry a `hive:pr-approval head=<sha>` marker, and the sweep reads that
as the release for exactly that head (rewriting its alert comment to say so),
so it does not re-apply the label the owner just released (dibs#510). A later
push re-arms it.

| Behavior | Fires when |
|---|---|
Expand Down
26 changes: 20 additions & 6 deletions src/pkg/dashboard/api_repo_item_decision.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -175,6 +175,11 @@
// contributor lane merges the head as-is and the adoption engine
// leaves the PR alone (hivecommons/hive#15136).
AdmittedBy string `json:"admitted_by,omitempty"`
// CommandsSkipped is set when an Approve did not post the `/lgtm` +
// `/approve` comments: "prow-rejects-bot-commands" on a Prow repo where
// the hive bot is not an approver, so they would only draw another
// "NOT APPROVED" (dibs#510). The approval itself is still recorded.
CommandsSkipped string `json:"commands_skipped,omitempty"`
}

// admitPullRequestHead records user's Approve as the trust override for
Expand Down Expand Up @@ -211,6 +216,10 @@
// came from the hive's account, which is not in OWNERS, so Prow ignores
// it and the toast must not claim the PR is approved for Prow.
Prow bool
// CommandsSkipped: the `/lgtm` + `/approve` comments were not posted
// because Prow already rejected the hive's commands on this PR
// (dibs#510); the hive's own approval record is what counts.
CommandsSkipped bool
}

// repoItemDecisionResult reads a recorded human decision into the shared
Expand Down Expand Up @@ -587,7 +596,7 @@
err error
)
var released []string
stage := ""
stage, commandsSkipped := "", ""
sentinelOpen, prow := false, false
if decision == repoItemDecisionApprove {
var event ghpkg.PullRequestApprovalEvent
Expand All @@ -598,6 +607,7 @@
})
head = event.HeadSHA
released, stage, sentinelOpen, prow = repoItemApprovalReleased(event), event.Stage, event.SentinelLabelOpen, event.ProwManaged
commandsSkipped = event.CommandsSkipped
} else {
var event ghpkg.PullRequestDecisionEvent
event, err = gh.RecordOperatorPullRequestDecision(ctx, repoFull, number, user, comment, repoItemDecisionChangeRequests())
Expand Down Expand Up @@ -632,13 +642,13 @@
released = append(released, "admitted")
}
}
s.audit.LogRecord(user, action, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", head, "decision", comment, "released", strings.Join(released, ","), "stage", stage, "admitted_by", admitted), "", repoFull, number)
s.audit.LogRecord(user, action, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", head, "decision", comment, "released", strings.Join(released, ","), "stage", stage, "admitted_by", admitted, "commands_skipped", commandsSkipped), "", repoFull, number)
// The row's park was just answered: serve the re-derived stage on the
// next tracker read instead of the cached 085.
s.invalidateStageTrackerForWebhook()
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: status, Released: released, Stage: stage, Head: head, AdmittedBy: admitted,
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: status, Released: released, Stage: stage, Head: head, AdmittedBy: admitted, CommandsSkipped: commandsSkipped,
Result: repoItemDecisionResultWith(repoFull, number, "pr", decision, comment, "", "", repoItemApproveFacts{
User: user, Released: released, Stage: stage, SentinelOpen: sentinelOpen, SentinelLabel: s.sentinelLabel(), SoakMinutes: s.approveSoakMinutes(admitted != ""), Prow: prow,
User: user, Released: released, Stage: stage, SentinelOpen: sentinelOpen, SentinelLabel: s.sentinelLabel(), SoakMinutes: s.approveSoakMinutes(admitted != ""), Prow: prow, CommandsSkipped: commandsSkipped != "",
})})
}

Expand Down Expand Up @@ -688,7 +698,11 @@
headline += " · sentinel alert still open"
}
out.Outcome = headline + "."
out.Posted = append(out.Posted, "`/lgtm` posted", "`/approve` posted")
if facts.CommandsSkipped {
out.Posted = append(out.Posted, "`/lgtm` + `/approve` not posted (Prow does not accept the hive bot's commands on this repo)")
} else {
out.Posted = append(out.Posted, "`/lgtm` posted", "`/approve` posted")
}
if released["needs-human"] {
out.Posted = append(out.Posted, "`needs-human` label removed")
}
Expand All @@ -706,7 +720,7 @@
default:
out.Next = "Hive's merge sweep merges it on its next pass once CI is green and the head has soaked" + repoItemSoakNote(facts.SoakMinutes) + "."
}
if facts.Prow {
if facts.Prow || facts.CommandsSkipped {
// Prow reads `/approve` only from OWNERS; the hive's account is not
// one, so the relayed command is "NOT APPROVED" there.
out.Next = "Prow approval still needs an OWNERS reviewer: the relayed `/approve` came from hive's account, which Prow does not count. " + out.Next
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hivecommons/hive/pkg/authorkind"
hgithub "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/intent"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -783,6 +784,51 @@ func TestTrySweepContributorLaneTrustedHumanApprovalClearsRequiresHuman(t *testi
}
}

// An owner's dashboard Approve admits the untrusted-author head
// (hivecommons/hive#15136) once the sentinel it released stays released:
// the recorded approval by a trusted merger admits the newcomer-tier claim
// the lane would otherwise refuse, and the PR merges. While the alert label
// is back on the PR — the sentinel re-applying it undid the approval on
// dibs#510 — the lane still stands down with sentinel-blocked, so the label
// memory, not the admission, is what the owner's approval depends on.
func TestTrySweepContributorLaneOperatorApprovalAdmitsReleasedSentinel(t *testing.T) {
for _, tt := range []struct {
name string
labels []string
wantReason string
wantMerges int
}{
{name: "sentinel released", labels: []string{"stage/085-needs-decision"}, wantMerges: 1},
{name: "sentinel re-applied", labels: []string{"stage/085-needs-decision", "hive-sentinel"}, wantReason: contributorLaneReasonSentinelBlocked},
} {
t.Run(tt.name, func(t *testing.T) {
fx := validContributorFixture()
fx.labels = tt.labels
fx.issueComments[0]["body"] = contributorClaimMarkerTier(contributorLaneTestAuthor, "contributor", contributorLaneTestHive, " tier=newcomer verified=true")
api := newContributorLaneAPI(t, &fx)
defer api.Close()
policy := defaultContributorLanePolicy()
clock := &contributorLaneClock{at: time.Date(2026, 10, 15, 13, 0, 0, 0, time.UTC)}
store := review.NewHumanChangeRequests("")
if err := store.Record(review.HumanChangeRequest{Repo: "acme/widget", Number: 7, HeadSHA: "sha7", Actor: "clubanderson", Kind: review.HumanChangeRequestKindApprove, Source: review.HumanChangeRequestSourceDecision, SourceID: 1}); err != nil {
t.Fatal(err)
}
engine := newContributorLaneEngine(api.URL, policy, clock, Options{ContributorSoak: soakedTracker(clock), HumanChangeRequests: store})
engine.SetMergerAuthorizer(func(login string) bool { return strings.EqualFold(login, "clubanderson") })
event, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy)
if err != nil {
t.Fatal(err)
}
if reason != tt.wantReason || fx.merges != tt.wantMerges {
t.Fatalf("reason=%q merges=%d, want %q/%d", reason, fx.merges, tt.wantReason, tt.wantMerges)
}
if tt.wantMerges == 1 && (!strings.Contains(fx.lastComment, "operator-approval:clubanderson") || event.Number != 7) {
t.Fatalf("merge comment must name the admission: %q (event %+v)", fx.lastComment, event)
}
})
}
}

// registryTiers returns a ContributorRegistryTierFunc over a fixed
// login→tier map (case-insensitive on login), standing in for the
// contributor registry on the hive's PVC.
Expand Down
91 changes: 84 additions & 7 deletions src/pkg/github/pr_decision_operator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package github

import (
Expand Down Expand Up @@ -79,6 +79,72 @@
// Stage is the stage label the engine derived when the approval was
// submitted to it, or "" when the stage write was deferred to the sweep.
Stage string
// CommandsSkipped is set when the `/lgtm` + `/approve` comments were
// not posted: PRApprovalCommandsSkippedProw when Prow rejected the
// hive's own earlier commands on this PR (the bot is not in OWNERS),
// so posting again would only draw the same "NOT APPROVED" reply. The
// hive's own approval record is unaffected.
CommandsSkipped string
}

// PRApprovalCommandsSkippedProw is the CommandsSkipped reason for a Prow
// repo where the hive bot is not an approver.
const PRApprovalCommandsSkippedProw = "prow-rejects-bot-commands"

// prowCommandRejections are the phrases Prow replies with when the hive
// bot's `/lgtm` or `/approve` carries no weight on the repo.
var prowCommandRejections = []string{"restricted to collaborators", "NOT APPROVED"}

// prowRejectedHiveCommands reports whether a bot other than the hive has
// replied to one of the hive's earlier dashboard approval commands on the
// PR with a Prow rejection (dibs#510: `/lgtm` → "changing LGTM is
// restricted to collaborators", `/approve` → "[APPROVALNOTIFIER] This PR is
// NOT APPROVED"). Prow quotes the comment it answers as
// "In response to [this](…#issuecomment-<id>)", so only replies bound to a
// hive command comment count.
func (c *Client) prowRejectedHiveCommands(ctx context.Context, owner, name string, number int) (bool, error) {
comments, err := c.listIssueComments(ctx, owner, name, number)
if err != nil {
return false, err
}
own := map[int64]bool{}
for _, comment := range comments {
if comment == nil || !c.markerAuthorTrusted(comment.GetUser()) {
continue
}
if _, _, _, ok := ParsePRApprovalCommandComment(comment.GetBody()); ok {
own[comment.GetID()] = true
}
}
if len(own) == 0 {
return false, nil
}
for _, comment := range comments {
if comment == nil || c.isHiveAccount(comment.GetUser()) {
continue
}
login := strings.ToLower(comment.GetUser().GetLogin())
if !strings.EqualFold(comment.GetUser().GetType(), "Bot") && !strings.HasSuffix(login, "[bot]") {
continue
}
body := comment.GetBody()
rejected := false
for _, phrase := range prowCommandRejections {
if strings.Contains(body, phrase) {
rejected = true
break
}
}
if !rejected {
continue
}
for id := range own {
if strings.Contains(body, fmt.Sprintf("#issuecomment-%d)", id)) {
return true, nil
}
}
}
return false, nil
}

// PullRequestApprovalOptions is what a person's Approve decision releases
Expand Down Expand Up @@ -250,14 +316,25 @@
return PullRequestApprovalEvent{}, err
}
full := owner + "/" + name
for _, command := range PRApprovalCommands {
if err := c.CreateIssueComment(ctx, full, number, renderPRApprovalCommandComment(command, actor, head)); err != nil {
return PullRequestApprovalEvent{}, fmt.Errorf("posting %s on %s/%s#%d: %w", command, owner, name, number, err)
}
}
event := PullRequestApprovalEvent{Repo: full, Number: number, HeadSHA: head, Actor: actor, ProwManaged: prowManagedLabels(labels)}
if c.logger != nil {
c.logger.Info("pull request approval commands posted by dashboard decision", "repo", event.Repo, "pr", number, "actor", actor, "head", head)
prowRejected, err := c.prowRejectedHiveCommands(ctx, owner, name, number)
if err != nil {
return PullRequestApprovalEvent{}, fmt.Errorf("reading comments of %s/%s#%d before posting approval commands: %w", owner, name, number, err)
}
if prowRejected {
event.CommandsSkipped = PRApprovalCommandsSkippedProw
if c.logger != nil {
c.logger.Info("pull request approval commands not posted: Prow rejected the hive's earlier commands on this PR (bot is not an approver); the hive's own approval record stands", "repo", event.Repo, "pr", number, "actor", actor, "head", head)
}
} else {
for _, command := range PRApprovalCommands {
if err := c.CreateIssueComment(ctx, full, number, renderPRApprovalCommandComment(command, actor, head)); err != nil {
return PullRequestApprovalEvent{}, fmt.Errorf("posting %s on %s/%s#%d: %w", command, owner, name, number, err)
}
}
if c.logger != nil {
c.logger.Info("pull request approval commands posted by dashboard decision", "repo", event.Repo, "pr", number, "actor", actor, "head", head)
}
}
if opts.HumanChangeRequests != nil && head != "" {
req := review.HumanChangeRequest{
Expand Down
49 changes: 49 additions & 0 deletions src/pkg/github/pr_decision_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package github
import (
"context"
"errors"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -241,3 +242,51 @@ func TestRecordOperatorPullRequestApprovalWithoutOptionsStaysCommentsOnly(t *tes
t.Fatalf("bare approval touched labels or the stage engine: removed=%v", rec.removed[liveDecisionPR])
}
}

// On a Prow repo where the hive bot is not an approver, the relayed
// commands only draw "changing LGTM is restricted to collaborators" and
// "[APPROVALNOTIFIER] This PR is NOT APPROVED" (dibs#510). Once Prow has
// answered the hive's own commands that way, a later Approve records the
// decision without posting them again and says so on the event; a Prow
// reply to someone else's comment, or no reply at all, changes nothing.
func TestRecordOperatorPullRequestApprovalSkipsCommandsProwRejected(t *testing.T) {
at := time.Date(2026, 10, 29, 0, 32, 0, 0, time.UTC).Format(time.RFC3339)
ownLGTM := unparkWireComment{ID: 501, Body: renderPRApprovalCommandComment("/lgtm", "clubanderson", liveDecisionHead), User: wireUser{Login: "hive[bot]"}, CreatedAt: at, UpdatedAt: at}
ownApprove := unparkWireComment{ID: 502, Body: renderPRApprovalCommandComment("/approve", "clubanderson", liveDecisionHead), User: wireUser{Login: "hive[bot]"}, CreatedAt: at, UpdatedAt: at}
prowReply := func(id int64, text string) unparkWireComment {
return unparkWireComment{ID: 600 + id, Body: text + "\n\n<details>\n\nIn response to [this](https://github.com/org/repo/pull/1#issuecomment-" + strconv.FormatInt(id, 10) + "):\n\n>/lgtm\n</details>", User: wireUser{Login: "kubestellar-prow[bot]"}, CreatedAt: at, UpdatedAt: at}
}
for _, tc := range []struct {
name string
comments []unparkWireComment
skipped string
}{
{"lgtm restricted", []unparkWireComment{ownLGTM, prowReply(501, "@hive[bot]: changing LGTM is restricted to collaborators")}, PRApprovalCommandsSkippedProw},
{"approve not approved", []unparkWireComment{ownApprove, prowReply(502, "[APPROVALNOTIFIER] This PR is **NOT APPROVED**")}, PRApprovalCommandsSkippedProw},
{"prow answered someone else", []unparkWireComment{ownLGTM, prowReply(77, "@eve: changing LGTM is restricted to collaborators")}, ""},
{"human quoting the phrase", []unparkWireComment{ownLGTM, {ID: 700, Body: "NOT APPROVED, see #issuecomment-501)", User: wireUser{Login: "eve"}, CreatedAt: at, UpdatedAt: at}}, ""},
{"no prior commands", nil, ""},
} {
t.Run(tc.name, func(t *testing.T) {
c, rec := newUnparkPRClient(t, []unparkWireIssue{hiveParkedPR(tc.comments...)}, map[string]string{"clubanderson": "admin"})
store := review.NewHumanChangeRequests("")
event, err := c.RecordOperatorPullRequestApprovalWith(context.Background(), "org/repo", liveDecisionPR, "clubanderson", PullRequestApprovalOptions{HumanChangeRequests: store})
if err != nil {
t.Fatalf("approval: %v", err)
}
if event.CommandsSkipped != tc.skipped || !event.Recorded {
t.Fatalf("event = %+v, want CommandsSkipped %q and the approval recorded", event, tc.skipped)
}
wantPosted := len(PRApprovalCommands)
if tc.skipped != "" {
wantPosted = 0
}
if got := rec.posted[liveDecisionPR]; len(got) != wantPosted {
t.Fatalf("posted %d command comments, want %d: %v", len(got), wantPosted, got)
}
if review.HumanApprovalFor(store, "org/repo", liveDecisionPR, liveDecisionHead) == nil {
t.Fatal("the approval must be recorded against the head whether or not the commands were posted")
}
})
}
}
Loading
Loading