From 372f579287e58b83762f337d57d28652cab3ab4f Mon Sep 17 00:00:00 2001 From: David Porkka <37228537+dporkka@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:44:51 -0300 Subject: [PATCH 1/3] feat(ci): add advisory cross-repository failure signals (scripts/pr-queue-report.mjs) --- scripts/pr-queue-report.mjs | 69 ++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/scripts/pr-queue-report.mjs b/scripts/pr-queue-report.mjs index 8c6802b2e..5ab56c350 100644 --- a/scripts/pr-queue-report.mjs +++ b/scripts/pr-queue-report.mjs @@ -241,6 +241,58 @@ async function getEvidence(repo, pr, getJson) { return diagnoseChecks(checkRuns.check_runs, statuses.statuses); } +const CORRELATABLE_OUTCOMES = new Set(['failure', 'error', 'timed_out', 'startup_failure', 'action_required']); + +// Pure advisory co-occurrence across inspected repositories; matching check names +// and outcomes cannot establish a shared runner or infrastructure root cause. +export function correlateObservedFailures(reports, { limit = 10 } = {}) { + if (!Array.isArray(reports) || !Number.isSafeInteger(limit) || limit < 1 || limit > 50) { + throw new Error('Invalid portfolio correlation input'); + } + const grouped = new Map(); + for (const report of reports) { + if (typeof report?.repo !== 'string' || !Array.isArray(report.priority)) { + throw new Error('Malformed repository report for CI correlation'); + } + for (const pr of report.priority) { + const diagnosis = pr?.ciDiagnosis; + if (diagnosis?.evidenceComplete !== true || !Array.isArray(diagnosis.attentionChecks)) continue; + for (const check of diagnosis.attentionChecks) { + if (!['check-run', 'commit-status'].includes(check?.source) + || typeof check.name !== 'string' || !check.name.trim() + || !CORRELATABLE_OUTCOMES.has(check.outcome)) continue; + const key = JSON.stringify([check.source, check.name, check.outcome]); + if (!grouped.has(key)) { + grouped.set(key, { + source: check.source, name: check.name, outcome: check.outcome, + repositories: new Set(), pullRequests: new Set(), + }); + } + const group = grouped.get(key); + group.repositories.add(report.repo); + if (Number.isSafeInteger(pr.number) && pr.number > 0) { + group.pullRequests.add(report.repo + '#' + pr.number); + } + } + } + } + const all = [...grouped.values()].filter(group => group.repositories.size >= 2) + .map(group => ({ + source: group.source, + name: group.name, + outcome: group.outcome, + repositoryCount: group.repositories.size, + repositories: [...group.repositories].sort(), + affectedPRs: group.pullRequests.size, + confidence: 'unverified', + })) + .sort((a, b) => b.repositoryCount - a.repositoryCount + || a.name.localeCompare(b.name) + || a.outcome.localeCompare(b.outcome) + || a.source.localeCompare(b.source)); + return { signals: all.slice(0, limit), total: all.length }; +} + export async function collectPortfolio(repos, getJson, { now = new Date(), days = 7, staleDays = 3, maxPages = 20, inspect = 5 } = {}) { const since = new Date(now.getTime() - days * DAY_MS); const reports = []; @@ -258,7 +310,7 @@ export async function collectPortfolio(repos, getJson, { now = new Date(), days } return { generatedAt: now.toISOString(), since: since.toISOString(), caveat: 'Read-only snapshot, checks are advisory. Passing observed checks do not certify required contexts, reviews, merged state, or deployment.', - reports }; + sharedFailureSignals: correlateObservedFailures(reports), reports }; } export function formatMarkdown(data, { show = 10 } = {}) { @@ -270,6 +322,21 @@ export function formatMarkdown(data, { show = 10 } = {}) { '| Repository | Created in cohort | Merged | Open in cohort | Closed unmerged | All open | Draft open | Stale open |', '|---|---:|---:|---:|---:|---:|---:|---:|', ]; + lines.push('', '## Cross-repository check co-occurrences', + 'Advisory only: matching observed check source, name, and outcome in multiple inspected repositories is not evidence of a common root cause.', ''); + const correlation = data.sharedFailureSignals ?? correlateObservedFailures(data.reports); + if (correlation.signals.length === 0) { + lines.push('No cross-repository check co-occurrences observed in the inspected subset.'); + } else { + for (const signal of correlation.signals) { + lines.push('- ' + escapeEvidenceLabel(signal.name) + ' (' + signal.source + ', ' + signal.outcome + '): ' + + signal.repositoryCount + ' repositories; ' + signal.affectedPRs + ' PRs; ' + + signal.repositories.map(escapeEvidenceLabel).join(', ') + '. Shared cause unverified.'); + } + if (correlation.total > correlation.signals.length) { + lines.push('- ' + (correlation.total - correlation.signals.length) + ' additional co-occurrence groups omitted by report limit.'); + } + } for (const r of data.reports) { lines.push(`| ${r.repo} | ${r.counts.created} | ${r.counts.merged} | ${r.counts.open} | ${r.counts.closedUnmerged} | ${r.inventory.open} | ${r.inventory.draft} | ${r.inventory.stale} |`); } From 1087de08285555481c1dd744390b2a42733c568c Mon Sep 17 00:00:00 2001 From: David Porkka <37228537+dporkka@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:45:00 -0300 Subject: [PATCH 2/3] feat(ci): add advisory correlation tests and documentation (scripts/pr-queue-report.test.mjs) --- scripts/pr-queue-report.test.mjs | 101 +++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/scripts/pr-queue-report.test.mjs b/scripts/pr-queue-report.test.mjs index f66810628..3e199dbb1 100644 --- a/scripts/pr-queue-report.test.mjs +++ b/scripts/pr-queue-report.test.mjs @@ -2,6 +2,7 @@ import assert from 'node:assert/strict'; import test from 'node:test'; import { classifyChecks, + correlateObservedFailures, diagnoseChecks, collectPortfolio, formatMarkdown, @@ -269,3 +270,103 @@ test('incomplete evidence guidance identifies commit-status pagination, check-ru assert.match(bothTruncated.nextAction, /check.run/i); assert.match(bothTruncated.nextAction, /commit.status/i); }); + +test('correlates only observed failed check outcomes across distinct repositories', () => { + const failed = (number, head, outcomes) => ({ + number, head, ciDiagnosis: { evidenceComplete: true, attentionChecks: outcomes, attentionTotal: outcomes.length }, + }); + const build = { source: 'check-run', name: 'build', outcome: 'startup_failure', url: 'https://ci.example/build' }; + const reports = [ + { repo: 'acme/api', priority: [failed(1, 'aaaa', [build]), failed(2, 'bbbb', [build])] }, + { repo: 'acme/web', priority: [failed(7, 'cccc', [build])] }, + { repo: 'acme/ops', priority: [failed(4, 'dddd', [{ ...build, outcome: 'failure' }])] }, + ]; + const result = correlateObservedFailures(reports); + assert.equal(result.total, 1); + assert.equal(result.signals.length, 1); + const signal = result.signals[0]; + assert.equal(signal.source, 'check-run'); + assert.equal(signal.name, 'build'); + assert.equal(signal.outcome, 'startup_failure'); + assert.equal(signal.repositoryCount, 2); + assert.equal(signal.confidence, 'unverified'); + assert.deepEqual(signal.repositories, ['acme/api', 'acme/web']); + assert.equal(signal.affectedPRs, 3); +}); + +test('avoids false correlation from missing, truncated, pending, and canceled evidence', () => { + const complete = (outcome, evidenceComplete = true) => ({ + number: 1, head: 'sha', ciDiagnosis: { + evidenceComplete, attentionChecks: [{ source: 'commit-status', name: 'Woodpecker', outcome }], + attentionTotal: 1, + }, + }); + const reports = [ + { repo: 'acme/api', priority: [complete('failure')] }, + { repo: 'acme/web', priority: [complete('failure', false)] }, + { repo: 'acme/pending', priority: [complete('pending')] }, + { repo: 'acme/canceled', priority: [complete('cancelled')] }, + { repo: 'acme/success', priority: [{ number: 2, ciDiagnosis: { evidenceComplete: true, attentionChecks: [] } }] }, + ]; + assert.deepEqual(correlateObservedFailures(reports), { signals: [], total: 0 }); +}); + +test('cross-repository signal summaries are bounded, escaped and explicitly advisory', () => { + const check = { source: 'check-run', name: 'build [a] | b', outcome: 'failure' }; + const reports = ['acme/a', 'acme/b'].map(repo => ({ + repo, priority: [{ + number: 1, head: 'abcdef123456789', ciDiagnosis: { + evidenceComplete: true, attentionTotal: 1, attentionChecks: [check], + }, + }], + })); + const signals = correlateObservedFailures(reports); + const markdown = formatMarkdown({ + generatedAt: now.toISOString(), since: now.toISOString(), caveat: 'observed only', + reports: reports.map(r => ({ + ...r, priority: [], counts: { created: 0, merged: 0, open: 0, closedUnmerged: 0 }, + inventory: { open: 0, draft: 0, stale: 0 }, + })), + sharedFailureSignals: signals, + }); + assert.match(markdown, /Cross-repository check co-occurrences/); + assert.match(markdown, /not evidence of a common root cause/i); + assert.match(markdown, /build \\[a\\] \\| b/); + assert.match(markdown, /acme\/a/); + assert.match(markdown, /acme\/b/); +}); + + +test('portfolio collection adds only bounded cross-repository co-occurrences from inspected PRs', async () => { + const getJson = async path => { + if (path.includes('/pulls?')) { + return [PR(1, 'open', false, '2026-10-17T12:00:00Z')]; + } + if (path.includes('/check-runs')) return { + total_count: 1, + check_runs: [{ name: 'bootstrap', status: 'completed', conclusion: 'startup_failure' }], + }; + if (path.includes('/status')) return { total_count: 0, statuses: [] }; + throw new Error('Unexpected route: ' + path); + }; + const result = await collectPortfolio(['acme/a', 'acme/b'], getJson, { now, inspect: 1 }); + assert.equal(result.sharedFailureSignals.total, 1); + assert.equal(result.sharedFailureSignals.signals[0].repositoryCount, 2); + assert.equal(result.sharedFailureSignals.signals[0].outcome, 'startup_failure'); + assert.equal(result.sharedFailureSignals.signals[0].confidence, 'unverified'); + assert.equal((await collectPortfolio(['acme/a', 'acme/b'], getJson, { now, inspect: 0 })).sharedFailureSignals.total, 0); +}); + +test('cross-repository correlation respects its output limit without hiding total groups', () => { + const checks = Array.from({ length: 4 }, (_, i) => + ({ name: 'check-' + i, source: 'check-run', outcome: 'failure' })); + const reports = ['acme/a', 'acme/b'].map(repo => ({ + repo, priority: [{ number: 1, ciDiagnosis: { + evidenceComplete: true, attentionChecks: checks, attentionTotal: checks.length, + } }], + })); + const result = correlateObservedFailures(reports, { limit: 2 }); + assert.equal(result.total, 4); + assert.equal(result.signals.length, 2); + assert.throws(() => correlateObservedFailures(reports, { limit: 0 }), /Invalid/); +}); From 33dc806396e53d662f5394e3636c76a34fa1b305 Mon Sep 17 00:00:00 2001 From: David Porkka <37228537+dporkka@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:45:03 -0300 Subject: [PATCH 3/3] feat(ci): add advisory correlation tests and documentation (docs/engineering/pr-integration-loop.md) --- docs/engineering/pr-integration-loop.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/engineering/pr-integration-loop.md b/docs/engineering/pr-integration-loop.md index eb3bd1c44..2be613f16 100644 --- a/docs/engineering/pr-integration-loop.md +++ b/docs/engineering/pr-integration-loop.md @@ -21,7 +21,28 @@ A token must have **read-only** Pull requests/Contents/Checks access to the sele **Terminology:** cohort totals count PRs *created in the lookback*, classified by their current state; they are not a throughput metric for PRs merged during the lookback. `All open` includes older PRs from all creation dates. `Stale` means no `updated_at` activity in the selected interval; it does not imply safe closure. Checks are inspected at the recorded PR head SHA of the top `--inspect` items; because the report does not re-fetch the PR after inspection, a moving PR head can make a snapshot stale. `passing-observed-only` does not establish branch protection, mandatory contexts, Woodpecker, CodeQL, test correctness, human approval, staging smoke tests, or production deployment. `no-evidence`, `pending`, `failed`, and `incomplete` are never passing states. `not-inspected` means no CI calls were made for that PR. Results can change immediately after snapshot collection. -**Read-only CI drilldowns (draft PR #209):** Inspected items include up to five non-success GitHub check runs and commit statuses, sorted by observed outcome priority, with provider detail links when they are well-formed HTTPS URLs. The JSON includes `attentionChecks`, `attentionTotal`, and `evidenceComplete`. These are status observations, not a verified first failed executable step or a root-cause determination. Incomplete/missing pagination counts, including truncated combined commit statuses, fail closed to `incomplete-evidence`; the drilldown is then withheld. The combined-status request explicitly fetches up to 100 statuses. No action is taken on a provider or repository. +**Read-only CI drilldowns (merged PR #209):** Inspected items include up to five non-success GitHub check runs and commit statuses, sorted by observed outcome priority, with provider detail links when they are well-formed HTTPS URLs. The JSON includes `attentionChecks`, `attentionTotal`, and `evidenceComplete`. These are status observations, not a verified first failed executable step or a root-cause determination. Incomplete/missing pagination counts, including truncated combined commit statuses, fail closed to `incomplete-evidence`; the drilldown is then withheld. The combined-status request explicitly fetches up to 100 statuses. No action is taken on a provider or repository. + +## Advisory cross-repository check co-occurrences + +The portfolio report includes a sharedFailureSignals object (signals and total) +in JSON and a human-readable cross-repository section in Markdown. A signal +requires the same **provider status source, exact check name and failed +conclusion** in at least two distinct repositories among the PRs inspected by +this bounded report. Multiple PRs in one repository do not manufacture an +additional affected repository. Only observed failure/error/timeout/startup/ +action-required outcomes participate. Canceled, pending, missing, uninspected, +and incomplete evidence do not yield positive correlation signals. + +The displayed groups are limited to ten, sorted by affected repository count. +Each PR contributes only its existing five highest-priority attention checks; +this is **sampled coverage**, not exhaustive failure discovery. Counts include +only observed PRs within that bounded subset. Even a shared startup_failure +check name does not prove a common runner, cause, infrastructure incident, or +dependency. Review actual provider execution logs and runner assignments +before acting. Re-fetch candidate PR heads if a release decision is involved. +This report remains read-only, does not create incidents, and grants no merge +or deployment authority. ## Advisory CI diagnosis in portfolio reports