From e2abf9fbf901b824f9c61618ce3d9bfea9a05242 Mon Sep 17 00:00:00 2001 From: Danathar Date: Thu, 5 Nov 2026 15:45:41 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix(workflows):=20verify=20"?= =?UTF-8?q?the=20App=20cannot=20push=20workflows"=20before=20parking=20on?= =?UTF-8?q?=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit projectbluefin/testsuite#1059 and #1073: scanner (ISSUES_PRS_MERGE, whose token asks for workflows: write) parked "the hive app cannot push .github/workflows/" the same day the App pushed e2e.yml (a017ce1), and the issues sat as "Blocked · App lacks workflows permission" for four days. - relay: a merger/trusted-tier lane's workflow-only park is refused when the installation grants workflows: write (cached 5 min); a contributor-tier hand-off is skipped when the installation is known to lack it. - blocker ledger: SetCapabilityCheck records a workflows blocker only when no capable lane can push on that repo; RecheckCapabilities releases existing ones, run with the un-park sweep, which adds hive/workflows-lane through the writeback gate. - config.AgentPushesWorkflows; merger/trusted-tier kicks say the token can push .github/workflows/**. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- .../fixed-workflows-blocker-verified.md | 1 + src/cmd/hive/github_client_config.go | 8 + src/cmd/hive/main_sweeps.go | 9 + .../dashboard-sections/activity-monitor.md | 2 +- src/docs/hive-open-issue.md | 11 +- .../labels-and-control-signals/reference.md | 4 +- src/docs/scale-envelope.md | 2 +- src/pkg/blocker/ledger.go | 66 +++++ .../blocker/ledger_capability_check_test.go | 63 +++++ src/pkg/config/workflows_lane.go | 7 + src/pkg/config/workflows_lane_test.go | 16 ++ src/pkg/github/client.go | 5 + src/pkg/github/issue_owner_step_test.go | 6 +- src/pkg/github/issue_request_watcher.go | 35 ++- src/pkg/github/issue_workflows_handoff.go | 163 +++++++++++- .../github/issue_workflows_self_push_test.go | 232 ++++++++++++++++++ src/pkg/scheduler/policy_overlays.go | 18 ++ .../scheduler/workflow_push_ceiling_test.go | 25 ++ 18 files changed, 647 insertions(+), 26 deletions(-) create mode 100644 changelog.d/fixed-workflows-blocker-verified.md create mode 100644 src/pkg/blocker/ledger_capability_check_test.go create mode 100644 src/pkg/github/issue_workflows_self_push_test.go diff --git a/changelog.d/fixed-workflows-blocker-verified.md b/changelog.d/fixed-workflows-blocker-verified.md new file mode 100644 index 0000000000..87995a833e --- /dev/null +++ b/changelog.d/fixed-workflows-blocker-verified.md @@ -0,0 +1 @@ +- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository, and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. diff --git a/src/cmd/hive/github_client_config.go b/src/cmd/hive/github_client_config.go index 082b971ca4..7fcea6faf4 100644 --- a/src/cmd/hive/github_client_config.go +++ b/src/cmd/hive/github_client_config.go @@ -13,6 +13,7 @@ import ( "github.com/hivecommons/hive/pkg/attention" "github.com/hivecommons/hive/pkg/authorkind" "github.com/hivecommons/hive/pkg/beads" + itemblocker "github.com/hivecommons/hive/pkg/blocker" "github.com/hivecommons/hive/pkg/claims" "github.com/hivecommons/hive/pkg/dashboard" "github.com/hivecommons/hive/pkg/github" @@ -157,6 +158,13 @@ func (b *boot) applyGitHubClientConfigHooks(client *github.Client) { // to the lane that can, instead of the owner (issue_workflows_handoff.go). // Live predicate over the shared config, like the scope funcs above. client.SetWorkflowsLaneFunc(b.cfg.WorkflowsLaneFor) + // A lane whose own token asks for the Workflows permission is refused a + // workflow-only park when the installation grants it, and the blocker + // ledger records "App lacks workflows" only when the hive cannot push + // them (projectbluefin/testsuite#1059). The ledger is process-wide, so a + // rebuilt client re-installs its check. + client.SetWorkflowsSelfPushFunc(b.cfg.AgentPushesWorkflows) + itemblocker.Shared().SetCapabilityCheck(client.CapabilityAvailable) client.SetReporterConfirmationEnabledFunc(func() bool { return b.cfg.Issues.ReporterConfirmationEnabled() }) diff --git a/src/cmd/hive/main_sweeps.go b/src/cmd/hive/main_sweeps.go index 8a6097a195..5e4bda4731 100644 --- a/src/cmd/hive/main_sweeps.go +++ b/src/cmd/hive/main_sweeps.go @@ -1499,6 +1499,15 @@ func runIssueUnparkSweepIfDue(ctx context.Context, ghClient *github.Client, cfg if lastRun != nil { *lastRun = now } + // Capability blockers recorded before the hive could check them, or + // before the permission was granted, are re-checked at the same cadence + // (and on the first pass after start), so a false "App lacks workflows + // permission" clears itself (projectbluefin/testsuite#1059). + if released, err := ghClient.SweepWorkflowsBlockers(ctx); err != nil { + logger.Warn("workflows blocker re-check: labelling released items failed", "released", len(released), "error", err) + } else if len(released) > 0 { + logger.Info("workflows blocker re-check released items", "released", len(released)) + } // `/hive approve` on a PR is answered with what the merge lane will do // with it (hivecommons/hive#13087); the engine here only reads policy. approveOpts := automerge.Options{ diff --git a/src/docs/dashboard-sections/activity-monitor.md b/src/docs/dashboard-sections/activity-monitor.md index 8c414aaa9b..4a4a9af057 100644 --- a/src/docs/dashboard-sections/activity-monitor.md +++ b/src/docs/dashboard-sections/activity-monitor.md @@ -382,7 +382,7 @@ A `blocked` issue with neither (a human-applied label) keeps the bare pill. This #### Blocked pill — capability gaps -**Blocked pill — capability gaps** ([#15099](https://github.com/hivecommons/hive/issues/15099)). An issue parked because the hive *cannot* act — the scanner reported "the App token cannot push `.github/workflows/*` (no `workflows` permission); needs a human" — is a blocker, not a question, so its row does not read *Needs human decision*: the pill reads **Blocked · App lacks workflows permission** and the same popover says in plain words *Hive can't do this one: the GitHub App has no `workflows` permission, so it cannot push changes to .github/workflows/\*.* followed by the ways out: *Grant the App workflows permission* (opens the App settings page; the hive re-tries on its own once it sees the permission), *Re-check permissions* (probes the installation now and releases every item blocked on it), *Prepare the patch for a person to push* (disabled with its reason until a human-authorised push identity exists), *Mark partially addressed and close*, *Keep waiting*. *Let hive decide* stays in the list but disabled with the sentence that explains why — a direction decision cannot grant a permission — instead of being greyed silently; running it anyway returns *no-effect* with the same words and never applies `approved-direction`. The loop that motivated this (un-park → sweep re-parks with the same text → "I tried let hive decide and it still needs human") is guarded: when the same needs-human reason comes back after a delegated un-park, the row is parked with a blocker and *Let hive decide* is disabled on it until the reason changes. The blocker comes from the agent's `` marker or, failing that, from the prose of the needs-human report (`pkg/blocker`), and ⚙ → Security shows the fleet view: *GitHub App permissions: missing `workflows` · N items blocked* with the settings link (`/api/status.capabilities`). +**Blocked pill — capability gaps** ([#15099](https://github.com/hivecommons/hive/issues/15099)). An issue parked because the hive *cannot* act — the scanner reported "the App token cannot push `.github/workflows/*` (no `workflows` permission); needs a human" — is a blocker, not a question, so its row does not read *Needs human decision*: the pill reads **Blocked · App lacks workflows permission** and the same popover says in plain words *Hive can't do this one: the GitHub App has no `workflows` permission, so it cannot push changes to .github/workflows/\*.* followed by the ways out: *Grant the App workflows permission* (opens the App settings page; the hive re-tries on its own once it sees the permission), *Re-check permissions* (probes the installation now and releases every item blocked on it), *Prepare the patch for a person to push* (disabled with its reason until a human-authorised push identity exists), *Mark partially addressed and close*, *Keep waiting*. *Let hive decide* stays in the list but disabled with the sentence that explains why — a direction decision cannot grant a permission — instead of being greyed silently; running it anyway returns *no-effect* with the same words and never applies `approved-direction`. The loop that motivated this (un-park → sweep re-parks with the same text → "I tried let hive decide and it still needs human") is guarded: when the same needs-human reason comes back after a delegated un-park, the row is parked with a blocker and *Let hive decide* is disabled on it until the reason changes. The blocker comes from the agent's `` marker or, failing that, from the prose of the needs-human report (`pkg/blocker`). A workflows blocker is recorded only when the hive cannot push workflow files on that repository: when the App installation grants `workflows: write` and an enabled lane whose token asks for it serves the repository, the report is kept as a plain reason and no pill is drawn. The same check runs with the issue un-park sweep (on start, then every five minutes) on blockers already recorded: a released one gets `hive/workflows-lane`, so the issue goes to that lane once its park is answered. ⚙ → Security shows the fleet view: *GitHub App permissions: missing `workflows` · N items blocked* with the settings link (`/api/status.capabilities`). #### New row (`000-new`, the pre-stage state) diff --git a/src/docs/hive-open-issue.md b/src/docs/hive-open-issue.md index f09c582fe3..0a45328de4 100644 --- a/src/docs/hive-open-issue.md +++ b/src/docs/hive-open-issue.md @@ -233,7 +233,16 @@ repository (a lane scoped to other repositories with `repos:` is never chosen), the watcher adds `hive/workflows-lane` instead of the park label, appends a "Handed to ``" note and no owner-step marker, and the scheduler routes the issue to that lane. On `issue` the new issue is created at -`stage/010-actionable` with the label. +`stage/010-actionable` with the label. The hand-off is skipped (the park +stands) when the App installation is known to lack `workflows: write`. + +A lane that can push workflow files itself is refused the park instead. When +the parking lane runs at the trusted or merger tier (ISSUES_PRS_MERGE), whose +token asks for the Workflows permission, and the App installation grants +`workflows: write` (read at most every five minutes), the watcher parks +nothing, adds no label, and appends a "Not parked: ``'s token can push +`.github/workflows/`" note: the issue stays with that lane to push the change. +If the installation lacks the permission, or cannot be read, the park stands. #### Withdrawing your own park diff --git a/src/docs/labels-and-control-signals/reference.md b/src/docs/labels-and-control-signals/reference.md index d7137adb08..9cc0352719 100644 --- a/src/docs/labels-and-control-signals/reference.md +++ b/src/docs/labels-and-control-signals/reference.md @@ -382,9 +382,9 @@ Not added when the same sweep is applying `needs-human`. **Applies to:** Issues. **Kind:** Routing. -Workflow hand-off. An ISSUES_AND_PRS lane's token is minted at the `contributor` tier, which has no Workflows permission, so it cannot push a change under `.github/workflows/`. When such a lane parks a workflow-only change (`hive-open-issue issue|comment --needs-decision` whose text says it cannot push the workflow file, with no lettered options for the owner) and an enabled lane that serves the repository runs at ISSUES_PRS_MERGE (one scoped to other repositories with `repos:` is never chosen), the relay does not park the issue: it adds this label, posts the lane's exact replacement with a "Handed to ``" note, and the scheduler sends the issue to that lane rather than back to the one that filed it. With no such lane, or when the ISSUES_PRS_MERGE lane itself could not push, the park goes to the owner as before. +Workflow hand-off. An ISSUES_AND_PRS lane's token is minted at the `contributor` tier, which has no Workflows permission, so it cannot push a change under `.github/workflows/`. When such a lane parks a workflow-only change (`hive-open-issue issue|comment --needs-decision` whose text says it cannot push the workflow file, with no lettered options for the owner) and an enabled lane that serves the repository runs at ISSUES_PRS_MERGE (one scoped to other repositories with `repos:` is never chosen), the relay does not park the issue: it adds this label, posts the lane's exact replacement with a "Handed to ``" note, and the scheduler sends the issue to that lane rather than back to the one that filed it. With no such lane, or when the App installation is known to lack `workflows: write`, the park goes to the owner as before. An ISSUES_PRS_MERGE lane's own workflow-only park is refused, with no label, when the installation grants `workflows: write`: its token can push the change. The scheduled blocker re-check also adds this label to an issue whose "App lacks workflows permission" blocker it releases. -**Who applies it:** Hive (issue-request relay). +**Who applies it:** Hive (issue-request relay, blocker re-check). **Checked by:** Scheduler kick assembly. **When:** Every kick build. diff --git a/src/docs/scale-envelope.md b/src/docs/scale-envelope.md index 3714ca3c68..99c8580dc2 100644 --- a/src/docs/scale-envelope.md +++ b/src/docs/scale-envelope.md @@ -34,7 +34,7 @@ ones to: 2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.** This holds today and is easy to assume backwards: - Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied - (`RankActionableIssues`, `src/pkg/github/client.go:5345-5355`, descending `AgeMinutes` within each tier). + (`RankActionableIssues`, `src/pkg/github/client.go:5350-5360`, descending `AgeMinutes` within each tier). - PRs are sorted by **review class then oldest-first within class** (`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`; fixes → refactors/docs → tests). diff --git a/src/pkg/blocker/ledger.go b/src/pkg/blocker/ledger.go index 0e5e4d428d..84be775ca1 100644 --- a/src/pkg/blocker/ledger.go +++ b/src/pkg/blocker/ledger.go @@ -56,6 +56,28 @@ type Ledger struct { entries map[string]Entry now func() time.Time loaded bool + // capabilityCheck refutes a capability report (SetCapabilityCheck). + capabilityCheck func(repo string, k Kind) bool +} + +// SetCapabilityCheck installs the check Observe asks before it records a +// capability blocker: true means the hive verified it holds that capability +// on repo (for workflows: the installation grants `workflows: write` and a +// lane whose token asks for it serves the repo), so an agent's "the App +// cannot push workflow files" is not recorded as a blocker +// (projectbluefin/testsuite#1059). Nil, the default, records every report. +func (l *Ledger) SetCapabilityCheck(fn func(repo string, k Kind) bool) { + l.mu.Lock() + defer l.mu.Unlock() + l.capabilityCheck = fn +} + +// capabilityHeld runs the check outside the ledger lock: it may read GitHub. +func (l *Ledger) capabilityHeld(repo string, k Kind) bool { + l.mu.Lock() + fn := l.capabilityCheck + l.mu.Unlock() + return fn != nil && k.IsCapability() && fn(repo, k) } // NewLedger returns a ledger backed by path (loaded lazily; a missing or @@ -140,6 +162,11 @@ func (l *Ledger) Observe(repo string, number int, text string, at time.Time) (En } return l.RecordReason(repo, number, NormalizeReason(text), at), true } + if l.capabilityHeld(repo, b.Kind) { + // The hive holds the capability the report says is missing: keep the + // reason for the loop guard, park nothing on it. + return l.RecordReason(repo, number, NormalizeReason(text), at), true + } return l.Record(repo, number, b, NormalizeReason(text)), true } @@ -278,6 +305,45 @@ func (l *Ledger) ClearKind(k Kind) int { return n } +// RecheckCapabilities lifts every capability blocker that held(repo, kind) +// now refutes and returns the released entries as they were. It is the +// scheduled form of the dashboard's Re-check permissions, per item rather +// than per kind, so a blocker on a repo no capable lane serves stays. held +// runs outside the ledger lock; a blocker that changed kind meanwhile is kept. +func (l *Ledger) RecheckCapabilities(held func(repo string, k Kind) bool) []Entry { + if held == nil { + return nil + } + var refuted []Entry + for _, e := range l.Blockers() { + if e.Blocker.Kind.IsCapability() && held(e.Repo, e.Blocker.Kind) { + refuted = append(refuted, e) + } + } + if len(refuted) == 0 { + return nil + } + l.mu.Lock() + defer l.mu.Unlock() + var released []Entry + for _, was := range refuted { + k := Key(was.Repo, was.Number) + e, ok := l.entries[k] + if !ok || e.Blocker == nil || e.Blocker.Kind != was.Blocker.Kind || !e.Blocker.Since.Equal(was.Blocker.Since) { + continue + } + e.Blocker = nil + e.Reapplied = false + e.ClearedAt = l.now() + l.entries[k] = e + released = append(released, was) + } + if len(released) > 0 { + _ = l.save() + } + return released +} + // Blockers lists every current blocker, sorted by item key. func (l *Ledger) Blockers() []Entry { l.mu.Lock() diff --git a/src/pkg/blocker/ledger_capability_check_test.go b/src/pkg/blocker/ledger_capability_check_test.go new file mode 100644 index 0000000000..a4845d62ef --- /dev/null +++ b/src/pkg/blocker/ledger_capability_check_test.go @@ -0,0 +1,63 @@ +package blocker + +import ( + "testing" + "time" +) + +// projectbluefin/testsuite#1059: "the hive app cannot push +// .github/workflows/" became a workflows blocker with no check, though the +// App pushed e2e.yml the same day. With a capability check installed, a +// report the hive refutes keeps its reason and parks nothing. +func TestObserveSkipsRefutedCapabilityBlocker(t *testing.T) { + report := "needs-human: the hive app cannot push `.github/workflows/e2e.yml`" + at := time.Date(2026, 11, 1, 5, 9, 13, 0, time.UTC) + + l := NewLedger("") + var asked []Kind + l.SetCapabilityCheck(func(repo string, k Kind) bool { + asked = append(asked, k) + return repo == "o/held" + }) + if e, _ := l.Observe("o/held", 1, report, at); e.Blocks() || e.Reason == "" { + t.Fatalf("refuted report: %+v, want no blocker and the reason kept", e) + } + if e, _ := l.Observe("o/lacking", 2, report, at); !e.Blocks() || e.Blocker.Kind != CapabilityWorkflowsPermission { + t.Fatalf("unrefuted report: %+v, want a workflows blocker", e) + } + asked = nil + if e, _ := l.Observe("o/held", 3, "needs-human: the contributor must sign the CLA", at); !e.Blocks() || len(asked) != 0 { + t.Fatalf("human-only report: %+v asked=%v, want a blocker and no capability check", e, asked) + } + if e, _ := NewLedger("").Observe("o/held", 1, report, at); !e.Blocks() { + t.Fatalf("no check installed: %+v, want the blocker as before", e) + } +} + +func TestRecheckCapabilitiesReleasesOnlyRefuted(t *testing.T) { + l := NewLedger("") + since := time.Date(2026, 11, 1, 5, 9, 13, 0, time.UTC) + l.Record("o/a", 1, Blocker{Kind: CapabilityWorkflowsPermission, Since: since}, "r") + l.Record("o/b", 2, Blocker{Kind: CapabilityWorkflowsPermission, Since: since}, "r") + l.Record("o/a", 3, Blocker{Kind: HumanOnlyCLA, Since: since}, "cla") + released := l.RecheckCapabilities(func(repo string, k Kind) bool { return repo == "o/a" }) + if len(released) != 1 || released[0].Number != 1 { + t.Fatalf("released = %+v, want o/a#1 only", released) + } + if _, ok := l.Blocking("o/a", 1); ok { + t.Fatal("o/a#1 still blocked") + } + if _, ok := l.Blocking("o/b", 2); !ok { + t.Fatal("o/b#2 released though the check did not refute it") + } + if _, ok := l.Blocking("o/a", 3); !ok { + t.Fatal("human-only blocker released") + } + // A report from before the release stays stale. + if e, _ := l.Observe("o/a", 1, "needs-human: the App cannot push workflow files", since); e.Blocks() { + t.Fatalf("stale report re-recorded: %+v", e) + } + if l.RecheckCapabilities(nil) != nil { + t.Fatal("nil check must release nothing") + } +} diff --git a/src/pkg/config/workflows_lane.go b/src/pkg/config/workflows_lane.go index 576a38115b..36f0cef7ef 100644 --- a/src/pkg/config/workflows_lane.go +++ b/src/pkg/config/workflows_lane.go @@ -46,6 +46,13 @@ func modePushesWorkflows(mode string) bool { return false } +// AgentPushesWorkflows reports whether agent's scoped token asks for the +// Workflows permission (trusted/merger tier), so its own push may touch +// .github/workflows/** when the installation grants it. +func (c *Config) AgentPushesWorkflows(agent string) bool { + return c != nil && modePushesWorkflows(c.AgentEffectiveMode(agent)) +} + // WorkflowsCapableLane names the enabled lane whose token can push // .github/workflows/** and serves repo, the first by name; replicas are // skipped because they share their source agent's lane. A lane scoped to diff --git a/src/pkg/config/workflows_lane_test.go b/src/pkg/config/workflows_lane_test.go index 84f7eaaa81..ba396b621f 100644 --- a/src/pkg/config/workflows_lane_test.go +++ b/src/pkg/config/workflows_lane_test.go @@ -75,3 +75,19 @@ func TestWorkflowsLaneFor(t *testing.T) { }) } } + +func TestAgentPushesWorkflows(t *testing.T) { + cfg := &Config{AgentRuntimeConfig: AgentRuntimeConfig{Agents: map[string]AgentConfig{ + "scanner": {Mode: "ISSUES_PRS_MERGE", Enabled: true}, + "scanner-2": {Mode: "ISSUES_PRS_MERGE", Enabled: true, ReplicaOf: "scanner"}, + "ci-maintainer": {Mode: "ISSUES_AND_PRS", Enabled: true}, + }}} + for agent, want := range map[string]bool{"scanner": true, "scanner-2": true, "ci-maintainer": false, "unknown": false, "": false} { + if got := cfg.AgentPushesWorkflows(agent); got != want { + t.Errorf("AgentPushesWorkflows(%q) = %v, want %v", agent, got, want) + } + } + if (*Config)(nil).AgentPushesWorkflows("scanner") { + t.Error("nil config must answer false") + } +} diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index 8a87f08e12..c6e472855f 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -135,6 +135,11 @@ type Client struct { // (SetWorkflowsLaneFunc, issue_workflows_handoff.go). workflowsLaneMu sync.RWMutex workflowsLane func(agent, repo string) string + // workflowsSelfPush reports whether an agent's own token asks for the + // Workflows permission (SetWorkflowsSelfPushFunc); workflowsGrant caches + // the installation's answer (installationGrantsWorkflows). + workflowsSelfPush func(agent string) bool + workflowsGrant workflowsGrantCache // reporterConfirmationEnabled restores the legacy close gate for all // human-filed bug-family issues when configured. Nil/false means only // per-issue opt-in markers activate the gate. diff --git a/src/pkg/github/issue_owner_step_test.go b/src/pkg/github/issue_owner_step_test.go index 6d28ca1d1d..7a56c6606e 100644 --- a/src/pkg/github/issue_owner_step_test.go +++ b/src/pkg/github/issue_owner_step_test.go @@ -241,11 +241,11 @@ func TestIssueOwnerStepNeverDowngradedByDecisionPolicy(t *testing.T) { c.SetAgentIssueDecisionPolicy("resolve") step := testReleaseStep() req := IssueRequest{Repo: "o/r", Title: "Release needed", Body: "Cut the release.", Agent: "scanner", NeedsDecision: true, OwnerStep: step} - if d := c.issueDecisionDowngradeForCreate(req, req.Body); d.Active { + if d := c.issueDecisionDowngradeForCreate(context.Background(), req, req.Body); d.Active { t.Fatalf("create with owner step must park under resolve: %+v", d) } req.Kind, req.Number = "comment", 5 - if d := c.issueDecisionDowngradeForComment(req, req.Body); d.Active { + if d := c.issueDecisionDowngradeForComment(context.Background(), req, req.Body); d.Active { t.Fatalf("comment with owner step must park under resolve: %+v", d) } // Without the owner step the same request is a plain engineering @@ -254,7 +254,7 @@ func TestIssueOwnerStepNeverDowngradedByDecisionPolicy(t *testing.T) { // classifier fails closed and an unclassified park stays a human decision. req.OwnerStep = nil req.Body = "Should the release notes live top-level or under docs/? Option A or option B." - if d := c.issueDecisionDowngradeForComment(req, req.Body); !d.Active { + if d := c.issueDecisionDowngradeForComment(context.Background(), req, req.Body); !d.Active { t.Fatal("plain engineering question must still be downgraded under resolve") } } diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index 874ac4349f..d68ea89755 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -738,7 +738,7 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f // `resolve` a non-risk Hive engineering question is not parked, // the comment records the decision and the owner-step marker is // withheld so the unpark menu does not offer `/hive done`. - issueDecisionDowngrade = c.issueDecisionDowngradeForComment(req, body) + issueDecisionDowngrade = c.issueDecisionDowngradeForComment(ctx, req, body) if !issueDecisionDowngrade.Active && len(req.BlockedBy) == 0 { if n := c.askFoldTarget(ctx, req.Repo, req.Number, body); n > 0 { req.BlockedBy, askFoldedInto = []int{n}, n @@ -775,7 +775,7 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f } if err == nil && (withdraw == nil || !withdraw.posted) { commentBody := issueOwnerStepBody(body, req.NeedsDecision && !issueDecisionDowngrade.Active, req.OwnerStep) - if issueDecisionDowngrade.Lane != "" { + if issueDecisionDowngrade.workflows() { commentBody = appendWorkflowsHandoff(commentBody, issueDecisionDowngrade) } else if issueDecisionDowngrade.Active { commentBody = appendHiveDecisionTaken(commentBody, issueDecisionDowngrade.Question) @@ -927,7 +927,7 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f } default: // "issue" var res CreateIssueResult - createLabels, createBody, d := c.issueCreateLabels(req, body) + createLabels, createBody, d := c.issueCreateLabels(ctx, req, body) if d.Active { issueDecisionDowngrade = d } @@ -1096,6 +1096,9 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f if issueDecisionDowngrade.Lane != "" { c.recordWriteAudit(AuditActionAgentIssueDecisionResolved, meta, WriteTarget{Repo: req.Repo, Number: resp.Number}, "policy", "workflows-handoff", "lane", issueDecisionDowngrade.Lane) + } else if issueDecisionDowngrade.SelfPush { + c.recordWriteAudit(AuditActionAgentIssueDecisionResolved, meta, WriteTarget{Repo: req.Repo, Number: resp.Number}, + "policy", "workflows-self-push", "lane", req.Agent) } else if issueDecisionDowngrade.Active { c.recordWriteAudit(AuditActionAgentIssueDecisionResolved, meta, WriteTarget{Repo: req.Repo, Number: resp.Number}, "policy", decisionpolicy.PolicyResolve, "question", issueDecisionDowngrade.Question) @@ -1117,16 +1120,24 @@ type issueDecisionDowngrade struct { // Lane is set when the park is a workflow-only change handed to the // lane that can push it (workflowsHandoff), not a decision the hive took. Lane string + // SelfPush is set when the parking lane's own token can push the + // workflow change and the installation grants it (workflowsHandoff): + // the park is refused and the issue stays with that lane. + SelfPush bool } +// workflows reports a workflow-only park the relay did not park: handed to +// another lane, or refused because the lane can push it itself. +func (d issueDecisionDowngrade) workflows() bool { return d.Lane != "" || d.SelfPush } + // A typed owner step (e.g. a release) proposes an action only a person // with owner credentials can take, so it is owner-only by construction and // never downgraded to a hive-taken decision, whatever the policy. -func (c *Client) issueDecisionDowngradeForCreate(req IssueRequest, body string) issueDecisionDowngrade { +func (c *Client) issueDecisionDowngradeForCreate(ctx context.Context, req IssueRequest, body string) issueDecisionDowngrade { if !req.NeedsDecision || req.OwnerStep != nil || !hiveIssueRequestActor(req.Agent, req.Labels) { return issueDecisionDowngrade{} } - if d := c.workflowsHandoff(req.Agent, req.Repo, req.Title, body); d.Active { + if d := c.workflowsHandoff(ctx, req.Agent, req.Repo, req.Title, body); d.Active { return d } return c.issueDecisionDowngrade(req.Title, body) @@ -1135,11 +1146,11 @@ func (c *Client) issueDecisionDowngradeForCreate(req IssueRequest, body string) // issueDecisionDowngradeForComment classifies a `comment --needs-decision` // park on an existing issue. A comment always carries its own text, so the // classification reads the comment body rather than the issue. -func (c *Client) issueDecisionDowngradeForComment(req IssueRequest, body string) issueDecisionDowngrade { +func (c *Client) issueDecisionDowngradeForComment(ctx context.Context, req IssueRequest, body string) issueDecisionDowngrade { if !req.NeedsDecision || req.OwnerStep != nil || !hiveIssueRequestActor(req.Agent, req.Labels) { return issueDecisionDowngrade{} } - if d := c.workflowsHandoff(req.Agent, req.Repo, "", body); d.Active { + if d := c.workflowsHandoff(ctx, req.Agent, req.Repo, "", body); d.Active { return d } return c.issueDecisionDowngrade("", body) @@ -1230,16 +1241,18 @@ func hiveDecisionDowngradeNote(question string) string { // the hive takes the engineering decision itself — stage/010-actionable in // its place and the decision recorded in the body. The labels travel in // the create call; the stage engine owns them from the first sweep on. -func (c *Client) issueCreateLabels(req IssueRequest, body string) (labels []string, createBody string, d issueDecisionDowngrade) { +func (c *Client) issueCreateLabels(ctx context.Context, req IssueRequest, body string) (labels []string, createBody string, d issueDecisionDowngrade) { labels, createBody = req.Labels, body if !req.NeedsDecision { return labels, createBody, d } - if d = c.issueDecisionDowngradeForCreate(req, createBody); d.Active { + if d = c.issueDecisionDowngradeForCreate(ctx, req, createBody); d.Active { labels = removeDecisionParkLabels(labels, c.needsDecisionLabel()) labels = appendLabelIfMissing(labels, stagelabels.Actionable.Label()) - if d.Lane != "" { - labels = appendLabelIfMissing(labels, WorkflowsLaneLabel) + if d.workflows() { + if d.Lane != "" { + labels = appendLabelIfMissing(labels, WorkflowsLaneLabel) + } createBody = appendWorkflowsHandoff(createBody, d) } else { createBody = appendHiveDecisionTaken(createBody, d.Question) diff --git a/src/pkg/github/issue_workflows_handoff.go b/src/pkg/github/issue_workflows_handoff.go index 1ea8266e3f..2b32c3620b 100644 --- a/src/pkg/github/issue_workflows_handoff.go +++ b/src/pkg/github/issue_workflows_handoff.go @@ -1,10 +1,14 @@ package github import ( + "context" "regexp" "strings" + "sync" + "time" itemblocker "github.com/hivecommons/hive/pkg/blocker" + "github.com/hivecommons/hive/pkg/writeback" ) // WorkflowsLaneLabel routes an issue to the lane that can push @@ -28,6 +32,28 @@ func (c *Client) SetWorkflowsLaneFunc(fn func(agent, repo string) string) { c.workflowsLane = fn } +// SetWorkflowsSelfPushFunc installs the fleet lookup (config.AgentPushesWorkflows) +// that says whether an agent's own scoped token asks for the Workflows +// permission. Nil, or never set, treats every lane as unable to push them. +func (c *Client) SetWorkflowsSelfPushFunc(fn func(agent string) bool) { + if c == nil { + return + } + c.workflowsLaneMu.Lock() + defer c.workflowsLaneMu.Unlock() + c.workflowsSelfPush = fn +} + +func (c *Client) workflowsSelfPushFor(agent string) bool { + if c == nil || strings.TrimSpace(agent) == "" { + return false + } + c.workflowsLaneMu.RLock() + fn := c.workflowsSelfPush + c.workflowsLaneMu.RUnlock() + return fn != nil && fn(strings.TrimSpace(agent)) +} + func (c *Client) workflowsLaneFor(agent, repo string) string { if c == nil { return "" @@ -64,22 +90,45 @@ func parkIsWorkflowsOnly(text string) bool { return strings.Contains(strings.ToLower(text), ".github/workflows") && workflowsPermissionRE.MatchString(text) } -// workflowsHandoff turns a lane's workflow-only park into a hand-off to the -// lane that can push it: the issue is not parked, it carries -// WorkflowsLaneLabel, and the posted text says where it went. Inactive when -// the requester can push workflows itself, when no lane can (the owner still -// applies it), or when the text is not a workflow-only park. -func (c *Client) workflowsHandoff(agent, repo, title, body string) issueDecisionDowngrade { +// workflowsHandoff checks a lane's workflow-only park against what the hive +// can actually push. A lane whose own token asks for the Workflows permission, +// on an installation that grants it, is refused the park and keeps the issue +// (projectbluefin/testsuite#1059: scanner, at the merger tier, parked "the +// hive app cannot push .github/workflows/" the same day the App pushed +// e2e.yml in #1089). Any other lane hands it to the lane that can push it: +// the issue is not parked, it carries WorkflowsLaneLabel, and the posted text +// says where it went. Inactive (the park stands) when the text is not a +// workflow-only park, when no lane can push it, or when the installation is +// known to lack `workflows: write`. +func (c *Client) workflowsHandoff(ctx context.Context, agent, repo, title, body string) issueDecisionDowngrade { if !parkIsWorkflowsOnly(title + "\n" + body) { return issueDecisionDowngrade{} } + if c.workflowsSelfPushFor(agent) { + if granted, known := c.installationGrantsWorkflows(ctx); known && granted { + return issueDecisionDowngrade{Active: true, SelfPush: true, Note: workflowsSelfPushNote(agent)} + } + return issueDecisionDowngrade{} + } lane := c.workflowsLaneFor(agent, repo) if lane == "" { return issueDecisionDowngrade{} } + if granted, known := c.installationGrantsWorkflows(ctx); known && !granted { + return issueDecisionDowngrade{} + } return issueDecisionDowngrade{Active: true, Lane: lane, Note: workflowsHandoffNote(agent, lane)} } +func workflowsSelfPushNote(agent string) string { + who := "this lane" + if a := strings.TrimSpace(agent); a != "" { + who = "`" + a + "`" + } + return "Not parked: " + who + "'s token can push `.github/workflows/`. Its tier asks for the Workflows permission and the App installation grants `workflows: write`, so " + + who + " pushes the change. If a push is still rejected, park again quoting GitHub's error. Owner may override with `/hive hold` or `needs-human`." +} + func workflowsHandoffNote(agent, lane string) string { from := "this lane" if a := strings.TrimSpace(agent); a != "" { @@ -92,7 +141,11 @@ func workflowsHandoffNote(agent, lane string) string { func appendWorkflowsHandoff(body string, d issueDecisionDowngrade) string { body = strings.TrimRight(body, "\n") - if strings.Contains(body, "Handed to `"+d.Lane+"`:") { + seen := d.Note + if d.Lane != "" { + seen = "Handed to `" + d.Lane + "`:" + } + if strings.Contains(body, seen) { return body } if body == "" { @@ -100,3 +153,99 @@ func appendWorkflowsHandoff(body string, d issueDecisionDowngrade) string { } return body + "\n\n" + d.Note } + +// workflowsGrantTTL is how long the installation's `workflows` grant is +// trusted before it is read again: a grant or revocation shows within a few +// minutes, and a burst of parks costs one GitHub call. +const workflowsGrantTTL = 5 * time.Minute + +type workflowsGrantCache struct { + mu sync.Mutex + at time.Time + granted bool +} + +// installationProbe reads the App installation's granted permissions; tests +// swap it. +var installationProbe = func(ctx context.Context, auth *AppAuth) (*InstallationInfo, error) { + return auth.VerifyInstallation(ctx) +} + +// installationGrantsWorkflows reports whether the App installation grants +// `workflows: write`. known is false for a token-authenticated client or a +// failed read, so callers keep their previous behaviour. +func (c *Client) installationGrantsWorkflows(ctx context.Context) (granted, known bool) { + if c == nil || c.appAuth == nil { + return false, false + } + g := &c.workflowsGrant + g.mu.Lock() + defer g.mu.Unlock() + if !g.at.IsZero() && time.Since(g.at) < workflowsGrantTTL { + return g.granted, true + } + if ctx == nil { + ctx = context.Background() + } + info, err := installationProbe(ctx, c.appAuth) + if err != nil { + return false, false + } + g.at, g.granted = time.Now(), info.Granted(itemblocker.CapabilityWorkflowsPermission.Permission(), "write") + return g.granted, true +} + +// WorkflowsPushable reports whether the hive can push .github/workflows/** +// in repo: a lane whose token asks for the Workflows permission serves it +// (an empty agent asks the lane lookup for any capable lane) and the +// installation grants `workflows: write`. Unknown is false. +func (c *Client) WorkflowsPushable(ctx context.Context, repo string) bool { + if c.workflowsLaneFor("", repo) == "" { + return false + } + granted, known := c.installationGrantsWorkflows(ctx) + return known && granted +} + +// CapabilityAvailable is the blocker ledger's check (blocker.Ledger +// SetCapabilityCheck): a workflows-permission blocker on repo is refuted +// when WorkflowsPushable holds. Other kinds are never refuted here. +// The ledger keys webhook reports by the configured repo name, which may be +// short, so the lane lookup gets owner/repo. +func (c *Client) CapabilityAvailable(repo string, k itemblocker.Kind) bool { + if c == nil || k != itemblocker.CapabilityWorkflowsPermission { + return false + } + owner, name := c.splitRepo(repo) + return c.WorkflowsPushable(context.Background(), owner+"/"+name) +} + +// SweepWorkflowsBlockers re-checks the blocker ledger's capability blockers +// against what the hive can push (CapabilityAvailable) and lifts the ones it +// refutes. Each released workflows blocker gets WorkflowsLaneLabel, so once +// its park is answered the issue goes to the lane that can push the change, +// not back to the lane that parked it. The park label itself stays: a person +// still answers it, and "Let hive decide" is no longer disabled by a blocker. +// It returns the released entries. +func (c *Client) SweepWorkflowsBlockers(ctx context.Context) ([]itemblocker.Entry, error) { + if c == nil { + return nil, nil + } + released := itemblocker.Shared().RecheckCapabilities(c.CapabilityAvailable) + var firstErr error + for _, e := range released { + if e.Blocker.Kind != itemblocker.CapabilityWorkflowsPermission { + continue + } + // An unsolicited routing label, gated like the stage engine's own + // labels; a refusal leaves the blocker released and the label off. + owner, name := c.splitRepo(e.Repo) + if d := c.WritebackAllowed(owner+"/"+name, writeback.Item{Number: e.Number}, writeback.KindStageLabel, WorkflowsLaneLabel); !d.Allowed { + continue + } + if err := c.AddLabels(ctx, e.Repo, e.Number, []string{WorkflowsLaneLabel}); err != nil && firstErr == nil { // writeback:gated + firstErr = err + } + } + return released, firstErr +} diff --git a/src/pkg/github/issue_workflows_self_push_test.go b/src/pkg/github/issue_workflows_self_push_test.go new file mode 100644 index 0000000000..651fe36d47 --- /dev/null +++ b/src/pkg/github/issue_workflows_self_push_test.go @@ -0,0 +1,232 @@ +package github + +import ( + "context" + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + "time" + + itemblocker "github.com/hivecommons/hive/pkg/blocker" +) + +// projectbluefin/testsuite#1059, scanner (ISSUES_PRS_MERGE, merger tier) on +// 2026-11-01 05:09Z. The App pushed .github/workflows/e2e.yml in #1089 the +// same day. +const selfPush1059 = "## Workflow change needed (the hive app cannot push `.github/workflows/`)\n\n" + + "A test-side PR on `scanner/fix-1059` fixes most of the 16 failures. One related cause is in `e2e.yml`, and the hive app can't push it.\n\n" + + "**Proposed diff** (`.github/workflows/e2e.yml`, \"Install gnome-ponytail-daemon\" step): run the daemon under `systemd-run --user`." + +// stubInstallation swaps the installation read and counts calls. +func stubInstallation(t *testing.T, perms map[string]string, err error) *int { + t.Helper() + calls := 0 + prev := installationProbe + installationProbe = func(context.Context, *AppAuth) (*InstallationInfo, error) { + calls++ + if err != nil { + return nil, err + } + return &InstallationInfo{Permissions: perms}, nil + } + t.Cleanup(func() { installationProbe = prev }) + return &calls +} + +// fleet installs the two lookups the relay asks: scanner is the merger-tier +// lane, and it serves the repo only when lane is true. +func fleet(appAuth, lane bool) func(*Client) { + return func(c *Client) { + if appAuth { + c.appAuth = &AppAuth{} + } + c.SetWorkflowsSelfPushFunc(func(agent string) bool { return agent == "scanner" }) + c.SetWorkflowsLaneFunc(func(agent, repo string) string { + if !lane || agent == "scanner" { + return "" + } + return "scanner" + }) + } +} + +// agent tier × installation grant × capable lane: a merger-tier lane is +// refused the park when the installation grants `workflows: write`; a +// contributor-tier lane hands it to the capable lane unless the installation +// is known to lack the permission; everything else parks as before. +func TestWorkflowsParkCheckedAgainstTierAndInstallation(t *testing.T) { + const ( + self = "comment" + handoff = "label:" + WorkflowsLaneLabel + ",comment" + park = "label:owner-call,comment" + ) + write := map[string]string{"workflows": "write"} + read := map[string]string{"workflows": "read"} + for _, tc := range []struct { + name string + agent string + appAuth bool + lane bool + perms map[string]string + err error + want string + }{ + {name: "merger tier, installation grants: back to the agent", agent: "scanner", appAuth: true, lane: true, perms: write, want: self}, + {name: "merger tier, no other lane needed", agent: "scanner", appAuth: true, lane: false, perms: write, want: self}, + {name: "merger tier, installation has read only: parks", agent: "scanner", appAuth: true, lane: true, perms: read, want: park}, + {name: "merger tier, installation read fails: parks", agent: "scanner", appAuth: true, lane: true, err: errors.New("502"), want: park}, + {name: "merger tier, token-authenticated client: parks", agent: "scanner", appAuth: false, lane: true, perms: write, want: park}, + {name: "contributor tier, installation grants: hand-off", agent: "ci-maintainer", appAuth: true, lane: true, perms: write, want: handoff}, + {name: "contributor tier, installation lacks it: parks", agent: "ci-maintainer", appAuth: true, lane: true, perms: read, want: park}, + {name: "contributor tier, installation unknown: hand-off as before", agent: "ci-maintainer", appAuth: true, lane: true, err: errors.New("502"), want: handoff}, + {name: "contributor tier, no capable lane: parks", agent: "ci-maintainer", appAuth: true, lane: false, perms: write, want: park}, + } { + t.Run(tc.name, func(t *testing.T) { + stubInstallation(t, tc.perms, tc.err) + writes, bodies, resp := runNeedsDecisionCommentCapture(t, needsDecisionFilter{label: "owner-call"}, IssueRequest{ + Kind: "comment", Repo: "o/r", Number: 1059, Agent: tc.agent, NeedsDecision: true, Body: selfPush1059, + }, false, fleet(tc.appAuth, tc.lane)) + if got := strings.Join(writes, ","); got != tc.want { + t.Fatalf("writes = %q, want %q", got, tc.want) + } + if !resp.OK || len(bodies) != 1 { + t.Fatalf("result = %+v bodies = %v", resp, bodies) + } + selfNote := strings.Contains(bodies[0], "Not parked: `scanner`'s token can push") + if selfNote != (tc.want == self) { + t.Fatalf("self-push note present = %v, want %v:\n%s", selfNote, tc.want == self, bodies[0]) + } + if tc.want != park && strings.Contains(bodies[0], unparkOwnerStepMarker) { + t.Fatalf("an unparked comment must not carry the owner-step marker:\n%s", bodies[0]) + } + }) + } +} + +// A burst of parks costs one installation read. +func TestInstallationGrantIsCached(t *testing.T) { + calls := stubInstallation(t, map[string]string{"workflows": "write"}, nil) + c := &Client{appAuth: &AppAuth{}} + for i := 0; i < 3; i++ { + if granted, known := c.installationGrantsWorkflows(context.Background()); !granted || !known { + t.Fatalf("granted=%v known=%v", granted, known) + } + } + if *calls != 1 { + t.Fatalf("installation reads = %d, want 1", *calls) + } + c.workflowsGrant.at = time.Now().Add(-workflowsGrantTTL - time.Second) + c.installationGrantsWorkflows(context.Background()) + if *calls != 2 { + t.Fatalf("installation reads after the TTL = %d, want 2", *calls) + } +} + +// The scheduled pass lifts a recorded workflows blocker once the hive can +// push workflow files on that repo, and routes the item to the capable lane. +// A repo no capable lane serves keeps its blocker. +func TestSweepWorkflowsBlockersReleasesGrantedBlockers(t *testing.T) { + stubInstallation(t, map[string]string{"workflows": "write"}, nil) + l := itemblocker.NewLedger("") + prev := itemblocker.SetShared(l) + t.Cleanup(func() { itemblocker.SetShared(prev) }) + since := time.Date(2026, 11, 1, 5, 9, 13, 0, time.UTC) + l.Record("o/testsuite", 1059, itemblocker.Blocker{Kind: itemblocker.CapabilityWorkflowsPermission, Since: since}, "the hive app cannot push .github/workflows/") + l.Record("o/other", 7, itemblocker.Blocker{Kind: itemblocker.CapabilityWorkflowsPermission, Since: since}, "the hive app cannot push .github/workflows/") + l.Record("o/testsuite", 1073, itemblocker.Blocker{Kind: itemblocker.HumanOnlyCLA, Since: since}, "sign the CLA") + l.Record("o/testsuite", 1080, itemblocker.Blocker{Kind: itemblocker.CapabilityBranchProtection, Since: since}, "cannot edit the ruleset") + + var mu sync.Mutex + var labelled []string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + if r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/labels") { + var body []string + _ = json.NewDecoder(r.Body).Decode(&body) + mu.Lock() + labelled = append(labelled, r.URL.Path+"="+strings.Join(body, ",")) + mu.Unlock() + _, _ = w.Write([]byte(`[{"name":"x"}]`)) + return + } + w.WriteHeader(http.StatusNotFound) + })) + defer srv.Close() + c := issueTestClient(t, srv.URL) + c.appAuth = &AppAuth{} + c.SetWorkflowsLaneFunc(func(agent, repo string) string { + if repo == "o/testsuite" { + return "scanner" + } + return "" + }) + + released, err := c.SweepWorkflowsBlockers(context.Background()) + if err != nil { + t.Fatalf("sweep: %v", err) + } + if len(released) != 1 || released[0].Number != 1059 { + t.Fatalf("released = %+v, want only o/testsuite#1059", released) + } + if _, blocked := l.Blocking("o/testsuite", 1059); blocked { + t.Fatal("#1059 still blocked") + } + if _, blocked := l.Blocking("o/other", 7); !blocked { + t.Fatal("o/other#7 has no capable lane and must stay blocked") + } + if _, blocked := l.Blocking("o/testsuite", 1073); !blocked { + t.Fatal("a human-only blocker is never re-checked away") + } + if _, blocked := l.Blocking("o/testsuite", 1080); !blocked { + t.Fatal("a workflows grant must not release another capability's blocker") + } + mu.Lock() + defer mu.Unlock() + if len(labelled) != 1 || labelled[0] != "/repos/o/testsuite/issues/1059/labels="+WorkflowsLaneLabel { + t.Fatalf("labels written = %v", labelled) + } + + // Once the hive can push, a fresh report of the same claim is a reason, + // not a blocker. + l.SetCapabilityCheck(c.CapabilityAvailable) + if e, _ := l.Observe("o/testsuite", 1059, "needs-human: the hive app cannot push `.github/workflows/e2e.yml`", time.Now().Add(time.Hour)); e.Blocks() { + t.Fatalf("re-report recorded a blocker: %+v", e) + } +} + +// A merger-tier lane filing a workflow-only issue gets it created unparked, +// actionable, with no routing label (it stays its own) and the note. +func TestCreateWorkflowsParkRefusedForMergerTier(t *testing.T) { + stubInstallation(t, map[string]string{"workflows": "write"}, nil) + var mu sync.Mutex + var got []issueCreatePayload + srv := newIssueCreateLabelServer(t, &mu, &got) + defer srv.Close() + c := issueTestClient(t, srv.URL) + c.SetAgentIssueDecisionPolicy("escalate") + fleet(true, true)(c) + dir := withIssueDir(t) + if _, err := WriteIssueRequest(dir, IssueRequest{ + Repo: "o/r", Title: "[scanner] ponytail daemon dies with the SSH session", + Body: selfPush1059, Labels: []string{"agent/scanner"}, Agent: "scanner", NeedsDecision: true, + }); err != nil { + t.Fatal(err) + } + c.ProcessIssueRequestsOnce(context.Background()) + mu.Lock() + defer mu.Unlock() + if len(got) != 1 { + t.Fatalf("creates = %d, want 1", len(got)) + } + p := got[0] + if hasLabelFold(p.Labels, NeedsDecisionStageLabel) || hasLabelFold(p.Labels, WorkflowsLaneLabel) || !hasLabelFold(p.Labels, "stage/010-actionable") { + t.Fatalf("labels = %v, want actionable, not parked, not handed off", p.Labels) + } + if strings.Contains(p.Body, unparkOwnerStepMarker) || !strings.Contains(p.Body, "Not parked: `scanner`'s token can push") { + t.Fatalf("body must carry the self-push note and no owner-step marker:\n%s", p.Body) + } +} diff --git a/src/pkg/scheduler/policy_overlays.go b/src/pkg/scheduler/policy_overlays.go index e6711c2f23..2786b4ab82 100644 --- a/src/pkg/scheduler/policy_overlays.go +++ b/src/pkg/scheduler/policy_overlays.go @@ -104,6 +104,9 @@ func (s *Scheduler) isHoldGatedPRAgent(agentName string) bool { // the same reason (kubestellar/hive#4744): a customized or remotely sourced // policy must not be able to omit it. func (s *Scheduler) addWorkflowPushCeiling(agentName, message string) string { + if message != "" && s.cfg.AgentPushesWorkflows(agentName) { + return insertAfterKickHeader(message, workflowPushReach) + } if message == "" || s.agentEffectiveMode(agentName) != "ISSUES_AND_PRS" { return message } @@ -159,6 +162,21 @@ serves the repository, the park stands and the owner applies it. return insertAfterKickHeader(message, section) } +// workflowPushReach is the other side of the ceiling: a trusted/merger-tier +// token asks for the Workflows permission, so the lane can push +// .github/workflows/** itself. projectbluefin/testsuite#1059: scanner, at +// ISSUES_PRS_MERGE, parked "the hive app cannot push .github/workflows/" the +// same day the App pushed e2e.yml; nothing in its kick said otherwise. The +// relay refuses such a park when the installation grants the permission. +const workflowPushReach = `## Workflow files are in reach at this mode + +This agent's token is minted at the trusted/merger tier, which asks for the +Workflows permission, so it can push changes under ` + "`.github/workflows/**`" + `. +Push a workflow fix like any other; do not park it as "the App cannot push +workflow files". Only if GitHub rejects the push for the ` + "`workflows`" + ` +permission, park it and quote the rejection. +` + // routeWorkflowsLane sends an issue the relay handed off for a workflow-only // change (github.WorkflowsLaneLabel) to the lane that can push workflow files. // Without it the issue keeps its `[lane]` title / `agent/` routing and diff --git a/src/pkg/scheduler/workflow_push_ceiling_test.go b/src/pkg/scheduler/workflow_push_ceiling_test.go index f31b61bcad..ff7cd6c139 100644 --- a/src/pkg/scheduler/workflow_push_ceiling_test.go +++ b/src/pkg/scheduler/workflow_push_ceiling_test.go @@ -84,3 +84,28 @@ func TestWorkflowPushCeilingSilentForUnknownAgent(t *testing.T) { t.Fatalf("ceiling stated for an agent with no configured mode:\n%s", msg) } } + +// projectbluefin/testsuite#1059: a merger-tier lane is told its token can +// push workflow files; a contributor-tier lane is not. +func TestWorkflowPushReachForMergerTier(t *testing.T) { + for _, tc := range []struct { + mode string + want bool + }{ + {mode: "ISSUES_PRS_MERGE", want: true}, + {mode: "ISSUES_AND_PRS", want: false}, + {mode: "ISSUES_ONLY", want: false}, + } { + t.Run(tc.mode, func(t *testing.T) { + s := heldPRCoordinationScheduler(t, 4, tc.mode) + msg := s.BuildAgentMessage("quality", nil, &github.ActionableResult{}) + got := strings.Contains(msg, "Workflow files are in reach at this mode") && strings.Contains(msg, "do not park it as") + if got != tc.want { + t.Fatalf("mode %s: reach stated = %v, want %v:\n%s", tc.mode, got, tc.want, msg) + } + if tc.want && strings.Index(msg, "Workflow files are in reach") > strings.Index(msg, "CUSTOM POLICY BODY") { + t.Fatalf("the line must precede policy work selection:\n%s", msg) + } + }) + } +} From 3d1ae0ecc169a0a8fda9d3e343939ce6a2a54c8a Mon Sep 17 00:00:00 2001 From: Danathar Date: Thu, 5 Nov 2026 16:58:41 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fix(workflows):=20keep=20a?= =?UTF-8?q?=20fork=20PR's=20workflows=20blocker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fork branch takes no workflow-file push from the App whatever the installation grants (projectbluefin/testsuite#1037: three refused fixer pushes), so the ledger check is per item: CapabilityAvailable reads the issue/PR and refutes a workflows blocker only on an issue or a same-repo PR. An unreadable item keeps its blocker. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- .../fixed-workflows-blocker-verified.md | 2 +- .../dashboard-sections/activity-monitor.md | 2 +- src/pkg/blocker/ledger.go | 25 +++++++------ .../blocker/ledger_capability_check_test.go | 9 +++-- src/pkg/github/issue_workflows_handoff.go | 37 ++++++++++++++++--- .../github/issue_workflows_self_push_test.go | 32 ++++++++++++++-- 6 files changed, 82 insertions(+), 25 deletions(-) diff --git a/changelog.d/fixed-workflows-blocker-verified.md b/changelog.d/fixed-workflows-blocker-verified.md index 87995a833e..f7168b7da1 100644 --- a/changelog.d/fixed-workflows-blocker-verified.md +++ b/changelog.d/fixed-workflows-blocker-verified.md @@ -1 +1 @@ -- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository, and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. +- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository or the item is a fork PR (a fork branch takes no workflow push from the App), and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. diff --git a/src/docs/dashboard-sections/activity-monitor.md b/src/docs/dashboard-sections/activity-monitor.md index 4a4a9af057..d0cb63a53d 100644 --- a/src/docs/dashboard-sections/activity-monitor.md +++ b/src/docs/dashboard-sections/activity-monitor.md @@ -382,7 +382,7 @@ A `blocked` issue with neither (a human-applied label) keeps the bare pill. This #### Blocked pill — capability gaps -**Blocked pill — capability gaps** ([#15099](https://github.com/hivecommons/hive/issues/15099)). An issue parked because the hive *cannot* act — the scanner reported "the App token cannot push `.github/workflows/*` (no `workflows` permission); needs a human" — is a blocker, not a question, so its row does not read *Needs human decision*: the pill reads **Blocked · App lacks workflows permission** and the same popover says in plain words *Hive can't do this one: the GitHub App has no `workflows` permission, so it cannot push changes to .github/workflows/\*.* followed by the ways out: *Grant the App workflows permission* (opens the App settings page; the hive re-tries on its own once it sees the permission), *Re-check permissions* (probes the installation now and releases every item blocked on it), *Prepare the patch for a person to push* (disabled with its reason until a human-authorised push identity exists), *Mark partially addressed and close*, *Keep waiting*. *Let hive decide* stays in the list but disabled with the sentence that explains why — a direction decision cannot grant a permission — instead of being greyed silently; running it anyway returns *no-effect* with the same words and never applies `approved-direction`. The loop that motivated this (un-park → sweep re-parks with the same text → "I tried let hive decide and it still needs human") is guarded: when the same needs-human reason comes back after a delegated un-park, the row is parked with a blocker and *Let hive decide* is disabled on it until the reason changes. The blocker comes from the agent's `` marker or, failing that, from the prose of the needs-human report (`pkg/blocker`). A workflows blocker is recorded only when the hive cannot push workflow files on that repository: when the App installation grants `workflows: write` and an enabled lane whose token asks for it serves the repository, the report is kept as a plain reason and no pill is drawn. The same check runs with the issue un-park sweep (on start, then every five minutes) on blockers already recorded: a released one gets `hive/workflows-lane`, so the issue goes to that lane once its park is answered. ⚙ → Security shows the fleet view: *GitHub App permissions: missing `workflows` · N items blocked* with the settings link (`/api/status.capabilities`). +**Blocked pill — capability gaps** ([#15099](https://github.com/hivecommons/hive/issues/15099)). An issue parked because the hive *cannot* act — the scanner reported "the App token cannot push `.github/workflows/*` (no `workflows` permission); needs a human" — is a blocker, not a question, so its row does not read *Needs human decision*: the pill reads **Blocked · App lacks workflows permission** and the same popover says in plain words *Hive can't do this one: the GitHub App has no `workflows` permission, so it cannot push changes to .github/workflows/\*.* followed by the ways out: *Grant the App workflows permission* (opens the App settings page; the hive re-tries on its own once it sees the permission), *Re-check permissions* (probes the installation now and releases every item blocked on it), *Prepare the patch for a person to push* (disabled with its reason until a human-authorised push identity exists), *Mark partially addressed and close*, *Keep waiting*. *Let hive decide* stays in the list but disabled with the sentence that explains why — a direction decision cannot grant a permission — instead of being greyed silently; running it anyway returns *no-effect* with the same words and never applies `approved-direction`. The loop that motivated this (un-park → sweep re-parks with the same text → "I tried let hive decide and it still needs human") is guarded: when the same needs-human reason comes back after a delegated un-park, the row is parked with a blocker and *Let hive decide* is disabled on it until the reason changes. The blocker comes from the agent's `` marker or, failing that, from the prose of the needs-human report (`pkg/blocker`). A workflows blocker is recorded only when the hive cannot push workflow files for that item: when the App installation grants `workflows: write`, an enabled lane whose token asks for it serves the repository and the item is an issue or a same-repository PR, the report is kept as a plain reason and no pill is drawn. A fork PR keeps the blocker, because a fork branch takes no workflow-file push from the App whatever it is granted. The same check runs with the issue un-park sweep (on start, then every five minutes) on blockers already recorded: a released one gets `hive/workflows-lane`, so the issue goes to that lane once its park is answered. ⚙ → Security shows the fleet view: *GitHub App permissions: missing `workflows` · N items blocked* with the settings link (`/api/status.capabilities`). #### New row (`000-new`, the pre-stage state) diff --git a/src/pkg/blocker/ledger.go b/src/pkg/blocker/ledger.go index 84be775ca1..ee5a1af07f 100644 --- a/src/pkg/blocker/ledger.go +++ b/src/pkg/blocker/ledger.go @@ -57,27 +57,28 @@ type Ledger struct { now func() time.Time loaded bool // capabilityCheck refutes a capability report (SetCapabilityCheck). - capabilityCheck func(repo string, k Kind) bool + capabilityCheck func(repo string, number int, k Kind) bool } // SetCapabilityCheck installs the check Observe asks before it records a // capability blocker: true means the hive verified it holds that capability -// on repo (for workflows: the installation grants `workflows: write` and a -// lane whose token asks for it serves the repo), so an agent's "the App -// cannot push workflow files" is not recorded as a blocker -// (projectbluefin/testsuite#1059). Nil, the default, records every report. -func (l *Ledger) SetCapabilityCheck(fn func(repo string, k Kind) bool) { +// for that item (for workflows: the installation grants `workflows: write`, +// a lane whose token asks for it serves the repo, and the item is not a fork +// PR), so an agent's "the App cannot push workflow files" is not recorded +// as a blocker (projectbluefin/testsuite#1059). Nil, the default, records +// every report. +func (l *Ledger) SetCapabilityCheck(fn func(repo string, number int, k Kind) bool) { l.mu.Lock() defer l.mu.Unlock() l.capabilityCheck = fn } // capabilityHeld runs the check outside the ledger lock: it may read GitHub. -func (l *Ledger) capabilityHeld(repo string, k Kind) bool { +func (l *Ledger) capabilityHeld(repo string, number int, k Kind) bool { l.mu.Lock() fn := l.capabilityCheck l.mu.Unlock() - return fn != nil && k.IsCapability() && fn(repo, k) + return fn != nil && k.IsCapability() && fn(repo, number, k) } // NewLedger returns a ledger backed by path (loaded lazily; a missing or @@ -162,7 +163,7 @@ func (l *Ledger) Observe(repo string, number int, text string, at time.Time) (En } return l.RecordReason(repo, number, NormalizeReason(text), at), true } - if l.capabilityHeld(repo, b.Kind) { + if l.capabilityHeld(repo, number, b.Kind) { // The hive holds the capability the report says is missing: keep the // reason for the loop guard, park nothing on it. return l.RecordReason(repo, number, NormalizeReason(text), at), true @@ -305,18 +306,18 @@ func (l *Ledger) ClearKind(k Kind) int { return n } -// RecheckCapabilities lifts every capability blocker that held(repo, kind) +// RecheckCapabilities lifts every capability blocker that held(repo, number, kind) // now refutes and returns the released entries as they were. It is the // scheduled form of the dashboard's Re-check permissions, per item rather // than per kind, so a blocker on a repo no capable lane serves stays. held // runs outside the ledger lock; a blocker that changed kind meanwhile is kept. -func (l *Ledger) RecheckCapabilities(held func(repo string, k Kind) bool) []Entry { +func (l *Ledger) RecheckCapabilities(held func(repo string, number int, k Kind) bool) []Entry { if held == nil { return nil } var refuted []Entry for _, e := range l.Blockers() { - if e.Blocker.Kind.IsCapability() && held(e.Repo, e.Blocker.Kind) { + if e.Blocker.Kind.IsCapability() && held(e.Repo, e.Number, e.Blocker.Kind) { refuted = append(refuted, e) } } diff --git a/src/pkg/blocker/ledger_capability_check_test.go b/src/pkg/blocker/ledger_capability_check_test.go index a4845d62ef..abd1825e26 100644 --- a/src/pkg/blocker/ledger_capability_check_test.go +++ b/src/pkg/blocker/ledger_capability_check_test.go @@ -15,9 +15,9 @@ func TestObserveSkipsRefutedCapabilityBlocker(t *testing.T) { l := NewLedger("") var asked []Kind - l.SetCapabilityCheck(func(repo string, k Kind) bool { + l.SetCapabilityCheck(func(repo string, number int, k Kind) bool { asked = append(asked, k) - return repo == "o/held" + return repo == "o/held" && number != 4 }) if e, _ := l.Observe("o/held", 1, report, at); e.Blocks() || e.Reason == "" { t.Fatalf("refuted report: %+v, want no blocker and the reason kept", e) @@ -25,6 +25,9 @@ func TestObserveSkipsRefutedCapabilityBlocker(t *testing.T) { if e, _ := l.Observe("o/lacking", 2, report, at); !e.Blocks() || e.Blocker.Kind != CapabilityWorkflowsPermission { t.Fatalf("unrefuted report: %+v, want a workflows blocker", e) } + if e, _ := l.Observe("o/held", 4, report, at); !e.Blocks() { + t.Fatalf("the check is asked per item: %+v, want #4 blocked", e) + } asked = nil if e, _ := l.Observe("o/held", 3, "needs-human: the contributor must sign the CLA", at); !e.Blocks() || len(asked) != 0 { t.Fatalf("human-only report: %+v asked=%v, want a blocker and no capability check", e, asked) @@ -40,7 +43,7 @@ func TestRecheckCapabilitiesReleasesOnlyRefuted(t *testing.T) { l.Record("o/a", 1, Blocker{Kind: CapabilityWorkflowsPermission, Since: since}, "r") l.Record("o/b", 2, Blocker{Kind: CapabilityWorkflowsPermission, Since: since}, "r") l.Record("o/a", 3, Blocker{Kind: HumanOnlyCLA, Since: since}, "cla") - released := l.RecheckCapabilities(func(repo string, k Kind) bool { return repo == "o/a" }) + released := l.RecheckCapabilities(func(repo string, number int, k Kind) bool { return repo == "o/a" }) if len(released) != 1 || released[0].Number != 1 { t.Fatalf("released = %+v, want o/a#1 only", released) } diff --git a/src/pkg/github/issue_workflows_handoff.go b/src/pkg/github/issue_workflows_handoff.go index 2b32c3620b..1def150c82 100644 --- a/src/pkg/github/issue_workflows_handoff.go +++ b/src/pkg/github/issue_workflows_handoff.go @@ -208,16 +208,43 @@ func (c *Client) WorkflowsPushable(ctx context.Context, repo string) bool { } // CapabilityAvailable is the blocker ledger's check (blocker.Ledger -// SetCapabilityCheck): a workflows-permission blocker on repo is refuted -// when WorkflowsPushable holds. Other kinds are never refuted here. +// SetCapabilityCheck): a workflows-permission blocker on repo#number is +// refuted when WorkflowsPushable holds and the item is not a fork PR. A fork +// branch takes no workflow-file push from the App whatever the installation +// grants (projectbluefin/testsuite#1037: the fixer's pushes were refused +// three times), so that blocker stands. Other kinds are never refuted here. // The ledger keys webhook reports by the configured repo name, which may be -// short, so the lane lookup gets owner/repo. -func (c *Client) CapabilityAvailable(repo string, k itemblocker.Kind) bool { +// short, so the lookups get owner/repo. +func (c *Client) CapabilityAvailable(repo string, number int, k itemblocker.Kind) bool { if c == nil || k != itemblocker.CapabilityWorkflowsPermission { return false } owner, name := c.splitRepo(repo) - return c.WorkflowsPushable(context.Background(), owner+"/"+name) + ctx := context.Background() + if !c.WorkflowsPushable(ctx, owner+"/"+name) { + return false + } + fork, known := c.forkPR(ctx, owner, name, number) + return known && !fork +} + +// forkPR reports whether owner/name#number is a pull request whose head is +// in another repository (or a deleted one). known is false when GitHub +// cannot be read. +func (c *Client) forkPR(ctx context.Context, owner, name string, number int) (fork, known bool) { + issue, _, err := c.client.Issues.Get(ctx, owner, name, number) + if err != nil { + return false, false + } + if !issue.IsPullRequest() { + return false, true + } + pr, _, err := c.client.PullRequests.Get(ctx, owner, name, number) + if err != nil { + return false, false + } + head := pr.GetHead().GetRepo().GetFullName() + return head == "" || !strings.EqualFold(head, owner+"/"+name), true } // SweepWorkflowsBlockers re-checks the blocker ledger's capability blockers diff --git a/src/pkg/github/issue_workflows_self_push_test.go b/src/pkg/github/issue_workflows_self_push_test.go index 651fe36d47..14beb7a991 100644 --- a/src/pkg/github/issue_workflows_self_push_test.go +++ b/src/pkg/github/issue_workflows_self_push_test.go @@ -139,11 +139,30 @@ func TestSweepWorkflowsBlockersReleasesGrantedBlockers(t *testing.T) { l.Record("o/other", 7, itemblocker.Blocker{Kind: itemblocker.CapabilityWorkflowsPermission, Since: since}, "the hive app cannot push .github/workflows/") l.Record("o/testsuite", 1073, itemblocker.Blocker{Kind: itemblocker.HumanOnlyCLA, Since: since}, "sign the CLA") l.Record("o/testsuite", 1080, itemblocker.Blocker{Kind: itemblocker.CapabilityBranchProtection, Since: since}, "cannot edit the ruleset") + // testsuite#1037's shape: a fork PR, whose branch takes no workflow push + // from the App whatever the grant. + l.Record("o/testsuite", 1037, itemblocker.Blocker{Kind: itemblocker.CapabilityWorkflowsPermission, Since: since}, "the fixer's push was refused") + // A same-repo PR is pushable like an issue. + l.Record("o/testsuite", 1089, itemblocker.Blocker{Kind: itemblocker.CapabilityWorkflowsPermission, Since: since}, "the hive app cannot push .github/workflows/") var mu sync.Mutex var labelled []string srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") + switch r.URL.Path { + case "/repos/o/testsuite/issues/1059": + _, _ = w.Write([]byte(`{"number":1059}`)) + return + case "/repos/o/testsuite/issues/1037", "/repos/o/testsuite/issues/1089": + _, _ = w.Write([]byte(`{"number":1,"pull_request":{"url":"x"}}`)) + return + case "/repos/o/testsuite/pulls/1037": + _, _ = w.Write([]byte(`{"number":1037,"head":{"repo":{"full_name":"arteeh/testsuite"}}}`)) + return + case "/repos/o/testsuite/pulls/1089": + _, _ = w.Write([]byte(`{"number":1089,"head":{"repo":{"full_name":"o/testsuite"}}}`)) + return + } if r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/labels") { var body []string _ = json.NewDecoder(r.Body).Decode(&body) @@ -169,8 +188,15 @@ func TestSweepWorkflowsBlockersReleasesGrantedBlockers(t *testing.T) { if err != nil { t.Fatalf("sweep: %v", err) } - if len(released) != 1 || released[0].Number != 1059 { - t.Fatalf("released = %+v, want only o/testsuite#1059", released) + got := []int{} + for _, e := range released { + got = append(got, e.Number) + } + if len(got) != 2 || got[0] != 1059 || got[1] != 1089 { + t.Fatalf("released = %v, want o/testsuite#1059 (issue) and #1089 (same-repo PR)", got) + } + if _, blocked := l.Blocking("o/testsuite", 1037); !blocked { + t.Fatal("a fork PR's workflows blocker must stay: the App cannot push workflow files to a fork") } if _, blocked := l.Blocking("o/testsuite", 1059); blocked { t.Fatal("#1059 still blocked") @@ -186,7 +212,7 @@ func TestSweepWorkflowsBlockersReleasesGrantedBlockers(t *testing.T) { } mu.Lock() defer mu.Unlock() - if len(labelled) != 1 || labelled[0] != "/repos/o/testsuite/issues/1059/labels="+WorkflowsLaneLabel { + if len(labelled) != 2 || labelled[0] != "/repos/o/testsuite/issues/1059/labels="+WorkflowsLaneLabel { t.Fatalf("labels written = %v", labelled) } From 6ed16c0ab5a687ca6330dd18d6289963be551e81 Mon Sep 17 00:00:00 2001 From: Danathar Date: Thu, 5 Nov 2026 17:08:01 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20fix(workflows):=20a=20park?= =?UTF-8?q?=20quoting=20GitHub's=20rejection=20stands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer finding on #16811: the self-push note tells a merger-tier lane to park again quoting GitHub's error when a push still bounces, but the same check refused that park too, looping the lane. A park or report quoting "refusing to allow a GitHub App to create or update workflow" is evidence: the relay lets it park, and the ledger records the blocker as Proven, which neither the record-time check nor the scheduled re-check releases. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- .../fixed-workflows-blocker-verified.md | 2 +- src/docs/hive-open-issue.md | 6 ++++- src/pkg/blocker/blocker.go | 22 ++++++++++++++-- src/pkg/blocker/ledger.go | 7 ++--- .../blocker/ledger_capability_check_test.go | 26 +++++++++++++++++++ src/pkg/github/issue_workflows_handoff.go | 10 +++++-- .../github/issue_workflows_self_push_test.go | 8 +++++- 7 files changed, 71 insertions(+), 10 deletions(-) diff --git a/changelog.d/fixed-workflows-blocker-verified.md b/changelog.d/fixed-workflows-blocker-verified.md index f7168b7da1..b52c6fc05d 100644 --- a/changelog.d/fixed-workflows-blocker-verified.md +++ b/changelog.d/fixed-workflows-blocker-verified.md @@ -1 +1 @@ -- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository or the item is a fork PR (a fork branch takes no workflow push from the App), and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. +- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository or the item is a fork PR (a fork branch takes no workflow push from the App), and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. A park that quotes GitHub's own rejection of the push still stands. diff --git a/src/docs/hive-open-issue.md b/src/docs/hive-open-issue.md index 0a45328de4..63e6754677 100644 --- a/src/docs/hive-open-issue.md +++ b/src/docs/hive-open-issue.md @@ -242,7 +242,11 @@ token asks for the Workflows permission, and the App installation grants `workflows: write` (read at most every five minutes), the watcher parks nothing, adds no label, and appends a "Not parked: ``'s token can push `.github/workflows/`" note: the issue stays with that lane to push the change. -If the installation lacks the permission, or cannot be read, the park stands. +If the installation lacks the permission, or cannot be read, the park stands. It +also stands when the park quotes GitHub's own rejection of the push ("refusing to +allow a GitHub App to create or update workflow … without `workflows` +permission"): that is evidence, and the blocker it records is never released by +the scheduled re-check. #### Withdrawing your own park diff --git a/src/pkg/blocker/blocker.go b/src/pkg/blocker/blocker.go index 41998aba52..a33a42f65b 100644 --- a/src/pkg/blocker/blocker.go +++ b/src/pkg/blocker/blocker.go @@ -132,6 +132,24 @@ type Blocker struct { // "loop-guard". Source string `json:"source,omitempty"` Since time.Time `json:"since,omitempty"` + // Proven: the report quotes GitHub's own refusal of the push + // (QuotesWorkflowsRejection), so it is evidence, not a claim, and no + // capability check refutes it. + Proven bool `json:"proven,omitempty"` +} + +// workflowsRejectionRE is GitHub's refusal of a workflow-file push, as it +// reads for an App, an OAuth App or a token: "refusing to allow a GitHub App +// to create or update workflow `.github/workflows/x.yml` without `workflows` +// permission". +var workflowsRejectionRE = regexp.MustCompile("(?i)refusing to allow an? (GitHub App|OAuth App|Personal Access Token|integration)[^.\n]{0,40}? to (create or update|create|update) workflow") + +// QuotesWorkflowsRejection reports whether text quotes GitHub's own refusal +// of a workflow-file push. A lane told its token can push workflow files +// parks again with that error when a push still bounces; the quote is what +// separates that from an unverified "the App cannot push workflows". +func QuotesWorkflowsRejection(text string) bool { + return workflowsRejectionRE.MatchString(text) } const ( @@ -210,10 +228,10 @@ func Infer(prose string) (Kind, bool) { // sentence the kind was inferred from. func Detect(text string, at time.Time) (Blocker, bool) { if k, ok := ParseMarker(text); ok { - return Blocker{Kind: k, Detail: ReasonSentence(text), Source: SourceMarker, Since: at}, true + return Blocker{Kind: k, Detail: ReasonSentence(text), Source: SourceMarker, Since: at, Proven: k == CapabilityWorkflowsPermission && QuotesWorkflowsRejection(text)}, true } if k, ok := Infer(text); ok { - return Blocker{Kind: k, Detail: ReasonSentence(text), Source: SourceInferred, Since: at}, true + return Blocker{Kind: k, Detail: ReasonSentence(text), Source: SourceInferred, Since: at, Proven: k == CapabilityWorkflowsPermission && QuotesWorkflowsRejection(text)}, true } return Blocker{}, false } diff --git a/src/pkg/blocker/ledger.go b/src/pkg/blocker/ledger.go index ee5a1af07f..b5ed92d716 100644 --- a/src/pkg/blocker/ledger.go +++ b/src/pkg/blocker/ledger.go @@ -163,7 +163,7 @@ func (l *Ledger) Observe(repo string, number int, text string, at time.Time) (En } return l.RecordReason(repo, number, NormalizeReason(text), at), true } - if l.capabilityHeld(repo, number, b.Kind) { + if !b.Proven && l.capabilityHeld(repo, number, b.Kind) { // The hive holds the capability the report says is missing: keep the // reason for the loop guard, park nothing on it. return l.RecordReason(repo, number, NormalizeReason(text), at), true @@ -309,7 +309,8 @@ func (l *Ledger) ClearKind(k Kind) int { // RecheckCapabilities lifts every capability blocker that held(repo, number, kind) // now refutes and returns the released entries as they were. It is the // scheduled form of the dashboard's Re-check permissions, per item rather -// than per kind, so a blocker on a repo no capable lane serves stays. held +// than per kind, so a blocker on a repo no capable lane serves stays, and so +// does one whose report quoted GitHub's rejection (Blocker.Proven). held // runs outside the ledger lock; a blocker that changed kind meanwhile is kept. func (l *Ledger) RecheckCapabilities(held func(repo string, number int, k Kind) bool) []Entry { if held == nil { @@ -317,7 +318,7 @@ func (l *Ledger) RecheckCapabilities(held func(repo string, number int, k Kind) } var refuted []Entry for _, e := range l.Blockers() { - if e.Blocker.Kind.IsCapability() && held(e.Repo, e.Number, e.Blocker.Kind) { + if e.Blocker.Kind.IsCapability() && !e.Blocker.Proven && held(e.Repo, e.Number, e.Blocker.Kind) { refuted = append(refuted, e) } } diff --git a/src/pkg/blocker/ledger_capability_check_test.go b/src/pkg/blocker/ledger_capability_check_test.go index abd1825e26..d703825cfd 100644 --- a/src/pkg/blocker/ledger_capability_check_test.go +++ b/src/pkg/blocker/ledger_capability_check_test.go @@ -64,3 +64,29 @@ func TestRecheckCapabilitiesReleasesOnlyRefuted(t *testing.T) { t.Fatal("nil check must release nothing") } } + +// A report quoting GitHub's own rejection of the push is evidence: no +// capability check refutes it, at record time or on the re-check. +func TestQuotedWorkflowsRejectionIsProven(t *testing.T) { + rejection := "needs-human: the push bounced: refusing to allow a GitHub App to create or update workflow `.github/workflows/e2e.yml` without `workflows` permission" + at := time.Date(2026, 11, 5, 21, 0, 0, 0, time.UTC) + l := NewLedger("") + l.SetCapabilityCheck(func(string, int, Kind) bool { return true }) + e, _ := l.Observe("o/r", 1, rejection, at) + if !e.Blocks() || !e.Blocker.Proven { + t.Fatalf("quoted rejection: %+v, want a proven workflows blocker", e) + } + if got := l.RecheckCapabilities(func(string, int, Kind) bool { return true }); len(got) != 0 { + t.Fatalf("re-check released a proven blocker: %+v", got) + } + for text, want := range map[string]bool{ + rejection: true, + "refusing to allow an OAuth App to create or update workflow `.github/workflows/ci.yml` without `workflow` scope": true, + "refusing to allow a Personal Access Token to create or update workflow `.github/workflows/ci.yml` without `workflow` scope": true, + "the hive app cannot push `.github/workflows/`": false, + } { + if got := QuotesWorkflowsRejection(text); got != want { + t.Errorf("QuotesWorkflowsRejection(%q) = %v, want %v", text, got, want) + } + } +} diff --git a/src/pkg/github/issue_workflows_handoff.go b/src/pkg/github/issue_workflows_handoff.go index 1def150c82..e529621598 100644 --- a/src/pkg/github/issue_workflows_handoff.go +++ b/src/pkg/github/issue_workflows_handoff.go @@ -98,13 +98,19 @@ func parkIsWorkflowsOnly(text string) bool { // e2e.yml in #1089). Any other lane hands it to the lane that can push it: // the issue is not parked, it carries WorkflowsLaneLabel, and the posted text // says where it went. Inactive (the park stands) when the text is not a -// workflow-only park, when no lane can push it, or when the installation is -// known to lack `workflows: write`. +// workflow-only park, when no lane can push it, when the installation is +// known to lack `workflows: write`, or when a lane that pushes workflow files +// quotes GitHub's rejection of its push. func (c *Client) workflowsHandoff(ctx context.Context, agent, repo, title, body string) issueDecisionDowngrade { if !parkIsWorkflowsOnly(title + "\n" + body) { return issueDecisionDowngrade{} } if c.workflowsSelfPushFor(agent) { + // A park quoting GitHub's rejection is what the note below asks + // for when a push still bounces: evidence, so it stands. + if itemblocker.QuotesWorkflowsRejection(title + "\n" + body) { + return issueDecisionDowngrade{} + } if granted, known := c.installationGrantsWorkflows(ctx); known && granted { return issueDecisionDowngrade{Active: true, SelfPush: true, Note: workflowsSelfPushNote(agent)} } diff --git a/src/pkg/github/issue_workflows_self_push_test.go b/src/pkg/github/issue_workflows_self_push_test.go index 14beb7a991..84a0f8ed6f 100644 --- a/src/pkg/github/issue_workflows_self_push_test.go +++ b/src/pkg/github/issue_workflows_self_push_test.go @@ -73,6 +73,7 @@ func TestWorkflowsParkCheckedAgainstTierAndInstallation(t *testing.T) { lane bool perms map[string]string err error + body string want string }{ {name: "merger tier, installation grants: back to the agent", agent: "scanner", appAuth: true, lane: true, perms: write, want: self}, @@ -80,6 +81,7 @@ func TestWorkflowsParkCheckedAgainstTierAndInstallation(t *testing.T) { {name: "merger tier, installation has read only: parks", agent: "scanner", appAuth: true, lane: true, perms: read, want: park}, {name: "merger tier, installation read fails: parks", agent: "scanner", appAuth: true, lane: true, err: errors.New("502"), want: park}, {name: "merger tier, token-authenticated client: parks", agent: "scanner", appAuth: false, lane: true, perms: write, want: park}, + {name: "merger tier quoting GitHub's rejection: parks", agent: "scanner", appAuth: true, lane: true, perms: write, body: selfPush1059 + "\n\nThe push bounced: `! [remote rejected] scanner/fix-1059 (refusing to allow a GitHub App to create or update workflow `.github/workflows/e2e.yml` without `workflows` permission)`", want: park}, {name: "contributor tier, installation grants: hand-off", agent: "ci-maintainer", appAuth: true, lane: true, perms: write, want: handoff}, {name: "contributor tier, installation lacks it: parks", agent: "ci-maintainer", appAuth: true, lane: true, perms: read, want: park}, {name: "contributor tier, installation unknown: hand-off as before", agent: "ci-maintainer", appAuth: true, lane: true, err: errors.New("502"), want: handoff}, @@ -87,8 +89,12 @@ func TestWorkflowsParkCheckedAgainstTierAndInstallation(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { stubInstallation(t, tc.perms, tc.err) + body := tc.body + if body == "" { + body = selfPush1059 + } writes, bodies, resp := runNeedsDecisionCommentCapture(t, needsDecisionFilter{label: "owner-call"}, IssueRequest{ - Kind: "comment", Repo: "o/r", Number: 1059, Agent: tc.agent, NeedsDecision: true, Body: selfPush1059, + Kind: "comment", Repo: "o/r", Number: 1059, Agent: tc.agent, NeedsDecision: true, Body: body, }, false, fleet(tc.appAuth, tc.lane)) if got := strings.Join(writes, ","); got != tc.want { t.Fatalf("writes = %q, want %q", got, tc.want) From 4a84f843153d6a634b10538c3b9a0f9c35cccb42 Mon Sep 17 00:00:00 2001 From: Danathar Date: Thu, 5 Nov 2026 18:17:51 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20fix(workflows):=20proven=20b?= =?UTF-8?q?lockers=20survive=20re-reports;=20only=20a=20pushing=20lane's?= =?UTF-8?q?=20quote=20proves?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review on #16811 (adjudicator, 6ed16c0): - Record keeps Proven when a later unquoted report of the same kind lands while the capability check could not refute it. - intent-alignment: Proven was tier-blind. A contributor-tier lane quoting GitHub's refusal proves only its own token lacks workflows; the ledger's new proof check (Client.WorkflowsRejectionProves, by the report's `— hive: agent=` trailer) keeps such a blocker refutable. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- .../fixed-workflows-blocker-verified.md | 2 +- src/cmd/hive/github_client_config.go | 1 + src/docs/hive-open-issue.md | 5 ++- src/pkg/blocker/ledger.go | 30 ++++++++++++++ .../blocker/ledger_capability_check_test.go | 39 +++++++++++++++++++ src/pkg/github/issue_workflows_handoff.go | 10 +++++ .../github/issue_workflows_self_push_test.go | 16 ++++++++ 7 files changed, 101 insertions(+), 2 deletions(-) diff --git a/changelog.d/fixed-workflows-blocker-verified.md b/changelog.d/fixed-workflows-blocker-verified.md index b52c6fc05d..aa3401ca8a 100644 --- a/changelog.d/fixed-workflows-blocker-verified.md +++ b/changelog.d/fixed-workflows-blocker-verified.md @@ -1 +1 @@ -- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository or the item is a fork PR (a fork branch takes no workflow push from the App), and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. A park that quotes GitHub's own rejection of the push still stands. +- An agent's "the App cannot push `.github/workflows/`" is checked before it parks anything. On projectbluefin/testsuite#1059 and #1073, scanner (ISSUES_PRS_MERGE, whose token asks for the Workflows permission) parked a workflow fix the same day the App pushed `e2e.yml` in #1089, and the issues showed "Blocked · App lacks workflows permission" for four days. Now the relay refuses that park when the parking lane's tier pushes workflows and the App installation grants `workflows: write` (read at most every five minutes), and hands a contributor-tier park to the workflows lane only when the installation is not known to lack the permission. The blocker ledger records a workflows blocker only when no lane can push workflow files on that repository or the item is a fork PR (a fork branch takes no workflow push from the App), and a re-check that runs with the un-park sweep releases existing ones and routes them to the workflows lane. Merger- and trusted-tier kicks now say their token can push `.github/workflows/**`. A park that quotes GitHub's own rejection of the push still stands, and that evidence is kept across later unquoted re-reports; a contributor-tier lane's quote is not treated as evidence about the App. diff --git a/src/cmd/hive/github_client_config.go b/src/cmd/hive/github_client_config.go index 7fcea6faf4..6d2cac5323 100644 --- a/src/cmd/hive/github_client_config.go +++ b/src/cmd/hive/github_client_config.go @@ -165,6 +165,7 @@ func (b *boot) applyGitHubClientConfigHooks(client *github.Client) { // rebuilt client re-installs its check. client.SetWorkflowsSelfPushFunc(b.cfg.AgentPushesWorkflows) itemblocker.Shared().SetCapabilityCheck(client.CapabilityAvailable) + itemblocker.Shared().SetProofCheck(client.WorkflowsRejectionProves) client.SetReporterConfirmationEnabledFunc(func() bool { return b.cfg.Issues.ReporterConfirmationEnabled() }) diff --git a/src/docs/hive-open-issue.md b/src/docs/hive-open-issue.md index 63e6754677..26925e2937 100644 --- a/src/docs/hive-open-issue.md +++ b/src/docs/hive-open-issue.md @@ -246,7 +246,10 @@ If the installation lacks the permission, or cannot be read, the park stands. It also stands when the park quotes GitHub's own rejection of the push ("refusing to allow a GitHub App to create or update workflow … without `workflows` permission"): that is evidence, and the blocker it records is never released by -the scheduled re-check. +the scheduled re-check. The quote counts as evidence only from a lane whose own +token asks for the permission (or from a report with no `— hive:` trailer, such +as a person pasting the error); a contributor-tier lane's quote shows only that +its own token lacks it, so that blocker stays releasable. #### Withdrawing your own park diff --git a/src/pkg/blocker/ledger.go b/src/pkg/blocker/ledger.go index b5ed92d716..e13f3416a8 100644 --- a/src/pkg/blocker/ledger.go +++ b/src/pkg/blocker/ledger.go @@ -58,6 +58,27 @@ type Ledger struct { loaded bool // capabilityCheck refutes a capability report (SetCapabilityCheck). capabilityCheck func(repo string, number int, k Kind) bool + // proofCheck confirms a quoted rejection proves the gap (SetProofCheck). + proofCheck func(text string) bool +} + +// SetProofCheck installs the check Observe asks before it marks a quoted +// GitHub rejection as proof (Blocker.Proven): true when the quote came from a +// reporter whose own token asks for the permission. A contributor-tier lane +// quoting GitHub's refusal shows only that its own token lacks `workflows`, +// not that the App does, so its blocker stays refutable. Nil, the default, +// trusts every quote. +func (l *Ledger) SetProofCheck(fn func(text string) bool) { + l.mu.Lock() + defer l.mu.Unlock() + l.proofCheck = fn +} + +func (l *Ledger) proofHolds(text string) bool { + l.mu.Lock() + fn := l.proofCheck + l.mu.Unlock() + return fn == nil || fn(text) } // SetCapabilityCheck installs the check Observe asks before it records a @@ -163,6 +184,9 @@ func (l *Ledger) Observe(repo string, number int, text string, at time.Time) (En } return l.RecordReason(repo, number, NormalizeReason(text), at), true } + if b.Proven && !l.proofHolds(text) { + b.Proven = false + } if !b.Proven && l.capabilityHeld(repo, number, b.Kind) { // The hive holds the capability the report says is missing: keep the // reason for the loop guard, park nothing on it. @@ -193,6 +217,12 @@ func (l *Ledger) Record(repo string, number int, b Blocker, reason string) Entry if e.Blocker != nil && e.Blocker.Kind == b.Kind && !e.Blocker.Since.IsZero() && e.Blocker.Since.Before(b.Since) { b.Since = e.Blocker.Since } + // Evidence outlives a later unquoted re-report of the same kind, which + // lands here whenever the capability check could not refute it (an + // unreadable installation): Proven must not drop with it. + if e.Blocker != nil && e.Blocker.Kind == b.Kind && e.Blocker.Proven { + b.Proven = true + } e.Blocker = &b e.Reason = reason e.ReportedAt = observedAt diff --git a/src/pkg/blocker/ledger_capability_check_test.go b/src/pkg/blocker/ledger_capability_check_test.go index d703825cfd..a5d2820a5d 100644 --- a/src/pkg/blocker/ledger_capability_check_test.go +++ b/src/pkg/blocker/ledger_capability_check_test.go @@ -1,6 +1,7 @@ package blocker import ( + "strings" "testing" "time" ) @@ -90,3 +91,41 @@ func TestQuotedWorkflowsRejectionIsProven(t *testing.T) { } } } + +// A same-kind re-report without the quote, recorded while the check could +// not refute it, keeps the earlier evidence (#16811 review). +func TestProvenSurvivesUnquotedReReport(t *testing.T) { + at := time.Date(2026, 11, 5, 21, 0, 0, 0, time.UTC) + l := NewLedger("") + l.Observe("o/r", 1, "needs-human: refusing to allow a GitHub App to create or update workflow `.github/workflows/e2e.yml` without `workflows` permission", at) + held := false + l.SetCapabilityCheck(func(string, int, Kind) bool { return held }) + e, _ := l.Observe("o/r", 1, "needs-human: the App cannot push workflow files", at.Add(time.Hour)) + if !e.Blocks() || !e.Blocker.Proven { + t.Fatalf("re-report dropped the evidence: %+v", e) + } + held = true + if got := l.RecheckCapabilities(func(string, int, Kind) bool { return held }); len(got) != 0 { + t.Fatalf("re-check released a proven blocker after an unquoted re-report: %+v", got) + } +} + +// A quoted rejection is proof only when the proof check accepts its +// reporter: a contributor-tier lane's quote stays refutable. +func TestQuotedRejectionProofIsReporterChecked(t *testing.T) { + at := time.Date(2026, 11, 5, 21, 0, 0, 0, time.UTC) + quote := "needs-human: refusing to allow a GitHub App to create or update workflow `.github/workflows/e2e.yml` without `workflows` permission\n— hive: agent=ci-maintainer" + l := NewLedger("") + l.SetProofCheck(func(text string) bool { return !strings.Contains(text, "agent=ci-maintainer") }) + l.SetCapabilityCheck(func(string, int, Kind) bool { return false }) + if e, _ := l.Observe("o/r", 1, quote, at); !e.Blocks() || e.Blocker.Proven { + t.Fatalf("contributor quote: %+v, want an unproven blocker", e) + } + if got := l.RecheckCapabilities(func(string, int, Kind) bool { return true }); len(got) != 1 { + t.Fatalf("an unproven contributor quote must be releasable: %+v", got) + } + scanner := strings.Replace(quote, "ci-maintainer", "scanner", 1) + if e, _ := l.Observe("o/r", 2, scanner, at); !e.Blocker.Proven { + t.Fatalf("merger-tier quote: %+v, want proven", e) + } +} diff --git a/src/pkg/github/issue_workflows_handoff.go b/src/pkg/github/issue_workflows_handoff.go index e529621598..d2de519c7c 100644 --- a/src/pkg/github/issue_workflows_handoff.go +++ b/src/pkg/github/issue_workflows_handoff.go @@ -234,6 +234,16 @@ func (c *Client) CapabilityAvailable(repo string, number int, k itemblocker.Kind return known && !fork } +// WorkflowsRejectionProves is the blocker ledger's proof check +// (blocker.Ledger SetProofCheck): a quoted GitHub rejection of a workflow +// push proves the App lacks `workflows` only when the reporting lane's own +// token asks for it. The reporter is the text's `— hive: agent=` trailer; a +// report without one (a person pasting the error) is trusted. +func (c *Client) WorkflowsRejectionProves(text string) bool { + agent := trailerAgent(text) + return agent == "" || c.workflowsSelfPushFor(agent) +} + // forkPR reports whether owner/name#number is a pull request whose head is // in another repository (or a deleted one). known is false when GitHub // cannot be read. diff --git a/src/pkg/github/issue_workflows_self_push_test.go b/src/pkg/github/issue_workflows_self_push_test.go index 84a0f8ed6f..36e048326c 100644 --- a/src/pkg/github/issue_workflows_self_push_test.go +++ b/src/pkg/github/issue_workflows_self_push_test.go @@ -262,3 +262,19 @@ func TestCreateWorkflowsParkRefusedForMergerTier(t *testing.T) { t.Fatalf("body must carry the self-push note and no owner-step marker:\n%s", p.Body) } } + +func TestWorkflowsRejectionProvesByReporterTier(t *testing.T) { + c := &Client{} + c.SetWorkflowsSelfPushFunc(func(agent string) bool { return agent == "scanner" }) + quote := "refusing to allow a GitHub App to create or update workflow `.github/workflows/e2e.yml` without `workflows` permission" + for text, want := range map[string]bool{ + quote + "\n\n— hive: agent=scanner backend=claude": true, + quote + "\n\n— hive: agent=scanner backend=claude\n": true, + quote + "\n\n— hive: agent=ci-maintainer backend=claude": false, + quote: true, + } { + if got := c.WorkflowsRejectionProves(text); got != want { + t.Errorf("WorkflowsRejectionProves(%q) = %v, want %v", text, got, want) + } + } +}