Skip to content

🐛 fix(close-on-merge): a Refs-only PR never closes the issue it references - #16835

Merged
hivecommons-hive[bot] merged 4 commits into
hivecommons:v6from
Danathar:fix/close-on-merge-refs
Nov 6, 2026
Merged

hivecommons-hive[bot] merged 4 commits into
hivecommons:v6from
Danathar:fix/close-on-merge-refs

Conversation

@Danathar

@Danathar Danathar commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Executive summary

Close-on-merge closed issues on PRs that only referenced them. projectbluefin/utah-packages#490 is the example. PR #860 said Refs #490, and the hive's own coverage comment said it would not close the issue. When #860 merged, the backfill sweep closed #490 anyway: "Fixed by #860 … Closing".

The Refs guard has existed since #12391; it never fired on this path. The backfill sweep passes the configured short repository name (utah-packages). The guard compared it with the parsed owner/repo and found no reference.

This PR does four things:

  • It compares references as owner/repo.
  • The close path reads the same "non-closing" decision as the coverage comment.
  • An issue marked hive/verified-open or hive/partially-addressed is never closed except by a PR whose own text closes it.
  • A read-only, owner-only GET /api/close-on-merge/wrong-closes lists past wrong closes for maintainers to reopen. Each scan is bounded: a 60 s deadline, at most 500 closed issues, and a 10-minute cache per window. Nothing is reopened automatically.

What

PR text / issue labels Before (backfill, short repo name) After
Closes #N closed closed
Refs #N (#490) closed left open, hive/partially-addressed
Part of #N closed left open, hive/partially-addressed
"#N stays open" / "leaves #N open" closed left open, hive/partially-addressed
branch-name claim only closed closed
branch-name claim only + hive/verified-open closed left open (issue_marked_open)
branch-name claim only + hive/partially-addressed closed left open (issue_marked_open)
Closes #N + hive/verified-open closed closed (the PR's own text closes it)

Why

  • The path: the projectbluefin hive log at 2026-11-01T12:22:30Z shows close-on-merge backfill sweep closed:1. fix: add default stats config for agents #490's events show the close at 12:22:26Z. The build then was a05d26a, which already had the Refs guard.
  • The mismatch: CloseOnMergeBackfill calls the close with repo from activeRepos(), which is the short name; its log lines read "repo":"utah-packages". The PR claim check two lines earlier used owner/repo, so the branch hive/490-dev-tools-parity claimed the issue. Inside, closeOnMergePRRefsIssue compared the parsed projectbluefin/utah-packages with utah-packages. The answer was "no reference", so partialForDirectClose let the close through.
  • The disagreeing decisions: the coverage comment's decision (EnsureIssueStagePRLink) is "no closing keyword, and a Refs/Part of reference or stays-open wording". The close path only looked at Refs.
  • The stale test: TestCloseOnMergeBackfillClosesLinkedMergedPR (from 🐛 Close fixed issues after hive PR merges #11290, before the guard) expected backfill to close an issue on Refs #7. It passed only through the same mismatch. Its body is now Fixes #7.

How

  • closeIssueForMergedPRClaimWithIssue:
    • It builds refRepo (owner/repo) once and uses it for every reference check: claim, Refs, coverage and closing keyword.
    • res.Repo, status notes and label writes keep the caller's name.
  • prLeavesIssueOpen: the shared decision, which feeds the direct-close guard.
  • closeOnMergeIssueMarkedOpen: skips with issue_marked_open when the PR has no closing keyword for the issue.
  • CloseOnMergeWrongCloses and GET /api/close-on-merge/wrong-closes?days=N:
    • They take closed issues per watched repo in the window, find the hive's own "Fixed by #N" comment and read PR #N.
    • An issue is listed when the shared decision says the PR left it open (pr_leaves_issue_open), or when the issue is marked open and the PR has no closing keyword (issue_marked_open).
    • Read-only.
    • The endpoint answers only a verified owner (requireOwnerRole), because the scan spends the installation token's API budget.
    • The scan runs under a 60 s deadline. It inspects at most 500 closed issues: one comments read each, plus a PR read when a close note names one. Past that it returns truncated: true with a note.
    • Each days value's answer is cached for 10 minutes. The cache lock is held for the scan, so concurrent requests wait and then read the cache. A failed scan is not cached.
    • GitHub's since filters on updated_at, so the close time is checked locally; the docs say so.

Files

File Change
src/pkg/github/close_on_merge.go refRepo, prLeavesIssueOpen, closeOnMergeIssueMarkedOpen
src/pkg/github/close_on_merge_audit.go New: the wrong-closes report
src/pkg/dashboard/api_close_on_merge_audit.go, api.go, dashboard/openapi.json New read-only endpoint and its spec entry
src/pkg/github/close_on_merge_test.go Stale Refs #7 close expectation becomes Fixes #7
Docs (hive-merge.md, API reference), changelog Behaviour and endpoint

Tests

Test Covers
TestCloseOnMergeRefsNeverCloses490 Real backfill, short repo name: Closes / Refs / Part of / stays-open / branch-only × verified-open / partially-addressed
TestPRLeavesIssueOpen The shared decision, including cross-repo Refs and "does not close #N" (a GitHub keyword)
TestCloseOnMergeWrongClosesReport Listed: #490 shape, marked-open; not listed: a closing PR, person-closed, quoted marker, PR, outside window
TestCloseOnMergeWrongClosesEndpoint days default and bounds, response shape
Mutants 24/24 caught (14 on the fix, 10 on the endpoint guards); two needed the report test strengthened
go test ./pkg/github/... ./pkg/writeback/ ./pkg/dashboard/ pass, incl. OpenAPI route parity; API-reference and docs citations, relative links all pass
check-docs-citations.py src/docs 2007 verified

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1

…ences

projectbluefin/utah-packages#490: PR hivecommons#860 said "Refs hivecommons#490" and the coverage
comment said Hive would not close the issue, yet the backfill sweep closed
it on merge. The backfill passes the configured short repo name; the Refs
guard compared it with the parsed owner/repo and saw no reference.

- every reference check in the close path compares owner/repo (refRepo)
- the close path reads the coverage comment's decision (prLeavesIssueOpen:
  no closing keyword + Refs/Part of or stays-open wording)
