From 1b65801a719e6091ab99f86888b777b5b31fe1bc Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Wed, 28 Oct 2026 20:45:39 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Activity=20Monitor:=20a=20delega?= =?UTF-8?q?ted=20adopt-supersede=20reports=20executing=20=E2=86=92=20adopt?= =?UTF-8?q?ed=20or=20could-not-adopt,=20routes=20workflow-path=20PRs=20to?= =?UTF-8?q?=20the=20workflows=20capability=20blocker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let hive decide → adopt-supersede settled the operator-action ledger as applied ("done") as soon as the adoption/supersede request label landed, and the ✓ hover kept saying so while nothing happened. - hivecommons/hive#14822 edits .github/workflows: the adoption engine's fence refused the supersession (adoption-stalled:contributor-lane: workflow-path) and the row fell back to a bare Needs human decision. The policy now decides such PRs as capability-gap (recommend-only), the ledger records blocked, and the badge names the capability:workflows-permission blocker with what a person can do. - hivecommons/hive#14947: the re-adoption after the copy #14977 was closed was replayed by the mutation journal; that fix landed in hivecommons/hive#15209 (prior_copy claim input, replayed provenance resolved). This PR layers the ledger / hover states over it. - settledDelegatedOutcome: adopt-supersede → executing, dedup → no-effect, capability-gap → blocked. The tracker derives the ✓ state from the stage record (adopted as #N / could not adopt / still executing / stuck) and exposes progress, blocker and human to the SPA hover. Fixes hivecommons/hive#15188 Signed-off-by: Andrew Anderson --- ...ixed-adopt-supersede-execution-feedback.md | 1 + dashboard/openapi.json | 21 +- .../api_repo_item_decide_delegated.go | 16 +- .../api_repo_item_decide_delegated_test.go | 93 ++++++ .../dashboard/delegated_decision_effect.go | 3 + src/pkg/dashboard/operator_actions.go | 273 ++++++++++++++++-- src/pkg/dashboard/operator_actions_test.go | 121 ++++++++ src/pkg/dashboard/static/index.html | 28 +- src/pkg/delegatedecision/decision_glossary.go | 54 ++-- src/pkg/delegatedecision/policy.go | 20 +- src/pkg/delegatedecision/policy_test.go | 8 + 11 files changed, 579 insertions(+), 59 deletions(-) create mode 100644 changelog.d/fixed-adopt-supersede-execution-feedback.md diff --git a/changelog.d/fixed-adopt-supersede-execution-feedback.md b/changelog.d/fixed-adopt-supersede-execution-feedback.md new file mode 100644 index 0000000000..93e28f08b8 --- /dev/null +++ b/changelog.d/fixed-adopt-supersede-execution-feedback.md @@ -0,0 +1 @@ +- A delegated `adopt-supersede` decision no longer reports "done" when only the request label landed: the Activity Monitor ✓ now reads "decided: adopt-supersede · executing…" until the adoption engine records the copy ("adopted as #N") or definitively cannot ("could not adopt: ", with what a person can do). A PR that edits `.github/workflows` is decided as a capability gap and routed to the `capability:workflows-permission` blocker instead of flipping back to a bare Needs human decision; re-adoption after a closed copy surviving the mutation journal landed in [#15209](https://github.com/hivecommons/hive/pull/15209) ([#15188](https://github.com/hivecommons/hive/issues/15188)). diff --git a/dashboard/openapi.json b/dashboard/openapi.json index c699ec23aa..2725ac7801 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -28354,12 +28354,27 @@ "applied", "no-op", "failed", - "superseded-by-state-change" + "superseded-by-state-change", + "executing", + "no-effect", + "blocked" ] }, "detail": { "type": "string" }, + "progress": { + "type": "string", + "description": "for an executing/blocked decision: what the worker has done so far or why it could not (e.g. \"adopted as #N\", \"could not adopt: …\")" + }, + "blocker": { + "type": "string", + "description": "capability-blocker slug holding the decision (e.g. capability:workflows-permission)" + }, + "human": { + "type": "string", + "description": "what, if anything, a person can do now" + }, "head_sha": { "type": "string" }, @@ -28373,7 +28388,9 @@ "addressed", "stuck", "pending", - "failed" + "failed", + "executing", + "blocked" ] }, "stuck_after_seconds": { diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated.go b/src/pkg/dashboard/api_repo_item_decide_delegated.go index 96b78f59cc..68f467a819 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated.go @@ -18,6 +18,7 @@ import ( "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/delegatedecision" ghpkg "github.com/hivecommons/hive/pkg/github" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -612,7 +613,9 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb for _, f := range files { if !delegatedLowRiskPath(f.GetFilename()) { in.LowRiskPaths = false - break + } + if delegatedWorkflowPath(f.GetFilename()) { + in.WorkflowPath = true } } } @@ -637,6 +640,9 @@ func (s *Server) gatherDelegatedInput(ctx context.Context, repoFull string, numb if in.Kind == delegatedecision.KindPR && !in.HiveAuthored { in.AdoptionGraceElapsed = s.delegatedAdoptionGraceElapsed(repoFull, number) } + if strings.Contains(lowerReason, stageengineprstage.ContributorLaneReasonWorkflowPath) { + in.WorkflowPath = true + } in.ReporterTrustHold = strings.Contains(lowerReason, "reporter-trust") || strings.Contains(lowerReason, "reporter trust") in.DCOMissing = strings.Contains(lowerReason, "dco") return in, nil @@ -679,6 +685,14 @@ func delegatedHeadCIGreen(ctx context.Context, api *gh.Client, owner, repoName s return len(summary.Red) == 0 && summary.Pending == 0 && summary.Green > 0, nil } +// delegatedWorkflowPath reports a file under .github/workflows: the adoption +// fence refuses to publish such edits from the App (no `workflows` +// permission), so an adopt-supersede on the PR cannot execute +// (hivecommons/hive#15188). +func delegatedWorkflowPath(path string) bool { + return strings.HasPrefix(strings.ToLower(strings.TrimSpace(path)), ".github/workflows/") +} + // delegatedLowRiskPath reports a file whose change the policy calls low-risk: // CI / workflow config, docs and text, changelog fragments. func delegatedLowRiskPath(path string) bool { diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_test.go b/src/pkg/dashboard/api_repo_item_decide_delegated_test.go index f2c5d96628..46efb2687c 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_test.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_test.go @@ -13,6 +13,7 @@ import ( "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/delegatedecision" "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" ) func newDelegatedServer(t *testing.T, mock *repoItemDecisionMock) *Server { @@ -684,3 +685,95 @@ func TestDelegatedAsyncFanOutSettlesOperatorAction(t *testing.T) { } } } + +// hivecommons/hive#15188: a delegated adopt-supersede is not "done" when +// the request label lands. The ledger reads `executing` until the adoption +// engine records a copy, then "adopted as #N"; a workflow-path PR is a +// capability gap and routes to the workflows blocker instead of a bare +// Needs human decision. +func TestDelegatedAdoptSupersedeReportsExecutingUntilAdopted(t *testing.T) { + pinDelegatedClock(t, "2026-10-28T14:23:00Z") + now := time.Date(2026, 10, 28, 14, 23, 0, 0, time.UTC) + mock := &repoItemDecisionMock{prForeign: true, prRedCI: true, prMergeState: "blocked", prLabels: []string{"stage/085-needs-decision", "needs-human"}} + srv := newDelegatedServer(t, mock) + srv.deps.Config.Governor.Labels.Stage.Adoption.Enabled = boolPtr(true) + srv.operatorActionStore = newOperatorActionStore("") + srv.stageStore = stagelabels.NewStore("", func() time.Time { return now }) + key := stagelabels.Key("testorg/testrepo", 8) + srv.stageStore.Observe(key, stagelabels.NeedsDecision, "adoption-stalled:contributor-lane:ci-red") + + w := postDelegated(t, srv, 8, "writer", `{"type":"pr","reason":"adoption-stalled:contributor-lane:ci-red","caption":"adoption stalled"}`, nil) + if w.Code != http.StatusOK { + t.Fatalf("code=%d body=%s", w.Code, w.Body.String()) + } + job := decodeDelegatedJob(t, w) + if job.Decision == nil || job.Decision.Verdict != delegatedecision.VerdictAdoptSupersede { + t.Fatalf("decision = %+v err=%s", job.Decision, job.Error) + } + if !strings.Contains(strings.Join(mock.added, ","), delegatedecision.LabelAdoptSupersede) { + t.Fatalf("request label not queued: %v", mock.added) + } + acts := srv.operatorActions().List("testorg/testrepo", 8) + if len(acts) != 1 || acts[0].Outcome != operatorActionOutcomeExecuting || !strings.Contains(acts[0].Detail, "executing") { + t.Fatalf("ledger after decision = %+v", acts) + } + + // Before the engine runs: the row says the hive is carrying it out. + items := []StageTrackerItem{{Repo: "testorg/testrepo", Number: 8, Stage: 85, Head: "aaa"}} + srv.applyOperatorActions(items, now.Add(time.Minute)) + last := items[0].LastOperatorAction + if last == nil || last.State != operatorActionStateExecuting || last.Progress == "" || last.Human != "" { + t.Fatalf("row before adoption = %+v", last) + } + + // The adoption engine opened the copy: the same record now reads + // "adopted as #91" and is addressed, whatever stage the row sits at. + srv.stageStore.MarkAdopted(key, "aaa", 91, now.Add(2*time.Minute)) + srv.invalidateStageTrackerCache() + items = []StageTrackerItem{{Repo: "testorg/testrepo", Number: 8, Stage: 85, Head: "aaa"}} + srv.applyOperatorActions(items, now.Add(3*time.Minute)) + last = items[0].LastOperatorAction + if last == nil || last.State != operatorActionStateAddressed || last.Outcome != operatorActionOutcomeApplied || !strings.Contains(last.Progress, "adopted as #91") { + t.Fatalf("row after adoption = %+v", last) + } + + // The engine refused the head instead (workflow path): blocked on the + // workflows capability, with what a person can do. + srv.stageStore.ClearAdoption(key) + srv.stageStore.MarkAdoptionEscalated(key, "aaa", "adoption-stalled:contributor-lane:workflow-path") + srv.invalidateStageTrackerCache() + items = []StageTrackerItem{{Repo: "testorg/testrepo", Number: 8, Stage: 85, Head: "aaa"}} + srv.applyOperatorActions(items, now.Add(3*time.Minute)) + last = items[0].LastOperatorAction + if last == nil || last.State != operatorActionStateBlocked || last.Blocker != operatorActionBlockerWorkflows || last.Human == "" || !strings.Contains(last.Progress, "could not adopt") { + t.Fatalf("row after refusal = %+v", last) + } +} + +// A PR that edits .github/workflows gets a capability-gap recommendation, +// not an adopt-supersede the engine would refuse; the ledger is `blocked`. +func TestDelegatedWorkflowPathIsCapabilityGap(t *testing.T) { + pinDelegatedClock(t, "2026-10-28T14:23:00Z") + mock := &repoItemDecisionMock{prForeign: true, prRedCI: true, prMergeState: "blocked", prLabels: []string{"stage/085-needs-decision", "needs-human"}} + srv := newDelegatedServer(t, mock) + srv.deps.Config.Governor.Labels.Stage.Adoption.Enabled = boolPtr(true) + srv.operatorActionStore = newOperatorActionStore("") + w := postDelegated(t, srv, 8, "writer", `{"type":"pr","reason":"adoption-stalled:contributor-lane:workflow-path","caption":"adoption stalled: contributor lane: workflow path"}`, nil) + if w.Code != http.StatusOK { + t.Fatalf("code=%d body=%s", w.Code, w.Body.String()) + } + job := decodeDelegatedJob(t, w) + if job.Decision == nil || job.Decision.Rule != delegatedecision.RuleCapabilityGap || !job.Decision.KeepsPark { + t.Fatalf("decision = %+v err=%s", job.Decision, job.Error) + } + if strings.Contains(strings.Join(mock.added, ","), delegatedecision.LabelAdoptSupersede) { + t.Fatalf("adoption queued despite the capability gap: %v", mock.added) + } + acts := srv.operatorActions().List("testorg/testrepo", 8) + if len(acts) != 1 || acts[0].Outcome != operatorActionOutcomeBlocked { + t.Fatalf("ledger = %+v", acts) + } + if got := srv.delegatedStuckWhy(delegatedecision.Input{Kind: delegatedecision.KindPR, WorkflowPath: true}, delegatedecision.Decision{Verdict: delegatedecision.VerdictAdoptSupersede}, delegatedDecisionRequest{}, delegatedPriorState{Found: true}); got != delegatedecision.GlossaryWorkflowPath { + t.Fatalf("stuck why = %q", got) + } +} diff --git a/src/pkg/dashboard/delegated_decision_effect.go b/src/pkg/dashboard/delegated_decision_effect.go index daa64eb823..47580aab17 100644 --- a/src/pkg/dashboard/delegated_decision_effect.go +++ b/src/pkg/dashboard/delegated_decision_effect.go @@ -104,6 +104,9 @@ func (s *Server) delegatedStuckWhy(in delegatedecision.Input, d delegatedecision return false } if d.Verdict == delegatedecision.VerdictAdoptSupersede { + if in.WorkflowPath { + return delegatedecision.GlossaryWorkflowPath + } if in.ContributorOnline { return delegatedecision.GlossaryAuthorOnline } diff --git a/src/pkg/dashboard/operator_actions.go b/src/pkg/dashboard/operator_actions.go index 1358421987..927dac5606 100644 --- a/src/pkg/dashboard/operator_actions.go +++ b/src/pkg/dashboard/operator_actions.go @@ -13,6 +13,8 @@ import ( "sync" "time" + "github.com/hivecommons/hive/pkg/delegatedecision" + stageengineprstage "github.com/hivecommons/hive/pkg/stageengine/prstage" "github.com/hivecommons/hive/pkg/stagelabels" ) @@ -60,6 +62,20 @@ const ( operatorActionOutcomeApplied = "applied" operatorActionOutcomeNoOp = "no-op" operatorActionOutcomeFailed = "failed" + // `executing`: the delegated decision is recorded and handed to a + // worker (today: adopt-supersede → the adoption engine's next stage + // pass). It is not `applied`: the ledger reports "done" only once the + // worker's outcome is on the stage record — "adopted as #N" — or it + // definitively failed (hivecommons/hive#15188). Detail carries the + // verdict the worker is executing. + operatorActionOutcomeExecuting = "executing" + // `no-effect`: the dedup path found the earlier decision and judged + // that it never took effect; Detail is the plain-words why. + operatorActionOutcomeNoEffect = "no-effect" + // `blocked`: the decision cannot take effect for a capability the hive + // lacks (the GitHub App has no `workflows` permission); Detail says so + // and the derived view names the blocker (hivecommons/hive#15099). + operatorActionOutcomeBlocked = "blocked" // Derived only: a failed / no-op action whose item moved stage anyway. operatorActionOutcomeSuperseded = "superseded-by-state-change" @@ -69,6 +85,15 @@ const ( operatorActionStateStuck = "stuck" operatorActionStateFailed = "failed" operatorActionStatePending = "pending" + // executing: a worker is carrying the decision out; blocked: it cannot + // be carried out until a person closes a capability gap. + operatorActionStateExecuting = "executing" + operatorActionStateBlocked = "blocked" + + // operatorActionBlockerWorkflows is the blocker slug for "the App lacks + // the `workflows` permission" — the kind name the capability-blocker + // model uses (hivecommons/hive#15134), so the two compose. + operatorActionBlockerWorkflows = "capability:workflows-permission" operatorActionsMaxPerItem = 20 operatorActionNoteMax = 280 @@ -378,17 +403,16 @@ func operatorActionOutcome(status int, body []byte) (outcome, detail, head strin } } if d, ok := resp["decision"].(map[string]any); ok && status == http.StatusOK { - if v, _ := d["verdict"].(string); v != "" { - detail = "hive decided: " + v - if rule, _ := d["rule"].(string); delegatedHumanMergeDecidedPath(rule) != "" { - detail = "hive decided: " + delegatedHumanMergeDecidedPath(rule) - } else if rule != "" { - detail += " (" + rule + ")" - } - } if st, _ := resp["status"].(string); st == delegatedJobStatusFailed { return operatorActionOutcomeFailed, str("error"), head, true } + if v, _ := d["verdict"].(string); v != "" { + rule, _ := d["rule"].(string) + if o, dd, ok := delegatedVerdictOutcome(v, rule); ok { + return o, dd, head, true + } + detail = delegatedDecidedDetail(v, rule) + } } return operatorActionOutcomeApplied, detail, head, true case status == http.StatusConflict: @@ -488,32 +512,87 @@ func (s *Server) settleOperatorAction(repoFull string, number int, job *delegate if s == nil || job == nil { return } - outcome, detail := operatorActionOutcomeApplied, "" + outcome, detail := settledDelegatedOutcome(job) + if _, err := s.operatorActions().Settle(repoFull, number, operatorActionLetHiveDecide, outcome, detail); err != nil && s.logger != nil { + s.logger.Warn("operator action ledger write failed", "path", operatorActionsPath, "error", err) + } + s.invalidateStageTrackerCache() +} + +// settledDelegatedOutcome maps a finished delegated job onto the ledger's +// outcome word and detail. The order matters: a failed job wins; a dedup +// no-op / no-effect result wins over the verdict; an adopt-supersede that +// executed is `executing`, because adding the request label is not the +// adoption (hivecommons/hive#15188); a capability-gap recommendation is +// `blocked`; everything else is `applied`. +func settledDelegatedOutcome(job *delegatedDecisionJob) (outcome, detail string) { + outcome, detail = operatorActionOutcomeApplied, "" + verdict, rule := "", "" if job.Decision != nil { - detail = "hive decided: " + string(job.Decision.Verdict) - if p := delegatedHumanMergeDecidedPath(job.Decision.Rule); p != "" { - detail = "hive decided: " + p - } else if job.Decision.Rule != "" { - detail += " (" + job.Decision.Rule + ")" - } + verdict, rule = string(job.Decision.Verdict), job.Decision.Rule + detail = delegatedDecidedDetail(verdict, rule) if job.Decision.KeepsPark { detail += " — kept for the owner" } } - if job.Result != nil && job.Result.Action == rowActionNoop { - verdict := "" - if job.Decision != nil { - verdict = string(job.Decision.Verdict) - } - outcome, detail = operatorActionOutcomeNoOp, operatorActionNoopDetail(verdict, job.Result) + switch { + case job.Status == delegatedJobStatusFailed: + return operatorActionOutcomeFailed, job.Error + case job.Result != nil && job.Result.Action == rowActionNoEffect: + return operatorActionOutcomeNoEffect, operatorActionNoEffectDetail(job.Result) + case job.Result != nil && job.Result.Action == rowActionNoop: + return operatorActionOutcomeNoOp, operatorActionNoopDetail(verdict, job.Result) } - if job.Status == delegatedJobStatusFailed { - outcome, detail = operatorActionOutcomeFailed, job.Error + if o, d, ok := delegatedVerdictOutcome(verdict, rule); ok { + return o, d } - if _, err := s.operatorActions().Settle(repoFull, number, operatorActionLetHiveDecide, outcome, detail); err != nil && s.logger != nil { - s.logger.Warn("operator action ledger write failed", "path", operatorActionsPath, "error", err) + return outcome, detail +} + +// delegatedDecidedDetail is the ✓ hover's "hive decided: …" sentence: the +// human-merge rules spell their path, every other rule is named in brackets. +func delegatedDecidedDetail(verdict, rule string) string { + if p := delegatedHumanMergeDecidedPath(rule); p != "" { + return "hive decided: " + p } - s.invalidateStageTrackerCache() + detail := "hive decided: " + verdict + if rule != "" { + detail += " (" + rule + ")" + } + return detail +} + +// delegatedVerdictOutcome is shared by the synchronous response path and +// the async settle: a capability-gap recommendation is `blocked`; an +// adopt-supersede is `executing` until the adoption engine records a copy +// or a refusal (hivecommons/hive#15188). ok is false for every other verdict. +func delegatedVerdictOutcome(verdict, rule string) (outcome, detail string, ok bool) { + switch { + case rule == delegatedecision.RuleCapabilityGap: + return operatorActionOutcomeBlocked, "decided: " + verdict + " (" + rule + ") — " + delegatedecision.Plain(delegatedecision.GlossaryWorkflowPath), true + case verdict == string(delegatedecision.VerdictAdoptSupersede): + if p := delegatedHumanMergeDecidedPath(rule); p != "" { + return operatorActionOutcomeExecuting, "hive decided: " + p, true + } + return operatorActionOutcomeExecuting, "decided: " + verdict + " (" + rule + ") · executing…", true + } + return "", "", false +} + +// operatorActionNoEffectDetail is the dedup path's own sentence ("Hive +// decided … but it hasn't taken effect: "), minus the leading verb. +func operatorActionNoEffectDetail(res *RowActionResult) string { + if res == nil { + return "the earlier decision has not taken effect" + } + out := strings.TrimSpace(res.Outcome) + if out == "" { + out = "the earlier decision has not taken effect" + if res.Why != "" { + out += ": " + delegatedecision.Plain(res.Why) + } + } + return strings.TrimSuffix(out, ".") } // operatorActionNoopDetail spells a repeat decision out in plain words: @@ -558,6 +637,105 @@ type StageTrackerOperatorAction struct { // action, oldest first (capped), so the row can tell the decision trail // — owner's choice, then the hive's moves — in order. Followed []StageTrackerHop `json:"followed,omitempty"` + // Progress is, for an `executing` decision, what the worker has done + // with it so far in plain words: "adopted as #N", "could not adopt: + // …", or that it is still being carried out (hivecommons/hive#15188). + Progress string `json:"progress,omitempty"` + // Blocker names the capability gap holding the decision, as the + // capability-blocker model spells it (capability:workflows-permission), + // when State is blocked. + Blocker string `json:"blocker,omitempty"` + // Human is what, if anything, a person can do now — "" when nothing. + Human string `json:"human,omitempty"` +} + +// operatorActionExecution is what the stage record says about the worker +// side of an `executing` decision: the adoption engine's outcome for an +// adopt-supersede (hivecommons/hive#15188). +type operatorActionExecution struct { + // AdoptedBy is the open hive copy (> 0 once the adoption ran). + AdoptedBy int + // AdoptedByState qualifies AdoptedBy (stageTrackerAdoptedByState). + AdoptedByState string + // Refused is the adoption engine's terminal refusal slug for this head + // ("adoption-stalled:contributor-lane:workflow-path"), "" when none. + Refused string + // Superseded: the original was closed in favour of the copy. + Superseded bool +} + +// operatorActionExecutionFor reads the execution state off the tracker item +// and its stage record. +func operatorActionExecutionFor(it StageTrackerItem, rec stagelabels.Record, hasRec bool) operatorActionExecution { + out := operatorActionExecution{AdoptedBy: it.AdoptedBy, AdoptedByState: it.AdoptedByState} + if !hasRec { + if strings.HasPrefix(it.Reason, stagelabels.LaneReasonAdoptionStalledPrefix) { + out.Refused = it.Reason + } + return out + } + if rec.AdoptedBy > 0 { + out.AdoptedBy, out.AdoptedByState = rec.AdoptedBy, stageTrackerAdoptedByState(rec) + } + out.Superseded = rec.Superseded() + if rec.AdoptEscalatedReason != "" && (rec.AdoptEscalatedHead == "" || it.Head == "" || rec.AdoptEscalatedHead == it.Head) { + out.Refused = rec.AdoptEscalatedReason + } else if strings.HasPrefix(it.Reason, stagelabels.LaneReasonAdoptionStalledPrefix) { + out.Refused = it.Reason + } + return out +} + +// operatorActionExecutingView fills State / Progress / Blocker / Human for +// an `executing` adopt-supersede from the worker's recorded outcome. +func operatorActionExecutingView(out *StageTrackerOperatorAction, exec operatorActionExecution, sinceAction time.Duration, stuckAfter time.Duration) { + switch { + case exec.Refused != "" && strings.Contains(exec.Refused, stageengineprstage.ContributorLaneReasonWorkflowPath): + out.State = operatorActionStateBlocked + out.Blocker = operatorActionBlockerWorkflows + out.Progress = "could not adopt: " + delegatedecision.Plain(delegatedecision.GlossaryWorkflowPath) + out.Human = "Grant the hive's GitHub App the `workflows` permission and re-run the decision, or rebase and merge it yourself on GitHub, or close it as superseded." + case exec.Refused != "": + out.State = operatorActionStateFailed + out.Progress = "could not adopt: " + delegatedecision.Plain(exec.Refused) + out.Human = "Re-run the decision once the cause is cleared, or act on GitHub." + case exec.AdoptedBy > 0 && exec.AdoptedByState == stageTrackerAdoptedClosedTwice: + out.State = operatorActionStateFailed + out.Progress = "could not adopt: the hive's copies (last #" + strconv.Itoa(exec.AdoptedBy) + ") were closed without merging twice; the hive stopped opening copies" + out.Human = "Reopen one of the copies, close this PR, or say what should happen." + case exec.AdoptedBy > 0 && exec.AdoptedByState == stageTrackerAdoptedCopyFailed: + out.State = operatorActionStateFailed + out.Progress = "could not adopt: the hive's copy #" + strconv.Itoa(exec.AdoptedBy) + " could not be finished" + out.Human = "Re-run the decision, or act on GitHub." + case exec.AdoptedBy > 0 && exec.AdoptedByState == stageTrackerAdoptedClosed: + out.State = operatorActionStateExecuting + out.Progress = "the hive's copy #" + strconv.Itoa(exec.AdoptedBy) + " was closed without merging; the hive is opening a fresh one" + case exec.AdoptedBy > 0: + out.State = operatorActionStateAddressed + out.Outcome = operatorActionOutcomeApplied + out.Progress = "adopted as #" + strconv.Itoa(exec.AdoptedBy) + if exec.Superseded { + out.Progress += " — this PR is closed in its favour" + } else { + out.Progress += " — the hive's copy carries the work; this PR closes when it merges" + } + case sinceAction >= stuckAfter: + out.State = operatorActionStateStuck + out.Progress = "no adoption on record " + formatSinceWords(sinceAction) + " after the decision — " + delegatedecision.Plain(delegatedecision.GlossaryAdoptionUndone) + out.Human = "Re-run the decision, or act on GitHub." + default: + out.State = operatorActionStateExecuting + out.Progress = delegatedecision.Plain(delegatedecision.GlossaryAdoptionExecuting) + } +} + +// formatSinceWords renders a duration the way the badge does ("12 min", +// "2 h"). +func formatSinceWords(d time.Duration) string { + if d < time.Hour { + return strconv.Itoa(int(d/time.Minute)) + " min" + } + return strconv.Itoa(int(d/time.Hour)) + " h" } const operatorActionFollowedMax = 5 @@ -595,6 +773,12 @@ func operatorActionAddressed(a OperatorAction, stage int, modifiers []string) bo // stageTrackerOperatorAction derives the row view of the newest record. func stageTrackerOperatorAction(actions []OperatorAction, stage int, modifiers []string, history []StageTrackerHop, now time.Time, stuckAfter time.Duration) *StageTrackerOperatorAction { + return stageTrackerOperatorActionExec(actions, stage, modifiers, history, now, stuckAfter, operatorActionExecution{}) +} + +// stageTrackerOperatorActionExec is stageTrackerOperatorAction with the +// worker-side execution state for an `executing` decision. +func stageTrackerOperatorActionExec(actions []OperatorAction, stage int, modifiers []string, history []StageTrackerHop, now time.Time, stuckAfter time.Duration, exec operatorActionExecution) *StageTrackerOperatorAction { if len(actions) == 0 { return nil } @@ -608,9 +792,27 @@ func stageTrackerOperatorAction(actions []OperatorAction, stage int, modifiers [ switch { case a.Outcome == operatorActionOutcomePending: out.State = operatorActionStatePending + case a.Outcome == operatorActionOutcomeExecuting: + // The worker's record decides, not the stage: an adopted PR sits + // at 074 or stays at 085 with its copy open; a refused one is back + // at 085 — "left the stage" would misread both. + var since time.Duration + if !a.At.IsZero() { + since = now.Sub(a.At) + } + operatorActionExecutingView(out, exec, since, stuckAfter) + case a.Outcome == operatorActionOutcomeBlocked: + out.State = operatorActionStateBlocked + out.Blocker = operatorActionBlockerWorkflows + out.Progress = "could not adopt: " + delegatedecision.Plain(delegatedecision.GlossaryWorkflowPath) + out.Human = "Grant the hive's GitHub App the `workflows` permission and re-run the decision, or rebase and merge it yourself on GitHub, or close it as superseded." + case a.Outcome == operatorActionOutcomeNoEffect && !addressed: + out.State = operatorActionStateStuck + out.Progress = a.Detail + out.Human = "Re-run the decision, or act on GitHub." case addressed: out.State = operatorActionStateAddressed - if a.Outcome == operatorActionOutcomeFailed || a.Outcome == operatorActionOutcomeNoOp { + if a.Outcome == operatorActionOutcomeFailed || a.Outcome == operatorActionOutcomeNoOp || a.Outcome == operatorActionOutcomeNoEffect { out.Outcome = operatorActionOutcomeSuperseded } case a.Outcome == operatorActionOutcomeFailed: @@ -639,6 +841,7 @@ func (s *Server) applyOperatorActions(items []StageTrackerItem, now time.Time) { have[k] = true } stuckAfter := operatorActionStuckAfter() + store := s.stageStoreOrShared() for i := range items { it := &items[i] if !have[operatorActionKey(it.Repo, it.Number)] { @@ -646,7 +849,12 @@ func (s *Server) applyOperatorActions(items []StageTrackerItem, now time.Time) { } actions := st.List(it.Repo, it.Number) it.OperatorActionCount = len(actions) - it.LastOperatorAction = stageTrackerOperatorAction(actions, it.Stage, it.Modifiers, it.History, now, stuckAfter) + var exec operatorActionExecution + if len(actions) > 0 && actions[len(actions)-1].Outcome == operatorActionOutcomeExecuting { + rec, hasRec := store.Get(stagelabels.Key(it.Repo, it.Number)) + exec = operatorActionExecutionFor(*it, rec, hasRec) + } + it.LastOperatorAction = stageTrackerOperatorActionExec(actions, it.Stage, it.Modifiers, it.History, now, stuckAfter, exec) } } @@ -676,15 +884,20 @@ func (s *Server) handleRepoItemDetail(w http.ResponseWriter, r *http.Request) { resp := repoItemDetailResponse{Repo: repoFull, Number: number, OperatorActions: actions, OperatorActionCount: len(actions)} var modifiers []string var history []StageTrackerHop - if rec, ok := s.stageStoreOrShared().Get(stagelabels.Key(repoFull, number)); ok && rec.Stage != stagelabels.None { + var exec operatorActionExecution + rec, hasRec := s.stageStoreOrShared().Get(stagelabels.Key(repoFull, number)) + if hasRec && rec.Stage != stagelabels.None { resp.Stage = rec.Stage.Number() resp.StageSlug = rec.Stage.Slug() history = stageTrackerHistory(rec) } if it, ok := s.stageTrackerItemFor(repoFull, number); ok { resp.Stage, resp.StageSlug, modifiers, history = it.Stage, it.StageSlug, it.Modifiers, it.History + exec = operatorActionExecutionFor(it, rec, hasRec) + } else { + exec = operatorActionExecutionFor(StageTrackerItem{Repo: repoFull, Number: number}, rec, hasRec) } - resp.LastOperatorAction = stageTrackerOperatorAction(actions, resp.Stage, modifiers, history, time.Now().UTC(), operatorActionStuckAfter()) + resp.LastOperatorAction = stageTrackerOperatorActionExec(actions, resp.Stage, modifiers, history, time.Now().UTC(), operatorActionStuckAfter(), exec) jsonResponse(w, resp) } diff --git a/src/pkg/dashboard/operator_actions_test.go b/src/pkg/dashboard/operator_actions_test.go index ad34dffbcc..54f90a6b7c 100644 --- a/src/pkg/dashboard/operator_actions_test.go +++ b/src/pkg/dashboard/operator_actions_test.go @@ -339,3 +339,124 @@ func stageTrackerActedJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerActedMatches"), }, "\n") } + +// hivecommons/hive#15188: an adopt-supersede that only queued the request +// label is `executing`, not `applied`; a dedup no-effect is `no-effect`; a +// capability-gap recommendation is `blocked`. +func TestSettledDelegatedOutcomeDistinguishesExecution(t *testing.T) { + adopt := &delegatedecision.Decision{Verdict: delegatedecision.VerdictAdoptSupersede, Rule: "contributor-offline"} + cases := []struct { + name string + job *delegatedDecisionJob + outcome string + detail string + }{ + {"adopt queued", &delegatedDecisionJob{Status: delegatedJobStatusDone, Decision: adopt, Result: &RowActionResult{Action: "adopt-supersede"}}, operatorActionOutcomeExecuting, "decided: adopt-supersede (contributor-offline) · executing…"}, + {"adopt no effect", &delegatedDecisionJob{Status: delegatedJobStatusDone, Decision: adopt, Result: &RowActionResult{Action: rowActionNoEffect, Outcome: "Hive decided X but it hasn't taken effect: the copy was closed."}}, operatorActionOutcomeNoEffect, "Hive decided X but it hasn't taken effect: the copy was closed"}, + {"capability gap", &delegatedDecisionJob{Status: delegatedJobStatusDone, Decision: &delegatedecision.Decision{Verdict: delegatedecision.VerdictRecommendOnly, Rule: delegatedecision.RuleCapabilityGap, KeepsPark: true}}, operatorActionOutcomeBlocked, ""}, + {"failed", &delegatedDecisionJob{Status: delegatedJobStatusFailed, Error: "boom", Decision: adopt}, operatorActionOutcomeFailed, "boom"}, + {"approve applied", &delegatedDecisionJob{Status: delegatedJobStatusDone, Decision: &delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove, Rule: "default-release"}}, operatorActionOutcomeApplied, "hive decided: approve (default-release)"}, + } + for _, c := range cases { + outcome, detail := settledDelegatedOutcome(c.job) + if outcome != c.outcome || (c.detail != "" && detail != c.detail) { + t.Errorf("%s: outcome=%q detail=%q, want %q / %q", c.name, outcome, detail, c.outcome, c.detail) + } + if c.name == "capability gap" && !strings.Contains(detail, "workflows") { + t.Errorf("capability gap detail should name the permission: %q", detail) + } + } +} + +// The ✓ for an `executing` adopt-supersede follows the worker, not the +// stage: adopted → addressed "adopted as #N"; a workflow-path refusal → +// blocked on the workflows capability with a human next step; a closed copy +// → still executing; nothing on record past the window → stuck. +func TestStageTrackerOperatorActionExecutingFollowsTheWorker(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + window := 30 * time.Minute + rec := func(ago time.Duration) []OperatorAction { + return []OperatorAction{{Action: operatorActionLetHiveDecide, Actor: "o", At: now.Add(-ago), Outcome: operatorActionOutcomeExecuting, Detail: "decided: adopt-supersede (contributor-offline) · executing…", Stage: 85}} + } + cases := []struct { + name string + actions []OperatorAction + stage int + exec operatorActionExecution + wantSt string + wantOutc string + progress string + blocker string + human bool + }{ + {"just decided", rec(2 * time.Minute), 85, operatorActionExecution{}, operatorActionStateExecuting, operatorActionOutcomeExecuting, "", "", false}, + {"adopted", rec(5 * time.Minute), 74, operatorActionExecution{AdoptedBy: 14977}, operatorActionStateAddressed, operatorActionOutcomeApplied, "adopted as #14977", "", false}, + {"adopted and superseded", rec(5 * time.Minute), 85, operatorActionExecution{AdoptedBy: 14977, Superseded: true}, operatorActionStateAddressed, operatorActionOutcomeApplied, "closed in its favour", "", false}, + {"copy closed, reopening", rec(5 * time.Minute), 85, operatorActionExecution{AdoptedBy: 14977, AdoptedByState: stageTrackerAdoptedClosed}, operatorActionStateExecuting, operatorActionOutcomeExecuting, "opening a fresh one", "", false}, + {"copies closed twice", rec(5 * time.Minute), 85, operatorActionExecution{AdoptedBy: 14977, AdoptedByState: stageTrackerAdoptedClosedTwice}, operatorActionStateFailed, operatorActionOutcomeExecuting, "could not adopt", "", true}, + {"workflow path refused", rec(5 * time.Minute), 85, operatorActionExecution{Refused: "adoption-stalled:contributor-lane:workflow-path"}, operatorActionStateBlocked, operatorActionOutcomeExecuting, "could not adopt", operatorActionBlockerWorkflows, true}, + {"other refusal", rec(5 * time.Minute), 85, operatorActionExecution{Refused: "adoption-stalled:contributor-lane:child-closed-twice"}, operatorActionStateFailed, operatorActionOutcomeExecuting, "could not adopt", "", true}, + {"nothing on record past window", rec(2 * time.Hour), 85, operatorActionExecution{}, operatorActionStateStuck, operatorActionOutcomeExecuting, "no adoption on record 2 h after the decision", "", true}, + } + for _, c := range cases { + got := stageTrackerOperatorActionExec(c.actions, c.stage, nil, nil, now, window, c.exec) + if got == nil || got.State != c.wantSt || got.Outcome != c.wantOutc { + t.Errorf("%s: got %+v, want state=%s outcome=%s", c.name, got, c.wantSt, c.wantOutc) + continue + } + if c.progress != "" && !strings.Contains(got.Progress, c.progress) { + t.Errorf("%s: progress %q missing %q", c.name, got.Progress, c.progress) + } + if got.Blocker != c.blocker { + t.Errorf("%s: blocker %q want %q", c.name, got.Blocker, c.blocker) + } + if (got.Human != "") != c.human { + t.Errorf("%s: human %q (want present=%v)", c.name, got.Human, c.human) + } + if got.Progress != "" && (strings.Contains(got.Progress, "contributor-lane") || strings.Contains(got.Progress, "adoption-stalled")) { + t.Errorf("%s: bare slug in progress %q", c.name, got.Progress) + } + } + // A `blocked` ledger record (capability-gap recommendation) carries the + // blocker and the human step regardless of exec state. + blocked := []OperatorAction{{Action: operatorActionLetHiveDecide, Actor: "o", At: now.Add(-time.Minute), Outcome: operatorActionOutcomeBlocked, Stage: 85}} + got := stageTrackerOperatorAction(blocked, 85, nil, nil, now, window) + if got == nil || got.State != operatorActionStateBlocked || got.Blocker != operatorActionBlockerWorkflows || got.Human == "" { + t.Fatalf("blocked record = %+v", got) + } + // A no-effect record on the same stage is stuck with its own words; once + // the item moved on it reads as superseded by the state change. + noEffect := []OperatorAction{{Action: operatorActionLetHiveDecide, Actor: "o", At: now.Add(-time.Minute), Outcome: operatorActionOutcomeNoEffect, Detail: "the copy was closed", Stage: 85}} + if got := stageTrackerOperatorAction(noEffect, 85, nil, nil, now, window); got == nil || got.State != operatorActionStateStuck || got.Progress != "the copy was closed" || got.Human == "" { + t.Fatalf("no-effect same stage = %+v", got) + } + if got := stageTrackerOperatorAction(noEffect, 74, nil, nil, now, window); got == nil || got.State != operatorActionStateAddressed || got.Outcome != operatorActionOutcomeSuperseded { + t.Fatalf("no-effect moved on = %+v", got) + } +} + +// operatorActionExecutionFor reads the adoption off the stage record over +// the tracker item and surfaces a terminal refusal for the current head. +func TestOperatorActionExecutionForReadsRecord(t *testing.T) { + now := time.Date(2026, 10, 28, 16, 0, 0, 0, time.UTC) + store := stagelabels.NewStore("", func() time.Time { return now }) + key := stagelabels.Key("testorg/testrepo", 8) + store.Observe(key, stagelabels.NeedsDecision, "test") + it := StageTrackerItem{Repo: "testorg/testrepo", Number: 8, Head: "aaa", Reason: "adoption-stalled:contributor-lane:workflow-path"} + if got := operatorActionExecutionFor(it, stagelabels.Record{}, false); got.Refused != it.Reason || got.AdoptedBy != 0 { + t.Fatalf("no record: %+v", got) + } + store.MarkAdopted(key, "aaa", 91, now) + rec, _ := store.Get(key) + if got := operatorActionExecutionFor(StageTrackerItem{Head: "aaa"}, rec, true); got.AdoptedBy != 91 || got.AdoptedByState != "" || got.Refused != "" { + t.Fatalf("adopted: %+v", got) + } + store.MarkAdoptionEscalated(key, "aaa", "adoption-stalled:contributor-lane:workflow-path") + rec, _ = store.Get(key) + if got := operatorActionExecutionFor(StageTrackerItem{Head: "aaa"}, rec, true); !strings.Contains(got.Refused, "workflow-path") { + t.Fatalf("escalated: %+v", got) + } + if got := operatorActionExecutionFor(StageTrackerItem{Head: "bbb"}, rec, true); got.Refused != "" { + t.Fatalf("escalation for another head leaked: %+v", got) + } +} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 2f1f6c6b7d..f2d4354851 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1540,6 +1540,11 @@ .config-info.ham-acted.ham-acted-failed { background: color-mix(in srgb, var(--red) 14%, transparent); border-color: color-mix(in srgb, var(--red) 55%, transparent); color: var(--red); } .config-info.ham-acted.ham-acted-failed:hover, .config-info.ham-acted.ham-acted-failed:focus-visible { background: var(--red); border-color: var(--red); color: var(--bg); } .config-info.ham-acted.ham-acted-pending { border-style: dotted; color: var(--text-muted); background: transparent; } + /* executing: decided, the worker is carrying it out (hivecommons/hive#15188) — dotted + green; blocked: a capability gap holds it — dashed amber. */ + .config-info.ham-acted.ham-acted-executing { border-style: dotted; } + .config-info.ham-acted.ham-acted-blocked { border-style: dashed; background: color-mix(in srgb, var(--yellow) 16%, transparent); border-color: color-mix(in srgb, var(--yellow) 60%, transparent); color: var(--yellow); } + .config-info.ham-acted.ham-acted-blocked:hover, .config-info.ham-acted.ham-acted-blocked:focus-visible { background: var(--yellow); border-color: var(--yellow); color: var(--bg); } .ham-acted-tip { white-space: normal; text-align: left; font-weight: 400; } /* Sentinel-flagged PR, #13535 follow-up: the chip beside needs rebase / regressed, and the human-decision chevron itself when its word @@ -15357,14 +15362,14 @@

