Skip to content

Move Code Scanning Fixer onto the native work queue - #79600

Merged
elefthei merged 3 commits into
mainfrom
work-queue-code-scanning-fixer
Nov 20, 2026
Merged

elefthei merged 3 commits into
mainfrom
work-queue-code-scanning-fixer

Conversation

@elefthei

@elefthei elefthei commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Moves the Code Scanning Fixer onto the native work queue and ports the AI Scan-first clustering and open-PR deduplication from #79559 into the queue design.

What changes

  • code-scanning-dispatcher (new, every 4h). A trusted step lists open alerts and every open PR with its complete changed-file list, builds the plan with actions/setup/js/code_scanning_portfolio.cjs, and stages submit + dispatch_next. Pre-activation skips the run when no open alert is left uncovered by an open PR.
  • code-scanning-fixer-worker (new). Assignment-only. One Claim is one cluster of up to 5 alerts, fixed in one PR. The worker finishes the Claim completed after the PR intent is accepted, otherwise emits noop and cancels. Before the agent starts, it re-checks open PRs and drops alerts they now cover.
  • Pool code-scanning (concurrency 3, 3 attempts) in .github/workflows/aw.json. The other dispatcher locks change only because each embeds the full queue policy.
  • Removed: code-scanning-fixer.md and its lock, .github/scripts/code-scanning-fixer-context.sh, .github/scripts/code-scanning-fixer-select.jq, scripts/code-scanning-fixer-selection.test.cjs. Their cases are ported to code_scanning_portfolio.test.cjs.
  • Smoke work-queue regression suite. actions/setup/js/smoke_work_queue_workflows.test.cjs now runs the dispatcher's pre-activation gate, its planning step and the worker's pre-agent step straight from the workflow sources. They run the way actions/github-script runs them, against the real setup modules, an Octokit test double and a ledger built with the installed code-scanning Policy. The suite also checks the compiled wiring: the gate and its permissions in pre-activation, the dispatcher and worker queue roles, the worker allowlist, and the selection step running before the agent.

Behaviour kept from #79559

  • AI Scan findings first (tool AI Scan or rule prefix ai-scan/), then severity, then alert number.
  • Clusters of up to 5 alerts sharing scanner, rule and parent directory, with the Code scanning cluster: KEY marker. The key uses the same encoding as Prioritize and batch AI Scan fixes without duplicating open PRs #79559, so [code-scanning-fix] PRs already open keep blocking their clusters.
  • An alert is skipped while any open PR changes its file (including rename sources), links its canonical URL, cites #N next to an alert keyword, or carries its cluster marker. Planning fails closed if any PR's files can't be listed completely (error, invalid entry, or 3,000-file cap).
  • A closed fix PR leaves its alerts eligible again. They come back as new Work, because the identity includes earlier attempts.

Differences from #79559

#79559 This PR
Per run 1 cluster up to 3 clusters in parallel; clusters in one batch never share an alert file
In-flight tracking cache-memory checkpoints, 30-min stale rule, 1-h pending window queued/claimed Work blocks its alerts, cluster and files
Failed attempt (no safe fix, details unavailable) retried every run queue retries up to 3 times, then the fingerprint stays suppressed until it changes
Stalled attempts diagnostic issue queue stall handling; no diagnostic issue
Manual level input yes no; workers launch only from queue assignments on router/balanced

Known edge: if an open PR starts covering a queued cluster before its worker runs, the worker cancels. If that exhausts the retries, the alert stays suppressed after the PR closes, until its fingerprint changes (any line shift does that).

Validation

  • make agent-report-progress: all stages pass. The first run hit Go lint's 10-minute timeout on a cold cache; golangci-lint run --timeout 40m ./pkg/workflow reports 0 issues.
  • npx vitest run code_scanning_portfolio.test.cjs: 9/9, covering ranking, clusters, every coverage rule, the queue lifecycle against a real ledger, worker projection, and fail-closed PR listing.
  • npx vitest run smoke_work_queue_workflows.test.cjs: 11/11, including the 3 code scanning regression cases.
  • 13 work-queue / portfolio vitest files that read aw.json or lock files: 258/258.
  • node --test scripts/workflow-tool-contracts.test.cjs: 7/7. go test ./pkg/workflow -run TestReportedWorkflowToolPermissions: pass.
  • make recompile: 370/370 compiled, no drift outside this change. Rebased on 6238b139cf and recompiled the 6 affected locks with no drift.

Not dispatched live.

- Add code-scanning-dispatcher: admits up to three severity-ranked open alerts per run into a dedicated code-scanning pool (concurrency 3) and stages one bounded dispatch request.
- Add code-scanning-fixer-worker: assignment-only worker that fixes one alert per Claim and finishes the Claim completed after a PR, or cancelled with noop.
- Add code_scanning_portfolio.cjs plan builder and tests; queue identity and retries replace the cache-memory ledger, checkpoints and stalled-alert diagnostics.
- Remove code-scanning-fixer and its selector test; retarget tool-permission and contract tests to the worker.
…nning queue

