Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Reclaim closed PR CI held before runner admission

pulse-triage[bot]50b5345be8f5
diff --git a/.github/scripts/reclaim-closed-pr-capacity.cjs b/.github/scripts/reclaim-closed-pr-capacity.cjs
index 138d7bd0b5..3a4597e23f 100644
--- a/.github/scripts/reclaim-closed-pr-capacity.cjs
+++ b/.github/scripts/reclaim-closed-pr-capacity.cjs
@@ -1,6 +1,9 @@
'use strict';
-const ACTIVE_STATUSES = ['queued', 'in_progress'];
+// Concurrency and environment admission can hold a run before it reaches the
+// runner queue. A closed PR no longer needs those runs either; otherwise they
+// can start obsolete work after this one-shot close-event cleanup has finished.
+const ACTIVE_STATUSES = ['queued', 'in_progress', 'requested', 'waiting', 'pending'];
function belongsToClosedPullRequest(run, pullRequestNumber, headRepository, headBranch) {
return (
diff --git a/.github/scripts/reclaim-closed-pr-capacity.test.cjs b/.github/scripts/reclaim-closed-pr-capacity.test.cjs
index 4858582156..a9ccd27ff7 100644
--- a/.github/scripts/reclaim-closed-pr-capacity.test.cjs
+++ b/.github/scripts/reclaim-closed-pr-capacity.test.cjs
@@ -15,6 +15,7 @@ function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, r
const messages = [];
const lifecycleReads = [];
const headReads = [];
+ const runLists = [];
const github = {
paginate: async (method, input) => method(input),
rest: {
@@ -29,7 +30,10 @@ function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, r
},
},
actions: {
- listWorkflowRunsForRepo: async ({ status }) => runs[status] || [],
+ listWorkflowRunsForRepo: async ({ status }) => {
+ runLists.push(status);
+ return runs[status] || [];
+ },
cancelWorkflowRun: async ({ run_id: runId }) => {
cancellationAttempts.push(runId);
if (cancelError) throw cancelError;
@@ -65,7 +69,7 @@ function fixture({ state = 'closed', openForHead = [], runs = {}, cancelError, r
warning: (message) => messages.push(message),
setFailed: (message) => messages.push(message),
};
- return { github, context, core, cancelled, cancellationAttempts, readbacks, messages, lifecycleReads, headReads };
+ return { github, context, core, cancelled, cancellationAttempts, readbacks, messages, lifecycleReads, headReads, runLists };
}
function requestError(status) {
@@ -109,7 +113,72 @@ test('cancels only unfinished runs for the exact closed head', async () => {
assert.deepEqual(subject.cancelled, [10]);
assert.match(subject.messages.at(-1), /Requested cancellation for 1 of 1 unfinished run/);
- assert.deepEqual(ACTIVE_STATUSES, ['queued', 'in_progress']);
+ assert.deepEqual(ACTIVE_STATUSES, ['queued', 'in_progress', 'requested', 'waiting', 'pending']);
+ assert.deepEqual(subject.runLists, ACTIVE_STATUSES);
+});
+
+for (const status of ['requested', 'waiting', 'pending']) {
+ test(`awaiting: reclaims an exclusively associated ${status} run`, async () => {
+ const subject = fixture({ runs: { [status]: [{ ...matchingRun(), status }] } });
+ await cancelClosedPullRequestRuns(subject);
+ assert.deepEqual(subject.cancelled, [10]);
+ assert.deepEqual(subject.readbacks, [10]);
+ assert.deepEqual(subject.lifecycleReads, [1858, 1858]);
+ assert.deepEqual(subject.headReads, ['rcourtman:topic/old', 'rcourtman:topic/old']);
+ assert.match(subject.messages.at(-1), /Requested cancellation for 1 of 1/);
+ });
+
+ test(`transition: admits queued to ${status} only after fresh identity checks`, async () => {
+ const subject = fixture({
+ runs: { queued: [{ ...matchingRun(), status: 'queued' }] },
+ observedRun: { ...matchingRun(), status },
+ });
+ await cancelClosedPullRequestRuns(subject);
+ assert.deepEqual(subject.cancelled, [10]);
+ assert.deepEqual(subject.readbacks, [10]);
+ assert.deepEqual(subject.lifecycleReads, [1858, 1858]);
+ assert.deepEqual(subject.headReads, ['rcourtman:topic/old', 'rcourtman:topic/old']);
+ });
+
+ test(`awaiting: ${status} does not admit unrelated, unbound or terminal work`, async () => {
+ const run = { ...matchingRun(), status };
+ const subject = fixture({ runs: { [status]: [
+ { ...run, id: 11, pull_requests: [] },
+ { ...run, id: 12, pull_requests: [{ number: 1858 }, { number: 1900 }] },
+ { ...run, id: 13, head_repository: { full_name: 'other/Pulse' } },
+ { ...run, id: 14, event: 'push' },
+ { ...run, id: 15, status: 'completed' },
+ { ...run, id: 16, status: 'unknown' },
+ ] } });
+ await cancelClosedPullRequestRuns(subject);
+ assert.deepEqual(subject.cancellationAttempts, []);
+ assert.deepEqual(subject.readbacks, []);
+ });
+
+ test(`awaiting: a refused ${status} inventory read stops without another query`, async () => {
+ const error = requestError(403);
+ const subject = fixture();
+ const original = subject.github.rest.actions.listWorkflowRunsForRepo;
+ subject.github.rest.actions.listWorkflowRunsForRepo = async (input) => {
+ if (input.status === status) throw error;
+ return original(input);
+ };
+ await assert.rejects(cancelClosedPullRequestRuns(subject), caught => caught === error);
+ assert.deepEqual(subject.runLists, ACTIVE_STATUSES.slice(0, ACTIVE_STATUSES.indexOf(status)));
+ assert.deepEqual(subject.cancellationAttempts, []);
+ assert.deepEqual(subject.readbacks, []);
+ });
+}
+
+test('awaiting: one run moving between discovery states is cancelled only once', async () => {
+ const subject = fixture({ runs: {
+ queued: [{ ...matchingRun(), status: 'queued' }],
+ pending: [{ ...matchingRun(), status: 'pending' }],
+ } });
+ await cancelClosedPullRequestRuns(subject);
+ assert.deepEqual(subject.cancelled, [10]);
+ assert.deepEqual(subject.readbacks, [10]);
+ assert.match(subject.messages.at(-1), /Requested cancellation for 1 of 1/);
});
test('does nothing when the pull request reopened', async () => {
diff --git a/.github/workflows/reclaim-closed-pr-capacity.yml b/.github/workflows/reclaim-closed-pr-capacity.yml
index 1022651e82..a164128a46 100644
--- a/.github/workflows/reclaim-closed-pr-capacity.yml
+++ b/.github/workflows/reclaim-closed-pr-capacity.yml
@@ -1,7 +1,8 @@
name: Reclaim closed PR CI capacity
-# A closed pull request no longer needs its queued or running verdicts. Run in
-# the base repository context so fork closures can release hosted capacity too;
+# A closed pull request no longer needs its requested, waiting, pending, queued
+# or running verdicts. Run in the base repository context so fork closures can
+# release hosted capacity too;
# no pull-request code, artifact, cache, or secret enters this privileged job.
on:
pull_request_target: