Skip to content

Commit d4c7873

Browse files
committed
perf(ci): cache declarations and remove test import tail
1 parent c2cc95b commit d4c7873

10 files changed

Lines changed: 240 additions & 71 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,9 @@ jobs:
10201020
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
10211021
with:
10221022
path: .artifacts/build-all-cache
1023-
key: ${{ runner.os }}-build-all-v3-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'npm-shrinkwrap.json', 'packages/plugin-sdk/package.json', 'packages/llm-core/package.json', 'packages/model-catalog-core/package.json', 'packages/memory-host-sdk/package.json', 'scripts/build-all.mjs', 'scripts/write-plugin-sdk-entry-dts.ts', 'scripts/lib/plugin-sdk-entries.mjs', 'tsconfig.json', 'tsconfig.plugin-sdk.dts.json', 'src/plugin-sdk/**', 'packages/llm-core/src/**', 'packages/model-catalog-core/src/**', 'packages/memory-host-sdk/src/**', 'src/types/**', 'src/video-generation/dashscope-compatible.ts', 'src/video-generation/types.ts', 'scripts/copy-export-html-templates.ts', 'scripts/lib/copy-assets.ts', 'src/auto-reply/reply/export-html/**') }}
1023+
key: ${{ runner.os }}-build-all-v4-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'npm-shrinkwrap.json', 'scripts/build-all.mjs', 'scripts/write-plugin-sdk-entry-dts.ts', 'scripts/lib/plugin-sdk-entries.mjs', 'scripts/lib/plugin-sdk-entrypoints.json', 'scripts/lib/plugin-sdk-private-local-only-subpaths.json', 'scripts/lib/plugin-sdk-deprecated-public-subpaths.json', 'scripts/lib/plugin-sdk-deprecated-barrel-subpaths.json', 'scripts/copy-export-html-templates.ts', 'scripts/lib/copy-assets.ts', 'tsconfig.json', 'tsconfig.plugin-sdk.dts.json', 'src/**', 'packages/**', '!src/**/dist/**', '!src/**/node_modules/**', '!packages/**/dist/**', '!packages/**/node_modules/**') }}
10241024
restore-keys: |
1025-
${{ runner.os }}-build-all-v3-
1025+
${{ runner.os }}-build-all-v4-
10261026
10271027
- name: Restore dist build cache
10281028
id: dist_build_cache

docs/ci.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ The slowest Node test families are split or balanced so each job stays small wit
112112
- Agentic gateway/server (control-plane) configs split across chat, auth, model, HTTP/plugin, runtime, and startup lanes instead of waiting on built artifacts.
113113
- Normal CI packs only isolated infra include-pattern shards into deterministic bundles of at most 64 test files, reducing the Node matrix without merging non-isolated command/cron, stateful agents-core, or gateway/server suites. Heavy fixed suites stay on 8 vCPU while the bundled and lower-weight lanes use 4 vCPU.
114114
- 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, manual dispatches, and release gates retain the full matrix because canceled superseded `main` runs make a single-push diff insufficient as integration proof.
115-
- The full Node matrix admits the consistently slow serial tooling and auto-reply command shards first. This keeps the 28-job cap while preventing short alphabetical groups from pushing critical-path work into a later wave.
115+
- 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.
116116
- 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.
117117
- Linux Node shard jobs persist Vitest's experimental filesystem module cache. Trusted Blacksmith jobs use PR-scoped writable overlays seeded from the protected snapshot only when their transform-input generations match; GitHub-hosted and fork jobs use an `actions/cache` fallback with coarse restore prefixes. The planner marks the broad `core-unit-fast` graph as the single writer without coupling cache ownership to matrix order, while every other job restores a private read-only clone. Concurrent Vitest workers retain separate live directories. A transform-input fingerprint clears incompatible lockfile, package, tsconfig, and Vitest-config generations inside stable sticky keys. Only the writer scans and prunes the cache to 75% after it exceeds 2 GiB. A non-cancelling daily or default-branch repository-dispatch warmer prevents rapid `main` pushes from starving the protected seed, and closed PR cache archives are deleted.
118118
- Node shard and build-artifact jobs also restore Node's portable on-disk compile cache. Independent `test` and `build` namespaces prevent their writers from replacing each other's snapshots: the scheduled test warmer owns the protected test seed, while `build-artifacts` publishes the protected build seed only from trusted `main` pushes. PR jobs read protected snapshots without publishing feature-branch bytecode; fallback archives remain PR-scoped. 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.
119+
- 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.
119120
- `check-additional-*` stripes the supplemental boundary guard list (`scripts/run-additional-boundary-checks.mjs`) into one prompt-heavy shard (`check-additional-boundaries-a`, which includes the Codex prompt snapshot drift check) and one combined shard for the remaining stripes (`check-additional-boundaries-bcd`), each running independent guards concurrently and printing per-check timings. Package-boundary compile/canary work stays together, and runtime topology architecture runs separately from the gateway watch coverage embedded in `build-artifacts`.
120121
- Gateway watch, channel tests, and the core support-boundary shard run concurrently inside `build-artifacts` after `dist/` and `dist-runtime/` are already built.
121122

