From 180c1d0f8f57adc39edaef1c1d2632dae2b27496 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:59:02 -0500 Subject: [PATCH 1/2] fix(controller): keep approved-direction after a human decision when the remainder is human-only Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com> --- changelog.d/fixed-16579.md | 1 + src/docs/maintainer-commands.md | 2 +- src/pkg/stageengine/derive_issue.go | 30 +++++++++--- src/pkg/stageengine/derive_issue_test.go | 59 ++++++++++++++++++++++-- src/pkg/stageengine/facts.go | 8 ++-- 5 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 changelog.d/fixed-16579.md diff --git a/changelog.d/fixed-16579.md b/changelog.d/fixed-16579.md new file mode 100644 index 0000000000..cefe4193cb --- /dev/null +++ b/changelog.d/fixed-16579.md @@ -0,0 +1 @@ +- Stage controller: an issue a maintainer already decided (`approved-direction`) whose remaining work is human-only (`needs-human`) is no longer re-parked on `stage/045-needs-decision` with the ack stripped; it keeps `approved-direction` and is held out of the pipeline, ending the decide → re-park bounce loop ([#16579](https://github.com/hivecommons/hive/issues/16579)). diff --git a/src/docs/maintainer-commands.md b/src/docs/maintainer-commands.md index 97053867d0..aa980f8394 100644 --- a/src/docs/maintainer-commands.md +++ b/src/docs/maintainer-commands.md @@ -15,7 +15,7 @@ https://github.com/hivecommons/hive/blob/v5/src/docs/maintainer-commands.md | Command | What it does | Who may use it | Where it works | Pickup speed | Labels changed | | --- | --- | --- | --- | --- | --- | | `/hive approve` | Accepts the recommendation already written on a parked issue. | Human commenter with `write`, `maintain`, or `admin` repository permission. | Open issues carrying `needs-human` or `stage/045-needs-decision` (or the retired `needs-decision` / `needs-direction` / a pre-045 `stage/085-needs-decision`, until migrated). On an open pull request the command gets one acknowledgement or explanation reply and changes no labels (see [PR approval command feedback](#pr-approval-command-feedback)). | Next un-park sweep, normally within 5 minutes. | Removes `stage/045-needs-decision` (and the retired spellings) when present; adds `approved-direction`; removes `needs-human` **whoever added it** — your approval is the human input the label asked for ([#13075](https://github.com/hivecommons/hive/issues/13075), [docs#419](https://github.com/hivecommons/docs/issues/419)); the reply names who had added it. Never removes `hold`: add `hold` to keep agents off an issue through a decision. | -| `/hive decision ` | Gives explicit direction for a parked issue. | Human commenter with `write`, `maintain`, or `admin` repository permission. | Open issues carrying `needs-human` or `stage/045-needs-decision` (or the retired `needs-decision` / `needs-direction` / a pre-045 `stage/085-needs-decision`, until migrated); pull requests are ignored. | Next un-park sweep, normally within 5 minutes. | Removes `stage/045-needs-decision` (and the retired spellings) when present; adds `approved-direction`; removes `needs-human` **whoever added it** — your decision is the human input the label asked for, and left in place it would re-derive 045 two minutes later ([#13075](https://github.com/hivecommons/hive/issues/13075), [docs#419](https://github.com/hivecommons/docs/issues/419)); the reply names who had added it. Never removes `hold`: add `hold` to keep agents off an issue through a decision. An agent's later re-park on 085 is refused while `approved-direction` is present and the recorded decision text is unchanged. | +| `/hive decision ` | Gives explicit direction for a parked issue. | Human commenter with `write`, `maintain`, or `admin` repository permission. | Open issues carrying `needs-human` or `stage/045-needs-decision` (or the retired `needs-decision` / `needs-direction` / a pre-045 `stage/085-needs-decision`, until migrated); pull requests are ignored. | Next un-park sweep, normally within 5 minutes. | Removes `stage/045-needs-decision` (and the retired spellings) when present; adds `approved-direction`; removes `needs-human` **whoever added it** — your decision is the human input the label asked for, and left in place it would re-derive 045 two minutes later ([#13075](https://github.com/hivecommons/hive/issues/13075), [docs#419](https://github.com/hivecommons/docs/issues/419)); the reply names who had added it. Never removes `hold`: add `hold` to keep agents off an issue through a decision. An agent's later re-park on 085 is refused while `approved-direction` is present and the recorded decision text is unchanged; an agent's later `needs-human` (the remaining work is human-only) keeps `approved-direction` and holds the issue out of the pipeline instead of re-deriving `stage/045-needs-decision` ([#16579](https://github.com/hivecommons/hive/issues/16579)). | | `/hive decision proceed — ` | Confirms a feature request parked by the prior-art gate is a real gap. | The issue author, or a human commenter with `write`, `maintain`, or `admin`. | Open issues carrying `stage/017-possible-existing` below a `` comment. | Next un-park sweep. | Removes `stage/017-possible-existing`, appends a **Scope vs existing** section with `` to the issue body, records the un-park so the issue re-derives `stage/010-actionable` ([#13575](https://github.com/hivecommons/hive/issues/13575)). | | `/hive decision exists` | Agrees the request already exists. | Same as above. | Same as above. | Next un-park sweep. | Adds `already-exists`, closes the issue `not_planned`, replies with a pointer at the quoted findings. Reopen the issue to continue; the gate does not ask again. | | `/hive help` | Posts this command list. On parked issues it also repeats the issue-specific approve/decision options. | Any human commenter with at least `triage` repository permission for the on-demand workflow; the sweep path on parked issues requires `write`, `maintain`, or `admin`. | Any open issue or pull request. | GitHub Actions on the new comment; if Actions is unavailable on a parked issue, the next un-park sweep can also answer. | None. | diff --git a/src/pkg/stageengine/derive_issue.go b/src/pkg/stageengine/derive_issue.go index bd596cc4ba..2a67d7b993 100644 --- a/src/pkg/stageengine/derive_issue.go +++ b/src/pkg/stageengine/derive_issue.go @@ -26,6 +26,10 @@ const ( // reasonIssueOpenPRPartial is 040 under a PR that references the issue // without closing it (ClaimFact.Partial); ReasonIsPartialCover reads it. reasonIssueOpenPRPartial = "open PR addresses part of it (references it without a closing keyword)" + // reasonIssueDecidedHumanWork prefixes the reason of an issue whose + // direction a person already gave and whose remainder is held for a + // person (hivecommons/hive#16579). + reasonIssueDecidedHumanWork = "decided; remaining work held for a person: " ) // ReasonIsPartialCover reports whether a 040 reason describes a PR that @@ -94,13 +98,12 @@ func deriveIssue(f Facts) Decision { } } -// issueParkClear reconciles `needs-human` against `approved-direction`, -// which cannot both stand (hivecommons/hive#15099). The un-park that -// applies the ack removes `needs-human` in the same write, so a -// `needs-human` found next to the ack was applied after it — the later -// signal (DecisionLiftsNeedsHuman's own rule), whether an agent parked the -// issue on a blocker or a person asked again. The ack is the stale one: -// the issue stays 045 and the writer clears `approved-direction`. +// issueParkClear reconciles `needs-human` against `approved-direction` on +// an issue parked at 045 (hivecommons/hive#15099). That happens only for a +// structured blocker — no decision grants the App a permission, so the ack +// is the stale one and the writer clears it. A plain `needs-human` next to +// the ack derives out of the pipeline instead and keeps the ack +// (hivecommons/hive#16579), so nothing is cleared for it. func issueParkClear(f Facts, stage stagelabels.Stage) []string { is := f.Issue label := strings.TrimSpace(is.ApprovedDirectionLabel) @@ -161,6 +164,19 @@ func issueStage(f Facts) (stage stagelabels.Stage, covered bool, reason string) } return stagelabels.IssueNeedsDecision, false, "blocked: " + short } + // A decision is already recorded (`approved-direction`): a + // `needs-human` next to it is the agent standing down on work only + // a person can do (a cluster rollout, a backup, an out-of-repo + // step) — what the re-park refusal tells agents to do — not a new + // question. Re-deriving 045 stripped the ack and re-opened the + // decision inbox on every scanner pass, and the un-park sweep + // re-applied the same old decision: a bounce loop + // (hivecommons/hive#16579, seen on hivecommons/dibs#567). The + // issue is held out of the pipeline like a hold and keeps the ack; + // a person who wants to decide again removes `approved-direction`. + if strings.TrimSpace(is.ApprovedDirectionLabel) != "" { + return stagelabels.None, false, reasonIssueDecidedHumanWork + is.NeedsHumanLabel + } return stagelabels.IssueNeedsDecision, false, "held for a person: " + is.NeedsHumanLabel } // The prior-art gate's park is its own stage, 017, not 045: nothing is diff --git a/src/pkg/stageengine/derive_issue_test.go b/src/pkg/stageengine/derive_issue_test.go index ca41d03da3..ce6744a21a 100644 --- a/src/pkg/stageengine/derive_issue_test.go +++ b/src/pkg/stageengine/derive_issue_test.go @@ -134,9 +134,10 @@ func TestDeriveIssueFlags(t *testing.T) { } // hivecommons/hive#15099: `needs-human` with a structured blocker stays -// 045 and names the blocker. `approved-direction` next to `needs-human` -// is the stale label either way (the un-park that applies the ack removes -// the park label, so a surviving park label came later) and is cleared. +// 045 and names the blocker, and `approved-direction` next to it is the +// stale label and is cleared. A plain `needs-human` next to the ack is the +// agent standing down on human-only work after a decision and stays out of +// 045 with the ack kept (hivecommons/hive#16579). func TestDeriveIssueBlockerAndApprovedDirection(t *testing.T) { blocked := func(f *Facts) { f.Issue.Bucket = BucketFiltered @@ -160,8 +161,8 @@ func TestDeriveIssueBlockerAndApprovedDirection(t *testing.T) { f.Park.NeedsHuman = true f.Issue.ApprovedDirectionLabel = "approved-direction" })) - if d.Stage != stagelabels.IssueNeedsDecision || d.Reason != "held for a person: needs-human" || len(d.Clear) != 1 || d.Clear[0] != "approved-direction" { - t.Fatalf("a later needs-human outranks the ack: %+v", d) + if d.Stage != stagelabels.None || d.Reason != "decided; remaining work held for a person: needs-human" || len(d.Clear) != 0 { + t.Fatalf("a plain needs-human after a decision keeps the ack out of 045 (#16579): %+v", d) } d = DeriveIssue(derivedIssueFacts(func(f *Facts) { blocked(f); f.Issue.BlockerShort = "" })) if d.Reason != "blocked: capability:workflows-permission" { @@ -177,3 +178,51 @@ func TestDeriveIssueBlockerAndApprovedDirection(t *testing.T) { t.Fatalf("held: %+v", d) } } + +// hivecommons/hive#16579 (seen on hivecommons/dibs#567): parked → +// `/hive decision` → `approved-direction` + 010 → a later scanner pass +// finds the remaining checklist human-only and adds `needs-human`. That +// evaluation must neither re-derive 045 nor strip the ack — doing so put +// the decision back in the inbox and the un-park sweep re-applied the same +// decision, bouncing the issue every pass. +func TestDeriveIssueDecisionSticksOverHumanOnlyRemainder(t *testing.T) { + steps := []struct { + name string + mutate func(f *Facts) + wantStage stagelabels.Stage + }{ + {"agent parks", func(f *Facts) { + f.Issue.Bucket = BucketFiltered + f.Park.NeedsHuman = true + }, stagelabels.IssueNeedsDecision}, + {"maintainer decides", func(f *Facts) { + f.Park.ApprovedDirection = true + f.Issue.ApprovedDirectionLabel = "approved-direction" + }, stagelabels.Actionable}, + {"remainder is human-only", func(f *Facts) { + f.Issue.Bucket = BucketFiltered + f.Park.NeedsHuman = true + f.Issue.ApprovedDirectionLabel = "approved-direction" + }, stagelabels.None}, + {"next pass re-evaluates", func(f *Facts) { + f.Issue.Bucket = BucketFiltered + f.Park.NeedsHuman = true + f.Issue.ApprovedDirectionLabel = "approved-direction" + f.Issue.Stalled = true + }, stagelabels.None}, + } + for _, tc := range steps { + d := DeriveIssue(derivedIssueFacts(tc.mutate)) + if d.Stage != tc.wantStage { + t.Fatalf("%s: stage = %v, want %v (%+v)", tc.name, d.Stage, tc.wantStage, d) + } + for _, c := range d.Clear { + if c == "approved-direction" { + t.Fatalf("%s: stripped approved-direction: %+v", tc.name, d) + } + } + if d.Terminal { + t.Fatalf("%s: an open decided issue is not terminal: %+v", tc.name, d) + } + } +} diff --git a/src/pkg/stageengine/facts.go b/src/pkg/stageengine/facts.go index e6802c83d5..93a2ced676 100644 --- a/src/pkg/stageengine/facts.go +++ b/src/pkg/stageengine/facts.go @@ -162,9 +162,11 @@ type IssueFacts struct { BlockerShort string // ApprovedDirectionLabel is the `approved-direction` label the issue // wears (a recorded /hive approve|decision), "" when absent. Next to - // `needs-human` it is the stale one — the un-park that applied it - // removed the park label, so a surviving `needs-human` came later — - // and the writer clears it (hivecommons/hive#15099). + // `needs-human` and a structured Blocker it is the stale one and the + // writer clears it (hivecommons/hive#15099); next to a plain + // `needs-human` the decision stands and the remainder is held for a + // person out of the pipeline, not re-parked at 045 + // (hivecommons/hive#16579). ApprovedDirectionLabel string // UmbrellaLabel is the never-claim label the issue carries // (governor.claims.never_claim_labels, default `epic`). From ccc21c45546188b52077f7134c0c867c328e7b14 Mon Sep 17 00:00:00 2001 From: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:22:03 -0500 Subject: [PATCH 2/2] fix(controller): keep the newer-decision re-park reachable after the human-only stand-down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 16579 derive rule returned no stage for every `needs-human` next to `approved-direction`, so a park the label relay let through because a newer, different `/hive decision` was pending never landed on 045 (TestIssueRequestWatcher_LabelRefusesReparkOnRecordedDecision/new_decision_pending). Carry that as an engine fact: ParkFacts.DecisionSuperseded, submitted by FactSink.ReparkedOnNewDecision when reparkDecisionRefusal reports the park allowed on a superseding decision. With it set the ack is stale again — the issue re-parks at 045 and the writer clears `approved-direction`; without it the stand-down from 16579 holds. 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> --- changelog.d/fixed-16579.md | 2 +- src/docs/maintainer-commands.md | 2 +- src/pkg/github/issue_request_label.go | 23 +++++++++------ src/pkg/github/issue_request_label_test.go | 16 ++++++++--- src/pkg/github/issue_request_watcher.go | 14 +++++++--- src/pkg/stageengine/derive_issue.go | 20 ++++++++----- src/pkg/stageengine/derive_issue_test.go | 12 ++++++++ src/pkg/stageengine/facts.go | 11 +++++++- src/pkg/stageengine/facts_sink.go | 31 +++++++++++++++++---- src/pkg/stageengine/facts_sink_test.go | 7 ++++- src/pkg/stageengine/stageenginetest/fake.go | 5 +++- 11 files changed, 109 insertions(+), 34 deletions(-) diff --git a/changelog.d/fixed-16579.md b/changelog.d/fixed-16579.md index cefe4193cb..05a0773154 100644 --- a/changelog.d/fixed-16579.md +++ b/changelog.d/fixed-16579.md @@ -1 +1 @@ -- Stage controller: an issue a maintainer already decided (`approved-direction`) whose remaining work is human-only (`needs-human`) is no longer re-parked on `stage/045-needs-decision` with the ack stripped; it keeps `approved-direction` and is held out of the pipeline, ending the decide → re-park bounce loop ([#16579](https://github.com/hivecommons/hive/issues/16579)). +- Stage controller: an issue a maintainer already decided (`approved-direction`) whose remaining work is human-only (`needs-human`) is no longer re-parked on `stage/045-needs-decision` with the ack stripped; it keeps `approved-direction` and is held out of the pipeline, ending the decide → re-park bounce loop; a newer, different `/hive decision` still lets an agent's park through and clears the stale ack ([#16579](https://github.com/hivecommons/hive/issues/16579)). diff --git a/src/docs/maintainer-commands.md b/src/docs/maintainer-commands.md index aa980f8394..251108f7a8 100644 --- a/src/docs/maintainer-commands.md +++ b/src/docs/maintainer-commands.md @@ -15,7 +15,7 @@ https://github.com/hivecommons/hive/blob/v5/src/docs/maintainer-commands.md | Command | What it does | Who may use it | Where it works | Pickup speed | Labels changed | | --- | --- | --- | --- | --- | --- | | `/hive approve` | Accepts the recommendation already written on a parked issue. | Human commenter with `write`, `maintain`, or `admin` repository permission. | Open issues carrying `needs-human` or `stage/045-needs-decision` (or the retired `needs-decision` / `needs-direction` / a pre-045 `stage/085-needs-decision`, until migrated). On an open pull request the command gets one acknowledgement or explanation reply and changes no labels (see [PR approval command feedback](#pr-approval-command-feedback)). | Next un-park sweep, normally within 5 minutes. | Removes `stage/045-needs-decision` (and the retired spellings) when present; adds `approved-direction`; removes `needs-human` **whoever added it** — your approval is the human input the label asked for ([#13075](https://github.com/hivecommons/hive/issues/13075), [docs#419](https://github.com/hivecommons/docs/issues/419)); the reply names who had added it. Never removes `hold`: add `hold` to keep agents off an issue through a decision. | -| `/hive decision ` | Gives explicit direction for a parked issue. | Human commenter with `write`, `maintain`, or `admin` repository permission. | Open issues carrying `needs-human` or `stage/045-needs-decision` (or the retired `needs-decision` / `needs-direction` / a pre-045 `stage/085-needs-decision`, until migrated); pull requests are ignored. | Next un-park sweep, normally within 5 minutes. | Removes `stage/045-needs-decision` (and the retired spellings) when present; adds `approved-direction`; removes `needs-human` **whoever added it** — your decision is the human input the label asked for, and left in place it would re-derive 045 two minutes later ([#13075](https://github.com/hivecommons/hive/issues/13075), [docs#419](https://github.com/hivecommons/docs/issues/419)); the reply names who had added it. Never removes `hold`: add `hold` to keep agents off an issue through a decision. An agent's later re-park on 085 is refused while `approved-direction` is present and the recorded decision text is unchanged; an agent's later `needs-human` (the remaining work is human-only) keeps `approved-direction` and holds the issue out of the pipeline instead of re-deriving `stage/045-needs-decision` ([#16579](https://github.com/hivecommons/hive/issues/16579)). | +| `/hive decision ` | Gives explicit direction for a parked issue. | Human commenter with `write`, `maintain`, or `admin` repository permission. | Open issues carrying `needs-human` or `stage/045-needs-decision` (or the retired `needs-decision` / `needs-direction` / a pre-045 `stage/085-needs-decision`, until migrated); pull requests are ignored. | Next un-park sweep, normally within 5 minutes. | Removes `stage/045-needs-decision` (and the retired spellings) when present; adds `approved-direction`; removes `needs-human` **whoever added it** — your decision is the human input the label asked for, and left in place it would re-derive 045 two minutes later ([#13075](https://github.com/hivecommons/hive/issues/13075), [docs#419](https://github.com/hivecommons/docs/issues/419)); the reply names who had added it. Never removes `hold`: add `hold` to keep agents off an issue through a decision. An agent's later re-park on 085 is refused while `approved-direction` is present and the recorded decision text is unchanged; an agent's later `needs-human` (the remaining work is human-only) keeps `approved-direction` and holds the issue out of the pipeline instead of re-deriving `stage/045-needs-decision` ([#16579](https://github.com/hivecommons/hive/issues/16579)). A newer `/hive decision` with different text means direction is changing: an agent's park goes through, the stale `approved-direction` is cleared, and the issue waits at `stage/045-needs-decision` until the sweep applies the new decision. | | `/hive decision proceed — ` | Confirms a feature request parked by the prior-art gate is a real gap. | The issue author, or a human commenter with `write`, `maintain`, or `admin`. | Open issues carrying `stage/017-possible-existing` below a `` comment. | Next un-park sweep. | Removes `stage/017-possible-existing`, appends a **Scope vs existing** section with `` to the issue body, records the un-park so the issue re-derives `stage/010-actionable` ([#13575](https://github.com/hivecommons/hive/issues/13575)). | | `/hive decision exists` | Agrees the request already exists. | Same as above. | Same as above. | Next un-park sweep. | Adds `already-exists`, closes the issue `not_planned`, replies with a pointer at the quoted findings. Reopen the issue to continue; the gate does not ask again. | | `/hive help` | Posts this command list. On parked issues it also repeats the issue-specific approve/decision options. | Any human commenter with at least `triage` repository permission for the on-demand workflow; the sweep path on parked issues requires `write`, `maintain`, or `admin`. | Any open issue or pull request. | GitHub Actions on the new comment; if Actions is unavailable on a parked issue, the next un-park sweep can also answer. | None. | diff --git a/src/pkg/github/issue_request_label.go b/src/pkg/github/issue_request_label.go index 0bc2e22f0f..268f66a403 100644 --- a/src/pkg/github/issue_request_label.go +++ b/src/pkg/github/issue_request_label.go @@ -208,34 +208,41 @@ func (c *Client) reservedLabelRefusal(add, remove []string) (string, bool) { // the agent what to do instead: follow the decision, or — when it reserves // the work for people — add `needs-human` and unclaim. A lookup failure is // returned so the caller retries rather than reading "unknown" as allowed. -func (c *Client) reparkDecisionRefusal(ctx context.Context, repo string, number int, add []string) (string, bool, error) { +// +// superseded is true when the park is allowed through on that newer, +// different decision: the issue still wears `approved-direction` for the +// old one, and the stage engine must read the ack as stale +// (FactSink.ReparkedOnNewDecision) rather than as a standing decision the +// agent is standing down on (hivecommons/hive#16579), or the park never +// lands. +func (c *Client) reparkDecisionRefusal(ctx context.Context, repo string, number int, add []string) (reason string, refused, superseded bool, err error) { if number <= 0 || !containsDecisionParkLabel(add, c.needsDecisionLabel()) { - return "", false, nil + return "", false, false, nil } owner, name := c.splitRepo(repo) issue, _, err := c.client.Issues.Get(ctx, owner, name, number) if err != nil { - return "", false, fmt.Errorf("checking issue park labels: %w", err) + return "", false, false, fmt.Errorf("checking issue park labels: %w", err) } labels := extractLabels(issue.Labels) if !labelPresent(labels, HumanAckLabel) { - return "", false, nil + return "", false, false, nil } comments, err := c.listIssueComments(ctx, owner, name, number) if err != nil { - return "", false, err + return "", false, false, err } decision, at, ok := c.lastRecordedUnparkDecision(comments) if !ok { - return "", false, nil + return "", false, false, nil } if hasNewerDifferentDecisionCommand(comments, at, decision) { - return "", false, nil + return "", false, true, nil } return fmt.Sprintf("a maintainer already decided on %s#%d (recorded by Hive: %q) and `%s` is applied; "+ "re-parking it on `%s` asks for a decision that has been given. Follow the decision. "+ "If it reserves the work for people, add `%s` through this relay and `/unclaim` instead.", - repo, number, decision, HumanAckLabel, c.needsDecisionLabel(), issueNeedsHumanLabel), true, nil + repo, number, decision, HumanAckLabel, c.needsDecisionLabel(), issueNeedsHumanLabel), true, false, nil } func containsDecisionParkLabel(labels []string, configured string) bool { diff --git a/src/pkg/github/issue_request_label_test.go b/src/pkg/github/issue_request_label_test.go index 6f51a74872..72ad11621f 100644 --- a/src/pkg/github/issue_request_label_test.go +++ b/src/pkg/github/issue_request_label_test.go @@ -420,7 +420,9 @@ func TestNormalizeLabelList(t *testing.T) { // With `approved-direction` applied and Hive's own un-park reply recording // the decision, the re-park is refused and the agent is told to add // `needs-human` and unclaim instead. A newer `/hive decision` with different -// text means direction is changing, and the park goes through. +// text means direction is changing, and the park goes through — as a +// ReparkedOnNewDecision fact, so the stale ack does not read as a standing +// decision that would hold the issue out of 045 (hivecommons/hive#16579). func TestIssueRequestWatcher_LabelRefusesReparkOnRecordedDecision(t *testing.T) { const decision = "Agents stand down; owner/Console owners handle this" reply := unparkWireComment{ @@ -456,9 +458,15 @@ func TestIssueRequestWatcher_LabelRefusesReparkOnRecordedDecision(t *testing.T) resp := readIssueResultFile(t, reqPath) if tc.wantAdded { - if !resp.OK || len(rec.added[12680]) != 1 { + if !resp.OK || len(rec.added[12680]) != 1 || rec.added[12680][0] != NeedsDecisionStageLabel { t.Fatalf("expected the park to go through, resp=%+v added=%v", resp, rec.added[12680]) } + // Direction is changing, so the old `approved-direction` + // is stale: the park re-derives 045 with it cleared rather + // than standing down on the old decision (#16579). + if got := strings.Join(rec.removed[12680], ","); !strings.Contains(got, HumanAckLabel) { + t.Fatalf("expected the stale %s cleared with the re-park, removed=%v", HumanAckLabel, rec.removed[12680]) + } return } if resp.OK || len(rec.added[12680]) != 0 { @@ -489,11 +497,11 @@ func TestReparkDecisionRefusalRecognizesRetiredDecisionLabels(t *testing.T) { server, _ := newUnparkServer(t, "org", "repo", []unparkWireIssue{issue}, nil) c := newTestClient(t, server, "org", []string{"repo"}) - reason, refused, err := c.reparkDecisionRefusal(context.Background(), "org/repo", 12680, []string{label}) + reason, refused, superseded, err := c.reparkDecisionRefusal(context.Background(), "org/repo", 12680, []string{label}) if err != nil { t.Fatalf("reparkDecisionRefusal: %v", err) } - if !refused || !strings.Contains(reason, "already decided") || !strings.Contains(reason, issueNeedsHumanLabel) { + if !refused || superseded || !strings.Contains(reason, "already decided") || !strings.Contains(reason, issueNeedsHumanLabel) { t.Fatalf("label %q refused=%v reason=%q, want recorded-decision refusal", label, refused, reason) } }) diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index 363f80cf9f..d3fe80d9ce 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -698,10 +698,12 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f } case "label": // A re-park on a decision a maintainer already gave is refused; a - // failed lookup takes the retry path like the claim gate. + // failed lookup takes the retry path like the claim gate. One let + // through on a newer, different decision is submitted as such so + // the stale `approved-direction` does not read as a standing one. var reason string - var refused bool - reason, refused, err = c.reparkDecisionRefusal(ctx, req.Repo, req.Number, addLabels) + var refused, superseded bool + reason, refused, superseded, err = c.reparkDecisionRefusal(ctx, req.Repo, req.Number, addLabels) if err != nil { break } @@ -726,7 +728,11 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f err = c.StageFacts().Unparked(ctx, c.IssueStageRef(req.Repo, req.Number), req.Agent) } if err == nil && parkLabel != "" { - err = c.StageFacts().Parked(ctx, c.IssueStageRef(req.Repo, req.Number), parkLabel) + if superseded { + err = c.StageFacts().ReparkedOnNewDecision(ctx, c.IssueStageRef(req.Repo, req.Number), parkLabel) + } else { + err = c.StageFacts().Parked(ctx, c.IssueStageRef(req.Repo, req.Number), parkLabel) + } if err == nil { err = c.verifyIssueParkLanded(ctx, req.Repo, req.Number, parkLabel) } diff --git a/src/pkg/stageengine/derive_issue.go b/src/pkg/stageengine/derive_issue.go index 2a67d7b993..dd83ef878a 100644 --- a/src/pkg/stageengine/derive_issue.go +++ b/src/pkg/stageengine/derive_issue.go @@ -99,11 +99,13 @@ func deriveIssue(f Facts) Decision { } // issueParkClear reconciles `needs-human` against `approved-direction` on -// an issue parked at 045 (hivecommons/hive#15099). That happens only for a -// structured blocker — no decision grants the App a permission, so the ack -// is the stale one and the writer clears it. A plain `needs-human` next to -// the ack derives out of the pipeline instead and keeps the ack -// (hivecommons/hive#16579), so nothing is cleared for it. +// an issue parked at 045 (hivecommons/hive#15099). That happens for a +// structured blocker — no decision grants the App a permission — and for a +// park let through because a newer, different `/hive decision` is pending +// (Park.DecisionSuperseded): either way the ack is the stale one and the +// writer clears it. A plain `needs-human` next to a standing ack derives +// out of the pipeline instead and keeps it (hivecommons/hive#16579), so +// nothing is cleared for it. func issueParkClear(f Facts, stage stagelabels.Stage) []string { is := f.Issue label := strings.TrimSpace(is.ApprovedDirectionLabel) @@ -173,8 +175,12 @@ func issueStage(f Facts) (stage stagelabels.Stage, covered bool, reason string) // re-applied the same old decision: a bounce loop // (hivecommons/hive#16579, seen on hivecommons/dibs#567). The // issue is held out of the pipeline like a hold and keeps the ack; - // a person who wants to decide again removes `approved-direction`. - if strings.TrimSpace(is.ApprovedDirectionLabel) != "" { + // a person who wants to decide again removes `approved-direction` + // — or posts a new `/hive decision`: the label relay lets an + // agent's park through on that newer, different decision + // (Park.DecisionSuperseded), the ack is stale again, and the issue + // re-parks at 045 with it cleared until the un-park sweep answers. + if strings.TrimSpace(is.ApprovedDirectionLabel) != "" && !f.Park.DecisionSuperseded { return stagelabels.None, false, reasonIssueDecidedHumanWork + is.NeedsHumanLabel } return stagelabels.IssueNeedsDecision, false, "held for a person: " + is.NeedsHumanLabel diff --git a/src/pkg/stageengine/derive_issue_test.go b/src/pkg/stageengine/derive_issue_test.go index ce6744a21a..cbe1245dc2 100644 --- a/src/pkg/stageengine/derive_issue_test.go +++ b/src/pkg/stageengine/derive_issue_test.go @@ -164,6 +164,18 @@ func TestDeriveIssueBlockerAndApprovedDirection(t *testing.T) { if d.Stage != stagelabels.None || d.Reason != "decided; remaining work held for a person: needs-human" || len(d.Clear) != 0 { t.Fatalf("a plain needs-human after a decision keeps the ack out of 045 (#16579): %+v", d) } + // A newer, different `/hive decision` is pending (the label relay let + // an agent's park through on it): the ack is stale again, the issue + // re-parks at 045 and the writer clears it. + d = DeriveIssue(derivedIssueFacts(func(f *Facts) { + f.Issue.Bucket = BucketFiltered + f.Park.NeedsHuman = true + f.Park.DecisionSuperseded = true + f.Issue.ApprovedDirectionLabel = "approved-direction" + })) + if d.Stage != stagelabels.IssueNeedsDecision || d.Reason != "held for a person: needs-human" || len(d.Clear) != 1 || d.Clear[0] != "approved-direction" { + t.Fatalf("a park on a newer decision outranks the stale ack: %+v", d) + } d = DeriveIssue(derivedIssueFacts(func(f *Facts) { blocked(f); f.Issue.BlockerShort = "" })) if d.Reason != "blocked: capability:workflows-permission" { t.Fatalf("blocker without short falls back to the kind: %+v", d) diff --git a/src/pkg/stageengine/facts.go b/src/pkg/stageengine/facts.go index 93a2ced676..59e707f2b3 100644 --- a/src/pkg/stageengine/facts.go +++ b/src/pkg/stageengine/facts.go @@ -83,6 +83,13 @@ type ParkFacts struct { HumanOnlyReason string // lane rule unrelated to trust (workflow edits, tests removed, …) ApprovedDirection bool // /hive approve|decision recorded; un-park keeps needs-human (#12715) DecisionQuestion string + // DecisionSuperseded says a newer `/hive decision` with different text + // is on the timeline after the recorded one: direction is changing, so + // the `approved-direction` the issue still wears is stale and a + // `needs-human` park re-derives 045 with the ack cleared instead of + // standing down on it (FactSink.ReparkedOnNewDecision; + // hivecommons/hive#16579). + DecisionSuperseded bool } // AdoptionFacts is the stage-074 ownership state of a contributor PR. @@ -166,7 +173,9 @@ type IssueFacts struct { // writer clears it (hivecommons/hive#15099); next to a plain // `needs-human` the decision stands and the remainder is held for a // person out of the pipeline, not re-parked at 045 - // (hivecommons/hive#16579). + // (hivecommons/hive#16579) — unless Park.DecisionSuperseded says a + // newer, different decision is pending, when the ack is stale again + // and the park re-derives 045 with it cleared. ApprovedDirectionLabel string // UmbrellaLabel is the never-claim label the issue carries // (governor.claims.never_claim_labels, default `epic`). diff --git a/src/pkg/stageengine/facts_sink.go b/src/pkg/stageengine/facts_sink.go index d9143c74f5..c5e0a1da1b 100644 --- a/src/pkg/stageengine/facts_sink.go +++ b/src/pkg/stageengine/facts_sink.go @@ -25,8 +25,15 @@ type FactSink interface { AddressedBy(ctx context.Context, issue Ref, pr Ref) error Uncovered(ctx context.Context, issue Ref, pr Ref) error Parked(ctx context.Context, ref Ref, label string) error // agent escalation (045/085/needs-human) - Unparked(ctx context.Context, ref Ref, by string) error // /hive approve|decision - Closed(ctx context.Context, ref Ref) error // the issue closed; its stage lifts + // ReparkedOnNewDecision is Parked for an issue that already wears + // `approved-direction` when a newer, different `/hive decision` is + // pending on its timeline (the label relay's recorded-decision refusal + // let the park through): direction is changing, so the ack is stale + // and the park derives 045 with it cleared rather than standing down + // on the old decision (hivecommons/hive#16579). + ReparkedOnNewDecision(ctx context.Context, ref Ref, label string) error + Unparked(ctx context.Context, ref Ref, by string) error // /hive approve|decision + Closed(ctx context.Context, ref Ref) error // the issue closed; its stage lifts // PRDecided is a trusted merger's `/hive decision` answered on a PR // parked at 085: the decision is recorded for Head, so the park lifts // now — in the same breath as the reply — instead of waiting for the @@ -191,19 +198,31 @@ func (s *factSink) Uncovered(ctx context.Context, issue Ref, pr Ref) error { // Parked implements FactSink: an agent (or a person) parked the item on a // human with label → 045 on an issue, 085 on a PR. func (s *factSink) Parked(ctx context.Context, ref Ref, label string) error { + return s.submit(ctx, parkedFacts(ref, label, false)) +} + +// ReparkedOnNewDecision implements FactSink: Parked with +// ParkFacts.DecisionSuperseded set, so a `needs-human` next to a stale +// `approved-direction` re-derives 045 and clears the ack. +func (s *factSink) ReparkedOnNewDecision(ctx context.Context, ref Ref, label string) error { + return s.submit(ctx, parkedFacts(ref, label, true)) +} + +func parkedFacts(ref Ref, label string, superseded bool) Facts { label = strings.TrimSpace(label) f := Facts{Ref: ref, Labels: []string{label}} f.Park = ParkFacts{ - Holds: stagelabels.Holds(f.Labels), - NeedsHuman: strings.EqualFold(label, NeedsHumanLabel), - DecisionLabel: label, + Holds: stagelabels.Holds(f.Labels), + NeedsHuman: strings.EqualFold(label, NeedsHumanLabel), + DecisionLabel: label, + DecisionSuperseded: superseded, } if ref.Kind == stagelabels.PRItem { f.PR = &PRFacts{} } else { f.Issue = &IssueFacts{Bucket: BucketFiltered, FilteredReason: label} } - return s.submit(ctx, f) + return f } // Unparked implements FactSink: /hive approve or /hive decision recorded by diff --git a/src/pkg/stageengine/facts_sink_test.go b/src/pkg/stageengine/facts_sink_test.go index daa6d53683..a3e7542035 100644 --- a/src/pkg/stageengine/facts_sink_test.go +++ b/src/pkg/stageengine/facts_sink_test.go @@ -73,7 +73,12 @@ func TestFactSinkBuildsMinimalFacts(t *testing.T) { } }}, {"parked issue", func() error { return sink.Parked(ctx, issue, " needs-human ") }, func(t *testing.T, f Facts) { - if !f.Park.NeedsHuman || f.Park.DecisionLabel != "needs-human" || f.Issue.Bucket != BucketFiltered || f.Issue.FilteredReason != "needs-human" || len(f.Labels) != 1 { + if !f.Park.NeedsHuman || f.Park.DecisionSuperseded || f.Park.DecisionLabel != "needs-human" || f.Issue.Bucket != BucketFiltered || f.Issue.FilteredReason != "needs-human" || len(f.Labels) != 1 { + t.Fatalf("%+v %+v", f.Park, f.Issue) + } + }}, + {"reparked on new decision", func() error { return sink.ReparkedOnNewDecision(ctx, issue, "stage/045-needs-decision") }, func(t *testing.T, f Facts) { + if !f.Park.DecisionSuperseded || f.Park.DecisionLabel != "stage/045-needs-decision" || f.Issue.Bucket != BucketFiltered || f.Issue.FilteredReason != "stage/045-needs-decision" { t.Fatalf("%+v %+v", f.Park, f.Issue) } }}, diff --git a/src/pkg/stageengine/stageenginetest/fake.go b/src/pkg/stageengine/stageenginetest/fake.go index 819a17a0e3..05430866f5 100644 --- a/src/pkg/stageengine/stageenginetest/fake.go +++ b/src/pkg/stageengine/stageenginetest/fake.go @@ -170,7 +170,7 @@ type Recorder struct { // Recorded is one FactSink call. type Recorded struct { - Method string // Claimed | ClaimReleased | InProgress | CoveredBy | Uncovered | Parked | Unparked | Closed | PRDecided + Method string // Claimed | ClaimReleased | InProgress | CoveredBy | Uncovered | Parked | ReparkedOnNewDecision | Unparked | Closed | PRDecided Ref stageengine.Ref Claim *stageengine.ClaimFact PR *stageengine.Ref @@ -216,6 +216,9 @@ func (r *Recorder) Uncovered(_ context.Context, issue, pr stageengine.Ref) error func (r *Recorder) Parked(_ context.Context, ref stageengine.Ref, label string) error { return r.record(Recorded{Method: "Parked", Ref: ref, Label: label}) } +func (r *Recorder) ReparkedOnNewDecision(_ context.Context, ref stageengine.Ref, label string) error { + return r.record(Recorded{Method: "ReparkedOnNewDecision", Ref: ref, Label: label}) +} func (r *Recorder) Unparked(_ context.Context, ref stageengine.Ref, by string) error { return r.record(Recorded{Method: "Unparked", Ref: ref, Who: by}) }