Where to get help

'merge-now': 'Approve & merge as maintainer', 'queue-merge': 'Approve — let hive merge', adopt: 'Adopt', 'adopt-now': 'Adopt now', reroute: 'Reroute to another clanker', }; - const STAGE_TRACKER_ACTED_STATES = ['waiting', 'addressed', 'stuck', 'pending', 'failed']; + const STAGE_TRACKER_ACTED_STATES = ['waiting', 'addressed', 'stuck', 'pending', 'failed', 'executing', 'blocked']; const STAGE_TRACKER_ACTED_FILTERS = ['any', 'awaiting', 'acted', 'stuck']; const STAGE_TRACKER_ACTED_STUCK_DEFAULT_S = 30 * 60; // Every state wears the same history mark (the clock-and-arrow the // column header uses): the badge is an audit affordance, never a "done" // tick. Colour and border carry the state; the aria-label says it in words. const STAGE_TRACKER_HISTORY_ICON = ''; - const STAGE_TRACKER_ACTED_GLYPH = { waiting: STAGE_TRACKER_HISTORY_ICON, addressed: STAGE_TRACKER_HISTORY_ICON, stuck: STAGE_TRACKER_HISTORY_ICON, pending: STAGE_TRACKER_HISTORY_ICON, failed: STAGE_TRACKER_HISTORY_ICON }; + const STAGE_TRACKER_ACTED_GLYPH = { waiting: STAGE_TRACKER_HISTORY_ICON, addressed: STAGE_TRACKER_HISTORY_ICON, stuck: STAGE_TRACKER_HISTORY_ICON, pending: STAGE_TRACKER_HISTORY_ICON, failed: STAGE_TRACKER_HISTORY_ICON, executing: STAGE_TRACKER_HISTORY_ICON, blocked: STAGE_TRACKER_HISTORY_ICON }; function stageTrackerActedLabel(action) { return STAGE_TRACKER_ACTED_LABELS[action] || String(action || '').replace(/-/g, ' '); } // Pure: the record a row's badge reads — the item's own, else (an issue // row drawn over its single covering PR) that PR's; null when none. @@ -15405,6 +15410,9 @@