- an issue marked hive/verified-open or hive/partially-addressed closes only
  on a PR whose own text closes it
- GET /api/close-on-merge/wrong-closes lists past wrong closes (read-only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 5, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hanthor for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#16807 🐛 fix: route workflow blockers to capable lanes CONFLICT src/docs/api-reference.md
src/docs/api-reference/dashboard-misc.md
src/docs/api-reference/packs-and-acmm.md

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Nov 5, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Check report (hive scanner, read-only — fork branch, nothing pushed) for head 2dc05ee:

The red relative links and anchors resolve check is caused by this diff, but not by any link. The workflow's last step, bash src/scripts/check-api-reference-citations.sh, fails because the PR moves code in src/pkg/dashboard/api.go and api_close_on_merge_audit.go, so the path:line citations in the docs no longer point at the route registrations (job log):

DRIFT api-reference.md:321 POST /api/repos/{owner}/{repo}/items/{number}/accept-triage -> pkg/dashboard/api.go:576 (line does not register it)
DRIFT api-reference/dashboard-misc.md:53 GET /api/hotspots -> pkg/dashboard/api.go:567 (line does not register it)
DRIFT api-reference/dashboard-misc.md:54 GET /api/close-on-merge/wrong-closes -> pkg/dashboard/api_close_on_merge_audit.go:24 (line does not register it)
DRIFT api-reference/packs-and-acmm.md:25 POST /api/repos/{owner}/{repo}/items/{number}/accept-triage -> pkg/dashboard/api.go:576 (line does not register it)
api-reference citations: 4 drifted citation(s).

Fix (on your branch, from the repo root):

bash src/scripts/check-api-reference-citations.sh --fix
git add src/docs && git commit -s -m "docs: refresh api-reference citations"

The script rewrites the four line numbers in src/docs/api-reference.md, src/docs/api-reference/dashboard-misc.md and src/docs/api-reference/packs-and-acmm.md; nothing else in the check is red.

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Danathar this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • check-failure

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Queued in your relay fix queue (5 waiting): fixes are handed out before new work as soon as you have capacity.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security perspective (read at head 2dc05ee; close logic changes look sound — refRepo normalisation and the isHiveAccount + marker check on the audit comment both hold up).

1. GET /api/close-on-merge/wrong-closes is an unbounded GitHub fan-out reachable by any read-role session (medium, in-scope)

src/pkg/dashboard/api_close_on_merge_audit.go:24-47 registers the route on the plain authenticated mux (src/pkg/dashboard/api.go:567) with no requireOwnerRole; roleEnforcement admits read role on any GET (src/pkg/dashboard/server.go:2853). Each request then runs CloseOnMergeWrongCloses (src/pkg/github/close_on_merge_audit.go:38-72): for every active repo, up to claimSearchMaxPages (=10, prclaims.go:59) × 100 issues, and for every issue one Issues.ListComments (:116) plus a PullRequests.Get when a marker is found (:87). IssueListByRepoOptions.Since filters on updated_at, not closed_at, so with days=90 this walks every issue touched in three months. Worst case is on the order of repos × 1,000 × 2 REST calls per GET, on the hive's installation token, with no cache, cooldown, singleflight or per-request deadline — only r.Context(), which a client can hold open. Every other dashboard handler that hits GitHub on request fetches a single item (e.g. api.go:1443, api_repo_item_decision_reroute.go:60).

Consequence: a read-only dashboard user (or a script) can drain the shared GitHub rate budget that the merge train, close-on-merge and webhooks depend on. That is a new availability/trust-boundary surface this PR adds, not a pre-existing one.

Suggested fix — owner-only, a hard deadline, and a scan cap:

--- a/src/pkg/dashboard/api_close_on_merge_audit.go
+++ b/src/pkg/dashboard/api_close_on_merge_audit.go
 func (s *Server) handleCloseOnMergeWrongCloses(w http.ResponseWriter, r *http.Request) {
+	if !requireOwnerRole(w, r) {
+		return
+	}
 	days := 30
@@
-	items, err := closeOnMergeWrongClosesFunc(r.Context(), s.deps.GHClient, since)
+	ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
+	defer cancel()
+	items, err := closeOnMergeWrongClosesFunc(ctx, s.deps.GHClient, since)
--- a/src/pkg/github/close_on_merge_audit.go
+++ b/src/pkg/github/close_on_merge_audit.go
+// closeOnMergeAuditMaxIssues caps the issues inspected per report so one
+// request cannot spend the installation token's rate budget.
+const closeOnMergeAuditMaxIssues = 500
@@
 	var out []CloseOnMergeWrongClose
 	var firstErr error
+	inspected := 0
 	for _, repo := range c.activeRepos() {
@@
 			for _, issue := range issues {
+				if inspected >= closeOnMergeAuditMaxIssues {
+					return out, fmt.Errorf("report truncated after %d issues; narrow ?days", inspected)
+				}
+				inspected++
 				if row, ok := c.closeOnMergeWrongClose(ctx, owner, name, full, since, issue); ok {

(Alternatively, cache the result per days for ~10 minutes behind a singleflight.Group; either is fine, but the endpoint should not stay read-role + uncapped.) The docs row in dashboard-misc.md and the openapi entry would then say "Owner only" / 403.

Scope note: the hive's contract link resolved to #490 (a May PR); the PR's actual target is projectbluefin/utah-packages#490, which I judged against.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

hivecommons-hive Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from ci-maintainer (folded here because this head already carries its hive review):

Correctness review @ 2dc05ee — the fix itself checks out; one CI gate this PR trips needs a 4-line docs fix.

1. relative links and anchors resolve fails on this head (in-scope, agent-fixable). check-api-reference-citations.sh reports 4 drifted citations. The new row in src/docs/api-reference/dashboard-misc.md:54 cites pkg/dashboard/api_close_on_merge_audit.go:24, but the checker wants the line that registers the route, which is src/pkg/dashboard/api.go:567; the 3-line insertion in api.go also shifts /api/hotspots (567→570) and accept-triage (576→579) in api-reference.md:321, dashboard-misc.md:53, packs-and-acmm.md:25. Verified locally: after the edit below plus bash src/scripts/check-api-reference-citations.sh --fix, the checker prints "all pkg/: references verified".

--- a/src/docs/api-reference/dashboard-misc.md
+++ b/src/docs/api-reference/dashboard-misc.md
@@ -54 +54 @@
-… Maintainers reopen what they agree with; the hive reopens nothing | `pkg/dashboard/api_close_on_merge_audit.go:24` |
+… Maintainers reopen what they agree with; the hive reopens nothing | `pkg/dashboard/api.go:567`, `pkg/dashboard/api_close_on_merge_audit.go` |

then bash src/scripts/check-api-reference-citations.sh --fix for the three shifted lines.

2. Advisory — the table under-states one behaviour change. Before this PR, on the backfill path closeOnMergeCoverage (close_on_merge.go:872) compared prRepo (owner/repo) against the short issueRepo, so cov.Closing was always false there and the cited-path rule (partialForDirectClose, close_on_merge.go:861-869) never ran. With refRepo it now runs: a Closes #N PR that touches none of the issue's cited paths is labelled partially_addressed instead of closed. That is the guard's designed behaviour (already live on the webhook path), so no change requested — just worth a line in the PR body/changelog since the "Closes #N → closed → closed" row doesn't cover it.

3. Low — audit resolves Fixed by #N in the issue's repo only. closeOnMergeCloseComment (close_on_merge.go:1035-1037) writes Fixed by #%d without a repo for cross-repo PRs, and close_on_merge_audit.go:89 reads getPullRequestForCloseOnMerge(ctx, full, pr) with full = the issue's repo. For an issue closed by a PR in another watched repo, the report reads an unrelated PR #N (or 404s and skips). Read-only, so no harm beyond a possible stray row; a follow-up could record PRRepo in the comment or skip when merged.Base.Repo.FullName != full.

Not verifiable here: go test is blocked on this host; CI's Go jobs are green on this head and go build ./pkg/github/ ./pkg/dashboard/ passes locally. Note the dispatcher resolved the contract to #490 (an unrelated merged PR); I judged against projectbluefin/utah-packages#490 as the body states.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Read the tree at 1a7a812, not just the diff. The mechanism in the body checks out:

  • CloseOnMergeBackfill (src/pkg/github/close_on_merge.go:417) runs the claim check with issueRepo (owner/repo), then at :424 calls closeIssueForMergedPRClaimWithIssue(ctx, repo, …) with the short configured name from activeRepos(). Before this PR, closeOnMergePRRefsIssue (:570-579) compared ref.Repo (owner/repo from ParseReferencedIssues) against that short name with EqualFold, so Refs #N never matched and partialForDirectClose(false) (:861-867) let the close through. Normalising to refRepo via c.splitRepo (:633-636) fixes exactly that comparison; res.Repo, markPartiallyAddressed and the label writes still get the caller's name, so nothing else changes shape.
  • prLeavesIssueOpen (:586-601) is a strict superset of the old closeOnMergePRRefsIssue input to partialForDirectClose: it returns false whenever FindClosingKeywordReference matches, and partialForDirectClose only consults it when !cov.Closing, so Closes #N behaviour is unchanged.
  • The new issue_marked_open guard (:785-794) sits after the partial check and only fires when !cov.Closing, matching the table in the body (Closes #N + hive/verified-open still closes).
  • TestCloseOnMergeRefsNeverCloses490 builds the client with newTestClient(t, srv, "o", []string{"r"}) and drives the real CloseOnMergeBackfill, so it exercises the short-name path that produced fix: add default stats config for agents #490 rather than calling the inner function directly. The Refs #7 → Fixes #7 edit in TestCloseOnMergeBackfillClosesLinkedMergedPR is the right call: that expectation only ever passed through the same mismatch.
  • GET /api/close-on-merge/wrong-closes is gated by requireOwnerRole (api_agent_control.go:554), read-only, and bounded (60 s / 500 issues / 10 min cache); closeOnMergeFixedByRE only matches same-repo Fixed by #N (merged notes, so cross-repo close notes are silently skipped — fine for a maintainer report, just noting it is not exhaustive.

Looks correct to me. No Closes/Refs issue link in the body; if there is a tracking issue for #490-style wrong closes, linking it would help the queue.

Review findings from adjudicator-4 (folded here because this head already carries its hive review):

style — delta re-review at 1a7a812 (PR-authored delta is commit 5ce720e; the rest of the 165-file diff is v6 merges). Prior docs-currency finding (src/docs/api-reference/dashboard-misc.md:54 citation drift) is fixed: check-api-reference-citations.sh and check-docs-citations.py src/docs both pass at head.

One advisory, non-blocking:

Cache lock held across the 60 s scan serialises unrelated days windows — src/pkg/dashboard/api_close_on_merge_audit.go:65-67, :78. cache.Lock() + defer cache.Unlock() wraps the whole closeOnMergeWrongClosesFunc call, so a ?days=7 request (even a cache hit) blocks behind an in-flight ?days=90 scan for up to closeOnMergeAuditDeadline. The sibling cache in this package deliberately avoids this (api_version_release_notes.go:73-75: "Guarded by its own mutex so a slow build never holds the cache lock"). The comment at :33-35 documents the choice, so this is a known trade-off, but a per-key in-flight gate keeps the single-flight property without the cross-window stall:

 var closeOnMergeAuditCache = struct {
 	sync.Mutex
-	entries map[int]closeOnMergeAuditEntry
-}{entries: map[int]closeOnMergeAuditEntry{}}
+	entries  map[int]closeOnMergeAuditEntry
+	inFlight map[int]chan struct{}
+}{entries: map[int]closeOnMergeAuditEntry{}, inFlight: map[int]chan struct{}{}}
...
-	cache.Lock()
-	defer cache.Unlock()
-	if e, ok := cache.entries[days]; ok && time.Since(e.at) < closeOnMergeAuditCacheTTL {
-		... serve cached ...
-	}
+	for {
+		cache.Lock()
+		if e, ok := cache.entries[days]; ok && time.Since(e.at) < closeOnMergeAuditCacheTTL {
+			cache.Unlock()
+			... serve cached ...
+			return
+		}
+		wait, busy := cache.inFlight[days]
+		if !busy {
+			wait = make(chan struct{})
+			cache.inFlight[days] = wait
+			cache.Unlock()
+			break
+		}
+		cache.Unlock()
+		select {
+		case <-wait:
+		case <-r.Context().Done():
+			return
+		}
+	}
+	defer func() { cache.Lock(); close(cache.inFlight[days]); delete(cache.inFlight, days); cache.Unlock() }()
 	ctx, cancel := context.WithTimeout(r.Context(), closeOnMergeAuditDeadline)
 ...
-		cache.entries[days] = closeOnMergeAuditEntry{at: time.Now(), resp: resp}
+		cache.Lock()
+		cache.entries[days] = closeOnMergeAuditEntry{at: time.Now(), resp: resp}
+		cache.Unlock()

Everything else in the delta reads cleanly: labelled break repos and the closeOnMergeAuditCandidate extraction (src/pkg/github/close_on_merge_audit.go:81-89, :106-109) are idiomatic; requireOwnerRole matches the ~230 other handlers; tests cover the 403 path and truncation. Note: the dispatch pointed me at #490, which is an unrelated issue — the PR's #490 is projectbluefin/utah-packages#490.

Evidence bundle `#168351a7a812` sha256:d32b753aa59e87357667736a8930bbfab255578198e3dbbd11d0da8b6c0adf3f — download from the dashboard or `hivectl review evidence #16835`.

Danathar and others added 2 commits November 5, 2026 18:15
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
…PI citations

Security review on hivecommons#16835: the report fanned out unbounded GitHub reads on
the installation token for any read-role session.

- requireOwnerRole; 60 s request deadline
- at most 500 closed issues inspected per scan (truncated + note past it)
- 10-minute cache per days value; the lock is held for the scan so
  concurrent requests read the cache; failed scans are not cached
- document that GitHub's since filters on updated_at
- re-anchor the api-reference citations the new route line shifted

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@Danathar

Danathar commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Re the security review: finding 1 was valid, fixed in 5ce720e.

  • Owner only: requireOwnerRole. Read, read-write and unverified owner sessions get 403 before any GitHub call.
  • Deadline: each scan runs under a 60 s request deadline.
  • Cap: at most 500 closed issues are inspected. Past that the answer has truncated: true, a note, and complete: false.
  • Cache: each days value's answer is cached for 10 minutes. The lock is held for the scan, so concurrent requests wait and then read the cache. A failed scan is not cached.
  • since semantics: GitHub's since filters on updated_at. Kept and documented; the close time is checked locally.
  • Docs: openapi.json and the API reference say owner-only, with the 403, the cap and the cache.
  • Tests: read role → 403 with no scan; the cap truncates after N issues; a cache hit makes no GitHub call. Ten new mutants on the guards, all caught.

Also fixed the failing "relative links and anchors resolve" job. The new route line shifted the API-reference citations for /api/hotspots and accept-triage, and the new row cited the handler instead of the route. All are re-anchored, and check-api-reference-citations.sh passes.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness — delta re-review at 5ce720e (previous head 2dc05ee; only the owner-gate/deadline/cap/cache commit is new, the rest of the compare is the v6 merge).

Previous finding [docs-currency] src/docs/api-reference/dashboard-misc.md:54 — fixed: the citation now points at pkg/dashboard/api.go:567, which registers GET /api/close-on-merge/wrong-closes at head.

New (medium, in-scope): a scan cut off by the 60 s deadline or a client disconnect can be cached for 10 minutes as complete: true.

handleCloseOnMergeWrongCloses derives the scan context from r.Context() with a 60 s timeout (src/pkg/dashboard/api_close_on_merge_audit.go:77-80) and caches the answer whenever err == nil (:94-97). But inside the scan the per-issue reads swallow context errors: closeOnMergeCommentPR returns 0 on any ListComments error (src/pkg/github/close_on_merge_audit.go:148-151) and closeOnMergeWrongClose returns false when the PR read errors (:119-122). Only Issues.ListByRepo feeds firstErr (:70-76). So when the deadline (or the browser navigating away) hits during the per-issue loop of the last repo's last page — the likely place for a 30-day window with up to ~1000 reads — every remaining issue is silently classified "not a wrong close", CloseOnMergeWrongCloses returns nil error, and the handler stores that as complete: true, truncated: false and serves it to every owner for the next 10 minutes. For a report whose purpose is to tell a maintainer which issues to reopen, a confidently-complete list that is missing entries is worse than an error.

Smallest fix: surface the context error before caching.

--- a/src/pkg/github/close_on_merge_audit.go
+++ b/src/pkg/github/close_on_merge_audit.go
@@ func (c *Client) CloseOnMergeWrongCloses(ctx context.Context, opts CloseOnMergeAuditOptions) (CloseOnMergeAudit, error) {
 		}
 	}
+	// Per-issue reads swallow their errors; a scan cut short by the deadline
+	// or a cancelled request must not read as complete.
+	if firstErr == nil && ctx.Err() != nil {
+		firstErr = ctx.Err()
+	}
 	sort.Slice(out.Items, func(i, j int) bool {

(Optionally also derive the scan context from context.WithoutCancel(r.Context()) in the handler so a disconnect does not waste the 60 s budget already spent.) A test that cancels the context from the comments handler after N issues and asserts a non-nil error / no cache entry would pin it.

— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@Danathar this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • check-cancelled

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Queued in your relay fix queue (9 waiting): fixes are handed out before new work as soon as you have capacity.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the diff against the tree at merge-base (src/pkg/github/close_on_merge.go, prclaims.go, client.go), plus both production callers. The fix matches the mechanism described and looks correct to me.

Verified

  • client.go:1976 splitRepo returns (c.org, repo) for a short name, so refRepo at close_on_merge.go:634-637 becomes owner/repo; ParseReferencedIssues/FindClosingKeywordReference (prclaims.go:531-535) compare against that full form. The old call at the former closeOnMergePRRefsIssue(pr, prRepo, issueRepo, …) with a short issueRepo could never match — the Refs guard really was dead on the backfill path.
  • Both production call sites (close_on_merge.go:301, :424) obtain pr via getPullRequestForCloseOnMerge (REST Get / cached detail), so base.repo.full_name is populated and prRepo is already full. The new test fixture mirrors that shape (close_on_merge_refs_490_test.go:49, org o, short repo r).
  • issue_marked_open is checked only after partialForDirectClose and gated on !cov.Closing, so Closes #N + hive/verified-open still closes, as the table in the body says.
  • Endpoint: requireOwnerRole exists (api_agent_control.go:554); scan is bounded by closeOnMergeAuditDeadline, closeOnMergeAuditMaxIssues, and candidates are filtered on closed_at locally (close_on_merge_audit.go:109-110) since GitHub since is updated_at.

One low-severity note (not a defect in reachable code)
prRepo (close_on_merge.go:624-627) still falls back to the raw issueRepo when the PR lacks base.repo.full_name, while refRepo is normalized. In that fallback a bare Closes #N resolves to the short prRepo and no longer equals refRepo, so the claim check would skip with no_closing_or_claim_metadata. Unreachable via the two current callers, but normalizing prRepo through the same splitRepo would make the function safe for any future caller that passes a hand-built PR.

Holding the audit cache lock for the whole 60 s scan is fine for an owner-only endpoint; just noting that concurrent days values serialize.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@Danathar

Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

The only red check on 1a7a812 was overlayfs-exec-guard, and that job was cancelled (check-cancelled), not failed. I've re-run it. There's no code change; the head stays as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts-with-open-pr Open PR has a merge conflict with another open PR dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant