Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-owner-approve-clears-park.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Dashboard *Decide… → Approve* on a parked pull request now records the person's approval against the PR head (the auto-merge lanes and the stage engine read it as the answer to a `requires_human` / decision-requested verdict, like a trusted merger's Approve review), lifts the hive's `needs-human` park, removes the `sentinel-alert` label and records a head-keyed `sentinel_acknowledged` action in the review evidence bundle so bundle-only sentinel alerts clear too, re-derives the stage and drops the tracker cache. Before, it only posted the `/lgtm` + `/approve` comments, which no lane read, so the row stayed at stage/085 *Needs human decision*; the delegated *Let hive decide* path is unchanged (comments only, never clears a sentinel alert). The activity monitor's lit chevron for a detour (085 on the Merge gate column) now names the parking stage in its hover instead of borrowing "Awaiting merge admission … Next move: human" from the column.
2 changes: 1 addition & 1 deletion src/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Read the result from `GET /api/kick/{agent}/status`, which returns `status` of `

| `GET` | `/api/repos/{owner}/{repo}/hold-permission` | Dashboard auth/session | Reports whether the signed-in user can toggle hold chips for a repository card. Owners are allowed; otherwise the server checks GitHub `repos/{owner}/{repo}/collaborators/{user}/permission` and briefly caches the effective permission | `pkg/dashboard/api.go:332`, `pkg/dashboard/api_repo_hold.go` |
| `POST` | `/api/repos/{owner}/{repo}/items/{number}/hold` | Owner or repo write/maintain/admin | Add or remove a dashboard hold chip for an issue or PR. Body `{"held": true}` adds the hive's exact-match canonical `hive-pause/<hive-id>` label; `{"held": false}` removes exactly the labels causing the hold (`hive-pause/<hive-id>` and/or generic hold labels) and never removes `hive/<hive-id>` provenance. Every toggle writes an audit-log entry; the #8851 upgrade migration writes `/data/hive-hold-migration-<hive-id>.json` with audit-backed, provenance-only, and ambiguous legacy `hive/<hive-id>` classifications. | `pkg/dashboard/api.go:333`, `pkg/dashboard/api_repo_hold.go` |
| `POST` | `/api/repos/{owner}/{repo}/items/{number}/decision` | Owner or repo write/maintain/admin, signed-in GitHub user | Record an operator decision from the activity monitor's row menu / selection bar. Body `{"decision": "approve"|"direction"|"close-superseded"|"close-wontfix", "comment": "…", "type": "issue"|"pr", "superseded_by": "#458"}`. On an issue parked at 045, `approve`/`direction` act exactly as a maintainer's `/hive approve` / `/hive decision <text>` comment would (labels, `approved-direction`, stage-engine Unparked fact, reply comment naming the operator). On a PR parked at 085 (`type: "pr"`), `approve` posts the `/lgtm` and `/approve` commands as two comments attributed to the operator (the merge gate decides from there; no review, label or merge), and `direction` records the text as a human change request against the head — the `/hive decision` fix lane — on a hive-authored PR only (409 otherwise). The close variants post a comment naming the operator (and the superseding PR when `superseded_by` is given) and close the item as not planned. Never merges. Every decision writes an audit-log entry (`repo_item_decision_*`). | `pkg/dashboard/api.go:334`, `pkg/dashboard/api_repo_item_decision.go` |
| `POST` | `/api/repos/{owner}/{repo}/items/{number}/decision` | Owner or repo write/maintain/admin, signed-in GitHub user | Record an operator decision from the activity monitor's row menu / selection bar. Body `{"decision": "approve"|"direction"|"close-superseded"|"close-wontfix", "comment": "…", "type": "issue"|"pr", "superseded_by": "#458"}`. On an issue parked at 045, `approve`/`direction` act exactly as a maintainer's `/hive approve` / `/hive decision <text>` comment would (labels, `approved-direction`, stage-engine Unparked fact, reply comment naming the operator). On a PR parked at 085 (`type: "pr"`), `approve` posts the `/lgtm` and `/approve` commands as two comments attributed to the operator, records the approval against the head as the human answer to a `requires_human` / decision-requested verdict (the lanes and the stage engine honour it like a trusted merger's Approve review), lifts `needs-human`, clears the sentinel label and acknowledges the bundle's sentinel findings for that head, re-derives the stage and drops the tracker cache — the response adds `released` (`approval-recorded`, `needs-human`, `sentinel-label`, `sentinel-acknowledged`) and `stage`; the merge gate decides from there (no review as the operator, no merge) — and `direction` records the text as a human change request against the head — the `/hive decision` fix lane — on a hive-authored PR only (409 otherwise). The close variants post a comment naming the operator (and the superseding PR when `superseded_by` is given) and close the item as not planned. Never merges. Every decision writes an audit-log entry (`repo_item_decision_*`). | `pkg/dashboard/api.go:334`, `pkg/dashboard/api_repo_item_decision.go` |
| `POST` / `GET` | `/api/repos/{owner}/{repo}/items/{number}/decide-delegated` | Same as `…/hold` (owner or repo write), signed-in GitHub user; `decisions.delegate.enabled` (403 when off) | *Let hive decide*: enqueue a delegated-decision job in which the hive decides the parked item itself as the owner's delegate under `pkg/delegatedecision.PolicyText` and records it as a human decision (`/hive decision` comment with the `<!-- hive:delegated-decision … -->` marker, park labels off, `triage/accepted`, queue approval on a PR head). Body `{"type": "issue"|"pr", "reason", "caption", "sentinel_reason"}`. `POST` answers 202 with the job (`{id, status: "running"|"done"|"failed", decision: {verdict, rule, text, rationale, actions, keeps_park}, notes, error}`); 409 with the running job while one is in flight; `GET` reads it. Rails: never merges, refuses items wearing `hold`, never grants secrets/permissions (`needs-owner` + `hold` instead), recommends only on hive policy/governance questions (keeps 085). Audited as `repo_item_decision_delegated[_failed]`. See [dashboard-sections.md](dashboard-sections.md#let-hive-decide). | `pkg/dashboard/api.go:329`, `pkg/dashboard/api_repo_item_decide_delegated.go` |
| `POST` | `/api/repos/{owner}/{repo}/items/{number}/accept-triage` | Owner or repo write/maintain/admin | Accept triage on an issue from the activity monitor's row menu — what a maintainer accepting triage on GitHub does by hand: adds the reporter-trust triage label (`triage/accepted`, or the first of `issue_filter.reporter_trust.untrusted_require_labels`; the label is created in the repo if missing) and removes the awaiting label (`needs-triage` / `reporter_trust.awaiting_label`) and a Hive-written `stage/015-triage-needed`. Empty body. Returns `{ok, repo, number, acceptLabel, added, removed, alreadyAccepted, minStatusSeq}`; an issue already carrying the accept label with nothing left to remove is a no-op (`alreadyAccepted: true`, no write, no audit). 404 for a pull request or an unknown item. The status snapshot's labels are patched so the next reconcile reads 010 Actionable before the engine's own 015 → 010 derivation. Every write is audited as `repo_item_accept_triage` under the dashboard user. | `pkg/dashboard/api.go:524`, `pkg/dashboard/api_repo_item_accept_triage.go` |
| `GET` | `/api/acmm/evaluation` | Dashboard auth/session | ACMMEvaluation — combined codebase + operational result, cached server-side for 1 hour (`acmmEvalTTL`). `?refresh=1` (the dashboard's "🔄 Re-evaluate" button, #5877) bypasses the hourly TTL but is debounced server-side: requests within 1 minute of the last evaluation (`acmmRefreshDebounce`) still serve the cache, since a full refresh costs up to ~29 GitHub GetContents calls per repo. The response's `last_evaluated_at` timestamp reports when the cached evaluation was computed | `pkg/dashboard/api.go:338`, `pkg/dashboard/api_acmm_eval.go` |
Expand Down
4 changes: 2 additions & 2 deletions src/docs/dashboard-sections.md

Large diffs are not rendered by default.

52 changes: 47 additions & 5 deletions src/pkg/dashboard/api_repo_item_decision.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand All @@ -23,8 +23,15 @@
// maintainer with write access (Client.RecordOperatorIssueDecision):
// park labels cleared, approved-direction applied, reply posted. On a
// PR, the `/lgtm` and `/approve` commands posted as two attributed
// comments (Client.RecordOperatorPullRequestApproval) — the merge gate
// decides from there; nothing is reviewed, labelled or merged here.
// comments, the approval recorded against the head as the answer to a
// requires_human verdict, the hive's `needs-human` park and the
// sentinel alert (label and evidence-bundle findings) released, and the
// stage re-derived (Client.RecordOperatorPullRequestApprovalWith) — the
// merge gate decides from there; nothing is reviewed or merged here.
// The person's approval is the human review a requires_human verdict,
// a supersession ask or a sentinel alert was waiting for; before this
// the comments were read by no lane and the row stayed at stage/085
// (hivecommons/hive#14821, #14822, crux#30).
// - direction → `/hive decision <comment>`; the comment is required. On
// a hive-authored PR it is recorded as a human change request so the
// author agent is kicked with it (Client.RecordOperatorPullRequestDecision).
Expand Down Expand Up @@ -110,6 +117,12 @@
Decision string `json:"decision"`
Status string `json:"status"`
Label string `json:"label,omitempty"`
// Released lists what a PR approval cleared beyond posting the commands:
// "approval-recorded", "needs-human", "sentinel-label",
// "sentinel-acknowledged". Stage is the stage label the engine derived
// on the spot, when it did.
Released []string `json:"released,omitempty"`
Stage string `json:"stage,omitempty"`
}

func renderRepoItemDecisionCloseComment(verb, user, comment, supersededBy string) string {
Expand Down Expand Up @@ -258,10 +271,17 @@
head string
err error
)
var released []string
stage := ""
if decision == repoItemDecisionApprove {
var event ghpkg.PullRequestApprovalEvent
event, err = gh.RecordOperatorPullRequestApproval(ctx, repoFull, number, user)
event, err = gh.RecordOperatorPullRequestApprovalWith(ctx, repoFull, number, user, ghpkg.PullRequestApprovalOptions{
HumanChangeRequests: repoItemDecisionChangeRequests(),
LiftNeedsHuman: true,
SentinelLabel: s.sentinelLabel(),
})
head = event.HeadSHA
released, stage = repoItemApprovalReleased(event), event.Stage
} else {
var event ghpkg.PullRequestDecisionEvent
event, err = gh.RecordOperatorPullRequestDecision(ctx, repoFull, number, user, comment, repoItemDecisionChangeRequests())
Expand All @@ -288,6 +308,28 @@
if decision == repoItemDecisionDirection {
action, status = auditRepoItemDecisionDirection, "direction-recorded"
}
s.audit.LogRecord(user, action, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", head, "decision", comment), "", repoFull, number)
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: status})
s.audit.LogRecord(user, action, auditDetail("repo", repoFull, "number", numStr, "type", "pr", "head", head, "decision", comment, "released", strings.Join(released, ","), "stage", stage), "", repoFull, number)
// The row's park was just answered: serve the re-derived stage on the
// next tracker read instead of the cached 085.
s.invalidateStageTrackerForWebhook()
jsonResponse(w, repoItemDecisionResponse{OK: true, Repo: repoFull, Number: number, Decision: decision, Status: status, Released: released, Stage: stage})
}

// repoItemApprovalReleased names what a PR approval released, for the
// response and the audit line.
func repoItemApprovalReleased(event ghpkg.PullRequestApprovalEvent) []string {
var out []string
if event.Recorded {
out = append(out, "approval-recorded")
}
if event.NeedsHumanLifted {
out = append(out, "needs-human")
}
if event.SentinelLabelCleared {
out = append(out, "sentinel-label")
}
if event.SentinelAcknowledged {
out = append(out, "sentinel-acknowledged")
}
return out
}
55 changes: 53 additions & 2 deletions src/pkg/dashboard/api_repo_item_decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type repoItemDecisionMock struct {
removed []string
comments []string
edits []map[string]any
// prForeign makes PR #8 look like a human opened it.
// prForeign makes PR #8 look like a human opened it; prLabels are the
// labels pulls/8 reports.
prForeign bool
prLabels []string
// prMergeState is PR #8's mergeable_state ("" = clean); prRedCI and
// prNoCI shape the head's combined status when the state alone does not
// settle CI (e.g. "blocked").
Expand Down Expand Up @@ -64,7 +66,11 @@ func newRepoItemDecisionServer(t *testing.T, m *repoItemDecisionMock) *Server {
if mergeState == "" {
mergeState = "clean"
}
_ = json.NewEncoder(w).Encode(map[string]any{"number": 8, "state": "open", "labels": []any{}, "user": author, "mergeable": true, "mergeable_state": mergeState, "head": map[string]any{"sha": "feedfacefeedfacefeedfacefeedfacefeedface"}})
prLabels := make([]map[string]string, 0, len(m.prLabels))
for _, label := range m.prLabels {
prLabels = append(prLabels, map[string]string{"name": label})
}
_ = json.NewEncoder(w).Encode(map[string]any{"number": 8, "state": "open", "labels": prLabels, "user": author, "mergeable": true, "mergeable_state": mergeState, "head": map[string]any{"sha": "feedfacefeedfacefeedfacefeedfacefeedface"}})
case r.Method == http.MethodGet && strings.HasSuffix(path, "/commits/feedfacefeedfacefeedfacefeedfacefeedface/status"):
switch {
case m.prRedCI:
Expand Down Expand Up @@ -284,6 +290,51 @@ func TestRepoItemDecisionApprovePRPostsLgtmAndApproveComments(t *testing.T) {
}
}

// TestRepoItemDecisionApprovePRReleasesThePark: the owner's Approve on a
// parked PR is the human review it waited for — the approval is recorded
// against the head (the lanes and the stage engine read it as the answer to
// requires_human / decision-requested), `needs-human` and the sentinel label
// come off, and the tracker cache is dropped so the next read re-derives the
// stage (hivecommons/hive#14821, #14822, crux#30 stayed at 085 with only the
// command comments written).
func TestRepoItemDecisionApprovePRReleasesThePark(t *testing.T) {
mock := &repoItemDecisionMock{prForeign: true, prLabels: []string{"stage/085-needs-decision", "needs-human", "sentinel-alert", "role/trusted"}}
srv := newRepoItemDecisionServer(t, mock)
srv.stageTrackerCacheMu.Lock()
gen := srv.stageTrackerGen
srv.stageTrackerCacheMu.Unlock()

w := postRepoItemDecision(t, srv, 8, "writer", `{"decision":"approve","type":"pr"}`)
if w.Code != http.StatusOK {
t.Fatalf("approve PR: code=%d body=%s", w.Code, w.Body.String())
}
var resp repoItemDecisionResponse
_ = json.Unmarshal(w.Body.Bytes(), &resp)
if resp.Status != "approval-commented" || strings.Join(resp.Released, ",") != "approval-recorded,needs-human,sentinel-label" {
t.Fatalf("response = %+v", resp)
}
req, ok := repoItemDecisionChangeRequests().For("testorg/testrepo", 8, "feedfacefeedfacefeedfacefeedfacefeedface")
if !ok || !req.IsApproval() || req.Actor != "writer" {
t.Fatalf("approval must stand against the head: %+v ok=%v", req, ok)
}
if strings.Join(mock.removed, ",") != "needs-human,sentinel-alert" {
t.Fatalf("removed = %v", mock.removed)
}
if len(mock.comments) != 2 || len(mock.added)+len(mock.edits) != 0 {
t.Fatalf("approval still posts the two commands and nothing else: comments=%d added=%v edits=%v", len(mock.comments), mock.added, mock.edits)
}
srv.stageTrackerCacheMu.Lock()
stale, after := srv.stageTrackerCache.stale, srv.stageTrackerGen
srv.stageTrackerCacheMu.Unlock()
if !stale || after == gen {
t.Fatalf("tracker cache must be invalidated: stale=%v gen %d -> %d", stale, gen, after)
}
detail := srv.GetAudit().Recent(1)[0].Detail
if !strings.Contains(detail, "released=approval-recorded,needs-human,sentinel-label") {
t.Fatalf("audit detail = %q", detail)
}
}

func TestRepoItemDecisionDirectionPRRecordsChangeRequest(t *testing.T) {
mock := &repoItemDecisionMock{}
srv := newRepoItemDecisionServer(t, mock)
Expand Down
16 changes: 15 additions & 1 deletion src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,12 @@ const stageTrackerSentinelMoreFormat = " (+%d more)"
// label is gone is reported as cleared — findings and reason still fill
// the tooltip, alert does not. One file read per PR with a known head,
// ENOENT when the sentinel never wrote one; the tracker payload is memoised
// so this runs once per snapshot, not per request.
// so this runs once per snapshot, not per request. A person's sentinel
// acknowledgment on the bundle (evidence.ActionSentinelAcknowledged — the
// owner's Approve decision on a flagged PR) is the human review a
// notice-only alert asked for, so it clears the bundle-promoted alert (the
// label, while still on, still stands); the reason then names who
// acknowledged it.
func (s *Server) stageTrackerSentinel(verifier *github.ReviewEvidenceVerifier, repo string, number int, head string, labels []string) (alert bool, findings int, reason string) {
label := s.sentinelLabel()
for _, l := range labels {
Expand All @@ -693,6 +698,11 @@ func (s *Server) stageTrackerSentinel(verifier *github.ReviewEvidenceVerifier, r
if findings > 1 {
reason += fmt.Sprintf(stageTrackerSentinelMoreFormat, findings-1)
}
if by := b.SentinelAcknowledgedBy(); by != "" {
// The label, while still on, is the sweep's live block; only the
// bundle-promoted alert is answered by the acknowledgment.
return alert, findings, reason + stageTrackerSentinelAckSuffix + by
}
for _, f := range b.Sentinel {
if f.Notice {
alert = true
Expand All @@ -702,6 +712,10 @@ func (s *Server) stageTrackerSentinel(verifier *github.ReviewEvidenceVerifier, r
return alert, findings, reason
}

// stageTrackerSentinelAckSuffix precedes the login of the person whose
// approval acknowledged the bundle's sentinel findings.
const stageTrackerSentinelAckSuffix = " — acknowledged by @"

// stageTrackerModifierOrder is the modifier precedence the payload carries.
var stageTrackerModifierOrder = []string{modStalled, modRegressed, modHold, modUnauthorized, modNeedsHuman, modNeedsDecision, modNeedsTriage, modPossibleDupe, modNeedsRebase, modBlocked, modDraft}

Expand Down
Loading
Loading