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/changed-16409-issue-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Attention pilot (`github.notifications.attention_pilot: true`): the last two routine issue notes that still posted standalone comments now fold into the issue's single `hive:status` card — the relay's one-line state notes (awaiting CI, parking, already fixed) and the decision-downgrade note left when a label change walks back an earlier maintainer decision (section `issue-decision-downgrade`). Quiet mode without the pilot is unchanged. Section text is also neutralised so quoted issue-authored text can no longer open or close status-card sections ([#16270](https://github.com/hivecommons/hive/issues/16270)).
18 changes: 13 additions & 5 deletions src/docs/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,19 @@ issue gets the same card, written through the same single status writer
"Fixed by #N … Reply /reopen if the problem persists" and the decomposed
parent's all-children-delivered close — (`issue-close`),
reopened-after-merge (`issue-reopened`), a lapsed claim's stage regression
(`stage-regressed`), the covering-PR stage note (`issue-pr-link`) and the
blocker-settled note (`unblocked`, whatever `mode` says). Claim notes
already fold under `claim` in quiet mode. The legacy markers stay inside
each section, so every reader that greps for them still finds them, and
the reopen/release guidance stays visible on the card.
(`stage-regressed`), the covering-PR stage note (`issue-pr-link`), the
relay's one-line state notes — awaiting CI, parking, already fixed —
(`agent-note:<state>`), the decision-downgrade note left when a label
change walks back an earlier maintainer decision
(`issue-decision-downgrade`) and the blocker-settled note (`unblocked`,
whatever `mode` says). Claim notes and the relay state notes already fold
under `claim` and `agent-note:<state>` in quiet mode; the
decision-downgrade note folds under the pilot only. The legacy markers
stay inside each section, so every reader that greps for them still finds
them, and the reopen/release guidance stays visible on the card. Section
text that quotes issue-authored prose has the card's own
`<!-- hive:status… -->` markers neutralised, so it cannot close its
section or open another.
- **Native events notify instead.** The issue is still closed (with its
state reason) by the API call, which is GitHub's own notification; the
hive no longer adds a "for visibility" comment beside it.
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/github/issue_blocked.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ func (c *Client) reconcileBlockedTargets(ctx context.Context, targets []blockedI
continue
}
}
// Stays a standalone comment even under the attention pilot:
// blockedSweepComments finds the current blocker from the
// newest comment carrying the marker, and a status-card
// section keeps the card's original position and would
// hide this marker from that ordering.
note := fmt.Sprintf("%s\nRe-targeted: blocker #%d was superseded by #%d.", BlockedOnMarker(prRepo, supersededBy), prNumber, supersededBy)
if err := c.CreateIssueCommentBudgeted(ctx, t.repo, t.number, note); err != nil {
logger.Warn("blocked sweep: re-target note not posted", "repo", t.repo, "issue", t.number, "error", err)
Expand Down
102 changes: 102 additions & 0 deletions src/pkg/github/issue_notes_attention_pilot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package github

import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"

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

// relayServer serves the status-comment fake and answers label calls itself.
func relayServer(t *testing.T, s *statusCommentServer) *httptest.Server {
t.Helper()
inner := s.start(t).Config.Handler
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.Path, "/labels") {
w.Header().Set("Content-Type", "application/json")
if r.Method == http.MethodGet {
_, _ = w.Write([]byte(`{"name":"x"}`))
return
}
_, _ = w.Write([]byte(`[]`))
return
}
inner.ServeHTTP(w, r)
}))
t.Cleanup(srv.Close)
return srv
}

