From dc0f713926f565282cc2fbfe0b5fe10a12c92414 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 12:15:30 -0500 Subject: [PATCH 1/2] fix(github): delegated issue decisions never attribute reporter-authored option text verbatim Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../security-issue-decision-option-text.md | 1 + src/pkg/delegatedecision/competing_options.go | 6 +++- src/pkg/github/issue_decision_options.go | 18 +++++++--- src/pkg/github/issue_decision_options_test.go | 35 +++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 changelog.d/security-issue-decision-option-text.md diff --git a/changelog.d/security-issue-decision-option-text.md b/changelog.d/security-issue-decision-option-text.md new file mode 100644 index 0000000000..06e300b744 --- /dev/null +++ b/changelog.d/security-issue-decision-option-text.md @@ -0,0 +1 @@ +- Delegated issue decisions record reporter-authored option text only by option label: when the options come from the body of an issue a non-hive account filed, the owner-attributed `/hive decision go with option N` no longer quotes the reporter's summary, while options from hive-authored text keep their summary (#16937). diff --git a/src/pkg/delegatedecision/competing_options.go b/src/pkg/delegatedecision/competing_options.go index ef9cf2b557..429da94bfa 100644 --- a/src/pkg/delegatedecision/competing_options.go +++ b/src/pkg/delegatedecision/competing_options.go @@ -27,12 +27,16 @@ const ( type Option struct { Label string `json:"label"` Summary string `json:"summary,omitempty"` + // Untrusted marks an option read from an issue body a non-hive account + // wrote: its summary is reporter prose and is never quoted into the + // owner-attributed decision, which names the option by label alone. + Untrusted bool `json:"untrusted,omitempty"` } // Name is the option as a decision names it: "option 2: A ujust recipe". func (o Option) Name() string { name := "option " + o.Label - if s := strings.TrimSpace(o.Summary); s != "" { + if s := strings.TrimSpace(o.Summary); s != "" && !o.Untrusted { name += ": " + s } return name diff --git a/src/pkg/github/issue_decision_options.go b/src/pkg/github/issue_decision_options.go index f629cb1db5..a765b2212d 100644 --- a/src/pkg/github/issue_decision_options.go +++ b/src/pkg/github/issue_decision_options.go @@ -18,9 +18,12 @@ import ( // it names none. Fewer than two options reads as none. func (c *Client) IssueDecisionOptions(issueBody string, issueAuthor *gh.User, comments []*gh.IssueComment) (options []delegatedecision.Option, recommended string) { m := c.unparkMenuFor(issueBody, issueAuthor, comments) + // Options read from the body of an issue a non-hive account filed are + // reporter-authored; the delegated decision names them by label only. + bodyUntrusted := !c.isHiveAccount(issueAuthor) if len(m.options) >= 2 { for _, l := range m.options { - options = append(options, delegatedecision.Option{Label: l, Summary: m.optionText[l]}) + options = append(options, delegatedecision.Option{Label: l, Summary: m.optionText[l], Untrusted: bodyUntrusted && m.optionSource == ""}) } return options, m.recommended } @@ -28,9 +31,9 @@ func (c *Client) IssueDecisionOptions(issueBody string, issueAuthor *gh.User, co // wins, as for letters. The hive's own notices, replies and the // delegate's verdicts are not park text; a withdrawn ask takes its // options with it. - source := "" + source, fromBody := "", false if numberedDecisionOptions(issueBody) != nil { - source = issueBody + source, fromBody = issueBody, true } for _, cm := range comments { if cm == nil || !c.isHiveAccount(cm.GetUser()) { @@ -39,18 +42,23 @@ func (c *Client) IssueDecisionOptions(issueBody string, issueAuthor *gh.User, co body := cm.GetBody() switch { case strings.Contains(body, parkWithdrawnMarkerPrefix): - source = "" + source, fromBody = "", false case strings.Contains(body, unparkNoticeMarker), strings.Contains(body, unparkReplyMarkerPrefix), strings.Contains(body, unparkAcceptedMarker), strings.Contains(body, parkRecheckMarker), delegatedecision.IsDelegatedComment(body): case numberedDecisionOptions(body) != nil: - source = body + source, fromBody = body, false } } if source == "" { return nil, "" } options = numberedDecisionOptions(source) + if fromBody && bodyUntrusted { + for i := range options { + options[i].Untrusted = true + } + } return options, numberedRecommendedOption(source, options) } diff --git a/src/pkg/github/issue_decision_options_test.go b/src/pkg/github/issue_decision_options_test.go index e1b1d7d4f5..ae595e6c27 100644 --- a/src/pkg/github/issue_decision_options_test.go +++ b/src/pkg/github/issue_decision_options_test.go @@ -133,3 +133,38 @@ func TestIssueDecisionOptions(t *testing.T) { t.Errorf("a withdrawn ask kept its options: %+v", opts) } } + +func TestIssueDecisionOptionsMarkReporterBodyUntrusted(t *testing.T) { + c := menuTestClient() + person := &gh.User{Login: gh.Ptr("someone")} + hive := &gh.User{Login: gh.Ptr("hive[bot]")} + + for _, body := range []string{dakotaStyleOptions, utah920Body} { + opts, _ := c.IssueDecisionOptions(body, person, nil) + if len(opts) < 2 { + t.Fatalf("no options read from %q", body) + } + for _, o := range opts { + if !o.Untrusted { + t.Errorf("reporter body option %+v not marked untrusted", o) + } + if name := o.Name(); name != "option "+o.Label { + t.Errorf("Name() = %q, want the label alone", name) + } + } + opts, _ = c.IssueDecisionOptions(body, hive, nil) + for _, o := range opts { + if o.Untrusted { + t.Errorf("hive-authored option %+v marked untrusted", o) + } + } + } + + // A hive comment's options are the hive's own text, whoever filed the issue. + opts, _ := c.IssueDecisionOptions("Ship the debugging tools.", person, []*gh.IssueComment{ghComment("hive[bot]", utah920Park)}) + for _, o := range opts { + if o.Untrusted { + t.Errorf("hive comment option %+v marked untrusted", o) + } + } +} From 4a549358c4cd74b462a139029406e4153976b8f3 Mon Sep 17 00:00:00 2001 From: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 12:33:18 -0500 Subject: [PATCH 2/2] fix(github): explicit body provenance for untrusted options; plan previews the reporter's summary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-ups on #16949: - unparkMenu gains an explicit optionsFromBody flag instead of inferring provenance from optionSource == "": a hive comment read without its html_url is still hive-authored text. The test now covers lettered options from a hive comment on a reporter's issue, and a hive comment replacing the reporter's body options. - The "Let hive decide" plan sentence shows a reporter-authored option's summary as a quoted, one-line excerpt of the issue's words, so the owner sees what they approve while Name() — and the recorded decision — stay label-only. Changelog fragment says so. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../security-issue-decision-option-text.md | 2 +- ...repo_item_decide_delegated_options_test.go | 19 +++++++++++++ .../api_repo_item_decide_delegated_plan.go | 19 ++++++++++++- src/pkg/github/issue_decision_options.go | 2 +- src/pkg/github/issue_decision_options_test.go | 27 +++++++++++++++---- src/pkg/github/issue_unpark_menu.go | 8 +++++- 6 files changed, 68 insertions(+), 9 deletions(-) diff --git a/changelog.d/security-issue-decision-option-text.md b/changelog.d/security-issue-decision-option-text.md index 06e300b744..e7534b6eef 100644 --- a/changelog.d/security-issue-decision-option-text.md +++ b/changelog.d/security-issue-decision-option-text.md @@ -1 +1 @@ -- Delegated issue decisions record reporter-authored option text only by option label: when the options come from the body of an issue a non-hive account filed, the owner-attributed `/hive decision go with option N` no longer quotes the reporter's summary, while options from hive-authored text keep their summary (#16937). +- Delegated issue decisions record reporter-authored option text only by option label: when the options come from the body of an issue a non-hive account filed, the owner-attributed `/hive decision go with option N` no longer quotes the reporter's summary, while the "Let hive decide" preview still shows that summary as a quoted excerpt of the issue's words; options from hive-authored text keep their summary (#16937). diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_options_test.go b/src/pkg/dashboard/api_repo_item_decide_delegated_options_test.go index 465c8b19f5..75425274c0 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_options_test.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_options_test.go @@ -43,6 +43,25 @@ func TestDelegatedPlanWordingNamesTheOptionOrLeavesTheChoice(t *testing.T) { t.Errorf("an issue with options must never read as a bare direction: %q", s) } } + + // A reporter-authored option names itself by label alone in the recorded + // decision, but the preview still shows the owner what they approve: the + // issue's own words, quoted, on one line. + reporter := delegatedecision.Option{Label: "2", Summary: "A ujust\n recipe.", Untrusted: true} + summary, next = delegatedPlanWording(in, delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove, Rule: delegatedecision.RuleRecommendedOption, Option: &reporter}) + if want := "Go with option 2 (the issue's words: “A ujust recipe”) — the option #920 recommends — and let the hive build it."; summary != want { + t.Errorf("untrusted approve summary %q, want %q", summary, want) + } + if reporter.Name() != "option 2" { + t.Errorf("untrusted Name() = %q, want the label alone", reporter.Name()) + } + if strings.Join(next, "|") != "Hive records option 2 as the decision and removes the needs-decision hold.|An agent claims #920 on the next cycle and builds option 2." { + t.Errorf("untrusted approve consequences %q", next) + } + empty := delegatedecision.Option{Label: "2", Untrusted: true} + if got, _ := delegatedPlanWording(in, delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove, Rule: delegatedecision.RuleRecommendedOption, Option: &empty}); !strings.HasPrefix(got, "Go with option 2 — ") { + t.Errorf("empty untrusted summary must add no quote: %q", got) + } } func TestDelegatedDecisionPlanForAnIssueWithOptions(t *testing.T) { diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go index 4b289494cc..dd8b85553a 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_plan.go @@ -304,6 +304,23 @@ func (s *Server) planDelegatedDecision(ctx context.Context, repoFull string, num return plan, nil } +// delegatedPlanOptionName names the chosen option for the plan sentence. +// A reporter-authored option (Option.Untrusted) names itself by label alone +// in the recorded decision, but the owner still needs to see what they are +// approving: its summary is shown as a quoted, one-line preview of the +// issue's own words, never as hive's description of the option. +func delegatedPlanOptionName(o delegatedecision.Option) string { + name := strings.TrimSuffix(o.Name(), ".") + if !o.Untrusted { + return name + } + s := strings.TrimSuffix(strings.Join(strings.Fields(o.Summary), " "), ".") + if s == "" { + return name + } + return name + " (the issue's words: “" + s + "”)" +} + // delegatedPlanWording is the one decision sentence and the (at most // two) "then" items for the decision the hive would record. Operator // feedback on the preview (hivecommons/hive#15332's dialog: "this needs @@ -340,7 +357,7 @@ func delegatedPlanWording(in delegatedecision.Input, d delegatedecision.Decision // The issue offered a choice: the plan names the option, so // approving never leaves the pick to the claiming agent // (projectbluefin/utah#920). - return "Go with " + strings.TrimSuffix(d.Option.Name(), ".") + " — the option " + ref + " recommends — and let the hive build it.", + return "Go with " + delegatedPlanOptionName(*d.Option) + " — the option " + ref + " recommends — and let the hive build it.", []string{"Hive records option " + d.Option.Label + " as the decision and removes the needs-decision hold.", "An agent claims " + ref + " on the next cycle and builds option " + d.Option.Label + "."} case d.Verdict == delegatedecision.VerdictApprove && in.Kind == delegatedecision.KindIssue: // An issue has no commit to approve and nothing to merge diff --git a/src/pkg/github/issue_decision_options.go b/src/pkg/github/issue_decision_options.go index a765b2212d..a69aeb6145 100644 --- a/src/pkg/github/issue_decision_options.go +++ b/src/pkg/github/issue_decision_options.go @@ -23,7 +23,7 @@ func (c *Client) IssueDecisionOptions(issueBody string, issueAuthor *gh.User, co bodyUntrusted := !c.isHiveAccount(issueAuthor) if len(m.options) >= 2 { for _, l := range m.options { - options = append(options, delegatedecision.Option{Label: l, Summary: m.optionText[l], Untrusted: bodyUntrusted && m.optionSource == ""}) + options = append(options, delegatedecision.Option{Label: l, Summary: m.optionText[l], Untrusted: bodyUntrusted && m.optionsFromBody}) } return options, m.recommended } diff --git a/src/pkg/github/issue_decision_options_test.go b/src/pkg/github/issue_decision_options_test.go index ae595e6c27..a9d53087b6 100644 --- a/src/pkg/github/issue_decision_options_test.go +++ b/src/pkg/github/issue_decision_options_test.go @@ -160,11 +160,28 @@ func TestIssueDecisionOptionsMarkReporterBodyUntrusted(t *testing.T) { } } - // A hive comment's options are the hive's own text, whoever filed the issue. - opts, _ := c.IssueDecisionOptions("Ship the debugging tools.", person, []*gh.IssueComment{ghComment("hive[bot]", utah920Park)}) - for _, o := range opts { - if o.Untrusted { - t.Errorf("hive comment option %+v marked untrusted", o) + // A hive comment's options are the hive's own text, whoever filed the + // issue — numbered or lettered, and whether or not the comment was read + // with its html_url (provenance is not inferred from optionSource). + for _, park := range []string{utah920Park, dakotaStyleOptions} { + opts, _ := c.IssueDecisionOptions("Ship the debugging tools.", person, []*gh.IssueComment{ghComment("hive[bot]", park)}) + if len(opts) < 2 { + t.Fatalf("no options read from hive comment %q", park) } + for _, o := range opts { + if o.Untrusted { + t.Errorf("hive comment option %+v marked untrusted", o) + } + if o.Summary == "" { + t.Errorf("hive comment option %+v lost its summary", o) + } + } + } + + // A hive comment's lettered options replace the reporter's body options + // and are trusted. + opts, _ := c.IssueDecisionOptions(dakotaStyleOptions, person, []*gh.IssueComment{ghComment("hive[bot]", "- **A.** hive a\n- **B.** hive b\n")}) + if len(opts) != 2 || opts[0].Summary != "hive a" || opts[0].Untrusted || opts[1].Untrusted { + t.Errorf("hive comment did not replace reporter body options as trusted: %+v", opts) } } diff --git a/src/pkg/github/issue_unpark_menu.go b/src/pkg/github/issue_unpark_menu.go index 3eccd492b9..76edcd0ec7 100644 --- a/src/pkg/github/issue_unpark_menu.go +++ b/src/pkg/github/issue_unpark_menu.go @@ -39,6 +39,10 @@ type unparkMenu struct { // optionSource is the html_url of the hive comment the options came // from; "" when they came from the issue body. optionSource string + // optionsFromBody is true when options came from the issue body rather + // than a hive comment. It is the provenance signal, not optionSource: + // a comment read without its html_url still carries hive-authored text. + optionsFromBody bool // recommended is the option the text recommends, or "" when none is named. recommended string // hasRecommendation is true when the issue states a recommendation. @@ -61,6 +65,7 @@ type unparkMenu struct { // marker in its body; it is an owner step when it lists no options. func unparkMenuFromBody(issueBody string) unparkMenu { m := unparkMenu{options: unparkOptionLabels(issueBody), optionText: unparkOptionTexts(issueBody)} + m.optionsFromBody = len(m.options) > 0 m.hasRecommendation = unparkMentionsRecommendation(issueBody) if m.hasRecommendation { m.recommended = unparkRecommendedOption(issueBody, m.options) @@ -129,7 +134,7 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments // go with it, so a later park starts from its own text. ownerStep = false m.releaseStep = nil - m.options, m.optionText, m.optionSource = nil, nil, "" + m.options, m.optionText, m.optionSource, m.optionsFromBody = nil, nil, "", false m.hasRecommendation, recommendationSource = false, "" continue } @@ -155,6 +160,7 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments m.options = opts m.optionText = unparkOptionTexts(body) m.optionSource = cm.GetHTMLURL() + m.optionsFromBody = false } if unparkMentionsRecommendation(body) { m.hasRecommendation, recommendationSource = true, body