Where to get help

case 'no-op': return 'nothing changed' + (action.detail ? ': ' + stageTrackerActedPlain(action.detail) : ''); case 'failed': return 'failed' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); case 'pending': return 'the hive is deciding…'; + case 'executing': return (action.detail ? stageTrackerActedPlain(action.detail) : 'decided — the hive is carrying it out…'); + case 'no-effect': return "hasn't taken effect" + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); + case 'blocked': return 'blocked' + (action.detail ? ' — ' + stageTrackerActedPlain(action.detail) : ''); case 'superseded-by-state-change': return 'the item moved on by itself'; } return action.outcome || ''; @@ -15437,6 +15445,7 @@

Where to get help

if (!t) return ''; if (STAGE_TRACKER_ACTED_PLAIN[t]) return STAGE_TRACKER_ACTED_PLAIN[t]; if (/^hive decided: /.test(t)) return t.replace(/^hive decided: /, 'the hive decided: ').replace(/ \(([^)]+)\)/, (m, r) => ' (rule: ' + r.replace(/[-_:]/g, ' ') + ')'); + if (/^decided: /.test(t)) return t.replace(/^decided: /, 'the hive decided: ').replace(/ \(([^)]+)\)/, (m, r) => ' (rule: ' + r.replace(/[-_:]/g, ' ') + ')'); if (/^[a-z0-9]+([-_:][a-z0-9]+)+$/.test(t)) return t.replace(/[-_:]/g, ' '); // Slugs inside a sentence ("… — contributor-lane:changes-requested blocks it"). return t.replace(/\b[a-z0-9]+(?:[-_:][a-z0-9]+)+\b/g, m => STAGE_TRACKER_ACTED_PLAIN[m] || (/[a-z]/.test(m) ? m.replace(/[-_:]/g, ' ') : m)); @@ -15448,7 +15457,7 @@

