From 036bff04204f5f9908a5e395dc544be45daba885 Mon Sep 17 00:00:00 2001 From: SACHIN NAIK Date: Wed, 28 Oct 2026 22:22:28 -0700 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20fix:=20clear=20blocker=20led?= =?UTF-8?q?ger=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) { From 6e6253cb90401b367d3701ea0d2f8e52b18b4fca Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 07:34:32 -0400 Subject: [PATCH 2/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20drop=20red?= =?UTF-8?q?undant=20close-clear;=20keep=20realistic=20regression=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Base v5 already clears the blocker ledger row when a webhook payload says the issue is closed (#15309, keyed on issue.state via WebhookItemHint.Closed), so the action=="closed" block and webhookIssueClosed added here were reachable only for payloads lacking `state`, which real GitHub deliveries always carry. Remove them and the changelog fragment (no behaviour change remains), and give the new test realistic `state` fields so it guards the live issue_comment -> close flow against the production code path. Refs #15273 Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../fixed-15273-blocker-ledger-clear-on-close.md | 1 - src/pkg/github/issue_blocker_test.go | 13 +++++++------ src/pkg/github/webhook_cache.go | 16 ---------------- 3 files changed, 7 insertions(+), 23 deletions(-) delete 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 deleted file mode 100644 index 6992dc451e..0000000000 --- a/changelog.d/fixed-15273-blocker-ledger-clear-on-close.md +++ /dev/null @@ -1 +0,0 @@ -- 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 cbcd9cc6a8..05c23e67b3 100644 --- a/src/pkg/github/issue_blocker_test.go +++ b/src/pkg/github/issue_blocker_test.go @@ -59,9 +59,10 @@ 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. +// hivecommons/hive#15273: an issue whose blocker was recorded from a live +// issue_comment delivery is forgotten when GitHub later closes it, so +// capabilities.blocked_items stops counting it. Payloads carry issue.state +// as real deliveries do; the close is keyed on state, not action. func TestWebhookIssueClosedClearsBlocker(t *testing.T) { l := swapSharedLedger(t) c, _ := setupWebhookCacheTest(t) @@ -77,8 +78,8 @@ func TestWebhookIssueClosedClearsBlocker(t *testing.T) { } // 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"}}`, + `{"action":"labeled","issue":{"number":21,"state":"open"},"repository":{"full_name":"org/repo"}}`, + `{"action":"closed","issue":{"number":21,"state":"closed","pull_request":{"url":"x"}},"repository":{"full_name":"org/repo"}}`, } { if _, err := c.HandleWebhookEvent("issues", []byte(payload)); err != nil { t.Fatal(err) @@ -87,7 +88,7 @@ func TestWebhookIssueClosedClearsBlocker(t *testing.T) { 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 { + if _, err := c.HandleWebhookEvent("issues", []byte(`{"action":"closed","issue":{"number":21,"state":"closed"},"repository":{"full_name":"org/repo"}}`)); err != nil { t.Fatal(err) } if _, ok := l.Get(repo, 21); ok { diff --git a/src/pkg/github/webhook_cache.go b/src/pkg/github/webhook_cache.go index 407d4eafa9..c2cb8650b3 100644 --- a/src/pkg/github/webhook_cache.go +++ b/src/pkg/github/webhook_cache.go @@ -529,17 +529,6 @@ 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) - } - } - } } if reviewRequestWakeEvent(event, p) { c.reviewWake.wake() @@ -675,11 +664,6 @@ 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) { From b4a0c358b06ca554124541cfe3590e104525e8d1 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 07:51:08 -0400 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20test:=20name=20comment-seeded?= =?UTF-8?q?=20blocker=20test=20for=20what=20it=20adds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestWebhookIssueClosedClearsBlocker was a near-duplicate of the existing table test TestWebhookClosedIssueClearsBlocker, differing only by word order and re-asserting its labeled/PR-close cases. Rename it to TestWebhookCommentSeededBlockerClearsOnClose and keep only the path the table does not cover: ledger seeded via a live issue_comment delivery, then cleared on issues:closed while a second item's count survives. Refs #15273 Hive-Fix-Attempt: 2/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/github/issue_blocker_test.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/pkg/github/issue_blocker_test.go b/src/pkg/github/issue_blocker_test.go index 05c23e67b3..8e1dae4d36 100644 --- a/src/pkg/github/issue_blocker_test.go +++ b/src/pkg/github/issue_blocker_test.go @@ -59,11 +59,12 @@ func TestWebhookIssueCommentRecordsBlocker(t *testing.T) { } } -// hivecommons/hive#15273: an issue whose blocker was recorded from a live -// issue_comment delivery is forgotten when GitHub later closes it, so -// capabilities.blocked_items stops counting it. Payloads carry issue.state -// as real deliveries do; the close is keyed on state, not action. -func TestWebhookIssueClosedClearsBlocker(t *testing.T) { +// hivecommons/hive#15273: a blocker recorded from a live issue_comment +// delivery (not seeded via Observe) is forgotten when GitHub later closes +// the issue, so capabilities.blocked_items stops counting it while other +// items keep their count. Negative cases (labeled, PR close, reopen) live in +// TestWebhookClosedIssueClearsBlocker. +func TestWebhookCommentSeededBlockerClearsOnClose(t *testing.T) { l := swapSharedLedger(t) c, _ := setupWebhookCacheTest(t) at := time.Date(2026, 10, 20, 19, 33, 0, 0, time.UTC) @@ -76,18 +77,6 @@ func TestWebhookIssueClosedClearsBlocker(t *testing.T) { 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,"state":"open"},"repository":{"full_name":"org/repo"}}`, - `{"action":"closed","issue":{"number":21,"state":"closed","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,"state":"closed"},"repository":{"full_name":"org/repo"}}`)); err != nil { t.Fatal(err) }