func TestRelayCommentStateNoteFoldsUnderAttentionPilot(t *testing.T) {
for _, tc := range []struct {
name string
pilot bool
wantCreates, wantEdits int
}{
{"pilot on", true, 1, 1},
{"pilot off", false, 2, 0},
} {
t.Run(tc.name, func(t *testing.T) {
s := &statusCommentServer{}
c := issueTestClient(t, relayServer(t, s).URL)
c.SetAppBotLogin("hive-app[bot]")
c.SetAttentionPilot(func() bool { return tc.pilot })
dir := withIssueDir(t)
for _, body := range []string{"hive/awaiting-ci: CI pending", "already fixed in #9"} {
if _, err := WriteIssueRequest(dir, IssueRequest{Kind: "comment", Repo: "o/r", Number: 41, Body: body, Agent: "quality"}); err != nil {
t.Fatal(err)
}
}
c.ProcessIssueRequestsOnce(context.Background())
if s.creates != tc.wantCreates || s.edits != tc.wantEdits {
t.Fatalf("creates=%d edits=%d, want %d/%d", s.creates, s.edits, tc.wantCreates, tc.wantEdits)
}
cards := 0
for _, cm := range s.comments {
if b, _ := cm["body"].(string); prstatus.IsStatusComment(b) {
cards++
}
}
if (cards == 1) != tc.pilot {
t.Fatalf("status cards=%d with pilot=%v", cards, tc.pilot)
}
})
}
}