Where to get help

// (no-op) or the item has not moved (stuck): the enabled options from // the row's decision_needed payload, minus the one just taken. function stageTrackerActedOptions(item, action, state) { - if (!(action.outcome === 'no-op' || state === 'stuck' || state === 'failed')) return ''; + if (!(action.outcome === 'no-op' || state === 'stuck' || state === 'failed' || state === 'blocked')) return ''; const dn = item && item.decision_needed; const opts = dn && Array.isArray(dn.options) ? dn.options : []; const taken = STAGE_TRACKER_ACTED_OPTION_ID[action.action] || ''; @@ -15474,9 +15483,14 @@

Where to get help

if (state === 'addressed') lines.push('Addressed — now at ' + stageNow + '.'); else if (state === 'stuck') lines.push('Still at ' + stageNow + ' ' + ago.replace(/ ago$/, '') + ' after you asked' + (waitingOn ? ' — hive says: ' + waitingOn : '') + '.'); else if (state === 'pending') lines.push('At ' + stageNow + ' while the hive decides.'); - else if (state === 'failed') lines.push('Still at ' + stageNow + ' — try again, or act on GitHub.'); + else if (state === 'failed') lines.push('Still at ' + stageNow + (a.progress ? ' — ' + stageTrackerActedPlain(a.progress) : ' — try again, or act on GitHub') + '.'); + else if (state === 'executing') lines.push('At ' + stageNow + ' — the hive is carrying it out' + (a.progress ? ': ' + stageTrackerActedPlain(a.progress) : '') + '.'); + else if (state === 'blocked') lines.push('Blocked at ' + stageNow + (a.progress ? ' — ' + stageTrackerActedPlain(a.progress) : ' — the hive lacks a permission it needs') + '.'); else lines.push('At ' + stageNow + (waitingOn ? ' — ' + waitingOn : '') + '.'); lines.push(who + ' chose ' + label + ' · ' + agentNowClockTime(atMs, nowMs) + ' (' + ago + ') · ' + stageTrackerActedOutcomeWords(a) + '.'); + if (a.progress && state !== 'executing' && state !== 'blocked' && state !== 'failed') lines.push('Hive now: ' + stageTrackerActedPlain(a.progress) + '.'); + if (a.human) lines.push('You can: ' + a.human); + else if (state === 'executing') lines.push('Nothing for you to do — the badge updates when the adoption lands.'); if (a.note) lines.push('Your note: ' + a.note); const options = stageTrackerActedOptions(src.item, a, state); if (options) lines.push('Options: ' + options + '.'); @@ -17192,6 +17206,9 @@

