From d0dbfbb49d26aa8a63e7f6f211081b3104afd301 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Tue, 17 Nov 2026 07:30:21 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20scanner:=20not-agent-work=20?= =?UTF-8?q?verdict=20parks=20the=20issue=20and=20is=20not=20repeated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scanner's not-agent-work triage verdict (not a defect, needs a human, or needs an environment agents lack) was only a comment: the issue stayed stage/010-actionable and was re-triaged every pass. The comment relay now takes a structured verdict (--not-agent-work, or the hive:not-agent-work marker), posts it once, and parks the issue on needs-human. An identical verdict with no human comment since is dropped as already_existed, and a person's later comment re-queues the issue via the un-park sweep. Fixes #18675 Signed-off-by: Andy Anderson --- bin/hive-open-issue.sh | 35 ++- bin/test_hive_open_issue.sh | 24 ++ ...ed-18675-scanner-not-agent-work-verdict.md | 1 + src/docs/hive-open-issue.md | 3 +- src/pkg/github/issue_not_agent_work.go | 253 ++++++++++++++++++ src/pkg/github/issue_not_agent_work_test.go | 246 +++++++++++++++++ src/pkg/github/issue_request_watcher.go | 22 ++ src/pkg/github/issue_unpark_command.go | 7 + src/pkg/policies/defaults/scanner-advisory.md | 1 + src/pkg/policies/defaults/scanner-full.md | 1 + .../policies/defaults/scanner-holdgated.md | 1 + src/pkg/policies/defaults/scanner-issues.md | 1 + src/pkg/policies/defaults/scanner.md | 1 + src/policies/scanner-advisory.md | 1 + src/policies/scanner-full.md | 1 + src/policies/scanner-holdgated.md | 1 + src/policies/scanner-issues.md | 1 + src/policies/scanner.md | 1 + 18 files changed, 596 insertions(+), 5 deletions(-) create mode 100644 changelog.d/fixed-18675-scanner-not-agent-work-verdict.md create mode 100644 src/pkg/github/issue_not_agent_work.go create mode 100644 src/pkg/github/issue_not_agent_work_test.go diff --git a/bin/hive-open-issue.sh b/bin/hive-open-issue.sh index 0b7f9b7216..d59e91f814 100755 --- a/bin/hive-open-issue.sh +++ b/bin/hive-open-issue.sh @@ -17,7 +17,7 @@ # # Usage (drop-in for the common gh shapes): # hive-open-issue --repo --title "" [--body ""|--body-file f] [--label a,b] [--parent ] [--blocked-by ] [--close-on-merge] [--needs-decision] [--no-consolidate ] [--claim] -# hive-open-issue comment --repo --body "" [--blocked-on-pr ] +# hive-open-issue comment --repo --body "" [--blocked-on-pr ] [--not-agent-work ] # hive-open-issue claim --repo # hive-open-issue close --repo [--override-reason "..."] # hive-open-issue label --repo [--label a,b] [--remove-label c] @@ -73,6 +73,15 @@ # `blocked` label and removes `help wanted`; the hive lifts the label itself # once the PR merges or closes. Never @-mention the PR author in the note. # +# --not-agent-work (comment only) records a triage verdict that the +# issue is not agent work (hivecommons/hive#18675): `not-a-defect` (a +# configuration condition or expected behaviour), `needs-human` (a person's +# action, access or judgement), or `needs-environment` (real logins, hardware, +# a live meeting). The watcher posts the note once with a marker and parks the +# issue on `needs-human`, so it leaves the Actionable lane and the scanner's +# work list; the same verdict again with no human comment since is dropped +# (already_existed). A person's later comment re-queues the issue. +# # Every shape accepts --dry-run (-n): validate the arguments, print the exact # request that WOULD be written, and exit 0 without writing it — nothing is # created. USE IT TO TEST. A live call (no --dry-run) creates a real GitHub @@ -156,6 +165,7 @@ CLOSE_ON_MERGE=0 NEEDS_DECISION=0 CLAIM_ON_CREATE=0 BLOCKED_ON_PR="" +NOT_AGENT_WORK="" NO_CONSOLIDATE="" NO_CONSOLIDATE_SET=0 DRY_RUN=0 @@ -163,7 +173,7 @@ LABELS=() REMOVE_LABELS=() REVIEWERS=() TEAM_REVIEWERS=() -SUPPORTED_FLAGS="--repo/-R, --title/-t, --body/-b, --body-file/-F, --label/-l, --remove-label, --reviewer, --team-reviewer, --number, --parent, --blocked-by, --close-on-merge, --needs-decision, --claim, --no-consolidate, --blocked-on-pr, --override-reason, --dry-run/-n (plus the ignored gh flags --assignee/-a, --milestone/-m, --project/-p, --template/-T, --web/-w, --editor/-e)" +SUPPORTED_FLAGS="--repo/-R, --title/-t, --body/-b, --body-file/-F, --label/-l, --remove-label, --reviewer, --team-reviewer, --number, --parent, --blocked-by, --close-on-merge, --needs-decision, --claim, --no-consolidate, --blocked-on-pr, --not-agent-work, --override-reason, --dry-run/-n (plus the ignored gh flags --assignee/-a, --milestone/-m, --project/-p, --template/-T, --web/-w, --editor/-e)" while [ $# -gt 0 ]; do case "$1" in --repo|-R) REPO="$2"; shift 2;; @@ -197,6 +207,8 @@ while [ $# -gt 0 ]; do --no-consolidate=*) NO_CONSOLIDATE_SET=1; NO_CONSOLIDATE="${1#*=}"; shift;; --blocked-on-pr) BLOCKED_ON_PR="$2"; shift 2;; --blocked-on-pr=*) BLOCKED_ON_PR="${1#*=}"; shift;; + --not-agent-work) NOT_AGENT_WORK="$2"; shift 2;; + --not-agent-work=*) NOT_AGENT_WORK="${1#*=}"; shift;; --dry-run|-n) DRY_RUN=1; shift;; # Tolerate gh flags we don't need; skip a following value only for flags # that take one, so a bare flag can't swallow the next real argument. @@ -265,6 +277,14 @@ if [ -n "${BLOCKED_ON_PR:-}" ] && [ "$KIND" != "comment" ]; then echo "hive-open-issue: --blocked-on-pr only applies to a comment; nothing was written." >&2 exit 2 fi +if [ -n "${NOT_AGENT_WORK:-}" ] && [ "$KIND" != "comment" ]; then + echo "hive-open-issue: --not-agent-work only applies to a comment; nothing was written." >&2 + exit 2 +fi +if [ -n "${NOT_AGENT_WORK:-}" ] && ! [[ "$NOT_AGENT_WORK" =~ ^(not-a-defect|needs-human|needs-environment)$ ]]; then + echo "hive-open-issue: --not-agent-work needs one of not-a-defect, needs-human, needs-environment; nothing was written." >&2 + exit 2 +fi if [ -n "${BLOCKED_ON_PR:-}" ] && ! [[ "$BLOCKED_ON_PR" =~ ^[0-9]+$ && "$BLOCKED_ON_PR" -gt 0 ]]; then echo "hive-open-issue: --blocked-on-pr needs a positive PR number; nothing was written." >&2 exit 2 @@ -384,9 +404,9 @@ REMOVE_LABELS_JSON="$(printf '%s\n' "${REMOVE_LABELS[@]:-}" | python3 -c 'import REVIEWERS_JSON="$(printf '%s\n' "${REVIEWERS[@]:-}" | python3 -c 'import json,sys; print(json.dumps([x.rstrip("\n") for x in sys.stdin if x.rstrip("\n")]))')" TEAM_REVIEWERS_JSON="$(printf '%s\n' "${TEAM_REVIEWERS[@]:-}" | python3 -c 'import json,sys; print(json.dumps([x.rstrip("\n") for x in sys.stdin if x.rstrip("\n")]))')" BLOCKED_BY_JSON="$(printf '%s\n' "${BLOCKED_BY[@]:-}" | python3 -c 'import json,sys; print(json.dumps([x.rstrip("\n") for x in sys.stdin if x.rstrip("\n")]))')" -python3 - "$TEMP_FILE" "$REQ_FILE" "$KIND" "$REPO" "$TITLE" "${OVERRIDE_REASON:-$BODY}" "$AGENT" "$LABELS_JSON" "${NUMBER:-0}" "$DRY_RUN" "${PARENT:-0}" "$REMOVE_LABELS_JSON" "$REVIEWERS_JSON" "$TEAM_REVIEWERS_JSON" "$BLOCKED_BY_JSON" "$NEEDS_DECISION" "${BLOCKED_ON_PR:-0}" "$NO_CONSOLIDATE" "$CLAIM_ON_CREATE" <<'PY' +python3 - "$TEMP_FILE" "$REQ_FILE" "$KIND" "$REPO" "$TITLE" "${OVERRIDE_REASON:-$BODY}" "$AGENT" "$LABELS_JSON" "${NUMBER:-0}" "$DRY_RUN" "${PARENT:-0}" "$REMOVE_LABELS_JSON" "$REVIEWERS_JSON" "$TEAM_REVIEWERS_JSON" "$BLOCKED_BY_JSON" "$NEEDS_DECISION" "${BLOCKED_ON_PR:-0}" "$NO_CONSOLIDATE" "$CLAIM_ON_CREATE" "${NOT_AGENT_WORK:-}" <<'PY' import json, os, sys -temporary, path, kind, repo, title, body, agent, labels, number, dry_run, parent, remove_labels, reviewers, team_reviewers, blocked_by, needs_decision, blocked_on_pr, no_consolidate, claim_on_create = sys.argv[1:20] +temporary, path, kind, repo, title, body, agent, labels, number, dry_run, parent, remove_labels, reviewers, team_reviewers, blocked_by, needs_decision, blocked_on_pr, no_consolidate, claim_on_create, not_agent_work = sys.argv[1:21] labels = [part.strip() for value in json.loads(labels) for part in value.split(",") if part.strip()] remove_labels = [part.strip() for value in json.loads(remove_labels) @@ -464,6 +484,10 @@ if kind == "comment" and int(blocked_on_pr) > 0: # --blocked-on-pr: the watcher adds the marker and the `blocked` label # itself (hivecommons/hive#13093). req["blocked_on_pr"] = int(blocked_on_pr) +if kind == "comment" and not_agent_work: + # --not-agent-work: the watcher adds the marker and parks the issue on + # needs-human itself (hivecommons/hive#18675). + req["not_agent_work"] = not_agent_work if dry_run == "1": # Honour --dry-run: show exactly what would be queued, write nothing. print("hive-open-issue: DRY RUN — no request written, nothing will be created. Would write %s:" % path) @@ -491,6 +515,9 @@ if [ "$KIND" = "comment" ]; then if [ -n "${BLOCKED_ON_PR:-}" ]; then echo "hive-open-issue: will park the issue on $REPO#$BLOCKED_ON_PR (blocked label; help wanted removed; no one is @-mentioned)" fi + if [ -n "${NOT_AGENT_WORK:-}" ]; then + echo "hive-open-issue: will record the $NOT_AGENT_WORK verdict and park the issue on needs-human (an identical repeat is dropped)" + fi elif [ "$KIND" = "claim" ]; then echo "hive-open-issue: requested claim of $REPO#$NUMBER (hive/claimed-by-$AGENT label)" elif [ "$KIND" = "close" ]; then diff --git a/bin/test_hive_open_issue.sh b/bin/test_hive_open_issue.sh index 1af63bb4cd..e40beadd35 100755 --- a/bin/test_hive_open_issue.sh +++ b/bin/test_hive_open_issue.sh @@ -350,6 +350,30 @@ check "--claim refusal writes no request" "" "$(find_req claimcommentbot)" rm -rf "$REQ_DIR" mkdir -p "$REQ_DIR" +# --not-agent-work carries the verdict on a comment; a bad verdict or a non-comment is refused (#18675). +run_script "nawbot" comment --repo "hiveorg/widgets" 5 --body "not startable" --not-agent-work needs-environment >/dev/null +REQ_FILE="$(find_req nawbot)" +if [ -n "$REQ_FILE" ]; then + GOT="$(python3 -c "import json,sys; r=json.load(open(sys.argv[1])); print(r.get('kind'), r.get('not_agent_work'))" "$REQ_FILE")" + check "--not-agent-work sets not_agent_work on the comment request" "comment needs-environment" "$GOT" +else + echo " FAIL: request file not created for --not-agent-work test" + FAIL=$((FAIL + 1)) +fi +rm -rf "$REQ_DIR" +mkdir -p "$REQ_DIR" +set +e +run_script "nawbadbot" comment --repo "hiveorg/widgets" 5 --body "x" --not-agent-work maybe >/dev/null 2>&1 +BAD_RC=$? +run_script "nawissuebot" --repo "hiveorg/widgets" --title "t" --body "b" --not-agent-work needs-human >/dev/null 2>&1 +BAD_ISSUE_RC=$? +set -e +check "--not-agent-work with an unknown verdict is refused (exit 2)" "2" "$BAD_RC" +check "--not-agent-work on a create is refused (exit 2)" "2" "$BAD_ISSUE_RC" +check "--not-agent-work refusals write no request" "" "$(find_req nawbadbot)$(find_req nawissuebot)" +rm -rf "$REQ_DIR" +mkdir -p "$REQ_DIR" + # --no-consolidate carries the reason; an empty reason or a non-create is refused. run_script "noconsolbot" --repo "hiveorg/widgets" --title "Unrelated" --body "b" --no-consolidate "different work" REQ_FILE="$(find_req noconsolbot)" diff --git a/changelog.d/fixed-18675-scanner-not-agent-work-verdict.md b/changelog.d/fixed-18675-scanner-not-agent-work-verdict.md new file mode 100644 index 0000000000..202f2b554f --- /dev/null +++ b/changelog.d/fixed-18675-scanner-not-agent-work-verdict.md @@ -0,0 +1 @@ +- The scanner's "not agent work" triage verdict now changes the issue's state instead of only leaving a comment: `hive-open-issue comment --not-agent-work ` (or the `` marker) posts the note once and parks the issue on `needs-human`, so it leaves stage/010-actionable on the board and the scanner's work list. An identical verdict with no human comment since is dropped as `already_existed` rather than posted again, and a person's later comment lifts the hive's own `needs-human` and re-queues the issue (#18675). diff --git a/src/docs/hive-open-issue.md b/src/docs/hive-open-issue.md index 77f1106095..9f64c1df7e 100644 --- a/src/docs/hive-open-issue.md +++ b/src/docs/hive-open-issue.md @@ -43,7 +43,7 @@ Shapes are selected by an optional leading positional keyword (`comment`, ```sh hive-open-issue --repo --title "" [--body ""|--body-file f] [--label a,b] [--parent ] [--blocked-by ] [--needs-decision] [--no-consolidate ] [--claim] -hive-open-issue comment --repo --body "" [--blocked-on-pr ] +hive-open-issue comment --repo --body "" [--blocked-on-pr ] [--not-agent-work ] hive-open-issue claim --repo hive-open-issue label --repo [--label a,b] [--remove-label c] hive-open-issue request-review --repo [--reviewer a,b] [--team-reviewer t] @@ -65,6 +65,7 @@ hive-open-issue request-review --repo [--reviewer a,b] | `--claim` | — | issue | file the new issue **and** claim it for this agent in the same request (see [Filing your own next step](#filing-your-own-next-step)). The request carries `"claim": true`; the result reports `claimed`, or `claim_error` when the claim did not land | | `--no-consolidate` | — | issue | requires a non-empty reason; the watcher skips open-issue consolidation (same-subject, file-set and component folds) and files a new issue, echoing the reason as `consolidation_skipped_reason` in the result and logging it. Use it for unrelated work that only shares a file or component with an open issue ([#14360](https://github.com/hivecommons/hive/issues/14360)). The request carries `"no_consolidate_reason"`. A request that declares `--parent` or `--blocked-by` needs no reason: it is a distinct DAG node and never takes the file-set, component or canonical-subject folds, and a genuine create reports `consolidation_skipped_reason` as `parent` or `blocked_by` ([#16065](https://github.com/hivecommons/hive/issues/16065)) | | `--blocked-on-pr` | — | comment | park the issue on open PR `` in the same repo: the watcher prefixes the note with ``, strips `@`-mentions from it, adds the `blocked` label and removes `help wanted` (see [Blocked on an unmerged PR](#blocked-on-an-unmerged-pr)) | +| `--not-agent-work` | — | comment | record a triage verdict that the issue is not agent work (`not-a-defect`, `needs-human` or `needs-environment`, hivecommons/hive#18675): the watcher posts the note once with `` and adds `needs-human`, so the issue leaves the Actionable lane and the scanner's work list; the same verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue | | `--number` | — | comment, claim, close, label, request-review | the issue/PR number; a bare positional number or a `.../issues/N` or `.../pull/N` URL is also accepted | | `--dry-run` | `-n` | all | validate the arguments and print the exact request that would be written, then exit `0` **without writing it** — nothing is created, commented, claimed, or closed. **This is how you test the tool.** A live call creates a real GitHub issue/comment/label change under the hive's App identity | diff --git a/src/pkg/github/issue_not_agent_work.go b/src/pkg/github/issue_not_agent_work.go new file mode 100644 index 0000000000..e4e3a6e935 --- /dev/null +++ b/src/pkg/github/issue_not_agent_work.go @@ -0,0 +1,253 @@ +package github + +// Not-agent-work triage verdict (hivecommons/hive#18675). +// +// A scanner triage that concludes an issue is not agent work — a single-hive +// configuration condition rather than a defect, or work that needs a person +// or an environment agents do not have (a real subscription login, a Mac on +// a Zoom call) — used to be only a comment. The issue kept +// stage/010-actionable, the board showed it as Actionable for hours, and the +// scanner re-triaged it on every pass with the same verdict (#18636 got +// three identical comments in an hour). +// +// The verdict is now structured: the comment relay's `--not-agent-work +// ` flag (IssueRequest.NotAgentWork), or the marker +// `` in the comment body. The +// relay posts the note once with the marker and parks the issue on a person +// with `needs-human`, which the stage engine derives to the needs-human park +// (stage/045) and which keeps the issue out of the actionable set, so the +// next scanner pass does not see it. A repeat of the same verdict with no +// human comment since the last one is dropped (already_existed) instead of +// posted again. A later comment from a person re-queues the issue: the +// un-park sweep lifts the hive's own `needs-human` (never a person's) and +// answers once. + +import ( + "context" + "fmt" + "log/slog" + "net/http" + "net/url" + "regexp" + "strings" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/pkg/stageengine" +) + +// Not-agent-work verdicts the relay accepts. +const ( + // NotAgentWorkVerdictNotADefect: a configuration condition or expected + // behaviour, not a code defect; a person confirms and closes it. + NotAgentWorkVerdictNotADefect = "not-a-defect" + // NotAgentWorkVerdictNeedsHuman: the work needs a person's action, + // access or judgement. + NotAgentWorkVerdictNeedsHuman = "needs-human" + // NotAgentWorkVerdictNeedsEnvironment: the work needs an environment + // agents lack (real logins, hardware, a live meeting). + NotAgentWorkVerdictNeedsEnvironment = "needs-environment" +) + +var notAgentWorkVerdicts = map[string]bool{ + NotAgentWorkVerdictNotADefect: true, + NotAgentWorkVerdictNeedsHuman: true, + NotAgentWorkVerdictNeedsEnvironment: true, +} + +// notAgentWorkMarkerPrefix opens the marker; distinct from every other +// hive:* marker so only this file parses it. +const notAgentWorkMarkerPrefix = "`) + +// notAgentWorkRequeueMarker tags the hive's one reply when a person's comment +// re-queues a parked not-agent-work issue (the reply also carries the +// un-park reply marker for that comment, which is what keeps it idempotent). +const notAgentWorkRequeueMarker = "" + +// NormalizeNotAgentWorkVerdict lower-cases and validates a verdict. +func NormalizeNotAgentWorkVerdict(v string) (string, bool) { + v = strings.ToLower(strings.TrimSpace(v)) + return v, notAgentWorkVerdicts[v] +} + +// NotAgentWorkMarker renders the marker for a verdict. +func NotAgentWorkMarker(verdict string) string { + return notAgentWorkMarkerPrefix + verdict + " -->" +} + +// ParseNotAgentWorkMarker returns the verdict of the first valid marker in +// text. +func ParseNotAgentWorkMarker(text string) (string, bool) { + for _, m := range notAgentWorkMarkerRE.FindAllStringSubmatch(text, -1) { + if v, ok := NormalizeNotAgentWorkVerdict(m[1]); ok { + return v, true + } + } + return "", false +} + +// notAgentWorkVerdictFor returns the verdict a comment request carries: the +// structured field first, else a marker in the body. +func notAgentWorkVerdictFor(req IssueRequest, body string) (string, bool) { + if v, ok := NormalizeNotAgentWorkVerdict(req.NotAgentWork); ok { + return v, true + } + return ParseNotAgentWorkMarker(body) +} + +// notAgentWorkNoteBody makes body carry exactly the marker for verdict, +// first, so the note is recognisable on the next pass. +func notAgentWorkNoteBody(verdict, body string) string { + body = strings.TrimSpace(notAgentWorkMarkerRE.ReplaceAllString(body, "")) + return NotAgentWorkMarker(verdict) + "\n" + body +} + +// latestNotAgentWorkTriage finds the newest not-agent-work note the hive +// itself posted: its index in comments and its verdict; -1 when none. +func (c *Client) latestNotAgentWorkTriage(comments []*gh.IssueComment) (int, string) { + for i := len(comments) - 1; i >= 0; i-- { + cm := comments[i] + if cm == nil || !c.markerAuthorTrusted(cm.GetUser()) { + continue + } + if v, ok := ParseNotAgentWorkMarker(cm.GetBody()); ok { + return i, v + } + } + return -1, "" +} + +// firstHumanCommentAfter returns the first comment after index i written by a +// person other than this hive, or nil. +func (c *Client) firstHumanCommentAfter(comments []*gh.IssueComment, i int) *gh.IssueComment { + for j := i + 1; j < len(comments); j++ { + if cm := comments[j]; cm != nil && c.isHumanAuthor(cm.GetUser()) { + return cm + } + } + return nil +} + +// isRepeatedNotAgentWorkTriage reports whether the hive already posted the +// same verdict and no person has commented since: nothing changed, so there +// is nothing new to say. +func (c *Client) isRepeatedNotAgentWorkTriage(comments []*gh.IssueComment, verdict string) bool { + idx, prior := c.latestNotAgentWorkTriage(comments) + if idx < 0 || prior != verdict { + return false + } + return c.firstHumanCommentAfter(comments, idx) == nil +} + +// relayNotAgentWorkNote handles a comment request carrying a not-agent-work +// verdict on an issue. handled is false for a pull request (the comment then +// takes the ordinary path). A repeat is acknowledged as already_existed and +// only re-asserts the park; otherwise the note is posted with its marker and +// the issue is parked on `needs-human`. +func (c *Client) relayNotAgentWorkNote(ctx context.Context, req IssueRequest, verdict, body string, resp *IssueResponse) (handled bool, err error) { + if c == nil || c.client == nil { + return false, ErrNoGitHubClient + } + owner, name := c.splitRepo(req.Repo) + issue, _, err := c.client.Issues.Get(ctx, owner, name, req.Number) + if err != nil { + return true, fmt.Errorf("reading %s#%d before not-agent-work note: %w", req.Repo, req.Number, err) + } + if issue.IsPullRequest() { + return false, nil + } + comments, err := c.listIssueComments(ctx, owner, name, req.Number) + if err != nil { + return true, fmt.Errorf("reading comments on %s#%d before not-agent-work note: %w", req.Repo, req.Number, err) + } + labels := issueLabelNames(issue.Labels) + if c.isRepeatedNotAgentWorkTriage(comments, verdict) { + c.noteCommentSuppressed() + if c.logger != nil { + c.logger.Info("issue-request watcher: identical not-agent-work triage already on issue, not re-posting", + slog.String("repo", req.Repo), slog.Int("number", req.Number), slog.String("agent", req.Agent), slog.String("verdict", verdict)) + } + if !strings.EqualFold(issue.GetState(), "closed") && !hasIssueNeedsHumanLabel(labels) { + if err := c.parkNotAgentWork(ctx, req.Repo, req.Number); err != nil { + return true, err + } + } + resp.OK, resp.Number, resp.AlreadyExisted = true, req.Number, true + return true, nil + } + if err := c.CreateIssueCommentBudgeted(ctx, req.Repo, req.Number, notAgentWorkNoteBody(verdict, body)); err != nil { + return true, err + } + if !strings.EqualFold(issue.GetState(), "closed") && !hasIssueNeedsHumanLabel(labels) { + if err := c.parkNotAgentWork(ctx, req.Repo, req.Number); err != nil { + return true, err + } + } + resp.OK, resp.Number = true, req.Number + resp.LabelsAdded = []string{issueNeedsHumanLabel} + return true, nil +} + +// parkNotAgentWork adds `needs-human` and submits it to the stage engine as +// a park, as the label relay does for an agent-added `needs-human`, then +// checks the park landed (a failure retries the request, and the retry is +// a suppressed repeat that only re-parks). +func (c *Client) parkNotAgentWork(ctx context.Context, repo string, number int) error { + if err := c.AddLabels(ctx, repo, number, []string{issueNeedsHumanLabel}); err != nil { + return err + } + if err := c.StageFacts().Parked(ctx, c.IssueStageRef(repo, number), issueNeedsHumanLabel); err != nil { + return err + } + return c.verifyIssueParkLanded(ctx, repo, number, issueNeedsHumanLabel) +} + +// tryRequeueNotAgentWork re-queues an issue the hive parked on a +// not-agent-work verdict once a person comments after the verdict: the +// hive's own `needs-human` comes off, the stage engine is told the park +// lifted, and one reply (keyed to the comment) says so. A `/hive` command +// is left to the un-park paths; a `needs-human` a person applied stays. +func (c *Client) tryRequeueNotAgentWork(ctx context.Context, displayRepo, owner, repo string, issue *gh.Issue, comments []*gh.IssueComment, answered map[int64]bool, verbs []string, result *IssueUnparkSweepResult, audit func(IssueUnparkEvent)) (bool, error) { + labels := issueLabelNames(issue.Labels) + if !hasIssueNeedsHumanLabel(labels) { + return false, nil + } + idx, verdict := c.latestNotAgentWorkTriage(comments) + if idx < 0 { + return false, nil + } + reply := c.firstHumanCommentAfter(comments, idx) + if reply == nil || answered[reply.GetID()] { + return false, nil + } + if _, isCommand := parseUnparkCommandFor(reply.GetBody(), verbs); isCommand { + return false, nil + } + number := issue.GetNumber() + if out := c.needsHumanOutcome(ctx, owner, repo, number, nil); out.applier != stageengine.NeedsHumanApplierHive { + return false, nil + } + if _, err := c.client.Issues.RemoveLabelForIssue(ctx, owner, repo, number, url.PathEscape(issueNeedsHumanLabel)); err != nil && !githubStatusError(err, http.StatusNotFound) { + return false, fmt.Errorf("removing %s from %s/%s#%d: %w", issueNeedsHumanLabel, owner, repo, number, err) + } + actor := safeGetLogin(reply.GetUser()) + if err := c.StageFacts().Unparked(ctx, c.IssueStageRef(owner+"/"+repo, number), actor); err != nil { + return false, err + } + notifyItemRefresh(owner+"/"+repo, number, false) + body := notAgentWorkRequeueMarker + "\n" + fmt.Sprintf("Re-queued: %s commented after the hive's not-agent-work triage (%s), so `needs-human` is off and agents may pick this issue up again.", actor, verdict) + if err := c.postUnparkReply(ctx, owner, repo, number, reply.GetID(), body); err != nil { + return false, err + } + event := IssueUnparkEvent{Repo: displayRepo, Number: number, Actor: actor, Decision: "re-queued after not-agent-work triage (" + verdict + ")", CommentURL: reply.GetHTMLURL()} + result.Unparked = append(result.Unparked, event) + if audit != nil { + audit(event) + } + if c.logger != nil { + c.logger.Info("not-agent-work issue re-queued by a person's comment", "repo", displayRepo, "issue", number, "actor", actor, "verdict", verdict) + } + return true, nil +} diff --git a/src/pkg/github/issue_not_agent_work_test.go b/src/pkg/github/issue_not_agent_work_test.go new file mode 100644 index 0000000000..620ea37c6e --- /dev/null +++ b/src/pkg/github/issue_not_agent_work_test.go @@ -0,0 +1,246 @@ +package github + +import ( + "context" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#18675: the scanner's not-agent-work verdict changes the +// issue's state, is not repeated unchanged, and a person's later comment +// re-queues the issue. + +const notAgentWorkTestBot = "hive[bot]" + +func TestNotAgentWorkMarkerRoundTrip(t *testing.T) { + for _, v := range []string{NotAgentWorkVerdictNotADefect, NotAgentWorkVerdictNeedsHuman, NotAgentWorkVerdictNeedsEnvironment} { + got, ok := ParseNotAgentWorkMarker("Scanner triage.\n" + NotAgentWorkMarker(v)) + if !ok || got != v { + t.Fatalf("round trip %q: got %q ok=%v", v, got, ok) + } + } + if _, ok := ParseNotAgentWorkMarker(""); ok { + t.Fatal("unknown verdict must not parse") + } + if v, ok := NormalizeNotAgentWorkVerdict(" Needs-Environment "); !ok || v != NotAgentWorkVerdictNeedsEnvironment { + t.Fatalf("normalize = %q %v", v, ok) + } + body := notAgentWorkNoteBody(NotAgentWorkVerdictNeedsHuman, "note\n"+NotAgentWorkMarker(NotAgentWorkVerdictNeedsHuman)) + if strings.Count(body, notAgentWorkMarkerPrefix) != 1 || !strings.HasPrefix(body, NotAgentWorkMarker(NotAgentWorkVerdictNeedsHuman)) { + t.Fatalf("note body must carry the marker exactly once, first: %q", body) + } +} + +func actionableIssue(number int, comments ...unparkWireComment) unparkWireIssue { + return unparkWireIssue{ + Number: number, + Title: "ioscan selfreport", + Body: "something looks wrong", + User: wireUser{Login: "reporter"}, + Labels: []wireLabel{{Name: "kind/bug"}, {Name: "help wanted"}, {Name: stagelabels.Actionable.Label()}}, + Comments: comments, + } +} + +func notAgentWorkClient(t *testing.T, issues []unparkWireIssue) (*Client, *unparkServer, string) { + t.Helper() + server, rec := newUnparkServer(t, "org", "repo", issues, nil) + c := newTestClient(t, server, "org", []string{"repo"}) + c.SetAppBotLogin(notAgentWorkTestBot) + c.issueAuthz = func(agent string, uid int, kind string) error { return nil } + return c, rec, withIssueDir(t) +} + +func botComment(id int64, body string) unparkWireComment { + cm := humanComment(id, notAgentWorkTestBot, body) + cm.CreatedAt, cm.UpdatedAt = unparkOld(), unparkOld() + return cm +} + +// A "not startable" verdict moves the issue out of stage/010-actionable onto +// the needs-human park. +func TestIssueRequestWatcherNotAgentWorkParksIssue(t *testing.T) { + c, rec, dir := notAgentWorkClient(t, []unparkWireIssue{actionableIssue(18636)}) + reqPath, err := WriteIssueRequest(dir, IssueRequest{ + Kind: "comment", Repo: "org/repo", Number: 18636, Agent: "scanner", + NotAgentWork: NotAgentWorkVerdictNeedsEnvironment, + Body: "Scanner: not startable by an agent; it needs a Mac on a live Zoom call.", + }) + if err != nil { + t.Fatal(err) + } + c.ProcessIssueRequestsOnce(context.Background()) + resp := readIssueResultFile(t, reqPath) + if !resp.OK || resp.AlreadyExisted { + t.Fatalf("result = %+v, want a posted note", resp) + } + rec.mu.Lock() + defer rec.mu.Unlock() + if len(rec.posted[18636]) != 1 { + t.Fatalf("posted = %v, want one note", rec.posted[18636]) + } + if v, ok := ParseNotAgentWorkMarker(rec.posted[18636][0]); !ok || v != NotAgentWorkVerdictNeedsEnvironment { + t.Fatalf("note lacks the verdict marker: %q", rec.posted[18636][0]) + } + added := strings.Join(rec.added[18636], ",") + if !strings.Contains(added, issueNeedsHumanLabel) || !strings.Contains(added, NeedsDecisionStageLabel) { + t.Fatalf("added = %q, want needs-human and the needs-human park stage", added) + } + if !strings.Contains(strings.Join(rec.removed[18636], ","), stagelabels.Actionable.Label()) { + t.Fatalf("removed = %v, want %s off", rec.removed[18636], stagelabels.Actionable.Label()) + } +} + +// The marker in the body is read the same way as the structured field. +func TestIssueRequestWatcherNotAgentWorkMarkerInBody(t *testing.T) { + c, rec, dir := notAgentWorkClient(t, []unparkWireIssue{actionableIssue(18421)}) + reqPath, err := WriteIssueRequest(dir, IssueRequest{ + Kind: "comment", Repo: "org/repo", Number: 18421, Agent: "scanner", + Body: "Config-only condition, not a defect.\n" + NotAgentWorkMarker(NotAgentWorkVerdictNotADefect), + }) + if err != nil { + t.Fatal(err) + } + c.ProcessIssueRequestsOnce(context.Background()) + if resp := readIssueResultFile(t, reqPath); !resp.OK { + t.Fatalf("result = %+v", resp) + } + rec.mu.Lock() + defer rec.mu.Unlock() + if !strings.Contains(strings.Join(rec.added[18421], ","), issueNeedsHumanLabel) { + t.Fatalf("added = %v, want needs-human", rec.added[18421]) + } +} + +// The next scanner pass skips the parked issue: it is filtered out of the +// actionable set. +func TestEnumerateActionableSkipsNotAgentWorkParkedIssue(t *testing.T) { + const org, repo = "testorg", "testrepo" + issues := []wireIssue{ + {Number: 1, Title: "parked", User: wireUser{"alice"}, CreatedAt: hoursAgo(3), + Labels: []wireLabel{{Name: "kind/bug"}, {Name: "help wanted"}, {Name: issueNeedsHumanLabel}, {Name: NeedsDecisionStageLabel}}}, + {Number: 2, Title: "open work", User: wireUser{"bob"}, CreatedAt: hoursAgo(2), + Labels: []wireLabel{{Name: "kind/bug"}, {Name: "help wanted"}}}, + } + server := httptest.NewServer(buildMux(t, org, repo, issues, []wirePR{})) + t.Cleanup(server.Close) + c := newTestClient(t, server, org, []string{repo}) + result, err := c.EnumerateActionable(context.Background()) + if err != nil { + t.Fatalf("EnumerateActionable: %v", err) + } + for _, it := range result.Issues.Items { + if it.Number == 1 { + t.Fatalf("not-agent-work issue entered the actionable set: %+v", result.Issues.Items) + } + } + for _, row := range result.WorkDetailsByRepo[repo].Issues { + if row.Number == 1 && row.Bucket != workBucketFiltered { + t.Fatalf("parked row bucket = %q, want %q", row.Bucket, workBucketFiltered) + } + } +} + +// A repeated identical triage on the same issue is suppressed; a different +// verdict, or one after a person's comment, is posted. +func TestIssueRequestWatcherNotAgentWorkRepeatSuppressed(t *testing.T) { + prior := botComment(100, "Scanner triage: needs real logins.\n"+NotAgentWorkMarker(NotAgentWorkVerdictNeedsEnvironment)) + cases := []struct { + name string + comments []unparkWireComment + verdict string + wantPost bool + }{ + {"identical repeat", []unparkWireComment{prior}, NotAgentWorkVerdictNeedsEnvironment, false}, + {"different verdict", []unparkWireComment{prior}, NotAgentWorkVerdictNotADefect, true}, + {"human commented since", []unparkWireComment{prior, humanComment(101, "reporter", "I can run it on my Mac")}, NotAgentWorkVerdictNeedsEnvironment, true}, + {"marker pasted by a person", []unparkWireComment{humanComment(102, "reporter", prior.Body)}, NotAgentWorkVerdictNeedsEnvironment, true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + issue := actionableIssue(18659, tc.comments...) + c, rec, dir := notAgentWorkClient(t, []unparkWireIssue{issue}) + reqPath, err := WriteIssueRequest(dir, IssueRequest{ + Kind: "comment", Repo: "org/repo", Number: 18659, Agent: "scanner", + NotAgentWork: tc.verdict, Body: "Scanner triage: needs real logins.", + }) + if err != nil { + t.Fatal(err) + } + c.ProcessIssueRequestsOnce(context.Background()) + resp := readIssueResultFile(t, reqPath) + if !resp.OK { + t.Fatalf("result = %+v", resp) + } + rec.mu.Lock() + defer rec.mu.Unlock() + posted := len(rec.posted[18659]) > 0 + if posted != tc.wantPost || resp.AlreadyExisted == tc.wantPost { + t.Fatalf("posted=%v already_existed=%v, want post=%v (posted %v)", posted, resp.AlreadyExisted, tc.wantPost, rec.posted[18659]) + } + // Suppressed or not, the issue ends parked. + if !strings.Contains(strings.Join(rec.added[18659], ","), issueNeedsHumanLabel) { + t.Fatalf("added = %v, want needs-human", rec.added[18659]) + } + }) + } +} + +func notAgentWorkParkedIssue(number int, comments ...unparkWireComment) unparkWireIssue { + issue := actionableIssue(number, comments...) + issue.Labels = []wireLabel{{Name: "kind/bug"}, {Name: issueNeedsHumanLabel}, {Name: NeedsDecisionStageLabel}} + return issue +} + +// A person's comment after the verdict lifts the hive's own needs-human and +// puts the issue back in the queue; a person's needs-human stays. +func TestSweepIssueUnparkRequeuesNotAgentWorkOnHumanComment(t *testing.T) { + verdict := botComment(200, "Scanner triage.\n"+NotAgentWorkMarker(NotAgentWorkVerdictNeedsHuman)) + reply := humanComment(201, "reporter", "Here is the log you asked for.") + for _, tc := range []struct { + name string + applier string + comments []unparkWireComment + wantLift bool + wantReply bool + }{ + {"hive park, human reply", notAgentWorkTestBot, []unparkWireComment{verdict, reply}, true, true}, + {"hive park, no reply", notAgentWorkTestBot, []unparkWireComment{verdict}, false, false}, + {"person's needs-human", "maintainer", []unparkWireComment{verdict, reply}, false, false}, + } { + t.Run(tc.name, func(t *testing.T) { + issue := notAgentWorkParkedIssue(18700, tc.comments...) + server, rec := newUnparkServer(t, "org", "repo", []unparkWireIssue{issue}, nil) + rec.timelines = map[int][]unparkWireTimelineEvent{ + 18700: {labeledAt(1, tc.applier, issueNeedsHumanLabel, time.Now().Add(-48*time.Hour))}, + } + c := newTestClient(t, server, "org", []string{"repo"}) + c.SetAppBotLogin(notAgentWorkTestBot) + + result, err := c.SweepIssueUnparkCommands(context.Background(), IssueUnparkSweepOptions{}) + if err != nil { + t.Fatalf("sweep: %v", err) + } + rec.mu.Lock() + defer rec.mu.Unlock() + lifted := strings.Contains(strings.Join(rec.removed[18700], ","), issueNeedsHumanLabel) + if lifted != tc.wantLift { + t.Fatalf("needs-human lifted=%v, want %v (removed %v)", lifted, tc.wantLift, rec.removed[18700]) + } + replied := strings.Contains(strings.Join(rec.posted[18700], "\n"), notAgentWorkRequeueMarker) + if replied != tc.wantReply { + t.Fatalf("requeue reply=%v, want %v (posted %v)", replied, tc.wantReply, rec.posted[18700]) + } + if tc.wantLift && (len(result.Unparked) != 1 || result.Unparked[0].Actor != "reporter") { + t.Fatalf("unparked = %+v", result.Unparked) + } + if strings.Contains(strings.Join(rec.added[18700], ","), HumanAckLabel) { + t.Fatalf("a re-queue is not an approval: %s must not be added (added %v)", HumanAckLabel, rec.added[18700]) + } + }) + } +} diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index 521338df66..76f40f5907 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -148,6 +148,14 @@ type IssueRequest struct { // label and removes `help wanted`. The blocked sweep lifts the label when // the PR merges or closes. BlockedOnPR int `json:"blocked_on_pr,omitempty"` // comment only + // NotAgentWork is a scanner triage verdict that the issue is not agent + // work (hivecommons/hive#18675): "not-a-defect", "needs-human" or + // "needs-environment". On a "comment" request on an issue the watcher + // posts the note once with the not-agent-work marker and parks the issue + // on `needs-human`, so it leaves stage/010-actionable and the scanner's + // work list; the same verdict again with no human comment since is + // dropped (already_existed). A marker in the body is read the same way. + NotAgentWork string `json:"not_agent_work,omitempty"` // comment only // Claim makes an "issue" request file AND claim the new issue for Agent // in one request (hivecommons/hive#17299): right after the create the // watcher performs the same claim a "claim" request does and takes @@ -708,6 +716,20 @@ func (c *Client) handleOneIssueRequestFrom(ctx context.Context, path string, src break } } + // A not-agent-work triage verdict changes the issue's state, not + // only its timeline, and is never repeated unchanged + // (hivecommons/hive#18675). + if verdict, ok := notAgentWorkVerdictFor(req, body); ok && req.BlockedOnPR == 0 { + var handled bool + handled, err = c.relayNotAgentWorkNote(ctx, req, verdict, body, &resp) + if handled { + if errors.Is(err, ErrIssueCommentBudget) { + c.denyIssueRequest(path, req, "comment refused: "+err.Error()+"; this issue already received its daily quota of hive comments, nothing more is needed on it today", nowFn) + return + } + break + } + } var parkBlocked bool if req.BlockedOnPR > 0 { settled, merged, pErr := c.pullRequestSettledDetails(ctx, req.Repo, req.BlockedOnPR) diff --git a/src/pkg/github/issue_unpark_command.go b/src/pkg/github/issue_unpark_command.go index 82e9009ba1..87bd88667f 100644 --- a/src/pkg/github/issue_unpark_command.go +++ b/src/pkg/github/issue_unpark_command.go @@ -503,6 +503,13 @@ func (c *Client) tryUnparkIssue(ctx context.Context, displayRepo, owner, repo st answered := c.answeredUnparkCommentIDs(comments) verbs := issueModelReplyVerbs(profile, issue) + // A person's comment after the hive's not-agent-work verdict puts the + // issue back in the queue (hivecommons/hive#18675). + if !labelDriven { + if acted, err := c.tryRequeueNotAgentWork(ctx, displayRepo, owner, repo, issue, comments, answered, verbs, result, audit); err != nil || acted { + return acted, err + } + } candidate, command, err := c.eligibleUnparkCommand(ctx, owner, repo, comments, answered, cutoff, labelDriven && la.enabled, verbs) if err != nil { return false, err diff --git a/src/pkg/policies/defaults/scanner-advisory.md b/src/pkg/policies/defaults/scanner-advisory.md index 34875ad955..20ef76dbe4 100644 --- a/src/pkg/policies/defaults/scanner-advisory.md +++ b/src/pkg/policies/defaults/scanner-advisory.md @@ -91,6 +91,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/pkg/policies/defaults/scanner-full.md b/src/pkg/policies/defaults/scanner-full.md index 6c644935e7..81c75f5893 100644 --- a/src/pkg/policies/defaults/scanner-full.md +++ b/src/pkg/policies/defaults/scanner-full.md @@ -26,6 +26,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/pkg/policies/defaults/scanner-holdgated.md b/src/pkg/policies/defaults/scanner-holdgated.md index 1f93905e3a..485f190bb1 100644 --- a/src/pkg/policies/defaults/scanner-holdgated.md +++ b/src/pkg/policies/defaults/scanner-holdgated.md @@ -31,6 +31,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/pkg/policies/defaults/scanner-issues.md b/src/pkg/policies/defaults/scanner-issues.md index 092b689aa9..8d0150da28 100644 --- a/src/pkg/policies/defaults/scanner-issues.md +++ b/src/pkg/policies/defaults/scanner-issues.md @@ -23,6 +23,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/pkg/policies/defaults/scanner.md b/src/pkg/policies/defaults/scanner.md index 30228d46f3..b01fc78ac2 100644 --- a/src/pkg/policies/defaults/scanner.md +++ b/src/pkg/policies/defaults/scanner.md @@ -26,6 +26,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/policies/scanner-advisory.md b/src/policies/scanner-advisory.md index 34875ad955..20ef76dbe4 100644 --- a/src/policies/scanner-advisory.md +++ b/src/policies/scanner-advisory.md @@ -91,6 +91,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/policies/scanner-full.md b/src/policies/scanner-full.md index 6c644935e7..81c75f5893 100644 --- a/src/policies/scanner-full.md +++ b/src/policies/scanner-full.md @@ -26,6 +26,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/policies/scanner-holdgated.md b/src/policies/scanner-holdgated.md index 1f93905e3a..485f190bb1 100644 --- a/src/policies/scanner-holdgated.md +++ b/src/policies/scanner-holdgated.md @@ -31,6 +31,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/policies/scanner-issues.md b/src/policies/scanner-issues.md index 092b689aa9..8d0150da28 100644 --- a/src/policies/scanner-issues.md +++ b/src/policies/scanner-issues.md @@ -23,6 +23,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. diff --git a/src/policies/scanner.md b/src/policies/scanner.md index 30228d46f3..b01fc78ac2 100644 --- a/src/policies/scanner.md +++ b/src/policies/scanner.md @@ -26,6 +26,7 @@ Follow ADR-0019 when an item is stalled (any `hold` for more than 48h, or at lea Owner rule for Hive-authored issues: do not park for sequencing, naming, numbering, config-shape, scope, or "approach A vs B" engineering questions. Decide yourself, choose the simplest additive backward-compatible option, and record `Decision taken by hive: …` in the issue body. Park only for risk categories: security posture, data loss, irreversible or public-facing behaviour, governance/policy/licensing, spend, credentials/secrets/infra the hive cannot access (owner-only), or a question about a human's intent that cannot be inferred. When you park, include `Risk: ` in the issue body. - `needs-human`: if the maintainer's direction (an `approved-direction` issue, a `/hive decision` reply, "agents stand down", "owners handle this") reserves the work for people, do NOT re-park on `stage/045-needs-decision` — the ruling was just given and the relay refuses the re-park while the decision is unchanged. Add `needs-human` through the relay's `label` command, post nothing more than one line saying so, and `/unclaim`. Never remove `needs-human`: only a person lifts it. - `blocked` (code exists only in an open PR): nothing to ship on the base branch — do not park on `stage/045-needs-decision`, claim, start, or @-mention the PR author. Post one neutral note via the issue relay's `comment` command with `--blocked-on-pr ` (body: `Blocked on #: exists only on that PR.`); the relay adds the marker and `blocked`, strips `help wanted`, and lifts it when the PR merges or closes. `/unclaim` and move on. +- `needs-human` (not agent work: a config-only condition or expected behaviour, not a defect; or work that needs a person, real logins, hardware or a live meeting): do not just comment. Post one note via the issue relay's `comment` command with `--not-agent-work ` (body: the verdict and the remedy or what a person must do). The relay adds the marker and `needs-human`, so the issue leaves the Actionable lane and your work list; an identical verdict with no human comment since is dropped (`already_existed`), and a person's later comment re-queues the issue. `/unclaim` and move on. - `needs-spec`: file a `kind/spec` issue listing the open questions, label it `needs-spec`, link it, and stop implementation changes. - `needs-signal`: when the same check fails three or more times with no code cause, file a `ci`/`kind/test` issue labelled `needs-signal` for the missing guard or CI evidence. - `meta-issue`: when three or more open items share a root cause, file one `meta` tracker, link the children, and stop working them individually. From 403b258a5014043d72c16b202d529a7d4e3bf87a Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Tue, 17 Nov 2026 08:31:07 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20scanner:=20register=20the=20?= =?UTF-8?q?not-agent-work=20note=20write=20site=20and=20reuse=20the=20labe?= =?UTF-8?q?l=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestNotificationWriteSitesInventory wants every comment producer tagged with a class, and TestDirectWriteRatchet refuses a raw RemoveLabelForIssue in a file outside its baseline. Tag relayNotAgentWorkNote as attention (and list it in docs/notifications.md), and lift needs-human through removeIssueLabel. Signed-off-by: Andy Anderson --- src/docs/notifications.md | 1 + src/pkg/github/issue_not_agent_work.go | 4 +--- src/pkg/github/notification_write_sites.go | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/docs/notifications.md b/src/docs/notifications.md index bf0588ec78..1a5e2d1a4c 100644 --- a/src/docs/notifications.md +++ b/src/docs/notifications.md @@ -524,6 +524,7 @@ without a class. Review submissions and review requests are always counted as | `github.(*Client).handleOneIssueRequestFrom` | `attention` | | | `github.(*Client).parkClankerRequestedPR` | `attention` | | | `github.(*Client).redirectToExistingPR` | `attention` | | +| `github.(*Client).relayNotAgentWorkNote` | `attention` | scanner not-agent-work verdict: posted once with its marker and parks the issue on `needs-human`; an identical repeat records a suppressed comment (#18675) | | `github.(*Client).relayScannerNote` | `attention` | scanner PR note: an unchanged or edited note records a suppressed comment (#18451) | | `github.(*Client).remindAttention` | `attention` | attention-pilot reminder: at most one per unresolved episode per `reminder_interval`; write-back gate consulted first | | `github.(*Client).resolveDuplicateFixGroup` | `attention` | | diff --git a/src/pkg/github/issue_not_agent_work.go b/src/pkg/github/issue_not_agent_work.go index e4e3a6e935..65f5bc6616 100644 --- a/src/pkg/github/issue_not_agent_work.go +++ b/src/pkg/github/issue_not_agent_work.go @@ -26,8 +26,6 @@ import ( "context" "fmt" "log/slog" - "net/http" - "net/url" "regexp" "strings" @@ -229,7 +227,7 @@ func (c *Client) tryRequeueNotAgentWork(ctx context.Context, displayRepo, owner, if out := c.needsHumanOutcome(ctx, owner, repo, number, nil); out.applier != stageengine.NeedsHumanApplierHive { return false, nil } - if _, err := c.client.Issues.RemoveLabelForIssue(ctx, owner, repo, number, url.PathEscape(issueNeedsHumanLabel)); err != nil && !githubStatusError(err, http.StatusNotFound) { + if err := c.removeIssueLabel(ctx, owner, repo, number, issueNeedsHumanLabel); err != nil { return false, fmt.Errorf("removing %s from %s/%s#%d: %w", issueNeedsHumanLabel, owner, repo, number, err) } actor := safeGetLogin(reply.GetUser()) diff --git a/src/pkg/github/notification_write_sites.go b/src/pkg/github/notification_write_sites.go index cabe24864f..394a306df0 100644 --- a/src/pkg/github/notification_write_sites.go +++ b/src/pkg/github/notification_write_sites.go @@ -89,6 +89,7 @@ var notificationWriteSites = map[string]NotificationWriteSite{ "github.(*Client).handleOneIssueRequestFrom": {Class: NotificationClassAttention}, "github.(*Client).parkClankerRequestedPR": {Class: NotificationClassAttention}, "github.(*Client).redirectToExistingPR": {Class: NotificationClassAttention}, + "github.(*Client).relayNotAgentWorkNote": {Class: NotificationClassAttention}, "github.(*Client).relayScannerNote": {Class: NotificationClassAttention}, "github.(*Client).remindAttention": {Class: NotificationClassAttention}, "github.(*Client).resolveDuplicateFixGroup": {Class: NotificationClassAttention}, From 5dbd3c7a0b91e11414eaa81849c6e9fc0b326138 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Tue, 17 Nov 2026 09:31:23 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20scanner:=20add=20the=20not-a?= =?UTF-8?q?gent-work=20park=20through=20the=20relay's=20existing=20label?= =?UTF-8?q?=20write?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The direct-write ratchet refuses a wrapper write in a file outside its baseline. The comment relay already adds one park label after a note (blocked for --blocked-on-pr); the not-agent-work verdict now reuses that write for needs-human and only submits the Parked fact itself. Signed-off-by: Andy Anderson --- src/pkg/github/issue_not_agent_work.go | 53 ++++++++++--------------- src/pkg/github/issue_request_watcher.go | 45 ++++++++++++--------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/pkg/github/issue_not_agent_work.go b/src/pkg/github/issue_not_agent_work.go index 65f5bc6616..f3fa2c440a 100644 --- a/src/pkg/github/issue_not_agent_work.go +++ b/src/pkg/github/issue_not_agent_work.go @@ -141,61 +141,50 @@ func (c *Client) isRepeatedNotAgentWorkTriage(comments []*gh.IssueComment, verdi // relayNotAgentWorkNote handles a comment request carrying a not-agent-work // verdict on an issue. handled is false for a pull request (the comment then -// takes the ordinary path). A repeat is acknowledged as already_existed and -// only re-asserts the park; otherwise the note is posted with its marker and -// the issue is parked on `needs-human`. -func (c *Client) relayNotAgentWorkNote(ctx context.Context, req IssueRequest, verdict, body string, resp *IssueResponse) (handled bool, err error) { +// takes the ordinary path). A repeat is acknowledged as already_existed; +// otherwise the note is posted with its marker. park reports that the +// caller must add `needs-human` (the relay's one label write) and then call +// parkNotAgentWorkStage. +func (c *Client) relayNotAgentWorkNote(ctx context.Context, req IssueRequest, verdict, body string, resp *IssueResponse) (handled, park bool, err error) { if c == nil || c.client == nil { - return false, ErrNoGitHubClient + return false, false, ErrNoGitHubClient } owner, name := c.splitRepo(req.Repo) issue, _, err := c.client.Issues.Get(ctx, owner, name, req.Number) if err != nil { - return true, fmt.Errorf("reading %s#%d before not-agent-work note: %w", req.Repo, req.Number, err) + return true, false, fmt.Errorf("reading %s#%d before not-agent-work note: %w", req.Repo, req.Number, err) } if issue.IsPullRequest() { - return false, nil + return false, false, nil } comments, err := c.listIssueComments(ctx, owner, name, req.Number) if err != nil { - return true, fmt.Errorf("reading comments on %s#%d before not-agent-work note: %w", req.Repo, req.Number, err) + return true, false, fmt.Errorf("reading comments on %s#%d before not-agent-work note: %w", req.Repo, req.Number, err) } - labels := issueLabelNames(issue.Labels) + park = !strings.EqualFold(issue.GetState(), "closed") && !hasIssueNeedsHumanLabel(issueLabelNames(issue.Labels)) if c.isRepeatedNotAgentWorkTriage(comments, verdict) { c.noteCommentSuppressed() if c.logger != nil { c.logger.Info("issue-request watcher: identical not-agent-work triage already on issue, not re-posting", slog.String("repo", req.Repo), slog.Int("number", req.Number), slog.String("agent", req.Agent), slog.String("verdict", verdict)) } - if !strings.EqualFold(issue.GetState(), "closed") && !hasIssueNeedsHumanLabel(labels) { - if err := c.parkNotAgentWork(ctx, req.Repo, req.Number); err != nil { - return true, err - } - } - resp.OK, resp.Number, resp.AlreadyExisted = true, req.Number, true - return true, nil + resp.AlreadyExisted = true + return true, park, nil } if err := c.CreateIssueCommentBudgeted(ctx, req.Repo, req.Number, notAgentWorkNoteBody(verdict, body)); err != nil { - return true, err + return true, false, err } - if !strings.EqualFold(issue.GetState(), "closed") && !hasIssueNeedsHumanLabel(labels) { - if err := c.parkNotAgentWork(ctx, req.Repo, req.Number); err != nil { - return true, err - } + if park { + resp.LabelsAdded = []string{issueNeedsHumanLabel} } - resp.OK, resp.Number = true, req.Number - resp.LabelsAdded = []string{issueNeedsHumanLabel} - return true, nil + return true, park, nil } -// parkNotAgentWork adds `needs-human` and submits it to the stage engine as -// a park, as the label relay does for an agent-added `needs-human`, then -// checks the park landed (a failure retries the request, and the retry is -// a suppressed repeat that only re-parks). -func (c *Client) parkNotAgentWork(ctx context.Context, repo string, number int) error { - if err := c.AddLabels(ctx, repo, number, []string{issueNeedsHumanLabel}); err != nil { - return err - } +// parkNotAgentWorkStage submits the `needs-human` the relay just added to +// the stage engine as a park, as the label relay does for an agent-added +// `needs-human`, then checks the park landed (a failure retries the +// request, and the retry is a suppressed repeat that only re-parks). +func (c *Client) parkNotAgentWorkStage(ctx context.Context, repo string, number int) error { if err := c.StageFacts().Parked(ctx, c.IssueStageRef(repo, number), issueNeedsHumanLabel); err != nil { return err } diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index 76f40f5907..30d57b242a 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -716,21 +716,10 @@ func (c *Client) handleOneIssueRequestFrom(ctx context.Context, path string, src break } } - // A not-agent-work triage verdict changes the issue's state, not - // only its timeline, and is never repeated unchanged + // parkLabel is the one label the relay adds after the note: `blocked` + // for --blocked-on-pr, `needs-human` for a not-agent-work verdict // (hivecommons/hive#18675). - if verdict, ok := notAgentWorkVerdictFor(req, body); ok && req.BlockedOnPR == 0 { - var handled bool - handled, err = c.relayNotAgentWorkNote(ctx, req, verdict, body, &resp) - if handled { - if errors.Is(err, ErrIssueCommentBudget) { - c.denyIssueRequest(path, req, "comment refused: "+err.Error()+"; this issue already received its daily quota of hive comments, nothing more is needed on it today", nowFn) - return - } - break - } - } - var parkBlocked bool + var parkLabel string if req.BlockedOnPR > 0 { settled, merged, pErr := c.pullRequestSettledDetails(ctx, req.Repo, req.BlockedOnPR) if pErr != nil { @@ -743,10 +732,24 @@ func (c *Client) handleOneIssueRequestFrom(ctx context.Context, path string, src body = blockedTargetSettledNote(req.Repo, req.BlockedOnPR, merged, body) } else { body = blockedNoteBody(req.Repo, req.BlockedOnPR, body) - parkBlocked = true + parkLabel = BlockedLabel } } - if key := relayStatusNoteKey(body); key != "" && (c.notificationsQuiet() || c.attentionPilot()) { + // A not-agent-work triage verdict changes the issue's state, not + // only its timeline, and is never repeated unchanged + // (hivecommons/hive#18675). On a PR it is an ordinary comment. + verdict, notAgentWork := notAgentWorkVerdictFor(req, body) + notAgentWork = notAgentWork && req.BlockedOnPR == 0 && err == nil + if notAgentWork { + var park bool + notAgentWork, park, err = c.relayNotAgentWorkNote(ctx, req, verdict, body, &resp) + if park { + parkLabel = issueNeedsHumanLabel + } + } + if notAgentWork { + // Posted (or suppressed) above. + } else 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 or // under the attention pilot. @@ -776,10 +779,14 @@ func (c *Client) handleOneIssueRequestFrom(ctx context.Context, path string, src c.denyIssueRequest(path, req, "comment refused: "+err.Error()+"; this issue already received its daily quota of hive comments, nothing more is needed on it today", nowFn) return } - if err == nil && parkBlocked { - err = c.AddLabels(ctx, req.Repo, req.Number, []string{BlockedLabel}) - if err == nil { + if err == nil && parkLabel != "" { + err = c.AddLabels(ctx, req.Repo, req.Number, []string{parkLabel}) + switch { + case err != nil: + case parkLabel == BlockedLabel: err = stripHelpWanted(ctx, c, req.Repo, req.Number) + default: + err = c.parkNotAgentWorkStage(ctx, req.Repo, req.Number) } } if err == nil {