An open source design system that's fully customizable and agent ready
TypeScript
ci: admission counts a run at its planned most only in the 45 s before its jobs appear, ignores runs GitHub lists as active but has not updated in two hours, and logs what each run counted (AST-030 FR16, DEC-16) (#9299)
Cindy Zhanga1afd78fa18c
diff --git a/.github/actions/ci-admission/action.yml b/.github/actions/ci-admission/action.ymlindex 5d1ff2f8de..026f4bd576 100644--- a/.github/actions/ci-admission/action.yml+++ b/.github/actions/ci-admission/action.yml@@ -23,9 +23,10 @@# - Each CI or Main run counts its live jobs, read once per look. A# pull-request run still waiting here counts only that waiting job, so# waiting runs never hold each other back by more than they use; a waiting-# `main` run counts its whole peak. A run admitted in the last three minutes-# counts at least its planned most until its jobs appear. Every other-# workflow's run counts an estimate.+# `main` run counts its whole peak. A run admitted in the last 45 seconds,+# before its jobs appear, counts at least its planned most. Every other+# workflow's run counts an estimate. A run not updated in two hours is a+# stale record GitHub still lists as active, and counts nothing.# - A look costs two run listings plus one call per active CI or Main run, and# a run looks at most `max-looks` times: twice for a pull request (at once and# after its longest wait), every two minutes for the rare `main` run. When the@@ -95,7 +96,13 @@ runs:const ADMITTED = ['.github/workflows/ci.yml', '.github/workflows/deploy.yml'];const admitted = run => ADMITTED.includes(run.path);const LIVE = ['in_progress', 'queued', 'waiting', 'pending'];- const JUST_ADMITTED_MS = 3 * 60_000;+ // A run's jobs appear within seconds of its admission; until then it+ // counts at its planned most.+ const JUST_ADMITTED_MS = 45_000;+ // GitHub keeps listing some long-finished runs as queued; a run not+ // updated in this long holds no runner.+ const STALE_MS = 2 * 60 * 60_000;+ const short = run => (run.path ?? '').replace(/^.*\//, '').replace(/\.ya?ml$/, '');const isMain = run =>['push', 'schedule', 'workflow_dispatch'].includes(run.event) &&['.github/workflows/ci.yml', '.github/workflows/deploy.yml'].includes(run.path);@@ -125,6 +132,10 @@ runs:let large = 0;let small = 0;let mainWaiting = false;+ // What each run counted, logged on every look.+ const counted = [];+ const smallBy = {};+ let stale = 0;for (const status of ['in_progress', 'queued']) {calls += 1;const {data, headers} = await github.rest.actions.listWorkflowRunsForRepo({@@ -138,8 +149,13 @@ runs:for (const run of data.workflow_runs) {if (seen.has(run.id) || run.id === context.runId) continue;seen.add(run.id);+ if (Date.now() - Date.parse(run.updated_at ?? '') > STALE_MS) {+ stale += 1;+ continue;+ }if (!admitted(run)) {small += estimate(run);+ smallBy[short(run)] = (smallBy[short(run)] ?? 0) + estimate(run);continue;}calls += 1;@@ -153,20 +169,23 @@ runs:// Still waiting for room. A pull-request run holds only// the job that waits; a `main` run holds its whole peak,// ahead of this one.- if (isMain(run)) {- large += estimate(run);- if (!main) mainWaiting = true;- } else {- large += 1;- }+ const holds = isMain(run) ? estimate(run) : 1;+ if (isMain(run) && !main) mainWaiting = true;+ large += holds;+ counted.push(`${short(run)} ${run.id} ${run.event}: ${holds} waiting`);continue;}const live = jobs.filter(job => LIVE.includes(job.status)).length;const admittedAt = Date.parse(wait?.completed_at ?? '');- large += Date.now() - admittedAt < JUST_ADMITTED_MS ? Math.max(live, estimate(run)) : live;+ const fresh = Date.now() - admittedAt < JUST_ADMITTED_MS;+ const holds = fresh ? Math.max(live, estimate(run)) : live;+ large += holds;+ counted.push(`${short(run)} ${run.id} ${run.event}: ${holds}${fresh && holds > live ? ` (admitted just now, ${live} live)` : ' live'}`);}}const others = large + Math.max(small, SMALL_MOST);+ const smallList = Object.entries(smallBy).map(([name, count]) => `${name} ${count}`).join(', ');+ core.info(`Look ${look}: ${counted.join('; ') || 'no CI or Main runs'}. Small workflows ${small}${smallList ? ` (${smallList})` : ''}, counted as ${Math.max(small, SMALL_MOST)}.${stale ? ` Ignored ${stale} stale run${stale === 1 ? '' : 's'}.` : ''}`);if (others + peak <= CI_CEILING && !mainWaiting) {core.info(`Room under the CI ceiling: about ${others} other jobs + ${peak} <= ${CI_CEILING}.`);return;diff --git a/.github/scripts/ci-admission.test.mjs b/.github/scripts/ci-admission.test.mjsindex 26add0ea71..8e52c2c354 100644--- a/.github/scripts/ci-admission.test.mjs+++ b/.github/scripts/ci-admission.test.mjs@@ -404,16 +404,57 @@ describe('ci admission', () => {expect(result.calls).toBe(2 + 3 + 1 + 12);});- it('counts live jobs, and a run admitted in the last three minutes at least at its most', async () => {+ it('counts live jobs, and a run admitted in the last 45 seconds at least at its most', async () => {// 4 x 12 live + 18 small + 13 = 79: room.expect((await admit({active: prs(4), peak: 13})).looks).toBe(1);- // A just-admitted run with 2 jobs so far counts its planned 16 (95); a long-running one, 2 (81).- const fresh = admittedRun(60, 2, {admittedMinutesAgo: 1});- const old = admittedRun(60, 2, {admittedMinutesAgo: 9});+ // A run admitted 30 s ago with 2 jobs so far counts its planned 16 (95);+ // one admitted a minute ago has all its jobs, and counts its 2 (81).+ const fresh = admittedRun(60, 2, {admittedMinutesAgo: 0.5});+ const settled = admittedRun(60, 2, {admittedMinutesAgo: 1});expect((await admit({active: [...prs(4), fresh], peak: 13})).looks,).toBeGreaterThan(1);- expect((await admit({active: [...prs(4), old], peak: 13})).looks).toBe(1);+ expect((await admit({active: [...prs(4), settled], peak: 13})).looks).toBe(+ 1,+ );+ });++ it("admits at once at tonight's load, which the three-minute floor and stale runs counted as 81", async () => {+ // 2026-11-01 ~10:00Z: 49 jobs ran (CI 38, Main 6, small workflows 5)+ // while pull-request runs waited twelve minutes, "about 81 other jobs".+ // Runs admitted one to three minutes ago were counted at 16 or 14 though+ // their jobs had all appeared, and GitHub still listed nine long-finished+ // runs as queued.+ const stale = Array.from({length: 9}, (_, i) => ({+ ...slim(700 + i),+ status: 'queued',+ updated_at: ago(3 * 24 * 60),+ }));+ const active = [+ admittedRun(81, 12, {admittedMinutesAgo: 2.2}),+ admittedRun(82, 2, {admittedMinutesAgo: 2}),+ admittedRun(83, 7, {admittedMinutesAgo: 1.5}),+ admittedRun(84, 9, {admittedMinutesAgo: 6.6}),+ admittedRun(85, 8, {admittedMinutesAgo: 1}),+ admittedRun(86, 6, {+ event: 'push',+ path: '.github/workflows/deploy.yml',+ admittedMinutesAgo: 2,+ }),+ ...slims(5),+ ...stale,+ ];+ // 38 + 6 live + 18 kept for small workflows + this run's 16 = 78.+ const result = await admit({active, peak: 16, maxWait: 12, maxLooks: 2});+ expect(result.looks).toBe(1);+ expect(result.warning).toEqual([]);+ // Every look logs what each run counted, and the stale runs it ignored.+ const look = result.info.find(line => line.startsWith('Look 1:'));+ expect(look).toContain('ci 81 pull_request: 12 live');+ expect(look).toContain('deploy 86 push: 6 live');+ expect(look).toContain('Small workflows 5 (pr-comment 5), counted as 18.');+ expect(look).toContain('Ignored 9 stale runs.');+ expect(result.info.at(-2)).toContain('about 62 other jobs + 16 <= 90');});it("keeps room for small workflows' measured most", async () => {diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.mdindex 7b211d62d2..9987662919 100644--- a/docs/specs/AST-030/spec.md+++ b/docs/specs/AST-030/spec.md@@ -674,14 +674,16 @@ bookkeeping, report publishing) always count at least the most they weremeasured running at once, eighteen jobs, so the room they can take stays free.Each CI or Main run counts its live jobs: a pull-request run still waitingcounts only the job that waits, so waiting runs hold each other back by no more-than they use, and a run admitted in the last three minutes counts at least its-planned most. A look reads the active runs and each CI or Main run's jobs once,-so it costs two run listings plus one call per active CI or Main run. A pull-request looks at most twice, and a run starts rather than spend a low API-budget. A `main` full check, release re-check or baseline capture (every-dispatch of the CI workflow) goes first: while one waits, pull-request runs wait-too. Every job ends within its fifteen-minute budget, so `main` fits within-fifteen minutes. Nothing is reserved for `main` outside those minutes.+than they use, and a run admitted in the last forty-five seconds, before its+jobs appear, counts at least its planned most. A run GitHub still lists as+active but has not updated in two hours holds no runner and counts nothing. A+look reads the active runs and each CI or Main run's jobs once, so it costs two+run listings plus one call per active CI or Main run. A pull request looks at+most twice, and a run starts rather than spend a low API budget. A `main` full+check, release re-check or baseline capture (every dispatch of the CI workflow)+goes first: while one waits, pull-request runs wait too. Every job ends within+its fifteen-minute budget, so `main` fits within fifteen minutes. Nothing is+reserved for `main` outside those minutes.CI can still pass ninety in three rare, bounded ways: