Skip to content

Commit 392e1c0

Browse files
authored
fix(ci): preserve cache warmer shard envelopes (#119403)
Punchcard-Session: amber-orchard-valley-s4
1 parent 50c7444 commit 392e1c0

3 files changed

Lines changed: 83 additions & 12 deletions

File tree

‎.github/workflows/vitest-cache-warm.yml‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ jobs:
4545
import { appendFileSync } from "node:fs";
4646
import { createNodeTestShards } from "./scripts/lib/ci-node-test-plan.mjs";
4747
48-
// Warm whole configs for the striped unit-fast graph plus the import-
49-
// bound graphs that remained cold in measured protected-cache readers.
48+
// Warm the selected planner envelopes for the striped unit-fast graph
49+
// plus import-bound graphs that remained cold in protected-cache readers.
5050
const additionalShardNames = new Set([
5151
"agentic-agents-embedded",
5252
"agentic-gateway-methods",
@@ -72,11 +72,14 @@ jobs:
7272
throw new Error(`cache seed shards are missing: ${missingShardNames.join(", ")}`);
7373
}
7474
const shards = [...coreShards, ...additionalShards];
75-
const configs = [...new Set(shards.flatMap((shard) => shard.configs))];
76-
const groups = configs.map((config) => ({
77-
configs: [config],
78-
shard_name: `cache-warm:${config}`,
79-
}));
75+
const groups = shards.flatMap((shard) =>
76+
shard.configs.map((config) => ({
77+
configs: [config],
78+
...(shard.env ? { env: shard.env } : {}),
79+
...(shard.includePatterns ? { includePatterns: shard.includePatterns } : {}),
80+
shard_name: `cache-warm:${shard.shardName}:${config}`,
81+
})),
82+
);
8083
appendFileSync(
8184
process.env.GITHUB_ENV,
8285
[

‎docs/ci.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ The slowest Node test families are split or balanced so each job stays small wit
115115
- Pull requests on the canonical repository reuse the changed-test resolver against the synthetic merged-tree diff. Precise changes run one targeted Node job; each selected test file gets its own process so stateful suite isolation remains intact. The planner combines sibling tests with import-graph dependents and falls back to the existing 14-job compact full-suite plan for workspace package, package/lockfile, shared harness, split-config, renamed, or deleted changes, public extension-contract changes, tests with special shard setup, partially resolved or empty targets, oversized path or target plans, and planner errors. Targeted plans always retain the full built-artifact boundary gate because its repository scanners cannot be derived from imports. `main` pushes run the same full compact suite: pending intermediate push events can be coalesced, so the newest surviving run must validate the complete integration tree rather than only its final single-push diff. Manual dispatches and release gates retain the full named per-shard matrix.
116116
- The full Node matrix admits the consistently slow serial tooling, auto-reply command shards, and broad core-fast cache writer first. This keeps the 28-job cap while preventing critical-path work and the next run's transform seed from slipping into a later wave.
117117
- Broad browser, QA, media, and miscellaneous plugin tests use their dedicated Vitest configs instead of the shared plugin catch-all. Include-pattern shards record timing entries using the CI shard name, so `.artifacts/vitest-shard-timings.json` can distinguish a whole config from a filtered shard.
118-
- Linux Node shard jobs persist Vitest's experimental filesystem module cache through the upstream Actions cache API, which Blacksmith transparently accelerates on its runners. Every CI shard is restore-only and unpacks the protected seed into its own runner-local root; the shard wrapper then gives concurrent Vitest processes separate live subdirectories. Only the non-cancelling daily or explicitly dispatched warmer saves a new immutable archive, so pull requests cannot publish transforms or mint per-PR cache families. The warmer launches each selected whole config in a fresh child process with concurrency one while reusing the same serial cache leaf, preventing config-global state from leaking without discarding transforms produced by the previous config. A transform-input fingerprint clears incompatible lockfile, package, tsconfig, and Vitest-config generations. The protected writer scans and prunes its restored cache to 75% after it exceeds 2 GiB. Vitest hashes module id, source content, environment, and resolved transform config, so ordinary partial source changes keep unchanged entries warm while changed modules miss safely. Coarse restore prefixes bridge workflow runs; normal Actions cache LRU and inactivity eviction bound old immutable archives.
118+
- Linux Node shard jobs persist Vitest's experimental filesystem module cache through the upstream Actions cache API, which Blacksmith transparently accelerates on its runners. Every CI shard is restore-only and unpacks the protected seed into its own runner-local root; the shard wrapper then gives concurrent Vitest processes separate live subdirectories. Only the non-cancelling daily or explicitly dispatched warmer saves a new immutable archive, so pull requests cannot publish transforms or mint per-PR cache families. The warmer launches each selected shard/config envelope in a fresh child process with concurrency one, preserving its include patterns and environment while reusing the same serial cache leaf. This prevents config-global state from leaking, avoids expanding filtered shards into whole configs, and retains transforms produced by the previous child. A transform-input fingerprint clears incompatible lockfile, package, tsconfig, and Vitest-config generations. The protected writer scans and prunes its restored cache to 75% after it exceeds 2 GiB. Vitest hashes module id, source content, environment, and resolved transform config, so ordinary partial source changes keep unchanged entries warm while changed modules miss safely. Coarse restore prefixes bridge workflow runs; normal Actions cache LRU and inactivity eviction bound old immutable archives.
119119
- Trusted Linux Node jobs also bind the pnpm store and `node_modules` from one protected dependency disk per supported Node line. Package manifests, install settings, runner platform, and the exact Node patch stay out of the disk key; an exact runtime and install-input fingerprint decides whether a job reuses the tree or reinstalls and refreshes the same disk. Manifests are canonicalized before hashing. The audited direct root hooks retain only pnpm's install lifecycle scripts, so formatting and ordinary test/build script edits keep the warm dependency tree; unaudited lifecycle-hook drift fails closed until its source inputs join the fingerprint contract. Dependency, package-manager, hook-source, and lockfile changes always invalidate the snapshot. A matching fingerprint is necessary but not sufficient: setup also checks the importer archive and manifest checksums, then verifies registry-backed lockfile dependencies retained by postinstall against the package manifests Node resolves from their importers. Missing or stale importer content falls back to a fresh install instead of serving the root hoist. A pull request whose read-only snapshot is unusable detaches the workspace bind and installs into runner-local storage, avoiding slow writes to a clone it cannot publish. Sticky cold installs disable pnpm's inner fetch retries and make up to three bounded full-install attempts from the progressively warmed store; a timeout remains a failure. After a content-validated restore or frozen-lockfile install, setup disables pnpm's redundant pre-run dependency check: the repository intentionally prunes plugin-local `node_modules`, which pnpm otherwise treats as stale and repairs through unsafe concurrent implicit installs during shard fanout. Canonical main preflight is the sole writer and measures the store on every refresh, running `pnpm store prune` only after retired package versions push it above 8 GiB. Blacksmith snapshot publication is asynchronous even after a writer job completes, so the first run after a fresh key or fingerprint can remain cold; later content-validated exact-marker restores are the rollout proof. Required CI jobs and pull requests get disposable clones, so dependency changes do not create new disks, competing snapshots, or a cache lock that can cancel builds.
120120
- Node shard and build-artifact jobs also restore Node's portable on-disk compile cache through immutable Actions caches. Independent `test` and `build` namespaces prevent their writers from replacing each other's archives: the scheduled test warmer owns the protected test seed, while `build-artifacts` may publish at most one protected build archive per UTC day from trusted `main` pushes. PR and ordinary test jobs only read protected snapshots, so feature-branch bytecode never enters the shared seed and PR traffic creates no cache archives. This reuses V8 bytecode for Node-loaded orchestration, build tooling, and external dependencies across different checkout paths, including when only part of the source graph changes. Vitest child processes disable an inherited compile cache because coverage can be enabled inside dynamic configs and V8 coverage can lose source-position precision when scripts are deserialized from bytecode.
121121
- The build-artifact job also persists content-fingerprinted `build-all` step outputs. CI's self-built plugin SDK declarations hash the complete repository-owned TypeScript/JSON source graph, exclude installed and generated directories, and restore both flat declarations and package bridges after `tsdown` clears `dist`. Documentation, workflow, plugin, and other changes outside that graph can reuse the declaration snapshot; source changes rebuild it before the export gate runs.

‎test/scripts/ci-workflow-guards.test.ts‎

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import path from "node:path";
1717
import { expectDefined } from "@openclaw/normalization-core";
1818
import { describe, expect, it } from "vitest";
1919
import { parse } from "yaml";
20+
import { createNodeTestShards } from "../../scripts/lib/ci-node-test-plan.mjs";
2021
import { NATIVE_I18N_LOCALES } from "../../scripts/native-app-i18n.ts";
2122
import { SUPPORTED_LOCALES } from "../../ui/src/i18n/lib/registry.ts";
2223

@@ -2934,8 +2935,12 @@ describe("ci workflow guards", () => {
29342935
expect(warmerSource).toContain('"agentic-agents-embedded"');
29352936
expect(warmerSource).toContain('"agentic-gateway-methods"');
29362937
expect(warmerSource).toContain('"auto-reply-reply-commands-3"');
2937-
expect(warmerSource).toContain("const groups = configs.map((config) => ({");
2938+
expect(warmerSource).toContain("const groups = shards.flatMap((shard) =>");
29382939
expect(warmerSource).toContain("configs: [config]");
2940+
expect(warmerSource).toContain("...(shard.env ? { env: shard.env } : {})");
2941+
expect(warmerSource).toContain(
2942+
"...(shard.includePatterns ? { includePatterns: shard.includePatterns } : {})",
2943+
);
29392944
expect(warmerSource).toContain("`OPENCLAW_NODE_TEST_GROUPS_JSON=${JSON.stringify(groups)}`");
29402945
expect(warmerSource).not.toContain("OPENCLAW_NODE_TEST_CONFIGS_JSON");
29412946
expect(warmerSource).toContain('"OPENCLAW_NODE_TEST_PLAN_CONCURRENCY=1"');
@@ -2980,14 +2985,77 @@ describe("ci workflow guards", () => {
29802985
}
29812986
const groups = JSON.parse(serializedGroups) as Array<{
29822987
configs: string[];
2988+
env?: Record<string, string>;
2989+
includePatterns?: string[];
29832990
shard_name: string;
29842991
}>;
2985-
expect(groups.length).toBeGreaterThan(1);
2992+
const selectedShardNames = new Set([
2993+
"agentic-agents-embedded",
2994+
"agentic-gateway-methods",
2995+
"auto-reply-reply-commands-3",
2996+
]);
2997+
const selectedShards = createNodeTestShards().filter(
2998+
(shard) =>
2999+
shard.shardName.startsWith("core-unit-fast") || selectedShardNames.has(shard.shardName),
3000+
);
3001+
const expectedGroups = selectedShards.flatMap((shard) =>
3002+
shard.configs.map((config) => ({
3003+
configs: [config],
3004+
...(shard.env ? { env: shard.env } : {}),
3005+
...(shard.includePatterns ? { includePatterns: shard.includePatterns } : {}),
3006+
shard_name: `cache-warm:${shard.shardName}:${config}`,
3007+
})),
3008+
);
3009+
3010+
expect(groups).toEqual(expectedGroups);
3011+
expect(groups).toHaveLength(10);
29863012
expect(groups.every((group) => group.configs.length === 1)).toBe(true);
2987-
expect(new Set(groups.flatMap((group) => group.configs)).size).toBe(groups.length);
2988-
expect(groups.every((group) => group.shard_name === `cache-warm:${group.configs[0]}`)).toBe(
3013+
expect(new Set(groups.flatMap((group) => group.configs))).toHaveProperty("size", 9);
3014+
expect(new Set(groups.map((group) => group.shard_name))).toHaveProperty(
3015+
"size",
3016+
groups.length,
3017+
);
3018+
3019+
const coreStripeGroups = groups.filter(
3020+
(group) => group.configs[0] === "test/vitest/vitest.unit-fast.config.ts",
3021+
);
3022+
expect(coreStripeGroups).toHaveLength(2);
3023+
expect(coreStripeGroups.every((group) => (group.includePatterns?.length ?? 0) > 0)).toBe(
29893024
true,
29903025
);
3026+
const coreStripePatterns = coreStripeGroups.flatMap((group) => group.includePatterns ?? []);
3027+
expect(new Set(coreStripePatterns).size).toBe(coreStripePatterns.length);
3028+
3029+
const isolatedGroups = groups.filter((group) =>
3030+
group.shard_name.startsWith("cache-warm:core-unit-fast-isolated:"),
3031+
);
3032+
expect(isolatedGroups).toHaveLength(2);
3033+
expect(isolatedGroups.every((group) => group.includePatterns === undefined)).toBe(true);
3034+
expect(isolatedGroups.every((group) => group.env === undefined)).toBe(true);
3035+
3036+
const embeddedGroups = groups.filter((group) =>
3037+
group.shard_name.startsWith("cache-warm:agentic-agents-embedded:"),
3038+
);
3039+
expect(embeddedGroups).toHaveLength(4);
3040+
expect(
3041+
embeddedGroups.every(
3042+
(group) => group.env?.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS === "660000",
3043+
),
3044+
).toBe(true);
3045+
3046+
const gatewayGroups = groups.filter((group) =>
3047+
group.shard_name.startsWith("cache-warm:agentic-gateway-methods:"),
3048+
);
3049+
expect(gatewayGroups).toHaveLength(1);
3050+
expect(gatewayGroups[0]?.includePatterns).toBeUndefined();
3051+
expect(gatewayGroups[0]?.env).toBeUndefined();
3052+
3053+
const autoReplyGroups = groups.filter((group) =>
3054+
group.shard_name.startsWith("cache-warm:auto-reply-reply-commands-3:"),
3055+
);
3056+
expect(autoReplyGroups).toHaveLength(1);
3057+
expect(autoReplyGroups[0]?.includePatterns).toHaveLength(18);
3058+
expect(autoReplyGroups[0]?.env).toBeUndefined();
29913059
expect(seedEnv.OPENCLAW_NODE_TEST_PLAN_CONCURRENCY).toBe("1");
29923060
expect(seedEnv).not.toHaveProperty("OPENCLAW_NODE_TEST_CONFIGS_JSON");
29933061
} finally {

0 commit comments

Comments
 (0)