Repository navigation
✨ feat(github): the hive files grouped issues from GitHub code scanning alerts (opt-in per repo) - #17130
Conversation
An opt-in sweep (code_scanning, off by default, per repo) reads a repository's open code scanning alerts (CodeQL, OSSF Scorecard, Trivy, any SARIF uploader) and files them as issues sized for one PR: code alerts grouped by rule and at most five files (packed by directory), dependency alerts grouped by package. At most five new issues per repo per hourly pass, highest severity first. Each issue carries a hidden <!-- hive:code-scanning ... --> marker listing its alert numbers; the sweep lists its own hive/code-scanning issues to rebuild dedupe state from GitHub, adds new alerts in covered files, marks fixed/dismissed rows, closes an issue when every alert is gone, and never reopens or refiles. OSSF Scorecard repo-posture checks are excluded by default. Workflow-file issues get hive/workflows-lane when a lane can push workflows; fork issues say whether upstream changed the flagged code. Missing "Code scanning alerts: Read" surfaces as a dashboard banner and /api/status notice with a six-hour back-off. The job is a sweepOptional worker (staggered first pass, skipped outside normal API budget), and every write goes through WritebackAllowed as issue_file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
@Danathar this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (4 waiting): fixes are handed out before new work as soon as you have capacity. |
TestCommentMarkerRatchet failed: codeScanningForge.CloseIssue posted a comment without a hive marker (47 unmarked emitters against a baseline of 46). The closing note now starts with codescanning.CloseMarker, and CloseIssue checks for its own marked note before posting. A retry after a refused close then closes without posting the note again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
A critical fail-open author check trusts unverified marked issues when identity lookup fails, allowing other users’ issues to suppress filings or be edited or closed.
5 open issues
Unknown posting identity allows unverified issue authors · New Pathless alerts can panic during grouping · New Incomplete dismissed results incorrectly mark alerts as fixed · New Duplicate normalized repository keys cause nondeterministic overrides · New Code scanning notices are missing from SSE event payloads · New
What changed in this PR
Adds an opt-in code-scanning sweep that turns GitHub security alerts into grouped issues for Hive’s existing lanes, with lifecycle tracking, API-budget controls, and operator notices.
Changes:
- Adds severity filtering, alert grouping, persistent deduplication, and issue updates and closure.
- Integrates per-repository configuration, gated GitHub writes, and staggered optional scheduling.
- Exposes status and permission notices, with fixtures, tests, and operator documentation.
| File | Description |
|---|---|
src/pkg/github/notification_write_sites.go |
Registers closing comments in the notification inventory. |
src/pkg/github/code_scanning.go |
Implements GitHub access, gated writes, status, and backoff. |
src/pkg/github/code_scanning_test.go |
Tests filing, deduplication, permissions, and request bounds. |
src/pkg/github/client.go |
Adds client-held sweep state. |
src/pkg/dashboard/static/index.html |
Includes the generated notice banner and rendering logic. |
src/pkg/dashboard/static-src/js/refresh.js |
Calls the code-scanning banner renderer. |
src/pkg/dashboard/static-src/js/banners.js |
Renders repository notices and Security-tab links. |
src/pkg/dashboard/static-src/html/root-notices.html |
Adds the pinned notice container. |
src/pkg/dashboard/settings_parity_allowlist.txt |
Records YAML-only configuration keys. |
src/pkg/dashboard/server.go |
Exposes code-scanning status through /api/status. |
src/pkg/dashboard/code_scanning_status_test.go |
Tests status output and banner wiring. |
src/pkg/config/validate.go |
Invokes code-scanning configuration validation. |
src/pkg/config/testdata/agent_runtime_golden.json |
Updates the configuration serialization fixture. |
src/pkg/config/config.go |
Adds the top-level configuration block. |
src/pkg/config/code_scanning.go |
Defines defaults, repository overrides, and validation. |
src/pkg/config/code_scanning_test.go |
Tests defaults, overrides, and invalid settings. |
src/pkg/codescanning/testdata/scorecard-trivy-common.json |
Supplies mixed Scorecard and dependency alert fixtures. |
src/pkg/codescanning/testdata/scorecard-actions.json |
Supplies workflow and repository-posture alert fixtures. |
src/pkg/codescanning/sweep.go |
Coordinates filing, lifecycle updates, excerpts, and upstream checks. |
src/pkg/codescanning/sweep_test.go |
Tests filtering, grouping, deduplication, and lifecycle behavior. |
src/pkg/codescanning/render.go |
Generates issue bodies, alert tables, and closing comments. |
src/pkg/codescanning/group.go |
Groups alerts and encodes persistent tracking markers. |
src/pkg/codescanning/alert.go |
Defines alert models, severity mapping, and filtering policy. |
src/hive.yaml.example |
Shows per-repository opt-in configuration. |
src/docs/operator-reference/sweeps-and-operations.md |
Documents write surfaces and budget behavior. |
src/docs/operator-reference/README.md |
Lists the feature and configuration options. |
src/docs/notifications.md |
Documents the closing-comment notification class. |
src/docs/labels-and-control-signals/reference.md |
Documents issue provenance and the tracking label. |
src/docs/github-app-setup.md |
Documents the optional code-scanning permission. |
src/docs/documentation-map.md |
Links the feature guide. |
src/docs/dashboard-glossary.md |
Defines code-scanning issues and their markers. |
src/docs/code-scanning.md |
Explains configuration, grouping, lifecycle, and operations. |
src/docs/api-reference/health-status-events.md |
Documents the new status response block. |
src/cmd/hive/sweep_workers.go |
Registers the optional scheduled sweep. |
src/cmd/hive/sweep_workers_test.go |
Tests scheduling, cadence, and budget classification. |
src/cmd/hive/code_scanning.go |
Connects the sweep worker to the GitHub client. |
changelog.d/added-code-scanning-issues.md |
Announces the opt-in feature. |
Review effort: Balanced
|
|
||
| func (f codeScanningForge) ListIssues(ctx context.Context, repo string) ([]codescanning.TrackedIssue, error) { | ||
| owner, name := f.c.splitRepo(repo) | ||
| own := f.c.knowsOwnAccounts() |
| for _, files := range packFiles(distinctPaths(as)) { | ||
| in := map[string]bool{} | ||
| for _, f := range files { | ||
| in[f] = true | ||
| } | ||
| var sub []Alert | ||
| for _, a := range as { | ||
| if in[a.Path()] { | ||
| sub = append(sub, a) | ||
| } | ||
| } | ||
| out = append(out, newGroup(k.tool, "", sub)) | ||
| } |
| for _, is := range openIssues { | ||
| for _, n := range is.Marker.Alerts { | ||
| if _, ok := openByNum[n]; !ok && dismissed == nil { | ||
| ds, _, derr := f.ListAlerts(ctx, o.Repo, "dismissed", dismissedMaxPages) |
| sort.Strings(keys) | ||
| for _, k := range keys { | ||
| if !known[codeScanningRepoKey(c.Project.Org, k)] { | ||
| return fmt.Errorf("code_scanning.repos: %q is not listed in project.repos", k) | ||
| } | ||
| r := cs.Repos[k] |
| if cs := s.deps.GHClient.CodeScanningStatus(); cs.Enabled || len(cs.Repos) > 0 { | ||
| payload.CodeScanning = &cs | ||
| } |
…r the v6 merge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
There was a problem hiding this comment.
Intent alignment (read at 3fedee34c): the diff does what the summary says — opt-in code_scanning config with per-repo overrides (src/pkg/config/code_scanning.go:84-107), marker-based dedupe over App-authored issues only (src/pkg/github/code_scanning.go ListIssues), 403/404 → notice with 6h back-off, every write behind WritebackAllowed, cap + severity-first filing (src/pkg/codescanning/sweep.go Run), and the sweep job/dashboard wiring. No unrelated scope.
One small factual slip in a line this PR edits:
src/docs/scale-envelope.md: the citation is bumped fromclient.go:5470-5480to5475-5485, but at headRankActionableIssuesspanssrc/pkg/github/client.go:5461-5471(the PR adds one line toclient.goat :181);5475-5485points atmakeLabelSet/actionableIssueRankTier.
(`RankActionableIssues`, `src/pkg/github/client.go:5461-5471`, descending `AgeMinutes` within each tier).
— hive: agent=adjudicator-3 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Docs-currency pass on 3fedee3. The new
and in the summary table row's "Who applies" cell: Review findings from Style/maintainability review (read at head
Review findings from Security perspective, read at head 1. Identity-unknown fallback adopts anyone's labelled issue as the hive's own — (replace 2. Rule description is not escaped before the table delimiter — Review findings from Read the whole core path ( Finding (medium): the closing note cross-references unrelated issues/PRs.
Doc nit (info): the PR body and Verified no-ops I'd otherwise have flagged: the dismissed listing is bounded at 2 pages, so an alert dismissed beyond the 200th is reported as I have not approved or requested changes as a review event; this is a comment for the maintainer. Review findings from Correctness review (head 1. Re-scan is not idempotent when an alert message contains a mention-shaped --- a/src/pkg/codescanning/sweep.go
+++ b/src/pkg/codescanning/sweep.go
@@ func Run(ctx context.Context, f Forge, o Options) (Status, error) {
body := rewriteBody(is.Body, m, alertsSection(o.Repo, rows, gone, previousRows(is.Body)))
+ if n, ok := f.(interface{ Normalize(repo, text string) string }); ok {
+ body = n.Normalize(o.Repo, body)
+ }
if strings.TrimSpace(body) == strings.TrimSpace(is.Body) {
continue
}
--- a/src/pkg/github/code_scanning.go
+++ b/src/pkg/github/code_scanning.go
@@ func (f codeScanningForge) prepare(repo, text string) (string, error) {
return logscrub.ScrubString(advisory.NeutralizeMentions(text)), nil
}
+
+// Normalize is prepare without the canary check, so Run compares the body it
+// would actually post against the stored one.
+func (f codeScanningForge) Normalize(repo, text string) string {
+ return logscrub.ScrubString(advisory.NeutralizeMentions(text))
+}A test with a fixture message containing 2. Dismissed listing bound misreports closure reason. Review findings from Conclusion: the design is sound and every write is behind 1. An all-pathless rule produces an empty
Reachable with shipped config: 2. Dismissed listing cap discards
3. On the Copilot "fail-open author check" finding — I'd rate it info, not high
What I confirmed is right
Body matches diff throughout; the |
There was a problem hiding this comment.
Conclusion: read the sweep core, the gated forge, config and wiring; I found no defect. This looks correct to me. CI (test (rest 4/4), mobile-shots) was still pending when I read it — I have not waited on it.
What I verified (code first, body second)
src/pkg/codescanning/sweep.goRun: close happens only whencomplete && len(still)==0 && len(add)==0, so a truncated open-alert listing (Truncated) can never close or mark-fixed — matches the stated 1,000-alert guard. Alerts on closed tracked issues are skipped viaseen[](TrackedClosed), and that "never reopens / never refiles" rule is documented indocs/code-scanning.mdand pinned byTestRunClosesFixedAndDismissedIssuesAndNeverRefiles.src/pkg/github/code_scanning.go: every write (CreateIssue,EditIssueBody,CloseIssue) goes throughprepare(canary → mention-neutralise → logscrub) andgate(WritebackAllowedasissue_file,HiveAuthored: true) before the// writeback:gatedcall.ListIssuesdrops non-hive authors whenknowsOwnAccounts(), so a squatted marker cannot suppress a filing; pastcodeScanningIssuePagesit returns an error rather than a partial dedupe set, andRunthen files nothing.classifyCodeScanningErrormaps 403/404 ontoErrNoAccess/ErrNotEnabled;RunCodeScanningSweeptreats a notice as back-off (6h), notErrors++.src/pkg/config/code_scanning.go:repoOverridenormalises both sides throughNormalizeRepoForOrg, sorepos.exultandrepos.Danathar/exultresolve the same;validateCodeScanningrejects unknown repos, bad severities, negative caps andinterval < 10m.- Body claim "calls are tagged
hive:code_scanning": nothing in the diff tags them, butsweepJob.runTagged(src/cmd/hive/sweep_workers.go:49on v6) applieshive:<job name>to every job, so the claim holds via the job name.
One low-severity edge, not a blocker
sweep.go: the dismissed listing isListAlerts(ctx, repo, "dismissed", dismissedMaxPages)withdismissedMaxPages = 2and thecompleteflag discarded. On a repo with >200 dismissed alerts (exult has 697 open; its dismissed count is plausibly past that), a tracked alert dismissed beyond page 2 is classifiedStatusFixed, so the row says fixed and the close reason becomescompletedinstead ofnot_planned. Cosmetic — no filing or closing decision changes — but worth either raising the bound or noting it in the doc.
Body and diff agree on everything else I checked (page bounds 10/5/2, cap 5, default high, Scorecard exclusion list applied via Policy.Judge). Docs, changelog fragment, settings-parity allowlist and notificationWriteSites inventory are all updated.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88


Summary
The hive can now turn a repository's open GitHub code scanning alerts (CodeQL, OSSF Scorecard, Trivy, any SARIF uploader) into hive issues the lanes pick up. It is off by default and turned on per repo with
code_scanning.repos.<repo>.enabled: true. An hourly sweep groups alerts into issues sized for one PR, files at most five new ones per repo per pass, updates them as alerts are added, fixed or dismissed, and closes them when every alert is gone. The dedupe state is a hidden marker on the hive's own issues, so a restart rebuilds it from GitHub. It needs the App permission Code scanning alerts: Read-only; without it the dashboard shows a notice for that repo and the sweep backs off.Why
Nothing in v5 or v6 reads code scanning alerts today. The only code-scanning code is Sentinel treating CodeQL config edits as sensitive (
src/pkg/sentinel/sentinel.go:58-103) and the merge gate reading CodeQL check results. I found no open or closed hivecommons/hive issue or PR covering this (searched "code scanning", "codeql", "sarif", "security alerts", "code-scanning", "security_events").Two real cases shaped it:
security-extended,security-and-quality) and shows 697 open alerts: 11 critical, 73 high, and 613 quality findings (mostlynote). The owner triaged the 84 critical/high ones into issues by hand.TokenPermissionsIDandPinnedDependenciesIDare real work in workflow files.What changes
Config (
code_scanning, YAML-only for now):enabled(default off),interval(1h),min_severity(high),include_tools,exclude_rules,max_new_issues_per_run(5), andrepos.<repo>.*overrides. Validated at load (unknown repo, bad severity, bad pattern, negative cap, interval under 10m).Severity. One scale. A security rule's
security_severity_levelmaps to itself; a rule without one uses its SARIF level one step down (error→ medium,warning→ low,note→ note). Somin_severity: highselects exactly what the Security tab calls High or Critical: on exult, 84 alerts over 13 rules.Scorecard posture checks are excluded by default rather than rolled into an owner "posture" issue. They are repository settings or project decisions, the owner already sees them on the Security tab, and an issue an agent cannot act on would only park. They still count on the dashboard (
excluded), andexclude_rules: ["!SASTID"]re-includes one. The default list:BinaryArtifactsID,BranchProtectionID,CIIBestPracticesID,CITestsID,CodeReviewID,ContributorsID,DependencyUpdateToolID,FuzzingID,LicenseID,MaintainedID,PackagingID,SASTID,SecurityPolicyID,SignedReleasesID,VulnerabilitiesID(it repeats the dependency alerts),WebhooksID.Grouping (
pkg/codescanning/group.go,Cluster):Package:in the message, as Trivy writes) group by (tool, package): one issue per package with every CVE, pointing at thego.mod/lockfile orContainerfile/Dockerfilethat brings it in.TokenPermissionsID(one alert per job) therefore becomes one issue per up-to-5 workflow files.Issue body, in house style: summary with a plain "may be false positives" warning, evidence (analysed commit, alert table with links and
path:line, a numbered code excerpt, rule docs), wanted behaviour, acceptance criteria, test plan, what to do with a false positive (say so on the issue; never weaken code or suppress), and out of scope. Two extras:.github/workflows/, the body says the fix needs the Workflows permission. If a lane serving the repo can push workflow files (config.WorkflowsCapableLane), the issue also getshive/workflows-lane, so the scheduler routes it there; otherwise the body tells a lane to park it with the workflows blocker instead of trying and failing.<sha>", else it says upstream has no fix to port. At most two reads per new issue.Dedupe and lifecycle. Each issue starts with
<!-- hive:code-scanning tool=… rule=… paths=… alerts=… -->and carriesorigin/governor+hive/code-scanning. Each pass lists the hive's ownhive/code-scanningissues (App-authored only, so a squatted marker does nothing):fixed/dismissed; when all are gone the sweep comments and closes (completed, or not planned if all were dismissed);Permission. A
403, or a404for no access, becomes amissing_permissionnotice;404 no analysis found(or "Advanced Security must be enabled") becomesnot_enabled. The repo is logged once and skipped for 6h. The notice shows as a pinned Code Scanning Alerts Not Readable dashboard banner with a Security-tab link, and in/api/status.GitHub API budget. The sweep is a
sweepOptionaljob, so it gets the staggered first pass (#16958) and is skipped whenever the budget mode is not normal; it also re-checks the mode before each repo. Calls are taggedhive:code_scanning. Listings are stable URLs with nosince=(nocacheableSinceneeded), so unchanged pages are free304s; alert pages are bounded at 10, issue pages at 5, and the dismissed list (2 pages) is read only when a tracked alert left the open list. Hook point:src/cmd/hive/sweep_workers.go:194@3fedee34c, insweepJobs()beside its siblings.Write-back gate. Every write (create, body edit, closing comment, close) asks
WritebackAllowedasissue_fileon the hive's own issue and carries// writeback:gated. The closing comment is inventoried innotificationWriteSites(status class).Dashboard / API.
/api/statusgetscode_scanning {enabled, repos[], notices[]}: per repo, open alerts by severity, qualifying / below threshold / excluded, tracked by an open hive issue, tracked by a closed one, untracked (waiting for the cap), open issues, this pass's filed / updated / closed, and the Security-tab link.Files
src/pkg/codescanning/(new): alert model, severity scale, policy,Cluster, marker, issue rendering, andRunagainst aForgeinterface. No GitHub dependency.src/pkg/github/code_scanning.go(new): the gatedForgeover the App client,RunCodeScanningSweep, per-repo status, back-off and notices.src/pkg/config/code_scanning.go(new) +config.go,validate.go: thecode_scanningblock.src/cmd/hive/code_scanning.go(new),sweep_workers.go: thecode_scanningsweep job.src/pkg/dashboard/server.go,static-src/{html/root-notices.html,js/banners.js,js/refresh.js}(+ regeneratedindex.html): status field and notice banner.src/docs/code-scanning.md;github-app-setup.md(the permission), operator reference (feature row, write-surface sweeps table, API budget note), API reference (/api/status), labels reference (hive/code-scanning,origin/governorfilers), glossary (the marker),notifications.md,documentation-map.md,hive.yaml.example; settings-parity allowlist (YAML-only keys);changelog.d/added-code-scanning-issues.md.Tests
Fixtures are real alert payloads, slimmed and with owners replaced by
example/…: 93 Danathar/exult CodeQL alerts (the 84 critical/high plus 9 quality findings), and the projectbluefin actions + common mix (Scorecard posture checks, TokenPermissions, PinnedDependencies, Trivy).pkg/codescanning: severity mapping; exultmin_severity: highselects 84 alerts over 13 rules and every group stays within 5 files; directory packing; cap per pass and dedupe across runs and a restart (18 issues total, no alert on two issues, no writes on re-scan); 0 qualifying alerts files nothing; fixed → closed completed, dismissed → closed not planned, reappearing alerts never refiled; an added alert updates the issue, a partial fix marks the row; a truncated listing never closes; missing permission and not-enabled notices; Scorecard posture checks file nothing while TokenPermissions groups by workflow file with the routing label (or park advice with no capable lane) and Trivy groups by package; exclude/re-include patterns; marker round trip; fork upstream note.pkg/github: end-to-end sweep over an httptest GitHub (labels, filer tag, marker, status counts, dedupe until all 84 alerts are tracked, write-back gateoffstops writes); a403notice is recorded once and the repo is not re-read inside the back-off;404 no analysis found→ not-enabled; no calls when the sweep is off or the budget is in conserve; the alert listing honours its page bound.pkg/config: off by default, per-repo overrides, validation.pkg/dashboard:/api/status code_scanning(counts, tracked, link, notice), absent when off; banner wiring.cmd/hive:code_scanningis an optional job with a staggered first pass, a configurable hourly interval, and is shed in conserve.Fail-before: the
cmd/hiveandpkg/dashboardtests failed before the job and status field were wired (no code_scanning sweep job,code_scanning missing); thepkg/codescanningtests failed (11 of 13) against stubbedRun/Cluster/Judge/Level; thepkg/githubandpkg/configtests do not build on the v6 tip.Ran in full:
pkg/codescanning,pkg/writeback(TestDirectWriteRatchet),pkg/config,pkg/github(incl.TestNotificationWriteSitesInventory),pkg/dashboard(incl. settings parity),pkg/dashboard/webstatic,cmd/hive;go veton each;check-docs-links.py,check-docs-citations.py,check-api-reference-citations.sh.TestGateFailsClosedWithoutIP6Tablesinpkg/configfails on this machine on the v6 tip too (host lacks the expected ip6tables setup); it is unrelated.Not in this PR
/api/status; the UI shows only the notice banner today.🤖 Generated with Claude Code
https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1