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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Quiet notification mode (`github.notifications.mode: quiet`, the default) now folds the remaining per-event comments the hive posted into the single edited `<!-- hive:status -->` comment: the post-merge evidence pointer, the `hive:unblocked` note (now also idempotent per issue and settled PR in either mode, and skipped when the same merge closes the issue), the review backlog summary, the contribute hub's claim marker and an agent's relayed `hive/awaiting-ci`, `Parking on stage/045…` and `Already fixed` status notes. Closing an issue leaves one closing comment: the close-on-merge sweep and the issue-stage lane no longer both post `Fixed by #N`. The GitHub client logs `github notifications created=N edited=M suppressed=K` once an hour so the effect can be measured ([#15918](https://github.com/hivecommons/hive/issues/15918)).
29 changes: 29 additions & 0 deletions src/docs/operator-reference/sweeps-and-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,35 @@ no longer reported as a stage regression, and a PR the hive itself is
holding — queued behind the merge-train front, being rebased by the train,
or waiting on a base refresh — is never marked stalled.

The status comment also carries, in quiet mode, the notes the hive used to
post on issues and merged PRs as comments of their own:

- the post-merge **evidence pointer** (`<!-- hive-review-evidence -->`), as
an `Evidence:` section — the bundle is stored server-side and linked from
the Activity Monitor;
- the **unblocked** note (`<!-- hive:unblocked -->`) on an issue whose
blocking PR settled; it is also idempotent per cause in either mode (a
second sweep that sees the same issue and the same settled PR posts
nothing), and is skipped altogether when the same merge is closing the
issue;
- the **review backlog summary** (`<!-- hive:review-backlog-summary -->`);
- a contributor's **claim marker** (`<!-- hive:claim … -->`) posted by the
contribute hub — claim readers scan every hive comment body for the
marker, so the section is as authoritative as the comment was;
- an agent's relayed **status notes**: `hive/awaiting-ci: …`, `Parking on
stage/045-needs-decision: …` and `Already fixed …`. Any other relayed
comment — a finding, a triage verdict with evidence, a question — is still
posted as a comment.

Closing an issue leaves exactly one closing comment: when the issue-stage
lane has already said `Fixed by #N` the close-on-merge sweep closes without
repeating it, and vice versa.

The client counts what it did and logs one INFO line an hour,
`github notifications created=N edited=M suppressed=K` (cumulative since
start: comments created, comments edited in place, notes folded or found
already present), so the effect of the mode can be charted from the logs.

`normal` restores the previous behaviour: every note is its own comment,
every perspective's verdict its own review, every new head its own mention.

Expand Down
2 changes: 1 addition & 1 deletion src/docs/scale-envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ones to:
2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.**
This holds today and is easy to assume backwards:
- Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied
(`RankActionableIssues`, `src/pkg/github/client.go:4969-4979`, descending `AgeMinutes` within each tier).
(`RankActionableIssues`, `src/pkg/github/client.go:4996-5006`, descending `AgeMinutes` within each tier).
- PRs are sorted by **review class then oldest-first within class**
(`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`;
fixes → refactors/docs → tests).
Expand Down
20 changes: 19 additions & 1 deletion src/pkg/dashboard/contribute_claims.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand Down Expand Up @@ -164,7 +164,7 @@
postCtx, cancel := context.WithTimeout(ctx, claimCommentTimeout)
defer cancel()
body := ghpkg.IssueClaimCommentBody(claim.Identity, claim.StartedAt, claim.ExpiresAt)
if err := commenter.CreateIssueComment(postCtx, repoFull, number, body); err != nil {
if err := postClaimComment(postCtx, commenter, repoFull, number, body); err != nil {
h.logger.Warn("[contribute-ws] issue claim comment failed; claim recorded on the lease only",
"username", identityOf(c), "task", taskID, "repo", repoFull, "number", number, "error", err)
} else {
Expand All @@ -189,3 +189,21 @@
h.setLeaseClaim(identityOf(c), taskID, claim, posted)
return claim, posted
}

// claimNoteFolder is the optional seam a commenter offers to deliver a note
// as a section of the item's single hive status comment in quiet
// notification mode (*ghpkg.Client.PostClaimNote). Claim readers scan
// every hive comment body for the `<!-- hive:claim … -->` marker, so the
// marker inside a status section is as authoritative as its own comment.
type claimNoteFolder interface {
PostClaimNote(ctx context.Context, repo string, number int, body string) error
}

// postClaimComment posts the claim marker comment, folding it into the
// status comment when the commenter can and quiet mode asks for it.
func postClaimComment(ctx context.Context, commenter planIssueCommenter, repo string, number int, body string) error {
if folder, ok := commenter.(claimNoteFolder); ok {
return folder.PostClaimNote(ctx, repo, number, body)
}
return commenter.CreateIssueComment(ctx, repo, number, body)
}
27 changes: 27 additions & 0 deletions src/pkg/github/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package github

import (
Expand Down Expand Up @@ -274,6 +274,9 @@
// no-findings review, one hive review per head. nil (nothing wired)
// reads as normal, so unwired clients behave as before.
quietNotificationsFn func() bool
// notifications counts comments created, edited and suppressed; logged
// hourly so the effect of quiet mode is measurable.
notifications notificationTally
// reviewRequireLabelsFn returns review.require_labels, read live so a
// Features-tab edit gates the next relay request without a rebuild. nil
// or empty means the gate is off.
Expand Down Expand Up @@ -2879,6 +2882,27 @@
}
}

// issueCommentsContainAny reports whether any comment on repo#number
// contains any of needles, in one pass.
func (c *Client) issueCommentsContainAny(ctx context.Context, repo string, number int, needles ...string) (bool, error) {
if c == nil {
return false, ErrNoGitHubClient
}
owner, repoName := c.splitRepo(repo)
comments, err := c.listIssueComments(ctx, owner, repoName, number)
if err != nil {
return false, err
}
for _, comment := range comments {
for _, needle := range needles {
if needle != "" && strings.Contains(comment.GetBody(), needle) {
return true, nil
}
}
}
return false, nil
}

// CreateIssueComment posts a comment on an issue or PR. The signature mirrors
// forge.Forge.CreateIssueComment so escalation callers can swap in a neutral
// forge adapter on non-GitHub hives without changing call sites.
Expand Down Expand Up @@ -2918,6 +2942,9 @@
}
return effects.Result{Provenance: comment.GetHTMLURL()}, apiErr
})
if err == nil {
c.noteCommentCreated()
}
return err
}