All labels

"adopt-supersede": {"kind": "action", "plain": "close this PR and open a fresh hive-authored PR with the same commits", "detail": "Supersede means the hive closes this PR and opens a fresh hive-authored PR carrying the same commits and sign-off, then finishes it itself."}, "adopted": {"kind": "action", "plain": "close this PR and open a fresh hive-authored PR with the same commits", "detail": "Supersede means the hive closes this PR and opens a fresh hive-authored PR carrying the same commits and sign-off, then finishes it itself."}, "adoption-disabled": {"kind": "reason", "plain": "adoption is switched off on this hive", "detail": "Stage adoption is disabled on this hive (governor.labels.stage.adoption), so a request to take a PR over is never carried out."}, + "adoption-executing": {"kind": "reason", "plain": "the adoption engine is carrying it out", "detail": "The decision is recorded and the adoption engine picks it up on its next stage pass (a few minutes): it pushes the commits to a hive branch and opens the hive's copy. Nothing to do yet."}, + "adoption-stalled:contributor-lane:workflow-path": {"kind": "reason", "plain": "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", "detail": "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded."}, + "adoption-undone": {"kind": "reason", "plain": "the hive's copy was closed without merging and the adoption was undone", "detail": "The hive opened its copy, but the copy was closed without merging and a fresh one could not be opened, so the adoption was undone and the PR is back in its normal flow. Re-run the decision to adopt it again, or act on GitHub."}, "adoption/supersede": {"kind": "action", "plain": "close this PR and open a fresh hive-authored PR with the same commits", "detail": "Supersede means the hive closes this PR and opens a fresh hive-authored PR carrying the same commits and sign-off, then finishes it itself."}, "approve": {"kind": "action", "plain": "approved for merge", "detail": "The hive approved it; the merge gate merges it once every check passes."}, "approve-review": {"kind": "action", "plain": "approved for merge", "detail": "The hive approved it; the merge gate merges it once every check passes."}, @@ -17200,6 +17217,7 @@

