Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ concurrency:
jobs:
# Three-layer CI (#3295) plan: decide the matrix scope BEFORE paying for
# legs. One cheap ubuntu job picks one of three scopes:
# core — every PR (push) and master push: 9 test legs (all three combos at
# /3 shards: ubuntu 22, ubuntu 24, windows 22 — #4351 rebalance) + 2
# core — every PR (push) and master push: 11 test legs (ubuntu 22/24 at
# /3, windows 22 at /5 — #4351 rebalance, then duration-weighted
# re-shard below) + 2
# static legs (ubuntu 24, windows 22 — #3406 item 8: the windows
# static leg keeps typecheck/build + the kernel/pi-subagents
# suites covered on windows for EVERY PR, not only ci:full/nightly).
# The blocking layer. master's required-checks list still carries
# the legacy 12 FULL-matrix leg names; core produces 9 of them (the
# win node-24 legs appear only in FULL scope), enforce_admins off.
# The blocking layer. master's required-checks list still carries
# the legacy 12 FULL-matrix leg names; core produces 11 of the 16
# current names (windows node-24 legs appear only in FULL scope),
# and the four NEW windows shard-4/5 names must be added to branch
# protection before they gate merges, enforce_admins off.
# full — `ci:full` label on a PR, a release PR (#3688: bot-authored
# one-click fallback PRs, *_release-v* head branches, or a
# "[PR] release…"/"release vN…" title — no label needed),
# workflow_dispatch full=true, or the 30-min
# cron when master moved since the last green scheduled run: the
# historical 12-leg test matrix + 4-leg static-gates.
# cron when master moved since the last green scheduled run: the
# full 16-leg test matrix + 4-leg static-gates.
# skip — a `labeled` event for a label other than ci:full, or a cron tick
# where master HEAD == the last green scheduled run's head: nothing
# to do, every dependent job skips (run concludes success so the
Expand Down Expand Up @@ -115,20 +118,25 @@ jobs:
# core shape stayed frozen at its ~650-file design point (#3295), so
# its heaviest legs became the wall-clock floor: the ubuntu-24
# single-leg whole suite measured ~21 min and the windows 2-shard
# halves ~13-17 min (up to ~35 min tails on flake re-runs). All three
# combos now shard /3: partitionAll stays total for any i/N, so
# union of shards == every file — zero coverage loss; wall drops to
# the slowest shard (~7-12 min). The win node-24 legs stay FULL-only.
# halves ~13-17 min (up to ~35 min tails on flake re-runs). The
# combos now shard /3 on ubuntu and /5 on windows (duration-weighted
# re-balance: line-count LPT balanced bytes, not seconds — see
# scripts/ci-shard-partition.mjs): partitionAll stays total for any
# i/N, so union of shards == every file — zero coverage loss; wall
# drops to the slowest shard (~7 min windows target). The windows
# node-24 legs stay FULL-only.
CORE_TEST='{"include":[
{"os":"ubuntu-latest","node-version":22,"shard":1,"shardTotal":3},
{"os":"ubuntu-latest","node-version":22,"shard":2,"shardTotal":3},
{"os":"ubuntu-latest","node-version":22,"shard":3,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":1,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":2,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":3,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":3}]}'
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":4,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":5,"shardTotal":5}]}'
CORE_STATIC='{"include":[{"os":"ubuntu-latest","node-version":24},{"os":"windows-latest","node-version":22}]}'
FULL_TEST='{"include":[
{"os":"ubuntu-latest","node-version":22,"shard":1,"shardTotal":3},
Expand All @@ -137,12 +145,16 @@ jobs:
{"os":"ubuntu-latest","node-version":24,"shard":1,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":2,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":3,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":3},
{"os":"windows-latest","node-version":24,"shard":1,"shardTotal":3},
{"os":"windows-latest","node-version":24,"shard":2,"shardTotal":3},
{"os":"windows-latest","node-version":24,"shard":3,"shardTotal":3}]}'
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":4,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":5,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":1,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":2,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":3,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":4,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":5,"shardTotal":5}]}'
FULL_STATIC='{"include":[
{"os":"ubuntu-latest","node-version":22},
{"os":"ubuntu-latest","node-version":24},
Expand Down
8 changes: 8 additions & 0 deletions scripts/ci-shard-partition.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface ShardWeights {
msPerLineFallback: number;
files: Record<string, number>;
}

export function lineCount(rel: string): number;
export function fileWeight(rel: string, table?: ShardWeights): number;
export function partitionAll(files: string[], n: number, table?: ShardWeights): string[][];
58 changes: 58 additions & 0 deletions scripts/ci-shard-partition.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Shard partitioning with MEASURED-duration weights (#4360).
//
// Line-count LPT balanced bytes, not seconds: process-spawning suites
// (node child per case) cost orders of magnitude more per line than pure
// assertion files, and the line-count layout piled several of them into one
// shard (5-way split ran 5min..37min legs from a "perfectly balanced" 48.9K
// lines/shard). Weight = last measured wall-clock ms per file
// (scripts/ci-shard-weights.json, regenerated by
// scripts/measure-test-durations.mjs); files missing from the table fall
// back to lineCount * msPerLineFallback so a NEW file still gets a sane
// first-run weight. The partition stays DETERMINISTIC and TOTAL: fixed
// weights => same bins every run, and every file lands in exactly one bin.
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));

let defaultTable = { msPerLineFallback: 15, files: {} };
try {
const raw = JSON.parse(readFileSync(join(ROOT, "scripts", "ci-shard-weights.json"), "utf8"));
if (typeof raw?.msPerLineFallback === "number" && raw?.files && typeof raw.files === "object") {
defaultTable = raw;
}
} catch {
// absent/malformed table => pure line-count fallback (old behavior)
}

export function lineCount(rel) {
try {
return Math.max(1, readFileSync(join(ROOT, rel), "utf8").split("\n").length);
} catch {
return 1;
}
}

export function fileWeight(rel, table = defaultTable) {
const measured = table.files[rel];
if (typeof measured === "number" && measured > 0) return measured;
return Math.round(lineCount(rel) * (table.msPerLineFallback || 15));
}

// LPT bin-packing over fileWeight: sort desc (ties by path asc), assign each
// file to the currently-lightest bin (lowest index breaks ties). Targets the
// HEAVIEST shard (the wall clock), not equal file counts.
export function partitionAll(files, n, table = defaultTable) {
const weight = (f) => fileWeight(f, table);
const order = [...files].sort((a, b) => weight(b) - weight(a) || (a < b ? -1 : a > b ? 1 : 0));
const bins = Array.from({ length: n }, () => []);
const load = new Array(n).fill(0);
for (const f of order) {
let best = 0;
for (let k = 1; k < n; k++) if (load[k] < load[best]) best = k;
bins[best].push(f);
load[best] += weight(f);
}
return bins;
}
Loading
Loading