- Rank AI Scan findings first, then severity and alert number; admit up to three clusters per run of at most five alerts sharing scanner, rule and parent directory, never sharing an alert file within a batch.
- Skip alerts any open pull request covers (changed or renamed file, canonical URL, #N beside an alert keyword, or the fixer's cluster marker); fail closed when a pull request's files cannot be listed completely.
- Gate pre-activation on an uncovered open alert, and re-check coverage in the worker's pre-agent step before the agent runs.
- Completed Work blocks only through its open pull request; a closed pull request makes the alerts new Work. Fingerprints whose retries ran out stay suppressed until they change.
- Run the dispatcher every 4 hours; remove the cache-based context and selector scripts superseded by the plan builder.
@elefthei
elefthei marked this pull request as ready for review November 20, 2026 21:39
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 21:39
@github-actions

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output. Detected threat types: prompt injection.

Review the workflow run logs for details.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~7 AIC · ⌖ ~2 AIC · ⊞ 1.6K · ◷

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by Ponytail Reviewer for #79600 · codex · routed: gpt61 medium · ~9 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output. Detected threat types: prompt injection.

Review the workflow run logs for details.

PR Specification Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by PR Specification Reviewer for #79600 · copilot · gpt56 · ~4 AIC · ⌖ ~2 AIC · ⊞ 1.7K · ◷

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-b9151140-197a-43ca-9bde-dffd194508c2","parents":[],"payload":{"id":"ldg-4109360a-4a3b-4ef8-a6b6-671d4b1c36bf","operation":"append","value":{"finding_count":0,"head_sha":"c3e372ac77be70afaccfd235e611c5a98df8572a","outcome":"aligned"}},"sha":"sha256:57a2b3f4e870aa3feb91f77c5f6ec66978bdc78632b88a9355d4b4c8172ae100","timestamp":"2026-11-20T21:48:13.321Z","type":"ledger_append","version":1}
History

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output. Detected threat types: prompt injection.

Review the workflow run logs for details.

Reviewed the current diff and changed-line behavior, including the queue planner, PR coverage detection, worker assignment projection, and staged dispatcher/worker contracts. I found no actionable correctness, performance, or maintainability issues that warrant blocking this change. Static review only; tests were not run by this reviewer.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~7 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-70d57179-ffee-405d-a14b-f13d0377078b","parents":[],"payload":{"id":"ldg-9765a983-617d-4792-8fe6-c56a19338949","operation":"append","value":{"finding_count":0,"head_sha":"c3e372ac77be70afaccfd235e611c5a98df8572a","outcome":"no_findings"}},"sha":"sha256:d6994964d2be5e29bb7e7fe924a0017628a5efba0e34ea282a15c942320b6fa3","timestamp":"2026-11-20T21:50:20.583Z","type":"ledger_append","version":1}
History

- Run the dispatcher's pre-activation gate, its planning step and the worker's pre-agent step from the workflow sources, in-realm as actions/github-script does, against the real setup modules, an Octokit double and a ledger built with the installed code-scanning Policy.
- Check the compiled wiring: pre-activation gate and permissions, dispatcher and worker queue roles, the worker allowlist, and the selection step running before the agent.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The worker’s sed permission enables sandbox command-restriction bypasses, and plaintext queue fingerprints expose restricted scanner messages in public repositories.

8 open issues
What changed in this PR

This PR moves the repository’s Code Scanning Fixer onto gh-aw’s native work queue, replacing cache-based coordination while preserving AI Scan-first clustering and open-PR deduplication.

Changes:

  • Adds a four-hour dispatcher and an assignment-only worker that fixes clusters of up to five alerts.
  • Introduces a dedicated pool with three concurrent Claims and a three-attempt retry budget.
  • Ports selection and lifecycle coverage to JavaScript and removes the legacy workflow, helpers, and tests.
File Description
scripts/​workflow-tool-contracts.test.cjs Updates restricted-tool checks for the queue worker.
scripts/​code-scanning-fixer-selection.test.cjs Removes legacy selector tests.
pkg/​workflow/​reported_tool_permissions_test.go Checks the renamed worker’s tool permissions.
Makefile Removes the deleted selection-test invocation.
docs/​src/​content/​docs/​agent-factory-status.mdx Removes the obsolete fixer status entry.
actions/​setup/​js/​work_queue_binding_policy.test.cjs Expects the new code-scanning pool.
actions/​setup/​js/​code_scanning_portfolio.test.cjs Covers ranking, deduplication, and queue lifecycle.
actions/​setup/​js/​code_scanning_portfolio.cjs Plans alert clusters and projects worker assignments.
.github/​workflows/​code-scanning-fixer.md Removes the monolithic cache-based fixer.
.github/​workflows/​code-scanning-fixer-worker.md Defines assignment processing and Claim outcomes.
.github/​workflows/​code-scanning-fixer-worker.lock.yml Compiles worker execution and queue lifecycle wiring.
.github/​workflows/​code-scanning-dispatcher.md Defines scheduled planning and staged dispatch.
.github/​workflows/​aw.json Adds the three-slot code-scanning pool.
.github/​scripts/​code-scanning-fixer-select.jq Removes the cache-based alert selector.
.github/​scripts/​code-scanning-fixer-context.sh Removes legacy API and context collection.
.changeset/​patch-code-scanning-work-queue.md Records the migration in release notes.

Review effort: Max (adaptive)

require-assignment: true
worker: true
cli-proxy: true
bash: ["cat:*", cut, "git diff:*", "git diff --binary --no-ext-diff | wc -c", "git restore:*", "git status:*", grep, "head:*", jq, ls, "sed:*", tail, wc]
Comment on lines +83 to +88
* Compact JSON of [rule_id, path, line, message]; any change is a new finding.
* @param {any} alert
*/
function alertFingerprint(alert) {
const instance = alert.most_recent_instance ?? {};
return JSON.stringify([alert.rule?.id ?? "", alertPath(alert), instance.location?.start_line ?? 0, truncate(instance.message?.text, 256)]);
on:
workflow_dispatch:
concurrency:
job-discriminator: ${{ github.run_id }}
for (const pull of pulls) {
const files = await github.paginate(github.rest.pulls.listFiles, { ...repo, pull_number: pull.number, per_page: 100 });
if (files.length >= MAX_PULL_FILES) throw new Error(`Could not completely inspect changed files for pull request #${pull.number}: GitHub lists at most ${MAX_PULL_FILES}`);
if (files.some((/** @type {any} */ file) => typeof file?.filename !== "string" || !file.filename)) throw new Error(`Invalid changed-file listing for pull request #${pull.number}`);
*/
function clusterNode(members, repository, repositoryId) {
// An oversized payload would make admission reject the whole batch.
while (members.length > 1 && canonicalBytes(clusterPayload(members, repository, repositoryId)) > DEFAULT_LIMITS.payload_bytes) members = members.slice(0, -1);
// Earlier attempts on these alerts make a retry after a closed pull request a new Work identity.
node_key: digest({ alerts: members.map(member => [member.number, member.fingerprint]), after: [...new Set(members.flatMap(member => member.prior))].sort() }),
pool: POOL,
priority: isAIScan(lead.alert) ? 1 : 7 - Math.max(2, severityRank(lead.alert)),
if (work?.pool !== POOL) continue;
const payload = work.payload;
if (typeof work.graph_id !== "string" || !work.graph_id.startsWith(GRAPH_PREFIX) || typeof payload?.cluster_key !== "string" || !Array.isArray(payload.alerts)) throw new Error("Code scanning queue Work is malformed");
const live = !TERMINAL.has(work.state);
stored.push(work);
if (live) liveClusters.add(payload.cluster_key);
for (const member of payload.alerts) {
attempts.set(member.number, [...(attempts.get(member.number) ?? []), { work_id: work.work_id, live, cancelled: work.state === "cancelled", fingerprint: member.fingerprint }]);
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (.github/workflows/code-scanning-fixer-worker.md:43): address unresolved feedback - Review comment
  3. Review (actions/setup/js/code_scanning_portfolio.cjs:88): address unresolved feedback - Review comment
  4. Review (.github/workflows/code-scanning-fixer-worker.md:9): address unresolved feedback - Review comment
  5. Review (actions/setup/js/code_scanning_portfolio.cjs:129): address unresolved feedback - Review comment
  6. Review (actions/setup/js/code_scanning_portfolio.cjs:211): address unresolved feedback - Review comment
  7. Review (actions/setup/js/code_scanning_portfolio.cjs:218): address unresolved feedback - Review comment
  8. Review (actions/setup/js/code_scanning_portfolio.cjs:247): address unresolved feedback - Review comment
  9. Review (actions/setup/js/code_scanning_portfolio.cjs:251): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "bd912466ae88020ff8544f2b079e9219fdf504d9",
  "kind": "requested",
  "schema_version": "1",
  "state": "828b578bbd6a58c61f9632c3f18433e676c2e6ee2c626f0a7f968b5fd9790ae7",
  "work": [
    "046b162e70e22b7867c93960c166b9a6d5a7365c83c2cef2dcbe51c9a9e12945",
    "114152b8a58c02c608da6e2a7c1a09348c5111c9601bec2992033883cff223e1",
    "13ff18db75176d6e679abc16503d3c59b1ed870f6eac91634cc8acf7e60995cf",
    "30276a6c00e796e62b1ee3caacd25853b3489303b4037b956adf9afef837c4eb",
    "9335014caebe0fa03f93b9d81980cde7f4d9ef4c34a918110a837edd91c572e3",
    "a65a473ba434e565e1f4b571f8c5fdf14c36e98a61af367eb8c9d3646d10a519",
    "e54fd7e1a2305482408501a1c23e63a1e23f49e870e644301e357a3f01118815",
    "e6e58660f42ef83390efe5fcfa3a02eed62b50f64743b06a06c2f02773c63945"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 high · ~2 AIC · ⌖ ~2 AIC · ⊞ 7K · ◷
Comment /souschef to run again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants