Skip to content

Commit 5ccb789

Browse files
committed
perf(ci): partition the complete plugin catch-all with native sharding
1 parent 77df987 commit 5ccb789

6 files changed

Lines changed: 100 additions & 29 deletions

File tree

‎docs/ci.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ concurrent repositories, retries, and burst overlap.
474474

475475
The changed-target PR plan uses one Node test registration. Broad-risk PRs retain the metadata-complete compact fallback; canonical pushes use the integration compact. The `github` planner permits up to 112 hosted compact rows, with at most 96 running concurrently; `hybrid` retains its 96-row compact cap. Separately appended changed-plugin fallback descriptors must also be counted. Hybrid rows consume Blacksmith registrations on attempt 1 and move to hosted capacity on retries. Count every emitted matrix row and nonmatrix job, including all six Android rows despite its two-job concurrency cap.
476476

477-
The 2026-08-31 all-scope hybrid baseline at `8cc1e0f` emitted 59 compact rows, 67 plugin fallback rows, and 52 other Blacksmith jobs including the three control jobs: 178 registrations. Using the compact cap gives a conservative broad-PR bound of `96 + 67 + 52 = 215`; canonical main has no PR fallback descriptors, so its bound is 148. Two active main slots plus both pending successors and the observed peak of fourteen non-skipped PR arrivals, including superseded heads, give `4 × 148 + 14 × 215 = 3,602` registrations in five minutes. The three control routes add at most 54 within that envelope. This is an arrival-envelope estimate, not an organization-wide admission cap: re-evaluate emitted plugin rows, adjacent repositories, and queued-run overlap before increasing fanout. The remaining 2,398 below the 6,000 operating target is reserved for that work; an unused registration bucket does not prove physical runner capacity.
477+
The shared plugin catch-all uses native Vitest sharding, sized from a 90-file job budget. Its complete config still owns discovery and exclusions; the counting inventory never narrows execution to the directly changed plugin. The current 482 counting entries produce six jobs covering all 468 effective test files. Each job retains the existing worker limits, isolation policy and per-file module cleanup.
478+
479+
Before this catch-all split, the 2026-08-31 all-scope hybrid baseline at `8cc1e0f` emitted 59 compact rows, 67 plugin fallback rows, and 52 other Blacksmith jobs including the three control jobs: 178 registrations. Replacing its one catch-all row with six raises plugin fallback rows to 72. Using the compact cap gives a conservative broad-PR bound of `96 + 72 + 52 = 220`; canonical main has no PR fallback descriptors, so its bound remains 148. Two active main slots plus both pending successors and the observed peak of fourteen non-skipped PR arrivals, including superseded heads, give `4 × 148 + 14 × 220 = 3,672` registrations in five minutes. The three control routes add at most 54 within that envelope. This is an arrival-envelope estimate, not an organization-wide admission cap: re-evaluate emitted plugin rows, adjacent repositories, and queued-run overlap before increasing fanout. The remaining 2,328 below the 6,000 operating target is reserved for that work; an unused registration bucket does not prove physical runner capacity.
478480

479481
`checks-ui-e2e` is sized against its per-shard floor rather than its packing slack. The lane is serial Chromium work: roughly 2,114s of measured test body across 286 control-UI files, and a median 116s that every row pays before and around that body (about 25s checkout, about 44s Node setup dominated by `pnpm install`, about 27s of Vitest transform/import, with a p90 of 143s). Duration-weighted packing already lands the tallest row within about 10% of ideal on held-out runs, so the tallest row falls only by splitting the body further. The hosted-planner count is 14 rows — 13 control-UI shards plus the browser-extension row — which models to a 4:52 median and 5:20 p90 tallest row against 5:28/5:56 at the previous twelve. Two extra registrations per run is negligible against the operating target; the fixed floor, not the bucket, is what bounds further splitting.
480482

‎scripts/ci-run-node-test-shard.mts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ function isShardGroupConfig(value: unknown): value is ShardGroupConfig {
6262
return isRecord(value) && isStringArray(value.configs);
6363
}
6464

