Repository navigation
🐛 fix(close-on-merge): a Refs-only PR never closes the issue it references - #16835
Conversation
…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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
Check report (hive scanner, read-only — fork branch, nothing pushed) for head 2dc05ee: The red Fix (on your branch, from the repo root): The script rewrites the four line numbers in — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 🐝 Hive Agent: |
|
@Danathar this PR is back in your court ( Failing checks:
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. |
There was a problem hiding this comment.
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
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Correctness review @ 2dc05ee — the fix itself checks out; one CI gate this PR trips needs a 4-line docs fix. 1. --- 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 2. Advisory — the table under-states one behaviour change. Before this PR, on the backfill path 3. Low — audit resolves Not verifiable here: Review findings from Read the tree at
Looks correct to me. No Review findings from style — delta re-review at 1a7a812 (PR-authored delta is commit 5ce720e; the rest of the 165-file diff is One advisory, non-blocking: Cache lock held across the 60 s scan serialises unrelated 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 |
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>
|
Re the security review: finding 1 was valid, fixed in 5ce720e.
Also fixed the failing "relative links and anchors resolve" job. The new route line shifted the API-reference citations for |
There was a problem hiding this comment.
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
|
@Danathar this PR is back in your court ( Failing checks:
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. |
There was a problem hiding this comment.
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:1976splitReporeturns(c.org, repo)for a short name, sorefRepoatclose_on_merge.go:634-637becomesowner/repo;ParseReferencedIssues/FindClosingKeywordReference(prclaims.go:531-535) compare against that full form. The old call at the formercloseOnMergePRRefsIssue(pr, prRepo, issueRepo, …)with a shortissueRepocould never match — theRefsguard really was dead on the backfill path.- Both production call sites (
close_on_merge.go:301,:424) obtainprviagetPullRequestForCloseOnMerge(REST Get / cached detail), sobase.repo.full_nameis populated andprRepois already full. The new test fixture mirrors that shape (close_on_merge_refs_490_test.go:49, orgo, short repor). issue_marked_openis checked only afterpartialForDirectCloseand gated on!cov.Closing, soCloses #N+hive/verified-openstill closes, as the table in the body says.- Endpoint:
requireOwnerRoleexists (api_agent_control.go:554); scan is bounded bycloseOnMergeAuditDeadline,closeOnMergeAuditMaxIssues, and candidates are filtered onclosed_atlocally (close_on_merge_audit.go:109-110) since GitHubsinceisupdated_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
|
The only red check on 1a7a812 was |
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
Refsguard 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 parsedowner/repoand found no reference.This PR does four things:
owner/repo.hive/verified-openorhive/partially-addressedis never closed except by a PR whose own text closes it.GET /api/close-on-merge/wrong-closeslists 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
Closes #NRefs #N(#490)hive/partially-addressedPart of #Nhive/partially-addressedhive/partially-addressedhive/verified-openissue_marked_open)hive/partially-addressedissue_marked_open)Closes #N+hive/verified-openWhy
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 theRefsguard.CloseOnMergeBackfillcalls the close withrepofromactiveRepos(), which is the short name; its log lines read"repo":"utah-packages". The PR claim check two lines earlier usedowner/repo, so the branchhive/490-dev-tools-parityclaimed the issue. Inside,closeOnMergePRRefsIssuecompared the parsedprojectbluefin/utah-packageswithutah-packages. The answer was "no reference", sopartialForDirectCloselet the close through.EnsureIssueStagePRLink) is "no closing keyword, and aRefs/Part ofreference or stays-open wording". The close path only looked atRefs.TestCloseOnMergeBackfillClosesLinkedMergedPR(from 🐛 Close fixed issues after hive PR merges #11290, before the guard) expected backfill to close an issue onRefs #7. It passed only through the same mismatch. Its body is nowFixes #7.How
closeIssueForMergedPRClaimWithIssue: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 withissue_marked_openwhen the PR has no closing keyword for the issue.CloseOnMergeWrongClosesandGET /api/close-on-merge/wrong-closes?days=N:pr_leaves_issue_open), or when the issue is marked open and the PR has no closing keyword (issue_marked_open).requireOwnerRole), because the scan spends the installation token's API budget.truncated: truewith a note.daysvalue'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.sincefilters onupdated_at, so the close time is checked locally; the docs say so.Files
src/pkg/github/close_on_merge.gorefRepo,prLeavesIssueOpen,closeOnMergeIssueMarkedOpensrc/pkg/github/close_on_merge_audit.gosrc/pkg/dashboard/api_close_on_merge_audit.go,api.go,dashboard/openapi.jsonsrc/pkg/github/close_on_merge_test.goRefs #7close expectation becomesFixes #7hive-merge.md, API reference), changelogTests
TestCloseOnMergeRefsNeverCloses490TestPRLeavesIssueOpenRefsand "does not close #N" (a GitHub keyword)TestCloseOnMergeWrongClosesReportTestCloseOnMergeWrongClosesEndpointdaysdefault and bounds, response shapego test ./pkg/github/... ./pkg/writeback/ ./pkg/dashboard/check-docs-citations.py src/docsNotes
Running the report's logic now: I ran the same decision with
ghover the 49 projectbluefin issues that carry a hive close-on-merge comment. It finds 26 wrong closes, for a maintainer to judge and reopen:parity(gnome-apps): resolve factory outputs cairomm1.16 through glibmm2.68 projectbluefin/utah-packages#482 from the original report is not one: PR feat: advisory digest card + governor posting #543 has a closing keyword for it.
Not covered: parity(fonts-i18n): resolve factory outputs adobe-mappings-cmap through google-noto-serif-cjk-vf-fonts projectbluefin/utah-packages#493 was closed on the contributor "already resolved by feat(dashboard): publish snapshot.json and support HIVE_DOCS_SUBDIR #669" path, a different close path, and feat(dashboard): publish snapshot.json and support HIVE_DOCS_SUBDIR #669 never names fix: sparkline race condition on page load #493. fix: real-time agent output polling in detail panel #504 was closed with no hive comment on 10-27; the hive log no longer reaches that day.
🤖 Generated with Claude Code
https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1