From 036bff04204f5f9908a5e395dc544be45daba885 Mon Sep 17 00:00:00 2001 From: SACHIN NAIK Date: Wed, 28 Oct 2026 22:22:28 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20clear=20blocker=20ledger?= =?UTF-8?q?=20entry=20when=20an=20issue=20closes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An `issues: closed` webhook left the issue's blocker ledger row in place, so capabilities.blocked_items counted closed issues. Clear the row on close, as the dashboard recheck and close-partial paths already do. Hive-Run: hivecommons/hive#15273 Hive-Plan: review-backlog style finding, webhook_cache.go issue close Hive-Spec: blocker-ledger#clear-on-close Signed-off-by: SACHIN NAIK --- ...xed-15273-blocker-ledger-clear-on-close.md | 1 + src/pkg/github/issue_blocker_test.go | 39 +++++++++++++++++++ src/pkg/github/webhook_cache.go | 16 ++++++++ 3 files changed, 56 insertions(+) create mode 100644 changelog.d/fixed-15273-blocker-ledger-clear-on-close.md diff --git a/changelog.d/fixed-15273-blocker-ledger-clear-on-close.md b/changelog.d/fixed-15273-blocker-ledger-clear-on-close.md new file mode 100644 index 0000000000..6992dc451e --- /dev/null +++ b/changelog.d/fixed-15273-blocker-ledger-clear-on-close.md @@ -0,0 +1 @@ +- An `issues: closed` webhook now clears the closed issue's blocker ledger entry, so `capabilities.blocked_items` no longer counts closed issues ([#15273](https://github.com/hivecommons/hive/issues/15273)). diff --git a/src/pkg/github/issue_blocker_test.go b/src/pkg/github/issue_blocker_test.go index 44b74cee01..2ae967ab01 100644 --- a/src/pkg/github/issue_blocker_test.go +++ b/src/pkg/github/issue_blocker_test.go @@ -59,6 +59,45 @@ func TestWebhookIssueCommentRecordsBlocker(t *testing.T) { } } +// hivecommons/hive#15273: closing an issue through GitHub (not only the +// dashboard's recheck/close-partial handlers) clears its ledger row, so +// capabilities.blocked_items stops counting it. +func TestWebhookIssueClosedClearsBlocker(t *testing.T) { + l := swapSharedLedger(t) + c, _ := setupWebhookCacheTest(t) + at := time.Date(2026, 10, 20, 19, 33, 0, 0, time.UTC) + res, err := c.HandleWebhookEvent("issue_comment", []byte(`{"action":"created","issue":{"number":21},"comment":{"body":`+jsonString(workflowsReport)+`,"created_at":"2026-10-20T19:33:00Z"},"repository":{"full_name":"org/repo"}}`)) + if err != nil || res.BlockerKind == "" { + t.Fatalf("seed: %+v %v", res, err) + } + repo := res.ConfiguredRepo + l.Observe(repo, 22, workflowsReport, at) + if _, ok := l.Blocking(repo, 21); !ok { + t.Fatal("issue 21 not blocking before close") + } + // A labeled event leaves the row; a PR close is not an issue close. + for _, payload := range []string{ + `{"action":"labeled","issue":{"number":21},"repository":{"full_name":"org/repo"}}`, + `{"action":"closed","issue":{"number":21,"pull_request":{"url":"x"}},"repository":{"full_name":"org/repo"}}`, + } { + if _, err := c.HandleWebhookEvent("issues", []byte(payload)); err != nil { + t.Fatal(err) + } + if _, ok := l.Blocking(repo, 21); !ok { + t.Fatalf("payload %s cleared the ledger row", payload) + } + } + if _, err := c.HandleWebhookEvent("issues", []byte(`{"action":"closed","issue":{"number":21},"repository":{"full_name":"org/repo"}}`)); err != nil { + t.Fatal(err) + } + if _, ok := l.Get(repo, 21); ok { + t.Fatal("closed issue kept its ledger row") + } + if got := l.Capabilities(); got.BlockedItems != 1 { + t.Fatalf("blocked_items = %+v, want only issue 22", got) + } +} + func jsonString(s string) string { return `"` + strings.NewReplacer(`\`, `\\`, `"`, `\"`, "\n", `\n`).Replace(s) + `"` } diff --git a/src/pkg/github/webhook_cache.go b/src/pkg/github/webhook_cache.go index 23db230b4a..786d1b0baf 100644 --- a/src/pkg/github/webhook_cache.go +++ b/src/pkg/github/webhook_cache.go @@ -501,6 +501,17 @@ func (c *Client) HandleWebhookEvent(event string, payload []byte) (WebhookEventR res.BlockerKind = string(e.Blocker.Kind) } } + // A closed issue is no longer blocked: forget its ledger row so + // capabilities.blocked_items stops counting it, the same as the + // dashboard's recheck and close-partial paths do + // (hivecommons/hive#15273). + if webhookIssueClosed(event, p) { + if l := itemblocker.Shared(); l != nil { + if _, ok := l.Get(configured, n); ok { + l.Clear(configured, n) + } + } + } } res.Item = webhookItemHint(event, p) if reviewRequestWakeEvent(event, p) { @@ -633,6 +644,11 @@ func webhookIssueCommentBody(event string, p webhookEventPayload) (string, time. return p.Comment.Body, at, true } +// webhookIssueClosed reports whether an `issues` delivery closed an issue. +func webhookIssueClosed(event string, p webhookEventPayload) bool { + return event == "issues" && p.Action == "closed" +} + // webhookIssueReopenedTarget returns the issue number of an `issues` event // whose action reopened a non-PR issue. func webhookIssueReopenedTarget(event string, p webhookEventPayload) (int, bool) {