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-15148-close-hive-merged-pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Close issues fixed by contributor PRs merged by the hive, including merges into non-default release branches, so covered-by-PR stage labels and activity rows do not remain stale ([#15148](https://github.com/hivecommons/hive/issues/15148)).
2 changes: 1 addition & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Top-level YAML keys accepted by `config.Config`:
| `quality` | Optional quality-lane capabilities. | `formal: true` enables agent-authored Spin models only at ACMM L5/L6; see [Formal verification](formal-verification.md). |
| `runs` | Long-running run settings: `runs.external.flue`, the report-only external-execution binding pilot, and `runs.external.omp`, the OMP workbench host behind the same adapter. | Both default OFF and independent. `enabled: true` with no `mode` runs in `shadow` (persists admissions, observes, never starts external work); `mode: report-only` dispatches. Flue dispatches to a runtime at `endpoint` pinned to `workflow_version` and needs a build with the `extwork_flue` tag; OMP offers work over the contributor relay to a workbench peer declaring `ext-exec/omp` whose declared version matches `workflow_version`, and needs the `extwork_omp` tag. Neither host receives a repository credential, dashboard token, or publication tool; OMP (tier T3) is additionally refused any write-capable stage. See [External workflow admission](design/external-workflow-admission.md). |
| `auto_merge` | The App self-merge sweep: whether and how the Forge App merges its **own** CI-green PRs. | Default ON, but inert below `acmm_level: 6`. See [App self-merge sweep](#app-self-merge-sweep-auto_merge) below. |
| `issues.close_on_merge` | `true`. | When a hive-authored or trusted-author PR merges and closing keywords or Hive claim metadata show it fixed an open issue, Hive comments `Fixed by #<pr> (merged <sha>). Closing. Reply /reopen if the problem persists.` and closes the issue as `completed`. Issues labelled `needs-reporter-confirmation`, `epic`, or `needs-human` stay open: Hive comments that the fix merged, adds `hive/likely-done`, and waits for `/fixed` or more instructions. Both comments carry `<!-- hive-close-on-merge -->`, Hive's already-handled marker: an issue with that comment is never closed on merge again, so `/reopen` after a Hive close sticks. An issue reopened after the PR merged stays open even when GitHub's closing keyword, not Hive, closed it: before closing, Hive reads the issue timeline since that PR's merge, and a `reopened` event by anyone but Hive (including `github-actions[bot]` from `/reopen`) skips the close and posts one comment carrying `<!-- hive-reopened-after-merge pr=<pr> -->`, so later sweeps skip that PR without rereading the timeline. The marker is per PR: a different PR that merges after the reopen can still close the issue. If the timeline cannot be read, Hive leaves the issue open and retries on the next sweep. |
| `issues.close_on_merge` | `true`. | When a PR merges that was authored by Hive or a trusted author, or that Hive itself merged (the merge actor is the configured Hive identity, resolved from `merged_by` or a PR detail lookup when cached metadata omits it; [#15148](https://github.com/hivecommons/hive/issues/15148)), and closing keywords or Hive claim metadata show it fixed an open issue, Hive comments `Fixed by #<pr> (merged <sha>). Closing. Reply /reopen if the problem persists.` and closes the issue as `completed`. Issues labelled `needs-reporter-confirmation`, `epic`, or `needs-human` stay open: Hive comments that the fix merged, adds `hive/likely-done`, and waits for `/fixed` or more instructions. Both comments carry `<!-- hive-close-on-merge -->`, Hive's already-handled marker: an issue with that comment is never closed on merge again, so `/reopen` after a Hive close sticks. An issue reopened after the PR merged stays open even when GitHub's closing keyword, not Hive, closed it: before closing, Hive reads the issue timeline since that PR's merge, and a `reopened` event by anyone but Hive (including `github-actions[bot]` from `/reopen`) skips the close and posts one comment carrying `<!-- hive-reopened-after-merge pr=<pr> -->`, so later sweeps skip that PR without rereading the timeline. The marker is per PR: a different PR that merges after the reopen can still close the issue. If the timeline cannot be read, Hive leaves the issue open and retries on the next sweep. |
| Issue↔PR link safeguard | Always on with issue stage and claim-label sweeps. | GitHub shows its issue-list PR icon only when a default-branch PR body contains a closing keyword. When Hive sees a Hive-authored default-branch PR covering an issue and the PR body does not say the issue stays open, Hive appends `Fixes #N` to that PR body. Existing Hive-authored default-branch PRs that used `Refs #N` but are recorded by Hive stage/claim metadata as the implementation PR are retrofitted once with the same closer and `<!-- hive:issue-link-fixed -->`; human-authored PR bodies are never edited. If the body says `Part of #N` or otherwise leaves the issue open, Hive does not add a closer; it posts one stage-entry comment on the issue with the PR link and explains that GitHub will not show the icon without a closing keyword. Non-default-branch PRs get the same issue comment. |
| `issues.close_on_merge_backfill_interval` | `1h`. | How often Hive scans open issues carrying Hive PR-linkage signals (`stage/040-covered-by-pr` or the retired `🐝 covered by PR`, `hive/likely-done`, claim/covered comments, or timeline PR references) and applies the same close-on-merge policy to PRs that merged before the current process saw them. |
| `issues.close_on_merge_interval` | `10m`. | How often the close-on-merge **ledger sweep** walks every merged-PR claim in the duplicate-PR claim ledger. Passes in between (every governor eval cycle and manual rescan) only look at claims whose PR merged since the last full walk, so a fresh merge still closes its issue on the next pass without re-reading the whole ledger ([#11778](https://github.com/hivecommons/hive/issues/11778)). Both the ledger sweep and the backfill pause while the GitHub API budget mode is not `normal`; Hive logs one line on each pause and resume. Env override: `HIVE_CLOSE_ON_MERGE_INTERVAL` (Go duration). |
Expand Down
11 changes: 9 additions & 2 deletions src/pkg/github/close_on_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,15 @@ func (c *Client) closeIssueForMergedPRClaimWithIssue(ctx context.Context, issueR
}
author := safeGetLogin(pr.GetUser())
if !opts.Identity.Matches(author) && (opts.TrustedAuthor == nil || !opts.TrustedAuthor(prRepo, author)) {
res.Action, res.Reason = CloseOnMergeSkipped, "untrusted_author"
return res
// Merging is the hive's acceptance of an external contributor's PR.
// List/cache entries can omit merged_by; resolve the terminal actor
// before rejecting it, especially on non-default release branches
// where GitHub does not apply closing keywords itself (#15148).
owner, repoName := c.splitRepo(prRepo)
if !opts.Identity.Matches(c.prTerminalMergedBy(ctx, owner, repoName, pr)) {
res.Action, res.Reason = CloseOnMergeSkipped, "untrusted_author"
return res
}
}
if !claimMetadata && !closeOnMergePRClaimsIssue(pr, prRepo, issueRepo, issueNumber) {
res.Action, res.Reason = CloseOnMergeSkipped, "no_closing_or_claim_metadata"
Expand Down
1 change: 1 addition & 0 deletions src/pkg/github/close_on_merge_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func TestCloseOnMergeDecisionSkipAndFailurePaths(t *testing.T) {
head = "scanner/other"
}
pr := mergedTestPR(42, tc.author, head, tc.body)
pr.MergedBy = &gh.User{Login: gh.Ptr("maintainer")}
res := c.closeIssueForMergedPRClaim(context.Background(), "o/r", 7, pr, tc.claimMetadata, CloseOnMergeOptions{
Identity: HiveIdentity{AppLogin: "hive[bot]"},
TrustedAuthor: tc.trusted,
Expand Down
44 changes: 39 additions & 5 deletions src/pkg/github/close_on_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ func TestCloseOnMergeDecisionClosesOrAwaits(t *testing.T) {
prBody string
marker bool
unmerged bool
external bool
mergedBy string
lookup bool
wantReason string
wantAction CloseOnMergeAction
wantPatch bool
}{
{name: "plain open issue closes completed", wantAction: CloseOnMergeClosed, wantPatch: true},
{name: "external PR merged by someone else stays open", external: true, mergedBy: "maintainer", prBody: "Fixes #7", wantAction: CloseOnMergeSkipped, wantReason: "untrusted_author"},
{name: "external PR missing merge actor stays open", external: true, lookup: true, prBody: "Fixes #7", wantAction: CloseOnMergeSkipped, wantReason: "untrusted_author"},
{name: "external PR merged by hive closes", external: true, mergedBy: "hive[bot]", prBody: "Fixes #7", wantAction: CloseOnMergeClosed, wantPatch: true},
{name: "external PR merge actor resolved from API", external: true, mergedBy: "hive[bot]", lookup: true, prBody: "Fixes #7", wantAction: CloseOnMergeClosed, wantPatch: true},
{name: "hive merge still respects confirmation", external: true, mergedBy: "hive[bot]", labels: []string{"needs-human"}, prBody: "Fixes #7", wantAction: CloseOnMergeAwaiting},
{name: "hive merge still requires merged PR", external: true, mergedBy: "hive[bot]", unmerged: true, wantAction: CloseOnMergeNoop},
{name: "needs confirmation marker gets likely done comment", body: "body\n\nhive: needs-confirmation", labels: []string{"bug"}, prBody: "Fixes #7", wantAction: CloseOnMergeAwaiting},
{name: "needs reporter gets likely done comment", labels: []string{"needs-reporter-confirmation"}, prBody: "Fixes #7", wantAction: CloseOnMergeAwaiting},
{name: "needs human gets likely done comment", labels: []string{"needs-human"}, prBody: "Fixes #7", wantAction: CloseOnMergeAwaiting},
Expand All @@ -91,6 +101,10 @@ func TestCloseOnMergeDecisionClosesOrAwaits(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch {
case r.Method == "GET" && r.URL.Path == "/repos/o/r/pulls/42" && tc.lookup:
pr := mergedTestPR(42, "contributor", "topic", "Fixes #7")
pr.MergedBy = &gh.User{Login: gh.Ptr(tc.mergedBy)}
_ = json.NewEncoder(w).Encode(pr)
case r.Method == "GET" && r.URL.Path == "/repos/o/r/issues/7":
labels := make([]map[string]string, 0, len(tc.labels))
for _, l := range tc.labels {
Expand Down Expand Up @@ -137,6 +151,19 @@ func TestCloseOnMergeDecisionClosesOrAwaits(t *testing.T) {
prBody = "Refs #7"
}
pr := mergedTestPR(42, "hive[bot]", "scanner/fix-7", prBody)
pr.Base.Ref = gh.Ptr("v6")
if tc.external {
pr.User = &gh.User{Login: gh.Ptr("contributor")}
}
if !tc.lookup {
pr.MergedBy = &gh.User{Login: gh.Ptr(tc.mergedBy)}
}
if tc.lookup {
restore := resetPRDetailCacheForTest(time.Now, 0)
defer restore()
c.SetPRDetailTTLFunc(func() time.Duration { return time.Hour })
c.storePRDetail("o/r", 42, pr)
}
if tc.unmerged {
pr.Merged = gh.Ptr(false)
pr.MergedAt = nil
Expand All @@ -156,8 +183,14 @@ func TestCloseOnMergeDecisionClosesOrAwaits(t *testing.T) {
if tc.wantAction == CloseOnMergeAwaiting && (len(posted) != 1 || !strings.Contains(posted[0], "awaiting confirmation")) {
t.Fatalf("awaiting comment = %#v", posted)
}
if tc.wantAction == CloseOnMergeSkipped && (res.Reason != "partially_addressed" || len(posted) != 0) {
t.Fatalf("partial result = %+v, posted = %#v", res, posted)
if tc.wantAction == CloseOnMergeSkipped {
wantReason := tc.wantReason
if wantReason == "" {
wantReason = "partially_addressed"
}
if res.Reason != wantReason || len(posted) != 0 {
t.Fatalf("skipped result = %+v, posted = %#v, want %s without comments", res, posted, wantReason)
}
}
})
}
Expand Down Expand Up @@ -186,9 +219,10 @@ func TestCloseOnMergeBackfillClosesLinkedMergedPR(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{
"number": 42, "title": "fix", "body": "Refs #7", "merged": true,
"merged_at": "2026-10-09T12:00:00Z", "merge_commit_sha": "abcdef0123456789",
"user": map[string]string{"login": "hive[bot]"},
"head": map[string]string{"ref": "scanner/fix-7", "sha": "headsha"},
"base": map[string]any{"repo": map[string]string{"full_name": "o/r"}},
"user": map[string]string{"login": "contributor"},
"merged_by": map[string]string{"login": "hive[bot]"},
"head": map[string]string{"ref": "scanner/fix-7", "sha": "headsha"},
"base": map[string]any{"ref": "v6", "repo": map[string]string{"full_name": "o/r"}},
})
case r.Method == "GET" && r.URL.Path == "/repos/o/r/issues/7":
issueDetailGets++
Expand Down
Loading