mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Live 8-core PR runs (`45667106472`, `45665466678`, `45668834558`) showed two critical-path stragglers on Rust- and TypeScript-heavy PRs: > 1. `Verify Paperclip Runner (rust)` (`206s` step): ran a redundant `cargo check --workspace` (`8.1s`) before `cargo test --release`, executed all 44 compiled Rust test binaries **sequentially** (`119.2s` vs `~50s` parallel!), and then re-invoked `cargo test --release` twice more for `check:conformance-parity` and `check:replay-parity` (`~8s`). > 2. `Typecheck + Release Registry` (`100s–147s` step): ran `CLI guidance safety` (`2.9s`) and `typecheck @paperclipai/paperclip-runner` (`5.6s`) serially before `prepare:runner-vendor`, ran `packages/paperclip-runner` `build` (`17.1s` hit / `51.0s` miss) serially across 12 steps, and scheduled lighter `7–10s` test projects ahead of the 4 `17–25s` server test layers. > - This pull request parallelizes `check:runner` (`run-check-runner.mjs`), `packages/paperclip-runner` `build` (`run-build.mjs`), and `scripts/ci-typecheck-lane.mjs` cleanly across 8 cores with full process-group signal cleanup (`stopActiveChildren`), exact `CARGO_BIN_EXE_*` / `CARGO_MANIFEST_DIR` fidelity, fail-closed parity assertions, exact `record-build-inputs --begin/--finish` bracketing, and 100% check parity. ## Linked Issues or Issue Description Refs #22804 **What existing behavior does this improve?** Execution wall-clock of `Verify Paperclip Runner (rust)`, `Typecheck + Release Registry`, and `Build` on 8-core runners. **Subsystem affected** packages/paperclip-runner/ and scripts/ — Rust test orchestration, Runner package build, and monorepo typecheck DAG **Current behavior** `check:runner` runs `cargo check`, 44 Rust test binaries sequentially, and 2 redundant parity re-runs; `packages/paperclip-runner` `build` executes 12 build/check steps serially; `ci-typecheck-lane.mjs` blocks `prepare:runner-vendor` behind serial `prepare` steps and under-utilizes 8-core / 32 GiB runners. **Proposed behavior** Execute `check:runner` with overlapped `acpx-profiles` / `cargo fmt --check` / `cargo test --release --no-run` followed by LPT-ordered concurrent execution of all 44 test binaries + `--doc` + fail-closed parity verification; parallelize `packages/paperclip-runner` `build` into race-free pre-dist / build / staging / post-dist phases; parallelize `CLI guidance safety` and `typecheck @paperclipai/paperclip-runner` in `ci-typecheck-lane.mjs`, LPT-order post-declaration tasks, and tune 8-core / >=24 GiB concurrency (`laneConcurrency: 8`, `serverDeclCheckers: 6`). ## What Changed - **`packages/paperclip-runner/scripts/run-check-runner.mjs` & `run-check-runner.test.mjs`:** - Overlaps `check:acpx-profiles` and `cargo fmt --all -- --check` with `cargo test --release --locked --workspace --no-run --message-format=json-render-diagnostics`. - Parses all 44 compiled test binaries with exact `CARGO_BIN_EXE_*` and per-crate `CARGO_MANIFEST_DIR`, executes them concurrently in LPT order (`codex_provider` first, `acpx_sidecar_stopped_time` isolated in its own detached process group with `--test-threads=1`, plus `cargo test --release --workspace --doc`). - Verifies both `runs_the_mock_core_path_with_stable_output` and `replay_fixture_parity` passed in the workspace run (failing closed if missing or ignored), eliminating 2 redundant `cargo test` re-invocations. - **`packages/paperclip-runner/scripts/run-build.mjs` & `run-build.test.mjs`:** - Preserves exact `record-build-inputs.mjs --begin` / `--finish` bracketing from the same parent PID, overlaps `eval-kernel + tsc`, `cargo build --release` (honoring `PAPERCLIP_RELEASE_RUNNER_ARTIFACTS_DIR`), and all 9 pure source-only pre-dist checks, stages disjoint `dist/` outputs in parallel, and runs all 5 `dist/`-importing checks (`check:runner-workflow-traceability`, `check:protocol-coverage`, `check:semantic-contracts`, `check:replay-goldens`, `check:semantic-action-catalog`) in parallel post-dist. - **`scripts/ci-typecheck-lane.mjs`, `scripts/__tests__/ci-typecheck-lane.test.mjs`, & `.github/scripts/tests/ci-plan.test.mjs`:** - Moved `CLI guidance safety` and `typecheck @paperclipai/paperclip-runner` (`needs: [PREPARE_RUNNER_VENDOR]` when `runServer`) out of serial `prepare` into `tasks`. - Ordered post-declaration tasks LPT (`tests/runner-e2e` -> 4 `server layer test-*` -> smaller projects) and tuned 8+ core / >=24 GiB runners to `laneConcurrency: 8`, `serverDeclCheckers: 6`. - **`packages/paperclip-runner/scripts/run-check-static.mjs`, `run-prep-tests.mjs`, & `package.json`:** - Shared `stopActiveChildren` / process-group runner helpers across `run-check-static.mjs`, `run-check-runner.mjs`, and `run-build.mjs`; wired `run-build.test.mjs` and `run-check-runner.test.mjs` into `PREP_TEST_FILES`. ## Verification - `node --test .github/scripts/tests/*.test.mjs scripts/__tests__/ci-typecheck-lane.test.mjs scripts/check-test-budget.test.mjs scripts/__tests__/runner-release-crate-cache.test.mjs` — **855/855 PASS** - `node --test scripts/run-check-runner.test.mjs scripts/run-build.test.mjs scripts/run-check-static.test.mjs scripts/build-inputs.test.mjs scripts/stage-runner-binary.test.mjs` (in `packages/paperclip-runner`) — **32/32 PASS** - `node scripts/check-test-budget.mjs --base origin/master` and `node scripts/check-maps.mjs` — **PASS** - Live Linux Cargo/Runner and monorepo Typecheck/Build execution verified end-to-end by PR CI. ## Risks - Low risk: all 9 pre-dist checks were verified pure source read-only while all 5 `dist/`-importing checks run strictly after `tsc` and asset staging; Rust parity checks fail closed if either test is absent or ignored; process-group cancellation ensures zero orphaned test processes. ## Model Used - Gemini 4 Neon (High) via Antigravity agent swarm (`server-prune`, `verifier`, `ci-pipeline`). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
372 lines
12 KiB
JavaScript
372 lines
12 KiB
JavaScript
import { spawn } from "node:child_process";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
const node = process.execPath;
|
|
|
|
const SYNTAX_CHECK_SCRIPTS = [
|
|
"scripts/protocol-contract.mjs",
|
|
"scripts/generate-protocol-manifest.mjs",
|
|
"scripts/generate-protocol-schema-module.mjs",
|
|
"scripts/generate-acpx-sidecar-contract.mjs",
|
|
"scripts/generate-replay-goldens.mjs",
|
|
"scripts/generate-semantic-action-catalog.mjs",
|
|
];
|
|
|
|
const PROTOCOL_TYPE_GENERATORS = [
|
|
"scripts/generate-protocol-schema-module.mjs",
|
|
"scripts/generate-acpx-sidecar-contract.mjs",
|
|
"scripts/generate-runtime-context-contract.mjs",
|
|
"scripts/generate-provider-failure-contract.mjs",
|
|
];
|
|
|
|
function cmd(label, command, args, cwd = packageRoot) {
|
|
return { label, command, args, cwd };
|
|
}
|
|
|
|
export function buildStaticCheckPlan() {
|
|
return [
|
|
{
|
|
name: "eval-kernel",
|
|
mode: "serial",
|
|
steps: [
|
|
cmd("check:eval-kernel", pnpm, ["--filter", "@paperclipai/paperclip-eval-kernel", "test"]),
|
|
],
|
|
},
|
|
{
|
|
name: "read-only-checks",
|
|
mode: "parallel",
|
|
steps: [
|
|
cmd("check:acpx-profiles", node, ["scripts/generate-acpx-profiles.mjs", "--check"]),
|
|
cmd("check:antigravity-models", node, ["scripts/generate-antigravity-models.mjs", "--check"]),
|
|
cmd("check:protocol-manifest", node, ["scripts/generate-protocol-manifest.mjs", "--check"]),
|
|
...SYNTAX_CHECK_SCRIPTS.map((script) => cmd(`syntax:${script}`, node, ["--check", script])),
|
|
...PROTOCOL_TYPE_GENERATORS.map((script) => cmd(`protocol-types:${script}`, node, [script, "--check"])),
|
|
],
|
|
},
|
|
{
|
|
name: "disjoint-builds",
|
|
mode: "parallel-chains",
|
|
chains: [
|
|
{
|
|
name: "typescript-and-replay-goldens",
|
|
steps: [
|
|
cmd("tsc:version", node, ["./node_modules/typescript/bin/tsc", "--version"]),
|
|
cmd("tsc:tsconfig", node, ["./node_modules/typescript/bin/tsc", "-p", "tsconfig.json"]),
|
|
cmd("tsc:surfaces", node, ["./node_modules/typescript/bin/tsc", "-p", "tsconfig.surfaces.json"]),
|
|
cmd("build:verified-entrypoints", node, ["scripts/build-verified-provider-entrypoints.mjs"]),
|
|
cmd("install:copilot-assets", node, ["scripts/install-copilot-assets.mjs"]),
|
|
cmd("check:replay-goldens", node, ["scripts/generate-replay-goldens.mjs", "--check"]),
|
|
],
|
|
},
|
|
{
|
|
name: "rust-binaries",
|
|
steps: [
|
|
cmd("cargo:debug-bins", "cargo", [
|
|
"build", "--manifest-path", "runner/Cargo.toml", "--locked", "--workspace", "--bins",
|
|
]),
|
|
cmd("cargo:release-runnerd", "cargo", [
|
|
"build", "--release", "--manifest-path", "runner/Cargo.toml", "--locked",
|
|
"-p", "paperclip-runner-core", "--bin", "paperclip-runnerd",
|
|
]),
|
|
],
|
|
},
|
|
{
|
|
name: "plugin-sdk-deps",
|
|
steps: [
|
|
cmd("plugin-sdk:ensure-build-deps", pnpm, ["--filter", "@paperclipai/plugin-sdk", "ensure-build-deps"]),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "stage-runner-binary",
|
|
mode: "serial",
|
|
steps: [
|
|
cmd("stage:runner-binary", node, ["scripts/stage-runner-binary.mjs"]),
|
|
],
|
|
},
|
|
{
|
|
name: "heavy-test-suites",
|
|
mode: "parallel",
|
|
steps: [
|
|
cmd("test:typescript:prep", node, ["scripts/run-prep-tests.mjs", "--skip-build"]),
|
|
cmd("check:api-authority", node, ["scripts/check-api-authority.mjs", "--skip-build"]),
|
|
],
|
|
},
|
|
];
|
|
}
|
|
|
|
const activeChildren = new Map();
|
|
const SIGNAL_EXIT_CODES = { SIGHUP: 129, SIGINT: 130, SIGTERM: 143 };
|
|
let cancelSignal = null;
|
|
let shutdownPromise = null;
|
|
|
|
function killProcessTree(child, signal, detached) {
|
|
if (detached && typeof child.pid === "number" && child.pid > 0) {
|
|
try {
|
|
process.kill(-child.pid, signal);
|
|
return;
|
|
} catch (error) {
|
|
if (error?.code === "ESRCH") return;
|
|
}
|
|
}
|
|
try {
|
|
child.kill(signal);
|
|
} catch {
|
|
}
|
|
}
|
|
|
|
function destroyPipes(child) {
|
|
try {
|
|
child.stdout?.destroy();
|
|
} catch {
|
|
}
|
|
try {
|
|
child.stderr?.destroy();
|
|
} catch {
|
|
}
|
|
}
|
|
|
|
export async function stopActiveChildren(signal = "SIGTERM", { graceMs = 5_000, forceGraceMs = 500 } = {}) {
|
|
const entries = [...activeChildren.entries()];
|
|
if (entries.length === 0) return;
|
|
for (const [child, entry] of entries) {
|
|
if (child.exitCode === null && child.signalCode === null) {
|
|
killProcessTree(child, signal, entry.detached);
|
|
}
|
|
}
|
|
const waitForAll = Promise.all(entries.map(([, entry]) => entry.done));
|
|
let timer;
|
|
const timedOut = await Promise.race([
|
|
waitForAll.then(() => false),
|
|
new Promise((resolvePromise) => {
|
|
timer = setTimeout(() => resolvePromise(true), graceMs);
|
|
timer.unref?.();
|
|
}),
|
|
]);
|
|
clearTimeout(timer);
|
|
if (!timedOut) return;
|
|
for (const [child, entry] of entries) {
|
|
killProcessTree(child, "SIGKILL", entry.detached);
|
|
destroyPipes(child);
|
|
}
|
|
let forceTimer;
|
|
await Promise.race([
|
|
waitForAll,
|
|
new Promise((resolvePromise) => {
|
|
forceTimer = setTimeout(resolvePromise, forceGraceMs);
|
|
forceTimer.unref?.();
|
|
}),
|
|
]);
|
|
clearTimeout(forceTimer);
|
|
for (const [, entry] of entries) {
|
|
entry.forceResolve();
|
|
}
|
|
}
|
|
|
|
function forwardSignal(signal) {
|
|
cancelSignal = signal;
|
|
if (shutdownPromise) return;
|
|
shutdownPromise = stopActiveChildren(signal).finally(() => {
|
|
process.exit(SIGNAL_EXIT_CODES[signal] ?? 128);
|
|
});
|
|
}
|
|
|
|
export function installSignalHandlers() {
|
|
process.on("SIGINT", forwardSignal);
|
|
process.on("SIGTERM", forwardSignal);
|
|
process.on("SIGHUP", forwardSignal);
|
|
}
|
|
|
|
export function uninstallSignalHandlers() {
|
|
process.removeListener("SIGINT", forwardSignal);
|
|
process.removeListener("SIGTERM", forwardSignal);
|
|
process.removeListener("SIGHUP", forwardSignal);
|
|
}
|
|
|
|
export function getShutdownPromise() {
|
|
return shutdownPromise;
|
|
}
|
|
|
|
export function runCommand(step, { bufferOutput = false, env = process.env, shell = false } = {}) {
|
|
if (cancelSignal) {
|
|
return Promise.resolve({
|
|
label: step.label,
|
|
code: SIGNAL_EXIT_CODES[cancelSignal] ?? 128,
|
|
durationMs: 0,
|
|
chunks: [],
|
|
});
|
|
}
|
|
const startedAt = Date.now();
|
|
const detached = process.platform !== "win32";
|
|
return new Promise((resolvePromise) => {
|
|
const child = spawn(step.command, step.args, {
|
|
cwd: step.cwd,
|
|
env,
|
|
shell,
|
|
detached,
|
|
stdio: bufferOutput ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
});
|
|
let resolveDone;
|
|
const done = new Promise((r) => {
|
|
resolveDone = r;
|
|
});
|
|
const chunks = [];
|
|
let settled = false;
|
|
const finish = (payload) => {
|
|
if (settled) return;
|
|
settled = true;
|
|
activeChildren.delete(child);
|
|
resolveDone();
|
|
resolvePromise(payload);
|
|
};
|
|
activeChildren.set(child, {
|
|
done,
|
|
detached,
|
|
forceResolve: () => finish({
|
|
label: step.label,
|
|
code: SIGNAL_EXIT_CODES[cancelSignal] ?? 128,
|
|
durationMs: Date.now() - startedAt,
|
|
chunks,
|
|
}),
|
|
});
|
|
if (bufferOutput) {
|
|
child.stdout.on("data", (chunk) => chunks.push({ stream: "stdout", chunk }));
|
|
child.stderr.on("data", (chunk) => chunks.push({ stream: "stderr", chunk }));
|
|
}
|
|
child.once("error", (error) => {
|
|
finish({
|
|
label: step.label,
|
|
code: 1,
|
|
durationMs: Date.now() - startedAt,
|
|
chunks,
|
|
error,
|
|
});
|
|
});
|
|
child.once("close", (code, signal) => {
|
|
finish({
|
|
label: step.label,
|
|
code: signal ? (SIGNAL_EXIT_CODES[signal] ?? 128) : (code ?? 1),
|
|
durationMs: Date.now() - startedAt,
|
|
chunks,
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function flushResult(result, prefix) {
|
|
for (const { stream, chunk } of result.chunks) {
|
|
process[stream].write(chunk);
|
|
}
|
|
if (result.error) {
|
|
console.error(`${prefix} ${result.label} failed to spawn: ${result.error.message}`);
|
|
}
|
|
}
|
|
|
|
async function runChain(chain, { bufferOutput = true, prefix = "[check:static]", verbosePhases = true } = {}) {
|
|
const results = [];
|
|
for (const step of chain.steps) {
|
|
const result = await runCommand(step, { bufferOutput, env: step.env ?? process.env, shell: Boolean(step.shell) });
|
|
results.push(result);
|
|
if (result.code !== 0) break;
|
|
}
|
|
const totalMs = results.reduce((sum, result) => sum + result.durationMs, 0);
|
|
const failed = results.find((result) => result.code !== 0);
|
|
if (verbosePhases) {
|
|
console.log(`${prefix} --- chain:${chain.name} (${(totalMs / 1000).toFixed(1)}s, exit=${failed?.code ?? 0}) ---`);
|
|
}
|
|
for (const result of results) flushResult(result, prefix);
|
|
return { name: chain.name, results, failed };
|
|
}
|
|
|
|
export async function executePhases(phases, { prefix = "[check:static]", verbosePhases = true } = {}) {
|
|
installSignalHandlers();
|
|
try {
|
|
for (const phase of phases) {
|
|
if (shutdownPromise) {
|
|
await shutdownPromise;
|
|
return;
|
|
}
|
|
const phaseStart = Date.now();
|
|
if (verbosePhases) console.log(`${prefix} phase=${phase.name} mode=${phase.mode}`);
|
|
if (phase.mode === "serial") {
|
|
for (const step of phase.steps) {
|
|
const result = await runCommand(step, { bufferOutput: false, env: step.env ?? process.env, shell: Boolean(step.shell) });
|
|
if (shutdownPromise) {
|
|
await shutdownPromise;
|
|
return;
|
|
}
|
|
if (result.code !== 0) {
|
|
console.error(`${prefix} FAILED ${result.label} (exit=${result.code})`);
|
|
process.exit(result.code);
|
|
}
|
|
}
|
|
} else if (phase.mode === "parallel") {
|
|
const bufferOutput = phase.steps.length > 1;
|
|
const results = await Promise.all(
|
|
phase.steps.map(async (step) => {
|
|
const result = await runCommand(step, { bufferOutput, env: step.env ?? process.env, shell: Boolean(step.shell) });
|
|
if (bufferOutput) {
|
|
if (verbosePhases) {
|
|
console.log(`${prefix} --- ${result.label} (${(result.durationMs / 1000).toFixed(1)}s, exit=${result.code}) ---`);
|
|
}
|
|
flushResult(result, prefix);
|
|
}
|
|
return result;
|
|
}),
|
|
);
|
|
if (shutdownPromise) {
|
|
await shutdownPromise;
|
|
return;
|
|
}
|
|
const failed = results.find((result) => result.code !== 0);
|
|
if (failed) {
|
|
console.error(`${prefix} FAILED ${failed.label} (exit=${failed.code})`);
|
|
process.exit(failed.code);
|
|
}
|
|
} else if (phase.mode === "parallel-chains") {
|
|
const chains = await Promise.all(phase.chains.map((chain) => runChain(chain, { bufferOutput: true, prefix, verbosePhases })));
|
|
if (shutdownPromise) {
|
|
await shutdownPromise;
|
|
return;
|
|
}
|
|
const firstFailure = chains.find((chain) => chain.failed)?.failed ?? null;
|
|
if (firstFailure) {
|
|
console.error(`${prefix} FAILED ${firstFailure.label} (exit=${firstFailure.code})`);
|
|
process.exit(firstFailure.code);
|
|
}
|
|
}
|
|
if (verbosePhases) console.log(`${prefix} phase=${phase.name} done (${((Date.now() - phaseStart) / 1000).toFixed(1)}s)`);
|
|
}
|
|
} finally {
|
|
uninstallSignalHandlers();
|
|
}
|
|
}
|
|
|
|
async function executePlan(phases) {
|
|
await executePhases(phases, { prefix: "[check:static]", verbosePhases: true });
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
const dryRun = args.includes("--dry-run");
|
|
const unknown = args.filter((arg) => arg !== "--dry-run");
|
|
if (unknown.length > 0) {
|
|
console.error(`[check:static] unrecognized argument(s): ${unknown.join(" ")}`);
|
|
process.exit(1);
|
|
}
|
|
const phases = buildStaticCheckPlan();
|
|
if (dryRun) {
|
|
console.log(JSON.stringify({ phases }, null, 2));
|
|
return;
|
|
}
|
|
await executePlan(phases);
|
|
}
|
|
|
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
await main();
|
|
}
|