All labels

"author-online": {"kind": "reason", "plain": "the author's hive is connected, so hive won't take the PR over", "detail": "Adoption is for authors whose hive has gone offline; this author's hive is connected, so the hive leaves the PR with them."}, "behind": {"kind": "reason", "plain": "the branch is behind the base branch", "detail": "The branch is behind the base branch and must be updated before it can merge."}, "capability-gap": {"kind": "rule", "plain": "the GitHub App lacks a permission; deciding cannot clear it", "detail": "The blocker is a missing GitHub App permission (for example `workflows`). Approving a direction would only re-apply needs-human, so the park stays until the owner grants the permission or a person applies the change."}, + "capability:workflows-permission": {"kind": "reason", "plain": "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", "detail": "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded."}, "changes-requested": {"kind": "reason", "plain": "a reviewer asked for changes; a new commit is needed", "detail": "A reviewer asked for changes on this branch. Approving cannot override that: only a new commit, or a maintainer merging by hand, moves it."}, "changes_requested": {"kind": "reason", "plain": "a reviewer asked for changes; a new commit is needed", "detail": "A reviewer asked for changes on this branch. Approving cannot override that: only a new commit, or a maintainer merging by hand, moves it."}, "checks-failing": {"kind": "reason", "plain": "CI is failing on this branch", "detail": "Required checks are failing on this branch; nothing merges until they are green."}, @@ -17216,6 +17234,7 @@

All labels

"contributor-lane:author-association": {"kind": "reason", "plain": "no merge lane vouches for this PR's author; a maintainer merges", "detail": "The PR is ready, but its author is not a collaborator and holds no trusted or merger tier, so no merge lane vouches for them and the hive never merges it unattended. A maintainer merges it (Approve & merge as maintainer, or Approve — let hive merge), or trusts the author under 👥 Contributors."}, "contributor-lane:changes-requested": {"kind": "reason", "plain": "a reviewer asked for changes; a new commit is needed", "detail": "A reviewer asked for changes on this branch. Approving cannot override that: only a new commit, or a maintainer merging by hand, moves it."}, "contributor-lane:sentinel-blocked": {"kind": "reason", "plain": "security-sensitive files changed; a maintainer must approve", "detail": "Security-sensitive files changed. The hive never merges until a maintainer reviews and removes the sentinel label."}, + "contributor-lane:workflow-path": {"kind": "reason", "plain": "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", "detail": "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded."}, "contributor-offline": {"kind": "rule", "plain": "the author's hive hasn't been connected since the nudge", "detail": "The PR's author has been offline since the hive nudged them, so the hive takes the work over instead of waiting."}, "dco": {"kind": "reason", "plain": "a commit is missing its sign-off", "detail": "A commit on the branch is missing its Developer Certificate of Origin sign-off; the author must sign it off."}, "dco-missing": {"kind": "reason", "plain": "a commit is missing its sign-off", "detail": "A commit on the branch is missing its Developer Certificate of Origin sign-off; the author must sign it off."}, @@ -17270,6 +17289,7 @@

All labels