scripts/build-all.mjs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,50 @@ import { resolvePnpmRunner } from "./pnpm-runner.mjs";
1313

1414
const nodeBin = process.execPath;
1515
const FULL_GIT_COMMIT_RE = /^[0-9a-f]{40}$/iu;
16-
const BUILD_CACHE_VERSION = 3;
16+
const BUILD_CACHE_VERSION = 4;
1717
const PLUGIN_SDK_ENTRY_DTS_CACHE_ENV = [
1818
"OPENCLAW_BUILD_PRIVATE_QA",
1919
"OPENCLAW_PLUGIN_SDK_CANONICAL_DTS",
2020
];
21-
const PLUGIN_SDK_ENTRY_DTS_CACHE_INPUTS = [
21+
const PLUGIN_SDK_ENTRY_DTS_SHARED_CACHE_INPUTS = [
2222
"scripts/write-plugin-sdk-entry-dts.ts",
2323
"scripts/lib/plugin-sdk-entries.mjs",
2424
"scripts/lib/plugin-sdk-entrypoints.json",
2525
"scripts/lib/plugin-sdk-private-local-only-subpaths.json",
2626
"scripts/lib/plugin-sdk-deprecated-public-subpaths.json",
2727
"scripts/lib/plugin-sdk-deprecated-barrel-subpaths.json",
28+
];
29+
const PLUGIN_SDK_ENTRY_DTS_CACHE_INPUTS = [
30+
...PLUGIN_SDK_ENTRY_DTS_SHARED_CACHE_INPUTS,
2831
{ path: "dist/plugin-sdk", extensions: [".d.ts"], recursive: false },
2932
];
33+
const PLUGIN_SDK_SELF_BUILT_ENTRY_DTS_CACHE_INPUTS = [
34+
...PLUGIN_SDK_ENTRY_DTS_SHARED_CACHE_INPUTS,
35+
"package.json",
36+
"pnpm-lock.yaml",
37+
"npm-shrinkwrap.json",
38+
"tsconfig.json",
39+
"tsconfig.plugin-sdk.dts.json",
40+
{
41+
path: "src",
42+
extensions: [".ts", ".tsx", ".mts", ".cts", ".json"],
43+
excludeDirectories: ["dist", "node_modules"],
44+
},
45+
{
46+
path: "packages",
47+
extensions: [".ts", ".tsx", ".mts", ".cts", ".json"],
48+
excludeDirectories: ["dist", "node_modules"],
49+
},
50+
];
3051
const PLUGIN_SDK_ENTRY_DTS_CACHE_OUTPUTS = [
3152
"dist/plugin-sdk/webhook-path.js",
3253
"dist/plugin-sdk/.boundary-entry-shims.stamp",
3354
...pluginSdkEntrypoints.map((entry) => `packages/plugin-sdk/dist/src/plugin-sdk/${entry}.d.ts`),
3455
];
56+
const PLUGIN_SDK_SELF_BUILT_ENTRY_DTS_CACHE_OUTPUTS = [
57+
{ path: "dist/plugin-sdk", extensions: [".d.ts"], recursive: false },
58+
...PLUGIN_SDK_ENTRY_DTS_CACHE_OUTPUTS,
59+
];
3560
const PNPM_STEP_NODE_FALLBACKS = new Map([
3661
["plugins:assets:build", ["scripts/bundled-plugin-assets.mjs", "--phase", "build"]],
3762
["plugins:assets:copy", ["scripts/bundled-plugin-assets.mjs", "--phase", "copy"]],
@@ -275,14 +300,18 @@ export function resolveBuildAllSteps(profile = "full") {
275300
}
276301
const mergedEnv = Object.assign({}, step.env, env);
277302
const merged = Object.assign({}, step, { env: mergedEnv });
278-
// Self-built plugin-sdk declarations depend on the whole SDK source
279-
// graph, which the canonical-mode cache inputs do not cover; a cache hit
280-
// here would restore stale declarations after source changes.
303+
// Self-built declarations need both the complete repository-owned type
304+
// graph and the flat declarations that this step generates after tsdown
305+
// clears dist. Canonical mode keeps its narrower generated-dts cache.
281306
if (
282307
step.label === "write-plugin-sdk-entry-dts" &&
283308
mergedEnv.OPENCLAW_PLUGIN_SDK_CANONICAL_DTS !== "1"
284309
) {
285-
delete merged.cache;
310+
merged.cache = {
311+
...step.cache,
312+
inputs: PLUGIN_SDK_SELF_BUILT_ENTRY_DTS_CACHE_INPUTS,
313+
outputs: PLUGIN_SDK_SELF_BUILT_ENTRY_DTS_CACHE_OUTPUTS,
314+
};
286315
}
287316
return merged;
288317
});
@@ -396,6 +425,10 @@ function cacheEntryIncludesFile(entry, filePath) {
396425
return entry.extensions.some((extension) => filePath.endsWith(extension));
397426
}
398427

428+
function cacheEntryExcludesDirectory(entry, name) {
429+
return entry.excludeDirectories?.includes(name) ?? false;
430+
}
431+
399432
function listFilesRecursively(rootPath, fsImpl, cacheEntry = { path: rootPath }) {
400433
let stat;
401434
try {
@@ -417,6 +450,9 @@ function listFilesRecursively(rootPath, fsImpl, cacheEntry = { path: rootPath })
417450
continue;
418451
}
419452
const entryPath = path.join(rootPath, dirent.name);
453+
if (dirent.isDirectory() && cacheEntryExcludesDirectory(cacheEntry, dirent.name)) {
454+
continue;
455+
}
420456
if (dirent.isDirectory() && recursive) {
421457
out.push(...listFilesRecursively(entryPath, fsImpl, cacheEntry));
422458
} else if (dirent.isFile() && cacheEntryIncludesFile(cacheEntry, entryPath)) {

scripts/lib/ci-node-test-plan.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ const FULL_NODE_TEST_ADMISSION_PRIORITY = new Map([
205205
["auto-reply-reply-commands-1", 1],
206206
["auto-reply-reply-commands-2", 1],
207207
["auto-reply-reply-commands-3", 1],
208+
// Start the broad cache writer in the first admission wave so later jobs
209+
// can reuse its protected transform snapshot on the next run.
210+
["core-unit-fast", 1],
208211
]);
209212
// Commands and cron run non-isolated, so keep their split shards as separate
210213
// processes. Combining their include lists can retain test state across groups.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Keep command precedence inspectable without loading every handler module.
2+
// The runtime map must cover this complete union before it can build the list.
3+
export const commandHandlerOrder = [
4+
// Plugin text commands must win before built-in auth routing handles /login.
5+
"plugin",
6+
"login",
7+
"dock",
8+
"btw",
9+
"bash",
10+
"activation",
11+
"send-policy",
12+
"fast",
13+
"usage",
14+
"session",
15+
"restart",
16+
"tts",
17+
"help",
18+
"commands-list",
19+
// Keep deterministic /skill usage before broader tool/status fallthrough.
20+
"skill-usage",
21+
"tools",
22+
"status",
23+
"goal",
24+
"learn",
25+
"name",
26+
"diagnostics",
27+
"tasks",
28+
"steer",
29+
"allowlist",
30+
"approve",
31+
"context",
32+
"export-session",
33+
"export-trajectory",
34+
"whoami",
35+
"system-agent",
36+
"subagents",
37+
"acp",
38+
"mcp",
39+
"plugins",
40+
"config",
41+
"debug",
42+
"models",
43+
"stop",
44+
"compact",
45+
"abort-trigger",
46+
] as const;
47+
48+
export type CommandHandlerId = (typeof commandHandlerOrder)[number];
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
// Registration proof for the full command-handler barrel. Keep barrel-loading
2-
// assertions here so narrow per-command tests do not import every handler.
31
import { describe, expect, it } from "vitest";
4-
import { loadCommandHandlers } from "./commands-handlers.runtime.js";
5-
import { handleLoginCommand } from "./commands-login.js";
6-
import { handleNameCommand } from "./commands-name.js";
7-
import { handlePluginCommand } from "./commands-plugin.js";
2+
import { commandHandlerOrder } from "./commands-handlers.order.js";
83

94
describe("command handler registration", () => {
105
it("registers built-in handlers in the runtime handler list", () => {
11-
const handlers = loadCommandHandlers();
12-
expect(handlers).toContain(handleNameCommand);
13-
expect(handlers).toContain(handleLoginCommand);
6+
expect(commandHandlerOrder).toContain("name");
7+
expect(commandHandlerOrder).toContain("login");
8+
expect(new Set(commandHandlerOrder).size).toBe(commandHandlerOrder.length);
149
});
1510

1611
it("keeps plugin text commands ahead of built-in /login", () => {
17-
const handlers = loadCommandHandlers();
18-
expect(handlers.indexOf(handlePluginCommand)).toBeLessThan(
19-
handlers.indexOf(handleLoginCommand),
12+
expect(commandHandlerOrder.indexOf("plugin")).toBeLessThan(
13+
commandHandlerOrder.indexOf("login"),
2014
);
2115
});
2216
});

src/auto-reply/reply/commands-handlers.runtime.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { handleContextCommand } from "./commands-context-command.js";
1010
import { handleDiagnosticsCommand } from "./commands-diagnostics.js";
1111
import { handleDockCommand } from "./commands-dock.js";
1212
import { handleGoalCommand } from "./commands-goal.js";
13+
import { commandHandlerOrder, type CommandHandlerId } from "./commands-handlers.order.js";
1314
import {
1415
handleCommandsListCommand,
1516
handleExportTrajectoryCommand,
@@ -44,49 +45,49 @@ import { handleTtsCommands } from "./commands-tts.js";
4445
import type { CommandHandler } from "./commands-types.js";
4546
import { handleWhoamiCommand } from "./commands-whoami.js";
4647

48+
const commandHandlersById = {
49+
acp: handleAcpCommand,
50+
activation: handleActivationCommand,
51+
allowlist: handleAllowlistCommand,
52+
approve: handleApproveCommand,
53+
"abort-trigger": handleAbortTrigger,
54+
bash: handleBashCommand,
55+
btw: handleBtwCommand,
56+
"commands-list": handleCommandsListCommand,
57+
compact: handleCompactCommand,
58+
config: handleConfigCommand,
59+
context: handleContextCommand,
60+
debug: handleDebugCommand,
61+
diagnostics: handleDiagnosticsCommand,
62+
dock: handleDockCommand,
63+
"export-session": handleExportSessionCommand,
64+
"export-trajectory": handleExportTrajectoryCommand,
65+
fast: handleFastCommand,
66+
goal: handleGoalCommand,
67+
help: handleHelpCommand,
68+
learn: handleLearnCommand,
69+
login: handleLoginCommand,
70+
mcp: handleMcpCommand,
71+
models: handleModelsCommand,
72+
name: handleNameCommand,
73+
plugin: handlePluginCommand,
74+
plugins: handlePluginsCommand,
75+
restart: handleRestartCommand,
76+
"send-policy": handleSendPolicyCommand,
77+
session: handleSessionCommand,
78+
"skill-usage": handleSkillCommandUsage,
79+
status: handleStatusCommand,
80+
steer: handleSteerCommand,
81+
stop: handleStopCommand,
82+
subagents: handleSubagentsCommand,
83+
"system-agent": handleSystemAgentCommand,
84+
tasks: handleTasksCommand,
85+
tools: handleToolsCommand,
86+
tts: handleTtsCommands,
87+
usage: handleUsageCommand,
88+
whoami: handleWhoamiCommand,
89+
} satisfies Record<CommandHandlerId, CommandHandler>;
90+
4791
export function loadCommandHandlers(): CommandHandler[] {
48-
return [
49-
handlePluginCommand,
50-
handleLoginCommand,
51-
handleDockCommand,
52-
handleBtwCommand,
53-
handleBashCommand,
54-
handleActivationCommand,
55-
handleSendPolicyCommand,
56-
handleFastCommand,
57-
handleUsageCommand,
58-
handleSessionCommand,
59-
handleRestartCommand,
60-
handleTtsCommands,
61-
handleHelpCommand,
62-
handleCommandsListCommand,
63-
// Keep deterministic /skill usage on the native command path before the
64-
// broader tool/status handlers can fall through to an agent run.
65-
handleSkillCommandUsage,
66-
handleToolsCommand,
67-
handleStatusCommand,
68-
handleGoalCommand,
69-
handleLearnCommand,
70-
handleNameCommand,
71-
handleDiagnosticsCommand,
72-
handleTasksCommand,
73-
handleSteerCommand,
74-
handleAllowlistCommand,
75-
handleApproveCommand,
76-
handleContextCommand,
77-
handleExportSessionCommand,
78-
handleExportTrajectoryCommand,
79-
handleWhoamiCommand,
80-
handleSystemAgentCommand,
81-
handleSubagentsCommand,
82-
handleAcpCommand,
83-
handleMcpCommand,
84-
handlePluginsCommand,
85-
handleConfigCommand,
86-
handleDebugCommand,
87-
handleModelsCommand,
88-
handleStopCommand,
89-
handleCompactCommand,
90-
handleAbortTrigger,
91-
];
92+
return commandHandlerOrder.map((id) => commandHandlersById[id]);
9293
}

0 commit comments

Comments
 (0)