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-owner-step-menu-recommends-done.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix the "What to reply" notice on a re-parked owner step recommending `/hive approve` again after an accepted `/hive approve` did not do the step, which looped: it now recommends `/hive done` when the owner step asks for it or approve already answered that step, drops `/hive approve` on such a step, and a second `/hive approve` there gets a reply pointing at `/hive done`. Lane policies now ask for `-R <owner/repo>` on every `gh` command handed to the owner (Danathar/goodreads-mcp#443).
9 changes: 9 additions & 0 deletions src/docs/maintainer-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ recommendation; the issue stays parked. On a `blocked` park and on an owner
step `/hive approve` keeps its meaning (the blocker is cleared; accept the
proposed step) and needs no recommendation.

On an owner step, `/hive done` is the recommended reply when the owner-step
text asks for it, or when an accepted `/hive approve` already answered the
same step and an agent parked the issue again (approving cannot do a step only
the owner can take). A step parked again after an accepted reply is read from
its own text: the options and recommendation that reply answered do not carry
over. On a step `/hive approve` already answered, the notice drops
`/hive approve`, and a second `/hive approve` gets a reply pointing at
`/hive done`; the issue stays parked (Danathar/goodreads-mcp#443).

The notice is always the newest comment on a parked issue. While nothing newer
is posted it is edited in place when the options change; once a later comment
pushes it up the thread (an agent's new owner step, a question, a re-check
Expand Down
56 changes: 44 additions & 12 deletions src/pkg/github/issue_unpark_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,17 @@ func (c *Client) tryUnparkIssue(ctx context.Context, displayRepo, owner, repo st
// Approve needs no recommendation on a `blocked` park, where it means
// "the blocker is cleared" (hivecommons/hive#12376), or on an owner
// step, where it accepts the step the hive proposed.
// An owner step an accepted `/hive approve` already answered, parked
// again, is not answered by a second approve: it would un-park the
// issue only for the agent to park it once more.
if command.Kind == unparkCommandApprove && !(releasePolicy.enabled && menu.releaseStep != nil) && (!labelDriven || la.enabled) &&
menu.ownerStep && menu.approveAnswered {
if err := c.postUnparkReply(ctx, owner, repo, number, candidate.GetID(), unparkApproveAnsweredReply); err != nil {
return false, err
}
result.Replies++
return true, nil
}
if command.Kind == unparkCommandApprove && !(releasePolicy.enabled && menu.releaseStep != nil) && (!labelDriven || la.enabled) &&
!menu.ownerStep && menu.releaseStep == nil && !unparkTextsProposeOwnerStep(issue, comments) && !labelPresent(issueLabelNames(issue.Labels), issueBlockedLabel) {
decision, ok := menu.approveDecision()
Expand Down Expand Up @@ -1143,24 +1154,45 @@ func (c *Client) answeredUnparkCommentIDs(comments []*gh.IssueComment) map[int64
if cm == nil || !c.markerAuthorTrusted(cm.GetUser()) {
continue
}
body := cm.GetBody()
idx := strings.Index(body, unparkReplyMarkerPrefix)
if idx < 0 {
continue
}
rest := body[idx+len(unparkReplyMarkerPrefix):]
end := strings.Index(rest, " ")
if end < 0 {
continue
}
var id int64
if _, err := fmt.Sscanf(rest[:end], "%d", &id); err == nil && id > 0 {
if id := unparkReplyAnsweredID(cm.GetBody()); id > 0 {
answered[id] = true
}
}
return answered
}

// unparkReplyAnsweredID reads the comment ID a hive reply's marker names,
// or 0 when body carries no well-formed reply marker.
func unparkReplyAnsweredID(body string) int64 {
idx := strings.Index(body, unparkReplyMarkerPrefix)
if idx < 0 {
return 0
}
rest := body[idx+len(unparkReplyMarkerPrefix):]
end := strings.Index(rest, " ")
if end < 0 {
return 0
}
var id int64
if _, err := fmt.Sscanf(rest[:end], "%d", &id); err != nil || id <= 0 {
return 0
}
return id
}

// unparkReplyAnswersApprove reports whether the hive reply body answers a
// `/hive approve` command: the comment its marker names, read from byID,
// carries one. A reply whose command comment is not in byID (deleted, or
// a dashboard release with no marker) does not count.
func (c *Client) unparkReplyAnswersApprove(body string, byID map[int64]*gh.IssueComment) bool {
cm := byID[unparkReplyAnsweredID(body)]
if cm == nil || c.isHiveAccount(cm.GetUser()) {
return false
}
cmd, ok := parseUnparkCommand(cm.GetBody())
return ok && cmd.Kind == unparkCommandApprove
}

// unparkCandidateLimit bounds the permission lookups one issue can cost in a
// single pass. A maintainer's instruction is always among the last few
// comments; anything older has had cycles to be answered already.
Expand Down
89 changes: 81 additions & 8 deletions src/pkg/github/issue_unpark_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ type unparkMenu struct {
// whether `/hive approve` may execute it; without that opt-in it remains
// descriptive metadata and the legacy manual-step menu is unchanged.
releaseStep *IssueOwnerStep
// asksDone is true when the owner-step text itself asks the owner to
// reply `/hive done`; that reply is then the recommended one.
asksDone bool
// approveAnswered is true when an accepted `/hive approve` already
// answered this same owner step and the hive parked it again: approving
// did not do the step, so the menu recommends `/hive done` and offers
// no `/hive approve` (Danathar/goodreads-mcp#443).
approveAnswered bool
}

// doneRecommended reports whether `/hive done` is the recommended reply:
// the issue waits on an owner step that either asks for `/hive done` or
// was already approved once without being done.
func (m unparkMenu) doneRecommended() bool {
return m.ownerStep && (m.asksDone || m.approveAnswered)
}

// unparkAsksDone reports whether park text asks the owner to reply
// `/hive done`.
func unparkAsksDone(text string) bool {
return strings.Contains(strings.ToLower(text), "/hive done")
}

// unparkMenuFromBody reads the menu from the issue body alone. An issue
Expand All @@ -73,6 +94,7 @@ func unparkMenuFromBody(issueBody string) unparkMenu {
m.ownerStep = isUnparkOwnerStepText(issueBody)
if m.ownerStep {
m.releaseStep = parseIssueOwnerStep(issueBody)
m.asksDone = unparkAsksDone(issueBody)
}
return m
}
Expand All @@ -92,18 +114,38 @@ func isUnparkOwnerStepText(text string) bool {
// recommended option is read from the newest text that states a
// recommendation, so a body-level recommendation is never pinned onto
// options a later comment listed.
//
// An owner step the hive parks again after an accepted reply answered the
// earlier ask is read from its own text: the earlier options and
// recommendation were answered, so they do not carry over. When the
// accepted reply was a `/hive approve` on the same owner step, approving did
// not do it, and the menu says so (approveAnswered).
func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments []*gh.IssueComment) unparkMenu {
m := unparkMenuFromBody(issueBody)
if !c.isHiveAccount(issueAuthor) {
// Only a hive-authored body can park the issue on an owner step; the
// author of any other issue could otherwise edit the marker in.
m.ownerStep, m.releaseStep = false, nil
m.ownerStep, m.releaseStep, m.asksDone = false, nil, false
}
recommendationSource := ""
if m.hasRecommendation {
recommendationSource = issueBody
}
ownerStep := m.ownerStep
// pendingStep is the marker of the newest unanswered owner step;
// approvedStep is the marker of the owner step an accepted `/hive
// approve` answered. answered is true from an accepted reply until the
// next owner-step park.
pendingStep, approvedStep, answered := "", "", false
if ownerStep {
pendingStep = ownerStepMarkerRE.FindString(issueBody)
}
byID := make(map[int64]*gh.IssueComment, len(comments))
for _, cm := range comments {
if cm != nil && cm.GetID() != 0 {
byID[cm.GetID()] = cm
}
}
for _, cm := range comments {
if cm == nil || !c.isHiveAccount(cm.GetUser()) {
continue
Expand All @@ -113,8 +155,12 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments
// Accepted command replies and dashboard release replies both
// answer the step. Only command replies carry a per-comment
// unparkReplyMarkerPrefix.
ownerStep = false
if ownerStep && pendingStep != "" && c.unparkReplyAnswersApprove(body, byID) {
approvedStep = pendingStep
}
ownerStep, pendingStep, answered = false, "", true
m.releaseStep = nil
m.asksDone, m.approveAnswered = false, false
m.landedBy = ""
continue
}
Expand All @@ -132,8 +178,9 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments
if strings.Contains(body, parkWithdrawnMarkerPrefix) {
// The agent took its ask back: its options and recommendation
// go with it, so a later park starts from its own text.
ownerStep = false
ownerStep, pendingStep = false, ""
m.releaseStep = nil
m.asksDone, m.approveAnswered = false, false
m.options, m.optionText, m.optionSource, m.optionsFromBody = nil, nil, "", false
m.hasRecommendation, recommendationSource = false, ""
continue
Expand All @@ -152,9 +199,20 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments
if hasOwnerStepMarker(body) {
ownerStep = isUnparkOwnerStepText(body)
m.releaseStep = nil
m.asksDone, m.approveAnswered, pendingStep = false, false, ""
if ownerStep {
m.releaseStep = parseIssueOwnerStep(body)
pendingStep = ownerStepMarkerRE.FindString(body)
m.asksDone = unparkAsksDone(body)
m.approveAnswered = approvedStep != "" && pendingStep == approvedStep
if answered {
// A re-park after an answered ask: what was answered
// does not carry over to the new step.
m.options, m.optionText, m.optionSource, m.optionsFromBody = nil, nil, "", false
m.hasRecommendation, recommendationSource = false, ""
}
}
answered = false
}
if opts := unparkOptionLabels(body); len(opts) > 0 {
m.options = opts
Expand Down Expand Up @@ -214,15 +272,24 @@ func (m unparkMenu) replies(releaseOnApprove bool) []unparkReply {
if m.landedBy != "" {
out = append(out, unparkReply{command: "/fixed", does: "the change this issue asks for already landed in " + m.landedBy + "; close it as completed", recommended: true})
}
doneFirst := m.doneRecommended()
if m.ownerStep {
add("/hive done", "you did the step only you can do; Hive re-checks it and closes the issue once it is verified", false)
add("/hive done", "you did the step only you can do; Hive re-checks it and closes the issue once it is verified", doneFirst)
}
// addApprove offers `/hive approve`; it is never the recommended reply
// when `/hive done` is.
addApprove := func(does string, recommended bool) {
add("/hive approve", does, recommended && !doneFirst)
}
switch {
case releaseOnApprove && m.releaseStep != nil:
add("/hive approve", fmt.Sprintf("Hive creates release `%s` from `%s`", m.releaseStep.Tag, m.releaseStep.Target), false)
add("/hive decision <your instructions>", "go ahead, following your instructions", false)
case m.ownerStep && m.approveAnswered:
// `/hive approve` already answered this step and did not do it.
add("/hive decision <your instructions>", "go ahead, following your instructions", false)
case len(m.options) > 0 && m.recommended != "":
add("/hive approve", "go with the recommendation (option "+m.recommended+")"+m.summaryFor(m.recommended), true)
addApprove("go with the recommendation (option "+m.recommended+")"+m.summaryFor(m.recommended), true)
for _, opt := range m.options {
if opt == m.recommended {
continue
Expand All @@ -233,18 +300,18 @@ func (m unparkMenu) replies(releaseOnApprove bool) []unparkReply {
// A recommendation is stated but names none of the listed options,
// so no option is attributed to it; every option stays an explicit
// decision.
add("/hive approve", "go with the recommendation", true)
addApprove("go with the recommendation", true)
for _, opt := range m.options {
add("/hive decision "+opt, "go with option "+opt+m.summaryFor(opt), false)
}
case len(m.options) > 0:
first := m.options[0]
add("/hive approve", "go with option "+first+m.summaryFor(first), false)
addApprove("go with option "+first+m.summaryFor(first), false)
for _, opt := range m.options[1:] {
add("/hive decision "+opt, "go with option "+opt+m.summaryFor(opt), false)
}
case m.hasRecommendation:
add("/hive approve", "go with the recommendation", true)
addApprove("go with the recommendation", true)
add("/hive decision <your instructions>", "go ahead, following your instructions", false)
default:
add("/hive decision <your instructions>", "go ahead, following your instructions", false)
Expand Down Expand Up @@ -298,6 +365,12 @@ func (m unparkMenu) approveDecision() (string, bool) {
return "", false
}

// unparkApproveAnsweredReply answers `/hive approve` on an owner step an
// earlier `/hive approve` already answered: the hive parked it again because
// approving does not do a step only the owner can take, so a second approve
// would only repeat the loop (Danathar/goodreads-mcp#443).
const unparkApproveAnsweredReply = "`/hive approve` was already accepted for this step, and the hive parked the issue again because approving does not do a step only you can take. The issue stays parked. Do the step the newest park comment names, then reply `/hive done`; or reply `/hive decision <your instructions>` to un-park it with your own instructions, or `/hive help` for the commands."

// unparkApproveNothingReply answers `/hive approve` on a park with no
// recommendation and no options; the park stays.
const unparkApproveNothingReply = "`/hive approve` accepts the recommendation a park names, and this one names none: neither the issue nor the hive's comments on it recommend an option. The issue stays parked. Reply `/hive decision <your instructions>` to un-park it with your own instructions, or `/hive help` for the commands."
Expand Down
7 changes: 4 additions & 3 deletions src/pkg/github/issue_unpark_notice_last_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func TestUnparkNoticeMovesBelowAgentOwnerStep(t *testing.T) {
if len(posted) != 1 {
t.Fatalf("want one fresh notice below the owner step, got %v", rec.posted[12])
}
if !strings.Contains(posted[0], "> - `/hive done` β†’") {
t.Fatalf("the fresh notice should offer the owner step's /hive done, got %q", posted[0])
// The owner step asks for `/hive done`, so that is the recommended reply.
if !strings.Contains(posted[0], "> - **`/hive done` β†’") || strings.Contains(posted[0], "**`/hive approve`") {
t.Fatalf("the fresh notice should recommend the owner step's /hive done, got %q", posted[0])
}
if len(rec.deleted) != 1 || rec.deleted[0] != 61 {
t.Fatalf("the buried notice should be deleted, got %v", rec.deleted)
Expand Down Expand Up @@ -131,7 +132,7 @@ func TestUnparkNoticeMoveHonoursWritebackGate(t *testing.T) {
if len(rec.posted[18]) != 0 || len(rec.deleted) != 0 {
t.Fatalf("a refused gate must not move the notice: posted=%v deleted=%v", rec.posted[18], rec.deleted)
}
if body, ok := rec.edited[72]; !ok || !strings.Contains(body, "> - `/hive done` β†’") {
if body, ok := rec.edited[72]; !ok || !strings.Contains(body, "> - **`/hive done` β†’") {
t.Fatalf("the buried notice should still be edited in place, got %v", rec.edited)
}
}
Expand Down
Loading
Loading