From dae08a7ede031b041adc738db965ad3200e1c49c Mon Sep 17 00:00:00 2001 From: thatguywob Date: Thu, 29 Oct 2026 05:12:34 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix:=20share=20delegated=20c?= =?UTF-8?q?apability-gap=20inference=20with=20blocker=20ledger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Route the policy fallback through blocker.Infer so capability reports use the same classification as the dashboard ledger. Preserve the headline and issue-body limits and exclude human-only kinds. Hive-Run: hivecommons/hive#15217 Hive-Plan: shared-capability-inference Hive-Spec: hivecommons/hive#15217#shared-inference Signed-off-by: thatguywob --- .../fixed-delegated-capability-inference.md | 1 + src/pkg/delegatedecision/policy.go | 30 +++++++++-------- src/pkg/delegatedecision/policy_test.go | 33 +++++++++++++++++++ 3 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 changelog.d/fixed-delegated-capability-inference.md diff --git a/changelog.d/fixed-delegated-capability-inference.md b/changelog.d/fixed-delegated-capability-inference.md new file mode 100644 index 0000000000..831cbc52f1 --- /dev/null +++ b/changelog.d/fixed-delegated-capability-inference.md @@ -0,0 +1 @@ +- Delegated issue decisions now use the blocker ledger's shared capability inference, keeping repository-write, branch-protection, secret, and workflow permission gaps parked instead of approving ineffective directions (#15217). diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index 254ef418a7..c0c783696d 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -27,6 +27,8 @@ import ( "sort" "strconv" "strings" + + "github.com/hivecommons/hive/pkg/blocker" ) // PolicyName is the policy identifier the audit marker carries. @@ -242,16 +244,13 @@ func IsDelegatedComment(body string) bool { } var ( - secretsRE = regexp.MustCompile(`(?i)\b(secrets?|PATs?|personal access tokens?|org(?:anization)? (?:membership|permissions?|admin|owner)|token scopes?|GITHUB_TOKEN|credentials?|app installation|billing)\b`) - flakyRE = regexp.MustCompile(`(?i)\b(flak(?:y|e|iness)|intermittent(?:ly)? fail\w*|non-?deterministic test)\b`) - ratchetRE = regexp.MustCompile(`(?i)\b(actionlint|ratchet|duplication (?:gate|threshold|check)|link[- ]?checker|allow-?list|lint gate|hygiene gate|shellcheck|yamllint|markdownlint)\b`) - proposalRE = regexp.MustCompile(`(?i)\bacceptance criteria\b`) - hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`) - // capabilityGapRE matches a blocker no direction decision can clear: the - // GitHub App lacks a permission (for example `workflows`). - capabilityGapRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:cannot|can't|lacks?|no|without|missing)\b[^\n]{0,60}\b(?:workflows?|permissions?)\b|\bno [\x60]?workflows[\x60]? permission\b`) - duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`) - blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`) + secretsRE = regexp.MustCompile(`(?i)\b(secrets?|PATs?|personal access tokens?|org(?:anization)? (?:membership|permissions?|admin|owner)|token scopes?|GITHUB_TOKEN|credentials?|app installation|billing)\b`) + flakyRE = regexp.MustCompile(`(?i)\b(flak(?:y|e|iness)|intermittent(?:ly)? fail\w*|non-?deterministic test)\b`) + ratchetRE = regexp.MustCompile(`(?i)\b(actionlint|ratchet|duplication (?:gate|threshold|check)|link[- ]?checker|allow-?list|lint gate|hygiene gate|shellcheck|yamllint|markdownlint)\b`) + proposalRE = regexp.MustCompile(`(?i)\bacceptance criteria\b`) + hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`) + duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`) + blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`) ) // Classifier labels. @@ -322,10 +321,15 @@ func HivePolicyChange(in Input) bool { } // CapabilityGap reports a needs-human whose blocker is a missing GitHub App -// capability rather than an open question. +// capability rather than an open question. The ledger and this fallback use +// the same inference rules; human-only blockers are handled by the ledger. func CapabilityGap(in Input) bool { - return capabilityGapRE.MatchString(in.headline()) || - in.Kind == KindIssue && capabilityGapRE.MatchString(firstLines(in.Body, 12)) + isCapability := func(text string) bool { + k, ok := blocker.Infer(text) + return ok && k.IsCapability() + } + return isCapability(in.headline()) || + in.Kind == KindIssue && isCapability(firstLines(in.Body, 12)) } // OwnerOnly reports a secrets / PAT / org-permission item. diff --git a/src/pkg/delegatedecision/policy_test.go b/src/pkg/delegatedecision/policy_test.go index 23130f907d..e2cedfd07b 100644 --- a/src/pkg/delegatedecision/policy_test.go +++ b/src/pkg/delegatedecision/policy_test.go @@ -25,6 +25,39 @@ func sameKinds(a, b []ActionKind) bool { return true } +func TestCapabilityGapSharedInference(t *testing.T) { + for _, report := range []string{ + "The App cannot push changes to workflow files.", + "The App cannot push to the upstream repository.", + "The App cannot update the protected branch.", + "The App cannot set the repository secret.", + } { + t.Run(report, func(t *testing.T) { + for _, in := range []Input{ + {Kind: KindIssue, Title: report}, + {Kind: KindIssue, Question: report}, + {Kind: KindIssue, Reasons: []string{report}}, + {Kind: KindIssue, Body: report}, + } { + d := Run(in) + if !CapabilityGap(in) || d.Rule != RuleCapabilityGap || d.Verdict != VerdictRecommendOnly || !d.KeepsPark || !sameKinds(kinds(d), []ActionKind{ActionRecommendOnly}) { + t.Fatalf("capability report must keep the park: input=%+v decision=%+v", in, d) + } + } + }) + } + for _, in := range []Input{ + {Kind: KindIssue, Title: "The contributor must sign the CLA."}, + {Kind: KindIssue, Title: "Which workflow retry strategy should we use?"}, + {Kind: KindIssue, Body: strings.Repeat("context\n", 12) + "The App cannot push to the repository."}, + {Kind: KindPR, Body: "The App cannot push to the repository."}, + } { + if CapabilityGap(in) { + t.Errorf("unexpected capability gap: %+v", in) + } + } +} + func TestDecideIssueRules(t *testing.T) { t.Parallel() cases := []struct { From 5bba26fc2476a302c6aa921b45d3b83c99992150 Mon Sep 17 00:00:00 2001 From: thatguywob Date: Thu, 29 Oct 2026 05:50:45 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fix:=20keep=20generic=20App?= =?UTF-8?q?=20permission=20gaps=20parked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Retain shared blocker inference for known capabilities and preserve the generic App-permission guard for permissions without a ledger kind. Cover recommend-only actions and headline/body boundaries. Signed-off-by: thatguywob --- .../fixed-delegated-capability-inference.md | 2 +- src/pkg/delegatedecision/policy.go | 24 +++++++++++-------- src/pkg/delegatedecision/policy_test.go | 11 +++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/changelog.d/fixed-delegated-capability-inference.md b/changelog.d/fixed-delegated-capability-inference.md index 831cbc52f1..6b9b4c4122 100644 --- a/changelog.d/fixed-delegated-capability-inference.md +++ b/changelog.d/fixed-delegated-capability-inference.md @@ -1 +1 @@ -- Delegated issue decisions now use the blocker ledger's shared capability inference, keeping repository-write, branch-protection, secret, and workflow permission gaps parked instead of approving ineffective directions (#15217). +- Delegated issue decisions now use the blocker ledger's shared capability inference, keeping repository-write, branch-protection, secret, and workflow permission gaps parked instead of approving ineffective directions, while retaining the park for other missing App permissions (#15217). diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index c0c783696d..5069db500d 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -244,13 +244,16 @@ func IsDelegatedComment(body string) bool { } var ( - secretsRE = regexp.MustCompile(`(?i)\b(secrets?|PATs?|personal access tokens?|org(?:anization)? (?:membership|permissions?|admin|owner)|token scopes?|GITHUB_TOKEN|credentials?|app installation|billing)\b`) - flakyRE = regexp.MustCompile(`(?i)\b(flak(?:y|e|iness)|intermittent(?:ly)? fail\w*|non-?deterministic test)\b`) - ratchetRE = regexp.MustCompile(`(?i)\b(actionlint|ratchet|duplication (?:gate|threshold|check)|link[- ]?checker|allow-?list|lint gate|hygiene gate|shellcheck|yamllint|markdownlint)\b`) - proposalRE = regexp.MustCompile(`(?i)\bacceptance criteria\b`) - hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`) - duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`) - blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`) + secretsRE = regexp.MustCompile(`(?i)\b(secrets?|PATs?|personal access tokens?|org(?:anization)? (?:membership|permissions?|admin|owner)|token scopes?|GITHUB_TOKEN|credentials?|app installation|billing)\b`) + flakyRE = regexp.MustCompile(`(?i)\b(flak(?:y|e|iness)|intermittent(?:ly)? fail\w*|non-?deterministic test)\b`) + ratchetRE = regexp.MustCompile(`(?i)\b(actionlint|ratchet|duplication (?:gate|threshold|check)|link[- ]?checker|allow-?list|lint gate|hygiene gate|shellcheck|yamllint|markdownlint)\b`) + proposalRE = regexp.MustCompile(`(?i)\bacceptance criteria\b`) + hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`) + // appPermissionRE preserves the park for App permissions that have no + // specific capability kind in the blocker ledger. + appPermissionRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:lacks?|missing|without|no)\b[^\n]{0,60}\bpermissions?\b`) + duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`) + blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`) ) // Classifier labels. @@ -321,12 +324,13 @@ func HivePolicyChange(in Input) bool { } // CapabilityGap reports a needs-human whose blocker is a missing GitHub App -// capability rather than an open question. The ledger and this fallback use -// the same inference rules; human-only blockers are handled by the ledger. +// capability rather than an open question. Shared ledger inference handles +// known capability kinds; a generic App-permission guard keeps other missing +// permissions parked. Human-only blockers are handled by the ledger. func CapabilityGap(in Input) bool { isCapability := func(text string) bool { k, ok := blocker.Infer(text) - return ok && k.IsCapability() + return ok && k.IsCapability() || appPermissionRE.MatchString(text) } return isCapability(in.headline()) || in.Kind == KindIssue && isCapability(firstLines(in.Body, 12)) diff --git a/src/pkg/delegatedecision/policy_test.go b/src/pkg/delegatedecision/policy_test.go index e2cedfd07b..69ea0aa1e3 100644 --- a/src/pkg/delegatedecision/policy_test.go +++ b/src/pkg/delegatedecision/policy_test.go @@ -31,6 +31,12 @@ func TestCapabilityGapSharedInference(t *testing.T) { "The App cannot push to the upstream repository.", "The App cannot update the protected branch.", "The App cannot set the repository secret.", + "The GitHub App lacks the `issues: write` permission.", + "App lacks the `administration` permission to edit rulesets", + "The installation lacks the required permissions; needs a human.", + "The App token is missing the `checks: write` permission.", + "The installation has no permission to manage checks.", + "The App is without the required permission.", } { t.Run(report, func(t *testing.T) { for _, in := range []Input{ @@ -38,6 +44,7 @@ func TestCapabilityGapSharedInference(t *testing.T) { {Kind: KindIssue, Question: report}, {Kind: KindIssue, Reasons: []string{report}}, {Kind: KindIssue, Body: report}, + {Kind: KindIssue, Body: strings.Repeat("context\n", 11) + report}, } { d := Run(in) if !CapabilityGap(in) || d.Rule != RuleCapabilityGap || d.Verdict != VerdictRecommendOnly || !d.KeepsPark || !sameKinds(kinds(d), []ActionKind{ActionRecommendOnly}) { @@ -49,6 +56,10 @@ func TestCapabilityGapSharedInference(t *testing.T) { for _, in := range []Input{ {Kind: KindIssue, Title: "The contributor must sign the CLA."}, {Kind: KindIssue, Title: "Which workflow retry strategy should we use?"}, + {Kind: KindIssue, Title: "Which permissions should the GitHub App request?"}, + {Kind: KindIssue, Title: "The GitHub App has the required permissions."}, + {Kind: KindIssue, Body: strings.Repeat("context\n", 12) + "The GitHub App lacks the `issues: write` permission."}, + {Kind: KindPR, Body: "The GitHub App lacks the `issues: write` permission."}, {Kind: KindIssue, Body: strings.Repeat("context\n", 12) + "The App cannot push to the repository."}, {Kind: KindPR, Body: "The App cannot push to the repository."}, } { From 9614bda00e93ac7857ba92163b3eac1da1459f94 Mon Sep 17 00:00:00 2001 From: thatguywob Date: Thu, 29 Oct 2026 05:51:10 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20fix:=20preserve=20App=20perm?= =?UTF-8?q?ission=20denial=20phrasing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: thatguywob --- src/pkg/delegatedecision/policy.go | 2 +- src/pkg/delegatedecision/policy_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index 5069db500d..a09f50fe39 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -251,7 +251,7 @@ var ( hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`) // appPermissionRE preserves the park for App permissions that have no // specific capability kind in the blocker ledger. - appPermissionRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:lacks?|missing|without|no)\b[^\n]{0,60}\bpermissions?\b`) + appPermissionRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:cannot|can't|lacks?|missing|without|no)\b[^\n]{0,60}\bpermissions?\b`) duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`) blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`) ) diff --git a/src/pkg/delegatedecision/policy_test.go b/src/pkg/delegatedecision/policy_test.go index 69ea0aa1e3..ddbc5ac4b0 100644 --- a/src/pkg/delegatedecision/policy_test.go +++ b/src/pkg/delegatedecision/policy_test.go @@ -37,6 +37,8 @@ func TestCapabilityGapSharedInference(t *testing.T) { "The App token is missing the `checks: write` permission.", "The installation has no permission to manage checks.", "The App is without the required permission.", + "The App cannot obtain the required permission.", + "The App can't obtain the required permission.", } { t.Run(report, func(t *testing.T) { for _, in := range []Input{ From 357ddfdbf86aa809da6a526412cc0a997703c9f3 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 04:29:54 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20fix:=20keep=20free-text=20wo?= =?UTF-8?q?rkflow=20capability=20headlines=20parked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit appPermissionRE dropped the `workflows?` terminal the v5 regex had, so headlines like "The App cannot push workflows." or "The App cannot edit the workflow." — which name neither a permission nor a path shape the blocker ledger's workflows rule recognises — fell through decideIssue to RuleApprove. Restore the terminal and cover both phrasings in the test. 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> --- src/pkg/delegatedecision/policy.go | 6 ++++-- src/pkg/delegatedecision/policy_test.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pkg/delegatedecision/policy.go b/src/pkg/delegatedecision/policy.go index a09f50fe39..a6c0025a46 100644 --- a/src/pkg/delegatedecision/policy.go +++ b/src/pkg/delegatedecision/policy.go @@ -250,8 +250,10 @@ var ( proposalRE = regexp.MustCompile(`(?i)\bacceptance criteria\b`) hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`) // appPermissionRE preserves the park for App permissions that have no - // specific capability kind in the blocker ledger. - appPermissionRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:cannot|can't|lacks?|missing|without|no)\b[^\n]{0,60}\bpermissions?\b`) + // specific capability kind in the blocker ledger, and for free-text + // workflow headlines ("the App cannot push workflows") that name no + // permission or path shape the ledger's workflows rule recognises. + appPermissionRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:cannot|can't|lacks?|missing|without|no)\b[^\n]{0,60}\b(?:workflows?|permissions?)\b`) duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`) blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`) ) diff --git a/src/pkg/delegatedecision/policy_test.go b/src/pkg/delegatedecision/policy_test.go index ddbc5ac4b0..66f10091d2 100644 --- a/src/pkg/delegatedecision/policy_test.go +++ b/src/pkg/delegatedecision/policy_test.go @@ -28,6 +28,8 @@ func sameKinds(a, b []ActionKind) bool { func TestCapabilityGapSharedInference(t *testing.T) { for _, report := range []string{ "The App cannot push changes to workflow files.", + "The App cannot push workflows.", + "The App cannot edit the workflow.", "The App cannot push to the upstream repository.", "The App cannot update the protected branch.", "The App cannot set the repository secret.",