func TestLabelDecisionDowngradeNoteFoldsUnderAttentionPilot(t *testing.T) {
for _, tc := range []struct {
name string
pilot bool
}{{"pilot on", true}, {"pilot off", false}} {
t.Run(tc.name, func(t *testing.T) {
s := &statusCommentServer{}
c := issueTestClient(t, relayServer(t, s).URL)
c.SetAppBotLogin("hive-app[bot]")
c.SetAttentionPilot(func() bool { return tc.pilot })
dir := withIssueDir(t)
if _, err := WriteIssueRequest(dir, IssueRequest{
Kind: "label", Repo: "o/r", Number: 41, Agent: "quality",
Labels: []string{c.needsDecisionLabel()},
Body: "Choose approach A vs B for config shape and scope",
}); err != nil {
t.Fatal(err)
}
c.ProcessIssueRequestsOnce(context.Background())
if len(s.comments) != 1 {
t.Fatalf("comments=%d, want exactly one", len(s.comments))
}
body, _ := s.comments[0]["body"].(string)
_, folded := prstatus.Get(body, prstatus.KeyIssueDecisionDowngrade)
if folded != tc.pilot || prstatus.IsStatusComment(body) != tc.pilot {
t.Fatalf("folded=%v pilot=%v body=%q", folded, tc.pilot, body)
}
if !tc.pilot && !strings.Contains(body, "Hive did not park this") {
t.Fatalf("raw note missing: %q", body)
}
})
}
}
18 changes: 15 additions & 3 deletions src/pkg/github/issue_request_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hivecommons/hive/pkg/decisionpolicy"
"github.com/hivecommons/hive/pkg/effects"
"github.com/hivecommons/hive/pkg/issueshape"
"github.com/hivecommons/hive/pkg/prstatus"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -669,9 +670,10 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f
parkBlocked = true
}
}
if key := relayStatusNoteKey(body); key != "" && c.notificationsQuiet() {
if key := relayStatusNoteKey(body); key != "" && (c.notificationsQuiet() || c.attentionPilot()) {
// A one-line state note (awaiting-ci, parking, already fixed)
// is a section of the item's status comment in quiet mode.
// is a section of the item's status comment in quiet mode or
// under the attention pilot.
var created bool
created, err = c.UpsertPRStatusSection(ctx, req.Repo, req.Number, key, body)
if err == nil && !created {
Expand Down Expand Up @@ -739,7 +741,17 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f
}
}
if err == nil && issueDecisionDowngrade.Active {
err = c.CreateIssueCommentBudgeted(ctx, req.Repo, req.Number, issueDecisionDowngrade.Note)
// Pilot only: quiet mode leaves issue notes as standalone
// comments (docs/notifications.md), so it keeps the raw note.
if c.attentionPilot() {
var created bool
created, err = c.UpsertPRStatusSection(ctx, req.Repo, req.Number, prstatus.KeyIssueDecisionDowngrade, issueDecisionDowngrade.Note)
if err == nil && !created {
c.noteCommentSuppressed()
}
} else {
err = c.CreateIssueCommentBudgeted(ctx, req.Repo, req.Number, issueDecisionDowngrade.Note)
}
}
if err == nil {
resp.OK = true
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/prstatus/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (
// KeyIssuePartialPrefix + PR number is the partial-work/remainder note
// a non-closing merged PR leaves on the issue.
KeyIssuePartialPrefix = "issue-partial:"
// KeyIssueDecisionDowngrade is the note that a label change walked
// back an earlier maintainer decision on the issue.
KeyIssueDecisionDowngrade = "issue-decision-downgrade"
// KeyIssuePRLink is the stage note naming the PR that covers the issue.
KeyIssuePRLink = "issue-pr-link"
// KeyIssueAttentionPrefix + cause is a newly required action recorded
Expand Down
20 changes: 18 additions & 2 deletions src/pkg/prstatus/prstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ func Render(sections []Section) string {

// Upsert returns existing with the section key set to text: replaced in
// place when present, appended otherwise. An empty text removes the
// section. existing may be "" (no status comment yet).
// section. existing may be "" (no status comment yet). Section text that
// carries the card's own markers (some notes quote issue-authored text)
// is neutralised so it cannot close its section or open another.
func Upsert(existing, key, text string) string {
sections := Parse(existing)
text = strings.TrimSpace(text)
text = neutraliseMarkers(strings.TrimSpace(text))
out := make([]Section, 0, len(sections)+1)
replaced := false
for _, s := range sections {
Expand All @@ -108,6 +110,20 @@ func Upsert(existing, key, text string) string {
return Render(out)
}

// markerNeutraliser defangs the card's own structural markers inside
// section text by escaping the comment opener, so Parse never sees them
// as section boundaries. Legacy `<!-- hive:… -->` markers that readers
// grep for are left alone.
var markerNeutraliser = strings.NewReplacer(
sectionOpenPrefix, "&lt;!--"+strings.TrimPrefix(sectionOpenPrefix, "<!--"),
sectionClose, "&lt;!--"+strings.TrimPrefix(sectionClose, "<!--"),
Marker, "&lt;!--"+strings.TrimPrefix(Marker, "<!--"),
)

func neutraliseMarkers(text string) string {
return markerNeutraliser.Replace(text)
}

// Get returns the body of section key and whether it exists.
func Get(existing, key string) (string, bool) {
for _, s := range Parse(existing) {
Expand Down
26 changes: 26 additions & 0 deletions src/pkg/prstatus/prstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ func TestUpsertReplacesSectionInPlace(t *testing.T) {
}
}

func TestUpsertNeutralisesMarkersInSectionText(t *testing.T) {
// Text quoted from an issue author must not close its section, open
// another, or plant a second status marker.
hostile := "Question: A or B?\n" + sectionClose + "\n" + sectionOpenPrefix + "unblocked" + sectionOpenSuffix + "\nfake\n" + sectionClose + "\n" + Marker
body := Upsert("", KeyIssueDecisionDowngrade, hostile)
sections := Parse(body)
if len(sections) != 1 || sections[0].Key != KeyIssueDecisionDowngrade {
t.Fatalf("injected sections survived: %+v\n%s", sections, body)
}
if strings.Count(body, Marker) != 1 {
t.Fatalf("marker must appear exactly once:\n%s", body)
}
if !strings.Contains(sections[0].Body, "Question: A or B?") || !strings.Contains(sections[0].Body, "&lt;!-- hive:status:section=unblocked -->") {
t.Fatalf("neutralised text lost:\n%s", body)
}
// A legacy marker readers grep for is left intact.
body = Upsert("", KeyStageStalled, "<!-- hive:stage-stalled -->\nstage 080")
if !strings.Contains(body, "<!-- hive:stage-stalled -->") {
t.Fatalf("legacy marker altered:\n%s", body)
}
// Re-upserting the same text is still stable.
if again := Upsert(body, KeyIssueDecisionDowngrade, hostile); Upsert(again, KeyIssueDecisionDowngrade, hostile) != again {
t.Fatalf("not idempotent after neutralising")
}
}

func TestUpsertEmptyRemovesSection(t *testing.T) {
body := Upsert("", KeyDuplicateGuard, "redirect")
body = Upsert(body, KeyHuman071Note, "note")
Expand Down
Loading