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-issue-title-agent-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Every issue the hive files now carries the filing agent in its title (`[reviewer] Review backlog (security): …`, `[governor] refactor: … is a merge hotspot …`): one shared `issueshape.TitleFor` helper tags titles idempotently at `CreateIssue`, in the review-backlog, hotspot and upstream-watch title builders, and in the egress proxy for an agent's raw `gh issue create`; open-issue title dedupe ignores the tag so items filed before it still match instead of being refiled.
51 changes: 51 additions & 0 deletions src/crux/issueshape/issueshape.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,54 @@ func UnchosenOptionList(text string) (string, bool) {
m := unchosenOptionListRE.FindString(text)
return m, m != ""
}

// agentTitlePrefixRE matches the leading `[<agent>]` tag every hive-filed
// issue title carries (`[scanner] …`, `[reviewer] …`, `[selfreport] …`). A
// filer-chosen tag with spaces (`[ACMM L0] …`) counts too, so it is kept
// rather than stacked under a second tag.
var agentTitlePrefixRE = regexp.MustCompile(`^\s*\[([^\]\n]+)\]\s*`)

// TitleFor returns title carrying a leading `[<agent>]` tag, the convention
// every issue the hive files follows so a reader can tell which agent or
// subsystem filed it. The tag is the lowercased agent (lane) name as the
// dashboard shows it. It is idempotent: a title that already starts with a
// bracketed tag — the same agent, or a tag the filer chose itself such as
// `[Tests]` or `[DCO]` — is returned unchanged, so a title is never
// double-prefixed. An empty agent leaves the title as it is.
func TitleFor(agent, title string) string {
title = strings.TrimSpace(title)
agent = strings.ToLower(strings.TrimSpace(agent))
if agent == "" || title == "" || HasAgentPrefix(title) {
return title
}
return "[" + agent + "] " + title
}

// HasAgentPrefix reports whether title starts with a bracketed `[tag]`.
func HasAgentPrefix(title string) bool {
return agentTitlePrefixRE.MatchString(title)
}

// AgentPrefix returns the tag inside a title's leading `[tag]`, lowercased,
// or "" when the title carries none.
func AgentPrefix(title string) string {
m := agentTitlePrefixRE.FindStringSubmatch(title)
if m == nil {
return ""
}
return strings.ToLower(m[1])
}

// StripAgentPrefix returns title without its leading `[tag]`, trimmed. It is
// the key dedupe compares on so an issue filed before titles carried the
// filing agent still matches its prefixed re-filing.
func StripAgentPrefix(title string) string {
return strings.TrimSpace(agentTitlePrefixRE.ReplaceAllString(strings.TrimSpace(title), ""))
}

// SameTitle reports whether two issue titles are the same title once the
// leading `[<agent>]` tag is ignored: `Review backlog (security): x` and
// `[reviewer] Review backlog (security): x` are one finding, not two.
func SameTitle(a, b string) bool {
return StripAgentPrefix(a) == StripAgentPrefix(b)
}
47 changes: 47 additions & 0 deletions src/crux/issueshape/issueshape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,50 @@ func TestUnchosenOptionList(t *testing.T) {
})
}
}

// Every issue the hive files names its filer in the title; TitleFor is the
// one helper that adds the tag, and it never adds a second one.
func TestTitleForTagsOnceAndKeepsExistingTag(t *testing.T) {
cases := []struct{ agent, title, want string }{
{"reviewer", "Review backlog (security): token logged", "[reviewer] Review backlog (security): token logged"},
{"Reviewer", " Review backlog (style): x ", "[reviewer] Review backlog (style): x"},
{"reviewer", "[reviewer] Review backlog (security): token logged", "[reviewer] Review backlog (security): token logged"},
{"tester", "[Tests] v5 test failure on 4536f90", "[Tests] v5 test failure on 4536f90"},
{"dashboard", "[ACMM L0] Add CI/CD pipeline", "[ACMM L0] Add CI/CD pipeline"},
{"selfreport", "[selfreport] unclassified_error_repeated: x", "[selfreport] unclassified_error_repeated: x"},
{"governor", "refactor: src/a.go is a merge hotspot — split into 4 units", "[governor] refactor: src/a.go is a merge hotspot — split into 4 units"},
{"", "untagged stays untagged", "untagged stays untagged"},
{"scanner", "", ""},
}
for _, tc := range cases {
if got := TitleFor(tc.agent, tc.title); got != tc.want {
t.Errorf("TitleFor(%q, %q) = %q, want %q", tc.agent, tc.title, got, tc.want)
}
if again := TitleFor(tc.agent, TitleFor(tc.agent, tc.title)); again != tc.want {
t.Errorf("TitleFor is not idempotent for (%q, %q): %q", tc.agent, tc.title, again)
}
}
}