Expand Down
30 changes: 20 additions & 10 deletions src/pkg/github/close_on_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ func (c *Client) closeIssueForMergedPRClaimWithIssue(ctx context.Context, issueR
}
return res
}
closedMarker, reopenedMarker := c.closeOnMergeMarkers(ctx, owner, repoName, issueNumber, pr.GetNumber())
closedMarker, reopenedMarker, stageNoted := c.closeOnMergeMarkers(ctx, owner, repoName, issueNumber, pr.GetNumber())
if closedMarker {
res.Action, res.Reason = CloseOnMergeAlreadyDone, "marker_present"
return res
Expand Down Expand Up @@ -653,7 +653,12 @@ func (c *Client) closeIssueForMergedPRClaimWithIssue(ctx context.Context, issueR
res.Action, res.Reason = CloseOnMergeAwaiting, "needs_confirmation_or_human"
return res
}
if _, _, err := c.client.Issues.CreateComment(WithRESTCaller(ctx, "hive:close_on_merge"), owner, repoName, issueNumber, &gh.IssueComment{Body: gh.Ptr(closeOnMergeCloseComment(pr))}); err != nil {
// The issue-stage lane may already have said "Fixed by #N" for this
// PR (mergedPRClosedStageMarker) and only failed to close; one closing
// comment per issue is enough (hivecommons/hive#15727 vs #15843).
if stageNoted {
c.noteCommentSuppressed()
} else if _, _, err := c.client.Issues.CreateComment(WithRESTCaller(ctx, "hive:close_on_merge"), owner, repoName, issueNumber, &gh.IssueComment{Body: gh.Ptr(closeOnMergeCloseComment(pr))}); err != nil {
res.Action, res.Reason = CloseOnMergeNoop, "close_comment_failed"
return res
}
Expand Down Expand Up @@ -916,35 +921,40 @@ func closeOnMergeShortSHA(sha string) string {
}

func (c *Client) hasCloseOnMergeMarker(ctx context.Context, owner, repo string, number int) bool {
closed, _ := c.closeOnMergeMarkers(ctx, owner, repo, number, 0)
closed, _, _ := c.closeOnMergeMarkers(ctx, owner, repo, number, 0)
return closed
}

// closeOnMergeMarkers reports, in one pass over the issue's comments, whether
// Hive's close-on-merge marker is present and whether the reopened-after-merge
// marker for pr is present.
func (c *Client) closeOnMergeMarkers(ctx context.Context, owner, repo string, number, pr int) (closed, reopened bool) {
reopenedMarker := ""
// Hive's close-on-merge marker is present, whether the reopened-after-merge
// marker for pr is present, and whether the issue-stage lane already left
// its own "Fixed by #pr" closing note (mergedPRClosedStageMarker).
func (c *Client) closeOnMergeMarkers(ctx context.Context, owner, repo string, number, pr int) (closed, reopened, stageNoted bool) {
reopenedMarker, stageMarker := "", ""
if pr > 0 {
reopenedMarker = closeOnMergeReopenedMarker(pr)
stageMarker = mergedPRClosedStageMarkerFor(pr)
}
opts := &gh.IssueListCommentsOptions{ListOptions: gh.ListOptions{PerPage: closeOnMergeCommentPageSize}}
for {
comments, resp, err := c.client.Issues.ListComments(ctx, owner, repo, number, opts)
if err != nil {
return closed, reopened
return closed, reopened, stageNoted
}
for _, comment := range comments {
body := comment.GetBody()
if strings.Contains(body, CloseOnMergeMarker) {
return true, reopened
return true, reopened, stageNoted
}
if reopenedMarker != "" && strings.Contains(body, reopenedMarker) {
reopened = true
}
if stageMarker != "" && strings.Contains(body, stageMarker) {
stageNoted = true
}
}
if resp == nil || resp.NextPage == 0 {
return closed, reopened
return closed, reopened, stageNoted
}
opts.Page = resp.NextPage
}
Expand Down
1 change: 1 addition & 0 deletions src/pkg/github/gfi_forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c *Client) UpsertIssueMarkerComment(ctx context.Context, repo string, numb
if _, _, err := c.client.Issues.EditComment(ctx, owner, repoName, cm.GetID(), &gh.IssueComment{Body: gh.Ptr(body)}); err != nil {
return res, fmt.Errorf("editing marker comment on %s/%s#%d: %w", owner, repoName, number, err)
}
c.noteCommentEdited()
return res, nil
}
if !create || body == "" {
Expand Down
57 changes: 45 additions & 12 deletions src/pkg/github/issue_blocked.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package github

// Blocked-on-PR signal (hivecommons/hive#13093).
Expand Down Expand Up @@ -30,6 +30,7 @@
import (
"context"
"fmt"
"github.com/hivecommons/hive/pkg/prstatus"
"log/slog"
"regexp"
"sort"
Expand Down Expand Up @@ -468,9 +469,7 @@
continue
}
note := blockedUnblockedMarker + fmt.Sprintf("\nUnblocked: %s#%d (superseding #%d) is no longer open. This issue is actionable again.", prRepo, supersededBy, prNumber)
if err := c.CreateIssueCommentBudgeted(ctx, t.repo, t.number, note); err != nil {
logger.Warn("blocked sweep: unblock note not posted", "repo", t.repo, "issue", t.number, "error", err)
}
c.postUnblockedNote(ctx, t.repo, t.number, note, logger)
res.Unblocked++
logger.Info("blocked sweep: issue unblocked", "repo", t.repo, "issue", t.number, "pr", prRepo+"#"+strconv.Itoa(supersededBy), "superseded", prNumber)
continue
Expand Down Expand Up @@ -509,9 +508,7 @@
continue
}
note := blockedUnblockedMarker + "\nUnblocked: " + prRepo + "#" + strconv.Itoa(prNumber) + " is no longer open. This issue is actionable again."
if err := c.CreateIssueCommentBudgeted(ctx, t.repo, t.number, note); err != nil {
logger.Warn("blocked sweep: unblock note not posted", "repo", t.repo, "issue", t.number, "error", err)
}
c.postUnblockedNote(ctx, t.repo, t.number, note, logger)
res.Unblocked++
logger.Info("blocked sweep: issue unblocked", "repo", t.repo, "issue", t.number, "pr", prRepo+"#"+strconv.Itoa(prNumber))
continue
Expand Down Expand Up @@ -564,9 +561,7 @@
logger.Warn("blocked sweep: unblock failed", "repo", t.repo, "issue", t.number, "error", err)
return false
}
if err := client.CreateIssueCommentBudgeted(ctx, t.repo, t.number, blockedMarkerlessNote); err != nil {
logger.Warn("blocked sweep: unblock note not posted", "repo", t.repo, "issue", t.number, "error", err)
}
client.postUnblockedNote(ctx, t.repo, t.number, blockedMarkerlessNote, logger)
res.Unblocked++
logger.Info("blocked sweep: hive-applied marker-less block lifted", "repo", t.repo, "issue", t.number, "actor", actor)
return true
Expand Down Expand Up @@ -634,13 +629,51 @@
logger.Warn("blocked sweep: unblock failed", "repo", t.repo, "issue", t.number, "error", err)
return
}
if err := client.CreateIssueCommentBudgeted(ctx, t.repo, t.number, blockedDeadlineNote(deadline)); err != nil {
logger.Warn("blocked sweep: unblock note not posted", "repo", t.repo, "issue", t.number, "error", err)
}
client.postUnblockedNote(ctx, t.repo, t.number, blockedDeadlineNote(deadline), logger)
res.Unblocked++
logger.Info("blocked sweep: issue unblocked", "repo", t.repo, "issue", t.number, "recheck_after", deadline)
}

// postUnblockedNote leaves note on the issue once per cause: a comment
// already carrying this exact note — the sweep saw the issue again before
// the label removal was visible, or a second sweep path lifted the same
// block (hivecommons/hive#15536 ×2 within a minute) — means nothing is
// posted. An issue the hive is closing for the same merge (a close-on-merge
// or issue-stage closing note is present) gets no unblocked note either:
// it is done, not actionable again. In quiet notification mode the note is
// a section of the issue's status comment, so only the first note on an
// issue ever creates a comment.
func (c *Client) postUnblockedNote(ctx context.Context, repo string, number int, note string, logger *slog.Logger) {
owner, name := c.splitRepo(repo)
comments, err := c.listIssueComments(ctx, owner, name, number)
if err != nil {
logger.Warn("blocked sweep: comment lookup before unblock note failed; posting anyway", "repo", repo, "issue", number, "error", err)
}
for _, cm := range comments {
body := cm.GetBody()
switch {
case strings.Contains(body, note):
c.noteCommentSuppressed()
return
case strings.Contains(body, CloseOnMergeMarker), strings.Contains(body, mergedPRClosedStageMarker):
logger.Info("blocked sweep: issue is being closed by its merged PR; unblock note not posted", "repo", repo, "issue", number)
c.noteCommentSuppressed()
return
}
}
if c.notificationsQuiet() {
if created, err := c.UpsertPRStatusSection(ctx, repo, number, prstatus.KeyUnblocked, note); err != nil {
logger.Warn("blocked sweep: unblock note not recorded on status comment", "repo", repo, "issue", number, "error", err)
} else if !created {
c.noteCommentSuppressed()
}
return
}
if err := c.CreateIssueCommentBudgeted(ctx, repo, number, note); err != nil {
logger.Warn("blocked sweep: unblock note not posted", "repo", repo, "issue", number, "error", err)
}
}

// blockedDeadlineNote is the note posted when a recheck-after deadline
// lifts the block.
func blockedDeadlineNote(deadline string) string {
Expand Down
42 changes: 42 additions & 0 deletions src/pkg/github/issue_request_status_notes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package github

import (
"strings"

"github.com/hivecommons/hive/pkg/prstatus"
)

// Agent status notes the policies tell an agent to leave as a PR/issue
// comment. Each is a one-line state report — the dashboard already shows
// the same state — so in quiet notification mode it is a section of the
// item's status comment rather than an email to every watcher.
const (
agentNoteAwaitingCI = "awaiting-ci" // "hive/awaiting-ci: CI pending — sweep will merge when green."
agentNoteParking = "parking" // "Parking on stage/045-needs-decision: …"
agentNoteAlreadyFixed = "already-fixed" // "Already fixed by #N …" before a close
)

// relayStatusNoteKey classifies a relayed comment body as one of the agent
// status notes, by the prefix the policies prescribe, or returns "" for a
// comment that carries content of its own (a finding, a triage verdict
// with evidence, a question) and must stay a comment.
func relayStatusNoteKey(body string) string {
first := strings.ToLower(strings.TrimSpace(firstLine(body)))
switch {
case strings.HasPrefix(first, "hive/awaiting-ci"):
return prstatus.KeyAgentNotePrefix + agentNoteAwaitingCI
case strings.HasPrefix(first, "parking on "), strings.HasPrefix(first, "parked on "):
return prstatus.KeyAgentNotePrefix + agentNoteParking
case strings.HasPrefix(first, "already fixed"):
return prstatus.KeyAgentNotePrefix + agentNoteAlreadyFixed
}
return ""
}

func firstLine(s string) string {
s = strings.TrimLeft(s, "\r\n\t ")
if i := strings.IndexByte(s, '\n'); i >= 0 {
return s[:i]
}
return s
}
12 changes: 11 additions & 1 deletion src/pkg/github/issue_request_watcher.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package github

import (
Expand Down Expand Up @@ -659,7 +659,17 @@
parkBlocked = true
}
}
err = c.CreateIssueCommentBudgeted(ctx, req.Repo, req.Number, body)
if key := relayStatusNoteKey(body); key != "" && c.notificationsQuiet() {
// A one-line state note (awaiting-ci, parking, already fixed)
// is a section of the item's status comment in quiet mode.
var created bool
created, err = c.UpsertPRStatusSection(ctx, req.Repo, req.Number, key, body)
if err == nil && !created {
c.noteCommentSuppressed()
}
} else {
err = c.CreateIssueCommentBudgeted(ctx, req.Repo, req.Number, body)
}
if errors.Is(err, ErrIssueCommentBudget) {
c.denyIssueRequest(path, req, "comment refused: "+err.Error()+"; this issue already received its daily quota of hive comments, nothing more is needed on it today", nowFn)
return
Expand Down
Loading
Loading