From a82d7c25da01ec1352cd1dc5a451f51407ce4957 Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:44:24 +0300 Subject: [PATCH] fix: old queued runs no longer hide a complete queue listing A queue_wait case ends when its job is gone from two whole listings of its repository (#76). A listing counted as whole only when it returned fewer than the 30 runs it asked for. dashpay/platform carries 31 runs that GitHub still calls queued, 29 of them left over since September, and dashpay/rust-dashcore 40, so their listings never counted and the rule never applied to the repositories with most of the waiting jobs. Ask for 100 runs and go by GitHub's own total: a listing is whole when it holds every run with that status. Only runs created in the last day are looked into, as before, so the number of requests does not change. Co-Authored-By: Claude Fable 5.2 --- server/ci.js | 10 ++++++++-- server/ci.test.js | 23 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/server/ci.js b/server/ci.js index 1163075..bda2625 100644 --- a/server/ci.js +++ b/server/ci.js @@ -22,6 +22,8 @@ const SPAN_KEEP_MS = 49 * 3_600_000; const SPAN_MAX = 2000; // The queue poll follows runs created within this window. const QUEUE_WINDOW_MS = DAY; +// Runs asked for per status (GitHub's maximum page). +const RUN_PAGE = 100; const ID = /^[a-z0-9][a-z0-9-]{0,39}$/; const REPO = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/; const TS = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/; @@ -252,9 +254,13 @@ export function createCi({ dataDir, fetcher = fetch, clock = Date.now, github = let whole = true; for (const status of ['queued', 'in_progress']) { // A 404 comes back as null: no listing, so no coverage. - const page = (await api(`/repos/${repo}/actions/runs?status=${status}&per_page=30`))?.workflow_runs; + const listing = await api(`/repos/${repo}/actions/runs?status=${status}&per_page=${RUN_PAGE}`); + const page = listing?.workflow_runs; if (!Array.isArray(page)) { whole = false; continue; } - if (page.length >= 30) whole = false; + // Every run with this status, by GitHub's own count. A repository can + // carry dozens of runs that have sat "queued" for months; they must + // not make the listing look cut when all of them are in it. + if (Number.isSafeInteger(listing.total_count) ? listing.total_count > page.length : page.length >= RUN_PAGE) whole = false; for (const r of page) runs.set(r.id, r); } const recent = [...runs.values()].filter((r) => Date.parse(r.created_at) > now - QUEUE_WINDOW_MS); diff --git a/server/ci.test.js b/server/ci.test.js index a308534..43a559e 100644 --- a/server/ci.test.js +++ b/server/ci.test.js @@ -102,8 +102,17 @@ test('a queue listing that was cut short or failed does not claim to cover its r let mode = 'whole'; const fetcher = async (url) => { if (url.includes('/attempts/')) return new Response('{}', { status: 404, headers }); - const runs = mode === 'many-runs' ? 30 : 1; - if (url.includes('status=queued')) return Response.json({ workflow_runs: Array.from({ length: runs }, (_, n) => ({ id: 500 + n, name: 'Tests', created_at: iso(T0 - 30 * 60_000), head_branch: 'x' })) }, { headers }); + if (url.includes('status=queued')) { + assert.match(url, /per_page=100/); + const run = (n, ageMs) => ({ id: 500 + n, name: 'Tests', created_at: iso(T0 - ageMs), head_branch: 'x' }); + const fresh = Array.from({ length: mode === 'many-runs' ? 30 : mode === 'leftovers' ? 2 : 1 }, (_, n) => run(n, 30 * 60_000)); + // Runs that have sat "queued" for two months: listed, but too old to be followed. + const old = Array.from({ length: mode === 'leftovers' ? 40 : mode === 'full-page' ? 99 : 0 }, (_, n) => run(100 + n, 60 * 86_400_000)); + const body = { workflow_runs: [...fresh, ...old] }; + if (mode === 'leftovers') body.total_count = 42; + if (mode === 'more-than-listed') body.total_count = 101; + return Response.json(body, { headers }); + } if (url.includes('status=in_progress')) return mode === 'not-found' ? new Response('{}', { status: 404, headers }) : Response.json({ workflow_runs: [] }, { headers }); if (url.includes('/jobs')) { if (mode === 'error') return new Response('{}', { status: 502, headers }); @@ -123,8 +132,14 @@ test('a queue listing that was cut short or failed does not claim to cover its r assert.deepEqual([whole.queue.jobs.length, whole.queue.total, whole.queue.covered, whole.recent.length], [60, 60, ['dashpay/platform'], 70]); assert.equal(ci.publicSummary().queue.covered, undefined); assert.equal(whole.queue.queued.length, 60); - // A listing that was cut short, failed or answered "not found" covers nothing. - for (const cut of ['many-runs', 'many-jobs', 'not-found', 'jobs-not-found', 'error']) { + // Forty runs left "queued" for months do not hide a listing that has all 42: + // the repository is covered, and only its two recent runs are looked into. + mode = 'leftovers'; now += 3 * 60_000; ci.ingest(id, report()); + await ci.tick(); + assert.deepEqual([ci.summary({ whole: true }).queue.covered, ci.summary({ whole: true }).queue.queued.length], [['dashpay/platform'], 120]); + // A listing that was cut short (by GitHub's count, or a full page without one), + // failed or answered "not found" covers nothing. + for (const cut of ['many-runs', 'more-than-listed', 'full-page', 'many-jobs', 'not-found', 'jobs-not-found', 'error']) { mode = cut; now += 3 * 60_000; ci.ingest(id, report()); await ci.tick(); assert.deepEqual(ci.summary({ whole: true }).queue.covered, [], cut);