// Dedupe compares titles with the tag ignored, so an issue filed before
// titles carried the filer still matches its tagged re-filing.
func TestStripAgentPrefixAndSameTitle(t *testing.T) {
if got := StripAgentPrefix("[reviewer] Review backlog (security): x"); got != "Review backlog (security): x" {
t.Fatalf("StripAgentPrefix = %q", got)
}
if got := StripAgentPrefix(" no tag here "); got != "no tag here" {
t.Fatalf("StripAgentPrefix(untagged) = %q", got)
}
if got := AgentPrefix("[Scanner] split x.go"); got != "scanner" {
t.Fatalf("AgentPrefix = %q", got)
}
if AgentPrefix("plain") != "" || HasAgentPrefix("plain") {
t.Fatal("untagged title reported a tag")
}
if !SameTitle("Review backlog (security): x", "[reviewer] Review backlog (security): x") {
t.Fatal("legacy untagged title must match its tagged successor")
}
if SameTitle("[reviewer] Review backlog (security): x", "[reviewer] Review backlog (security): y") {
t.Fatal("different subjects must not match")
}
}
42 changes: 29 additions & 13 deletions src/crux/proxy/github_proxy_violations.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package proxy

import (
Expand Down Expand Up @@ -156,12 +156,13 @@

// injectOriginLabel ensures an agent's issue-create JSON body carries the
// canonical agent/<lane> label and no redundant origin/<lane> or bare <lane>
// label, so an issue filed with `gh issue create` through the proxy records
// the same provenance as one filed through the issue-request watcher. The
// body is returned unchanged (ok=false) for other routes, an unidentified
// caller, a body that is not a JSON object, or a labels field in an unexpected
// shape (GitHub accepts label objects too; those are forwarded as written
// rather than guessed at).
// label, and that its title starts with the `[<lane>]` tag every hive-filed
// issue carries, so an issue filed with `gh issue create` through the proxy
// records the same provenance as one filed through the issue-request
// watcher. The body is returned unchanged (ok=false) for other routes, an
// unidentified caller, a body that is not a JSON object, or a labels field in
// an unexpected shape (GitHub accepts label objects too; those are forwarded
// as written rather than guessed at).
func injectOriginLabel(method, path string, body []byte, agentName string) ([]byte, bool) {
lane := config.OriginLaneFromAgent(agentName)
if lane == "" || agentName == internalCallerName || !isIssueCreateRESTWrite(method, path) {
Expand All @@ -171,22 +172,37 @@
if err := json.Unmarshal(body, &payload); err != nil || payload == nil {
return body, false
}
changed := false
var labels []string
if raw, present := payload["labels"]; present && len(bytes.TrimSpace(raw)) > 0 && string(bytes.TrimSpace(raw)) != "null" {
if err := json.Unmarshal(raw, &labels); err != nil {
return body, false
}
}
filtered := config.WithIssueOriginLabel(labels, lane)
if sameLabels(labels, filtered) {
return body, false
if filtered := config.WithIssueOriginLabel(labels, lane); !sameLabels(labels, filtered) {
encoded, err := json.Marshal(filtered)
if err != nil {
return body, false
}
payload["labels"] = encoded
changed = true
}
labels = filtered
encoded, err := json.Marshal(labels)
if err != nil {
if raw, present := payload["title"]; present {
var title string
if err := json.Unmarshal(raw, &title); err == nil && title != "" {
if tagged := issueshape.TitleFor(lane, title); tagged != title {
encoded, err := json.Marshal(tagged)
if err != nil {
return body, false
}
payload["title"] = encoded
changed = true
}
}
}
if !changed {
return body, false
}
payload["labels"] = encoded
rewritten, err := json.Marshal(payload)
if err != nil {
return body, false
Expand Down
16 changes: 13 additions & 3 deletions src/crux/proxy/origin_label_inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ func TestInjectOriginLabelAddsLaneOnceAndKeepsAgentChoice(t *testing.T) {
agent string
wantOK bool
wantLabels []string
wantTitle string
}{
{name: "no labels field", method: http.MethodPost, path: path, body: `{"title":"t","body":"b"}`, agent: "scanner", wantOK: true, wantLabels: []string{"agent/scanner"}},
{name: "no labels field", method: http.MethodPost, path: path, body: `{"title":"t","body":"b"}`, agent: "scanner", wantOK: true, wantLabels: []string{"agent/scanner"}, wantTitle: "[scanner] t"},
{name: "already tagged title kept, replica suffix stripped", method: http.MethodPost, path: path, body: `{"title":"[scanner] t","body":"b","labels":["agent/scanner"]}`, agent: "scanner-2", wantOK: false},
{name: "foreign tag not double-prefixed", method: http.MethodPost, path: path, body: `{"title":"[Tests] t","body":"b"}`, agent: "tester", wantOK: true, wantLabels: []string{"agent/tester"}, wantTitle: "[Tests] t"},
{name: "bare lane label dropped, replica suffix stripped", method: http.MethodPost, path: path, body: `{"title":"t","body":"b","labels":["agent/scanner","scanner","kind/bug"]}`, agent: "scanner-2", wantOK: true, wantLabels: []string{"agent/scanner", "kind/bug"}},
{name: "agent-supplied origin kept while bare filing lane drops", method: http.MethodPost, path: path, body: `{"title":"t","body":"b","labels":["origin/dashboard","agent/scanner","scanner"]}`, agent: "scanner", wantOK: true, wantLabels: []string{"origin/dashboard", "agent/scanner"}},
{name: "agent-supplied matching origin drops redundant origin and bare label", method: http.MethodPost, path: path, body: `{"title":"t","body":"b","labels":["origin/scanner","agent/scanner","scanner","kind/bug"]}`, agent: "scanner", wantOK: true, wantLabels: []string{"agent/scanner", "kind/bug"}},
Expand Down Expand Up @@ -53,8 +56,12 @@ func TestInjectOriginLabelAddsLaneOnceAndKeepsAgentChoice(t *testing.T) {
if err := json.Unmarshal(got, &payload); err != nil {
t.Fatalf("rewritten body is not JSON: %v: %s", err, got)
}
if payload.Title != "t" || payload.Body != "b" {
t.Fatalf("title/body must survive the rewrite: %s", got)
wantTitle := tc.wantTitle
if wantTitle == "" {
wantTitle = "[" + strings.TrimSuffix(tc.agent, "-2") + "] t"
}
if payload.Title != wantTitle || payload.Body != "b" {
t.Fatalf("title = %q, want %q; body must survive the rewrite: %s", payload.Title, wantTitle, got)
}
if strings.Join(payload.Labels, ",") != strings.Join(tc.wantLabels, ",") {
t.Fatalf("labels = %v, want %v", payload.Labels, tc.wantLabels)
Expand Down Expand Up @@ -88,6 +95,9 @@ func TestEnforceIssueShapeForInjectsOriginAfterShapePasses(t *testing.T) {
if strings.Contains(forwarded, `"origin/tester"`) || !strings.Contains(forwarded, `"agent/tester"`) || strings.Contains(forwarded, `"tester"`) || !strings.Contains(forwarded, `"kind/bug"`) {
t.Fatalf("forwarded body = %s", forwarded)
}
if !strings.Contains(forwarded, `"title":"[tester] Real title"`) {
t.Fatalf("forwarded title must carry the filing lane: %s", forwarded)
}
if req.ContentLength != int64(len(forwarded)) {
t.Fatalf("ContentLength %d != forwarded %d", req.ContentLength, len(forwarded))
}
Expand Down
2 changes: 1 addition & 1 deletion src/docs/hive-open-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ hive-open-issue request-review --repo <owner/repo> <number|url> [--reviewer a,b]
| Flag | Aliases | Applies to | Notes |
| --- | --- | --- | --- |
| `--repo` | `-R` | all | required |
| `--title` | `-t` | issue | required for `issue` |
| `--title` | `-t` | issue | required for `issue`; must start with `[<your agent name>]` (`[scanner] …`) — the watcher and the proxy's `gh issue create` path both add the tag when it is missing and never double it |
| `--body` | `-b` | issue, comment | required for `issue` and `comment`; not used by `claim` |
| `--body-file` | `-F` | issue, comment | reads body from a file; `-` reads stdin |
| `--label` | `-l`, `--add-label` | issue, label | repeatable; comma-separated values are split |
Expand Down
2 changes: 1 addition & 1 deletion src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The default human threshold is `high`. Review-triggered fix cycles use the same

### Out-of-scope backlog filing

When the relay accepts a review verdict, cited out-of-scope findings (`review_scope: "out-of-scope"` with `file` and positive `line`) are filed as follow-up issues labeled `agent/reviewer` (the reviewer lane provenance/routing label — see [labels-and-control-signals.md](labels-and-control-signals.md#label-axes); the retired `from-review`, `origin/review`, and `origin/reviewer` names are accepted in config and migrated on open items). Each issue body links back to the reviewed PR and records the perspective, severity, evidence location, and finding summary. The relay deduplicates against open issues through the normal issue-create path and also persists a finding key in `/data/review-backlog-issues.json`, so re-reviewing a new commit does not file the same backlog issue or summary comment again.
When the relay accepts a review verdict, cited out-of-scope findings (`review_scope: "out-of-scope"` with `file` and positive `line`) are filed as follow-up issues labeled `agent/reviewer` (the reviewer lane provenance/routing label — see [labels-and-control-signals.md](labels-and-control-signals.md#label-axes); the retired `from-review`, `origin/review`, and `origin/reviewer` names are accepted in config and migrated on open items). Each issue is titled `[reviewer] Review backlog (<perspective>): <finding>` — like every issue the hive files, the title starts with the filing agent in square brackets (`issueshape.TitleFor`, applied once more in `CreateIssue` so no filer can forget it, and ignored by title dedupe so items filed before the tag still match). Each issue body links back to the reviewed PR and records the perspective, severity, evidence location, and finding summary. The relay deduplicates against open issues through the normal issue-create path and also persists a finding key in `/data/review-backlog-issues.json`, so re-reviewing a new commit does not file the same backlog issue or summary comment again.

The PR receives one summary comment listing the backlog issues filed from that review. Filing is enabled by default and bounded by `review.max_out_of_scope_backlog_issues` (default `3`) per PR; set `review.out_of_scope_backlog_disabled: true` to opt out.

Expand Down
42 changes: 40 additions & 2 deletions 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 @@ -1216,6 +1216,36 @@
return config.OriginLabelForAgent(r.Origin)
}

// TitleFiler returns the agent or subsystem name the issue title is tagged
// with (`[<filer>] …`): the Origin's agent lane (`reviewer-2` → `reviewer`),
// else a non-lane origin/* label the caller chose (the convergence publisher
// filing through the forge seam), else the Origin source as written
// (`governor`, `selfreport`, `dashboard`), else the source of the resolved
// provenance label.
func (r CreateIssueRequest) TitleFiler() string {
lane := config.OriginLaneFromAgent(r.Origin)
if lane != "" && config.IsKnownOriginLane(lane) {
return lane
}
for _, l := range r.Labels {
if source := config.OriginSourceOf(l); source != "" && !config.IsKnownOriginLane(source) {
return source
}
}
if lane != "" {
return lane
}
if source := config.OriginSourceOf(r.OriginLabel()); source != "" {
return source
}
for _, l := range r.Labels {
if source := config.OriginSourceOf(l); source != "" {
return source
}
}
return ""
}

// ErrOriginRequired is returned when a create carries no provenance label and
// names no Origin source.
var ErrOriginRequired = errors.New("CreateIssue: provenance is required (set Origin or pass an origin/* label)")
Expand Down Expand Up @@ -1255,6 +1285,11 @@
if title == "" {
return CreateIssueResult{}, fmt.Errorf("CreateIssue: title is required")
}
// Every issue the hive files names its filer in the title (`[reviewer]
// Review backlog (security): …`). Hive-internal filers and the watcher
// both land here, so a caller cannot forget it; TitleFor is idempotent
// for a title an agent already tagged.
title = issueshape.TitleFor(req.TitleFiler(), title)
// Same posture and same placement as validateRepoRef above: a request that
// is still carrying its template cannot become a useful issue, and unlike a
// bad repo ref it would SUCCEED, leaving a human to triage an empty report
Expand Down Expand Up @@ -1302,7 +1337,7 @@
// twin (#13906). An exact-title match is the same finding and stays
// unguarded.
if err == nil && scan.subject != nil && req.FoldMatch != nil &&
strings.TrimSpace(scan.subject.GetTitle()) != title &&
!issueshape.SameTitle(scan.subject.GetTitle(), title) &&
!req.FoldMatch(scan.subject.GetTitle(), scan.subject.GetBody()) {
scan.subject = nil
}
Expand Down Expand Up @@ -1778,7 +1813,10 @@
continue
}
candidate := strings.TrimSpace(is.GetTitle())
if candidate == title || reviewBacklogTitlesEqual(candidate, title) {
// Exact match ignores the leading `[<agent>]` tag so an issue
// filed before titles carried the filer still dedupes its
// prefixed re-filing instead of gaining a twin.
if candidate == title || issueshape.SameTitle(candidate, title) || reviewBacklogTitlesEqual(candidate, title) {
return openIssueMatches{subject: is}, nil
}
// Pages arrive newest-first, so overwriting leaves the oldest
Expand Down
Loading
Loading