"supersede-now": {"kind": "action", "plain": "close this PR and open a fresh hive-authored PR with the same commits", "detail": "Supersede means the hive closes this PR and opens a fresh hive-authored PR carrying the same commits and sign-off, then finishes it itself."}, "superseded": {"kind": "action", "plain": "closed because another PR carries the work", "detail": "Closed because another PR carries the same work; the author is credited there."}, "untrusted-author": {"kind": "reason", "plain": "no merge lane vouches for this PR's author; a maintainer merges", "detail": "The PR is ready, but its author is not a collaborator and holds no trusted or merger tier, so no merge lane vouches for them and the hive never merges it unattended. A maintainer merges it (Approve & merge as maintainer, or Approve — let hive merge), or trusts the author under 👥 Contributors."}, + "workflow-path": {"kind": "reason", "plain": "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", "detail": "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded."}, }; // Pure: plain words for a glossary slug ("supersede" → "close this PR and // open a fresh hive-authored PR with the same commits"). Strips a lane diff --git a/src/pkg/delegatedecision/decision_glossary.go b/src/pkg/delegatedecision/decision_glossary.go index 809c9bbba5..7fc24f0044 100644 --- a/src/pkg/delegatedecision/decision_glossary.go +++ b/src/pkg/delegatedecision/decision_glossary.go @@ -48,27 +48,32 @@ type GlossaryEntry struct { // rules in policy.go / llm.go; these are the action and reason slugs the // stuck-decision path coins. const ( - GlossarySupersede = "supersede" - GlossaryAdopt = "adopt" - GlossaryChangesRequest = "changes_requested" - GlossarySentinel = "sentinel" - GlossaryConflicting = "conflicting" - GlossaryCIRed = "ci-red" - GlossaryAuthorOnline = "author-online" - GlossaryHold = "hold" - GlossaryDCO = "dco" - GlossaryNeedsHuman = "needs-human" - GlossaryNoEffect = "no-effect" - GlossaryAdoptionOff = "adoption-disabled" - GlossaryStillParked = "still-parked" - GlossaryBehind = "behind" - GlossaryNotMergedYet = "not-merged-yet" - GlossaryNotClosedYet = "not-closed-yet" - GlossaryNoNewCommit = "no-new-commit" - GlossarySelfDecision = "self-decision-read-as-changes" - GlossaryEffectUnknown = "effect-unknown" - GlossaryHumanMerge = "human-merge" // 090: no lane vouches for the author (hivecommons/hive#15078) - glossaryFallbackUnknown = "the hive did not say why" + GlossarySupersede = "supersede" + GlossaryAdopt = "adopt" + GlossaryChangesRequest = "changes_requested" + GlossarySentinel = "sentinel" + GlossaryConflicting = "conflicting" + GlossaryCIRed = "ci-red" + GlossaryAuthorOnline = "author-online" + GlossaryHold = "hold" + GlossaryDCO = "dco" + GlossaryNeedsHuman = "needs-human" + GlossaryNoEffect = "no-effect" + GlossaryAdoptionOff = "adoption-disabled" + GlossaryStillParked = "still-parked" + GlossaryBehind = "behind" + GlossaryNotMergedYet = "not-merged-yet" + GlossaryNotClosedYet = "not-closed-yet" + GlossaryNoNewCommit = "no-new-commit" + GlossarySelfDecision = "self-decision-read-as-changes" + GlossaryEffectUnknown = "effect-unknown" + GlossaryHumanMerge = "human-merge" // 090: no lane vouches for the author (hivecommons/hive#15078) + // Adoption-execution reasons (hivecommons/hive#15188): what the + // adoption engine did with a recorded adopt-supersede. + GlossaryWorkflowPath = "workflow-path" + GlossaryAdoptionExecuting = "adoption-executing" + GlossaryAdoptionUndone = "adoption-undone" + glossaryFallbackUnknown = "the hive did not say why" ) var glossary = []GlossaryEntry{ @@ -166,6 +171,13 @@ var glossary = []GlossaryEntry{ {Slug: GlossaryNeedsHuman, Kind: GlossaryReason, Plain: "marked needs-human; a person must remove the label", Detail: "The item is marked needs-human: automated fixes ran out or a person flagged it. The hive waits until the label is removed.", Aliases: []string{"label:needs-human", "requires_human"}}, + {Slug: GlossaryWorkflowPath, Kind: GlossaryReason, Plain: "the PR edits .github/workflows; the hive's App lacks the `workflows` permission, so it cannot adopt it", + Detail: "The PR changes files under .github/workflows. The hive's GitHub App has no `workflows` permission, so the adoption fence refuses to publish those edits from the hive. Grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge it on GitHub, or close it as superseded.", + Aliases: []string{"contributor-lane:workflow-path", "adoption-stalled:contributor-lane:workflow-path", "capability:workflows-permission"}}, + {Slug: GlossaryAdoptionExecuting, Kind: GlossaryReason, Plain: "the adoption engine is carrying it out", + Detail: "The decision is recorded and the adoption engine picks it up on its next stage pass (a few minutes): it pushes the commits to a hive branch and opens the hive's copy. Nothing to do yet."}, + {Slug: GlossaryAdoptionUndone, Kind: GlossaryReason, Plain: "the hive's copy was closed without merging and the adoption was undone", + Detail: "The hive opened its copy, but the copy was closed without merging and a fresh one could not be opened, so the adoption was undone and the PR is back in its normal flow. Re-run the decision to adopt it again, or act on GitHub."}, {Slug: GlossaryAdoptionOff, Kind: GlossaryReason, Plain: "adoption is switched off on this hive", Detail: "Stage adoption is disabled on this hive (governor.labels.stage.adoption), so a request to take a PR over is never carried out."}, {Slug: GlossaryStillParked, Kind: GlossaryReason, Plain: "the item is still waiting on a person", diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index ee90a454c0..3196e35929 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -127,6 +127,9 @@ const ( const ( // LabelAdoptSupersede is the durable request consumed by the adoption engine. LabelAdoptSupersede = "adoption/supersede" + // RuleCapabilityGap is the recommend-only rule for a blocker no decision + // can clear: the GitHub App lacks a permission (hivecommons/hive#15099). + RuleCapabilityGap = "capability-gap" LabelNeedsOwner = "needs-owner" LabelHold = "hold" LabelTriageAccepted = "triage/accepted" @@ -190,6 +193,12 @@ type Input struct { // or nothing moved). The delegate picks Adopt now // (RuleAdoptNow) rather than wait any longer (hivecommons/hive#15038). AdoptionGraceElapsed bool + // WorkflowPath: the PR edits `.github/workflows/*` (read from its file + // list or from an `adoption-stalled:…workflow-path` park reason). The + // hive's App has no `workflows` permission, so supersede-adoption is + // refused by the adoption fence: deciding to adopt cannot take effect + // (hivecommons/hive#15188). + WorkflowPath bool // BlockedOnPRClosed: a review-backlog item whose PR closed unmerged. BlockedOnPRClosed bool } @@ -357,7 +366,7 @@ func decideIssue(in Input) Decision { return recommendOnly("hive-policy", "this changes the hive's own policy or scope (settings, governance, security posture); the owner confirms those", "accept the proposal as written with its stated defaults, or close it as won't-fix if it widens the hive's write scope") } if CapabilityGap(in) { - return recommendOnly("capability-gap", "the blocker is a missing GitHub App permission; approving a direction would un-park the item only for the same needs-human to be re-applied, so the park stays until the permission changes", + return recommendOnly(RuleCapabilityGap, "the blocker is a missing GitHub App permission; approving a direction would un-park the item only for the same needs-human to be re-applied, so the park stays until the permission changes", "grant the App the missing permission (for example `workflows`) or have a human apply the change, then re-check; hive cannot clear this by deciding") } if OwnerOnly(in) { @@ -460,6 +469,15 @@ func decidePR(in Input) Decision { return d } } + if !in.HiveAuthored && !in.ContributorOnline && in.WorkflowPath && (in.AdoptionStalled || in.AdoptionGraceElapsed || in.Conflicting || !in.CIGreen || in.DCOMissing) { + // The adoption engine refuses to publish a contributor's workflow + // edits from the App (contributor-lane:workflow-path), so an + // adopt-supersede here is decided and never executed + // (hivecommons/hive#15188). Same rule as the issue-side gap + // (#15127) so the tracker routes it to the capability blocker. + return recommendOnly(RuleCapabilityGap, "the PR edits .github/workflows and the hive's GitHub App lacks the `workflows` permission, so the adoption fence refuses to supersede it; deciding to adopt cannot take effect", + "grant the App the `workflows` permission and re-run the decision, or have a person rebase and merge "+ref+" on GitHub, or close it as superseded") + } if !in.HiveAuthored && in.Kind == KindPR && in.AdoptionGraceElapsed { text := "adopt now: the offline grace on " + ref + " has already elapsed; adopt in supersede mode at once, preserving the author's commits and sign-off" return Decision{ diff --git a/src/pkg/delegatedecision/policy_test.go b/src/pkg/delegatedecision/policy_test.go index 0f49450436..23130f907d 100644 --- a/src/pkg/delegatedecision/policy_test.go +++ b/src/pkg/delegatedecision/policy_test.go @@ -241,6 +241,14 @@ func TestDecidePRRules(t *testing.T) { in: Input{Kind: KindPR, Number: 54, Title: "Contributor fix", DCOMissing: true, CIGreen: true}, verdict: VerdictAdoptSupersede, rule: "contributor-offline", }, + { + // hivecommons/hive#15188: the App cannot publish .github/workflows + // edits, so adopt-supersede would be refused by the lane; the + // policy must say so instead of promising an adoption. + name: "offline contributor on a workflow path is a capability gap", + in: Input{Kind: KindPR, Number: 54, Title: "CI fix", AdoptionStalled: true, WorkflowPath: true, CIGreen: true}, + verdict: VerdictRecommendOnly, rule: RuleCapabilityGap, kinds: []ActionKind{ActionRecommendOnly}, keepsPark: true, + }, { name: "reporter trust hold cleared when PR sound", in: Input{Kind: KindPR, Number: 55, Title: "Fix", ReporterTrustHold: true, CIGreen: true, ContributorOnline: true},