65-
function parseJsonEnv(env: NodeJS.ProcessEnv, name: string, fallback: unknown = null): unknown {
65+
function parseJsonEnv(
66+
env: Record<string, unknown>,
67+
name: string,
68+
fallback: unknown = null,
69+
): unknown {
6670
try {
67-
return JSON.parse(env[name] ?? "null") ?? fallback;
71+
const value = env[name];
72+
return typeof value === "string" ? (JSON.parse(value) ?? fallback) : fallback;
6873
} catch {
6974
return fallback;
7075
}
@@ -306,8 +311,6 @@ function runChild(args: string[], childEnv: NodeJS.ProcessEnv, label: string) {
306311

307312
export async function runShardPlans(plans: ShardPlan[], options: RunShardOptions = {}) {
308313
const baseEnv = options.env ?? process.env;
309-
const parsedVitestExtraArgs = parseJsonEnv(baseEnv, VITEST_EXTRA_ARGS_ENV_KEY, []);
310-
const vitestExtraArgs = isStringArray(parsedVitestExtraArgs) ? parsedVitestExtraArgs : [];
311314
const concurrency = Math.max(1, options.concurrency ?? PLAN_CONCURRENCY);
312315
const runner = options.runChild ?? runChild;
313316
const scratchDir = options.scratchDir ?? mkdtempSync(join(tmpdir(), "openclaw-node-shard-"));
@@ -339,10 +342,15 @@ export async function runShardPlans(plans: ShardPlan[], options: RunShardOptions
339342
}
340343
continue;
341344
}
345+
const vitestExtraArgs = [
346+
baseEnv,
347+
entry.kind === "group" ? entry.plan.env : undefined,
348+
].flatMap((env) => {
349+
const value = parseJsonEnv(env ?? {}, VITEST_EXTRA_ARGS_ENV_KEY, []);
350+
return isStringArray(value) ? value : [];
351+
});
342352
const args =
343-
Array.isArray(vitestExtraArgs) && vitestExtraArgs.length > 0
344-
? [...targetArgs, "--", ...vitestExtraArgs]
345-
: targetArgs;
353+
vitestExtraArgs.length > 0 ? [...targetArgs, "--", ...vitestExtraArgs] : targetArgs;
346354
const childEnv = buildChildEnv(entry, baseEnv, scratchDir, index, {
347355
serial: concurrency === 1,
348356
cacheSlot,

‎scripts/lib/ci-changed-node-test-plan.mts‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import {
1919
listExtensionTestFilesForRoots,
2020
resolveExtensionTestConfig,
21+
resolveExtensionTestJobFileLimit,
2122
shouldSplitExtensionTestProcesses,
2223
splitExtensionTestJobTargets,
2324
} from "./extension-test-plan.mts";
@@ -30,6 +31,7 @@ import {
3031
type ChangedNodeTestShard = {
3132
checkName: string;
3233
configs: string[];
34+
env?: Record<string, string>;
3335
includePatterns?: string[];
3436
planConcurrency?: number;
3537
pretestBuildMode?: VitestPretestBuildMode;
@@ -363,19 +365,40 @@ function createChangedExtensionConfigShards(extensionRoots: string[]) {
363365
const config = resolveExtensionTestConfig(root);
364366
rootsByConfig.set(config, [...(rootsByConfig.get(config) ?? []), root]);
365367
}
366-
const plans: Array<{ config: string; includePatterns?: string[] }> = [...rootsByConfig].flatMap(
367-
([config, roots]) => {
368-
const testFiles = shouldSplitExtensionTestProcesses(config)
369-
? listExtensionTestFilesForRoots(roots)
370-
: [];
371-
const chunks =
372-
testFiles.length > 0 ? splitExtensionTestJobTargets(config, testFiles) : [roots];
373-
return chunks.length > 1
374-
? chunks.map((includePatterns) => ({ config, includePatterns }))
375-
: [{ config }];
376-
},
377-
);
378-
return plans.map(({ config, includePatterns }, index) => {
368+
const plans: Array<{
369+
config: string;
370+
env?: Record<string, string>;
371+
includePatterns?: string[];
372+
}> = [...rootsByConfig].flatMap(([config, roots]) => {
373+
const splitProcesses = shouldSplitExtensionTestProcesses(config);
374+
const testFiles = resolveExtensionTestJobFileLimit(config)
375+
? listExtensionTestFilesForRoots(splitProcesses ? roots : ["extensions"]).filter(
376+
(file) =>
377+
splitProcesses ||
378+
resolveExtensionTestConfig(file.split("/").slice(0, 2).join("/")) === config,
379+
)
380+
: [];
381+
const chunks = testFiles.length > 0 ? splitExtensionTestJobTargets(config, testFiles) : [roots];
382+
return chunks.length > 1
383+
? chunks.map((includePatterns, index) =>
384+
Object.assign(
385+
{ config },
386+
splitProcesses
387+
? { includePatterns }
388+
: {
389+
// Counts size jobs only. Vitest owns the complete config inventory,
390+
// including unrelated plugin roots, excludes and untracked tests.
391+
env: {
392+
OPENCLAW_NODE_TEST_VITEST_ARGS_JSON: JSON.stringify([
393+
`--shard=${index + 1}/${chunks.length}`,
394+
]),
395+
},
396+
},
397+
),
398+
)
399+
: [{ config }];
400+
});
401+
return plans.map(({ config, env, includePatterns }, index) => {
379402
const suffix = plans.length === 1 ? "" : `-${index + 1}`;
380403
const shard: ChangedNodeTestShard = {
381404
checkName: `checks-node-changed-extensions-config${suffix}`,
@@ -395,6 +418,9 @@ function createChangedExtensionConfigShards(extensionRoots: string[]) {
395418
if (includePatterns) {
396419
shard.includePatterns = includePatterns;
397420
}
421+
if (env) {
422+
shard.env = env;
423+
}
398424
return shard;
399425
});
400426
}

‎scripts/lib/extension-test-plan.mts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ const EXTENSION_TEST_PROCESS_FILE_LIMITS = new Map<string, number>([
114114
],
115115
]);
116116
const EXTENSION_TEST_JOB_FILE_LIMITS = new Map<string, number>([
117+
// The 468-file catch-all took 528–829s on two detected CPUs. Six jobs leave
118+
// room for checkout/setup without changing its non-isolated worker lifecycle.
119+
["test/vitest/vitest.extensions.config.ts", 90],
117120
// Bound Telegram CI jobs so isolate recycling stays inside one job instead
118121
// of minting one runner per test file. Ten files keeps the worst job near
119122
// 3 minutes (observed 2026-08: ~45s runner setup + ~7-24s per file) while
@@ -269,7 +272,7 @@ function splitTargetsByFileLimit(targets: string[], maxFilesPerChunk: number) {
269272
return chunks;
270273
}
271274

272-
function resolveExtensionTestJobFileLimit(config: string) {
275+
export function resolveExtensionTestJobFileLimit(config: string) {
273276
return (
274277
EXTENSION_TEST_JOB_FILE_LIMITS.get(config) ?? EXTENSION_TEST_PROCESS_FILE_LIMITS.get(config)
275278
);

‎test/scripts/ci-changed-node-test-plan.test.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ describe("CI changed Node test plan", () => {
105105
const hostTest = "src/agents/prepared-model-runtime.copilot.integration.test.ts";
106106
const shards = createChangedNodeTestShards([changedPath]);
107107
expect(shards).not.toBeNull();
108-
expect(shards).toHaveLength(2);
108+
expect(shards).toHaveLength(createChangedExtensionFallbackShards([changedPath]).length + 1);
109109
expect(shards?.flatMap((shard) => shard.targets ?? [])).toEqual([hostTest]);
110-
expect(shards?.flatMap((shard) => shard.configs)).toEqual([
111-
"test/vitest/vitest.extensions.config.ts",
112-
]);
110+
expect(new Set(shards?.flatMap((shard) => shard.configs))).toEqual(
111+
new Set(["test/vitest/vitest.extensions.config.ts"]),
112+
);
113113
expect(buildVitestRunPlans([hostTest])).toEqual([
114114
{
115115
config: "test/vitest/vitest.agents-core.config.ts",
@@ -544,6 +544,29 @@ describe("CI changed Node test plan", () => {
544544
expect(shards).toHaveLength(Math.ceil(targets.length / 10));
545545
});
546546

547+
it("partitions the whole catch-all config for direct and core-driven plugin changes", () => {
548+
const config = "test/vitest/vitest.extensions.config.ts";
549+
const direct = createChangedExtensionFallbackShards(["extensions/copilot/index.ts"]);
550+
const broad = createChangedExtensionFallbackShards([
551+
"scripts/lib/ci-changed-node-test-plan.mts",
552+
]).filter((shard) => shard.configs.includes(config));
553+
554+
expect(direct.length).toBeGreaterThan(1);
555+
expect(direct.every((shard) => shard.configs.length === 1 && shard.configs[0] === config)).toBe(
556+
true,
557+
);
558+
expect(direct.every((shard) => !shard.includePatterns && !shard.targets)).toBe(true);
559+
const shardArgs = (shards: typeof direct) => shards.map((shard) => shard.env);
560+
expect(shardArgs(direct)).toEqual(
561+
direct.map((_, index) => ({
562+
OPENCLAW_NODE_TEST_VITEST_ARGS_JSON: JSON.stringify([
563+
`--shard=${index + 1}/${direct.length}`,
564+
]),
565+
})),
566+
);
567+
expect(shardArgs(broad)).toEqual(shardArgs(direct));
568+
});
569+
547570
it("preserves Matrix process bounds in mixed package fallbacks", () => {
548571
const shards = createChangedExtensionFallbackShards([
549572
"packages/gateway-protocol/src/frame-guards.ts",

‎test/scripts/ci-run-node-test-shard.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,18 @@ describe("scripts/ci-run-node-test-shard.mts", () => {
220220
);
221221
});
222222

223-
it("forwards trusted Vitest arguments after the target separator", async () => {
223+
it("forwards job and group Vitest arguments without leaking them to sibling plans", async () => {
224224
const scratchDir = makeScratchDir();
225225
const seen: string[][] = [];
226226
const exitCode = await runShardPlans(
227227
resolveShardPlans({
228-
OPENCLAW_NODE_TEST_CONFIGS_JSON: JSON.stringify(["test/vitest/vitest.unit.config.ts"]),
228+
OPENCLAW_NODE_TEST_GROUPS_JSON: JSON.stringify([
229+
{
230+
configs: ["test/vitest/vitest.extensions.config.ts"],
231+
env: { OPENCLAW_NODE_TEST_VITEST_ARGS_JSON: JSON.stringify(["--shard=1/6"]) },
232+
},
233+
{ configs: ["test/vitest/vitest.unit.config.ts"] },
234+
]),
229235
}),
230236
{
231237
concurrency: 1,
@@ -241,7 +247,10 @@ describe("scripts/ci-run-node-test-shard.mts", () => {
241247
);
242248

243249
expect(exitCode).toBe(0);
244-
expect(seen).toEqual([["test/vitest/vitest.unit.config.ts", "--", "--hookTimeout=300000"]]);
250+
expect(seen).toEqual([
251+
["test/vitest/vitest.extensions.config.ts", "--", "--hookTimeout=300000", "--shard=1/6"],
252+
["test/vitest/vitest.unit.config.ts", "--", "--hookTimeout=300000"],
253+
]);
245254
});
246255

247256
it("reuses isolated persistent cache slots across serial work", async () => {

0 commit comments

Comments
 (0)