mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-04 11:01:16 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Required CI checks protect its server and Runner contracts. > - Recent full runs waited on general server files and the final Runner lane. > - That Runner lane ran package tests before native server tests. > - PR jobs also rebuilt unchanged debug workspace binaries. > - This pull request overlaps those workloads and reuses exact trusted build inputs. > - The benefit is a shorter critical path with the same test coverage and AWS authorization. ## Linked Issues or Issue Description Refs #18544, #18773, #18774, #18798, #18799. **What existing behavior does this improve?** The wall time of required PR tests and the precision of affected-test selection. **Current behavior** General server and native files use two workers. The second Runner Vitest lane runs its package shard and then the native server group. Each Runner job compiles debug workspace units again. A Vite raw import also retains its consumer for unrelated source edits. **Proposed behavior** Use three isolated workers for general server files and four for native files. Reuse the two Runner slots for a complete package suite and a complete native server suite. Restore all debug binaries only on an exact input key. Record raw imports as explicit file inputs. ## What Changed - Separate the Runner package and native server workloads without adding CI jobs. Preserve the old command arguments for master-pinned workflows, local commands, and other shard counts. - Increase file workers while retaining fork isolation, serial cases, and the shared-database guard. - Add an exact debug workspace cache. Derive binary targets from Cargo. Include source, fixtures, generated inputs, manifests, compiler identity, flags, Cargo configuration, and checkout path in its key. Discard incomplete restores. Only verified master pushes can save it. - Keep older PR checkouts working when they lack the new cache helper. - Track Vite `?raw` imports as repository file inputs. Keep unknown loaders, untracked files, and opaque effects conservative. - Add cache and coverage guards and document the behavior. AWS runner authorization is unchanged. - Keep paired test benchmarking available when install hooks correctly disable materialized dependency reuse. The old benchmark asserted a cache hit in that safe fallback. - Wait for active dispatch work to finish before asserting idle reads. Analyze the two 16,400-row database fixtures before their queries so they have current planner statistics. Suppress only PostgreSQL notices inside the cleanup transaction to avoid logging every cascaded table; warnings/errors remain visible. Row counts, real queries, assertions, database reset, and timeouts remain unchanged. ## Verification - 196 affected CI tests passed, including routing, coverage, selection failure fallbacks, shared-database serialization, and existing/new cache guards. Final worker/cache adjustments also passed their focused checks. - `pnpm build` and `pnpm -r typecheck` passed locally. Full test coverage is being verified by the Linux CI profile; `pnpm test:run` was not repeated as a full serial local run. The paired CI benchmark passed. Both paired benchmarks passed, and full CI passed again after integrating newer master commits. The external Paperclip Review app is the only pending status. - Actual debug artifacts remained fresh after simulating checkout timestamps: Cargo completed in 0.82 seconds; the content key was unchanged. This is local reuse evidence, not a measured GitHub cache transfer. - Same real UI inventory for a retention-test-only change: 861 files; retained selection fell from 413 to 401. All 12 omitted files are raw-input consumers; edits to their inputs remain covered by regression tests. - The first local worker comparison is invalid. Development dependency links disappeared during its second run. The two-worker baseline also had two macOS path assertions in company-skills. Neither result is counted as a successful speedup. Dependencies were restored. A local repeat was interrupted before producing results. The completed Linux comparison below supplies the valid paired evidence. - [Paired Linux benchmark](https://github.com/paperclipai/paperclip/actions/runs/41671244016): baseline and candidate ran the same 113 general-server files and 1,777 cases on one host. Wall time fell from 381.29s to 346.89s (9.0%). Both exited successfully and file/case inventories matched exactly. The fixture command took 31.77s versus 28.65s. This is one sequential pair, excluding setup, queueing and the full CI critical path. - [Repeat paired Linux benchmark](https://github.com/paperclipai/paperclip/actions/runs/41675496862): the same 113 files and 1,974 cases took 485.06s in the baseline versus 368.54s in the candidate (24.0%). File and case inventories again matched exactly. The baseline includes newer master changes than the first pair, so these are two independent comparisons, not repeated timings of an identical tree. - Initial full AWS profile: package suite passed 4,891 tests (289 files, one skipped); native suite passed 172 tests (9 files, 12 pre-existing platform/feature skips). Native execution took 239.06 seconds; the older sample ran 165 native tests in 391.29 seconds. The package lane now takes 11m01 including setup and debug compilation. This is an indicative cross-run comparison, not a paired full-CI speedup claim. - The initial run failed two UI fixtures, one serialized inbox settlement assertion, and one dispatch idle assertion. The two UI failures reproduced locally. The fixes preserve authorization, admission, and zero-idle-read assertions. All four affected files passed locally: 48/48 tests. Token gates passed. All four also passed in the next AWS profile. That profile passed every other workload but timed out the 16,400-row keyed attention fixture at its existing 180s limit; this is accounted for by the explicit fixture-statistics change. Local focused comparisons pass both large cases before and after; their roughly 33s test execution is unchanged locally, so this is not claimed as an additional speed gain. A full local file run passed both large cases (7.57s / 18.05s) but hit the unchanged 30s teardown deadline on its first test while emitting thousands of cascade notices. Cleanup now suppresses those notices within its transaction; the complete file then passed 34/34 in 107.72s. The latest-head AWS run passed the previously failing shard: the keyed bulk case took 40.25s (previously exceeded 180s), the keyless case took 8.02s, and the complete attention file took 89.61s. The 16,400-row fixtures and original timeouts remain intact. - [Full CI profile before master integration](https://github.com/paperclipai/paperclip/actions/runs/41675497699) passed on commit `5858956d4ac2c99c911ad2447b63e1f8fc84e31e`, including all tests, build, typecheck and final verification. Greptile reviewed that exact commit at 5/5; the only actionable review thread is resolved. The separate Paperclip Review app is still queued. - [Final merged-head CI](https://github.com/paperclipai/paperclip/actions/runs/41678956312) passed on `499aa206a6e03bf8f3249692ea731367a000591d`: 48 successful jobs and one intentionally skipped file-selection job. Backup checkpoint qualification and legacy security status passed. Greptile reviewed this exact commit at 5/5. The PR is conflict-free; only the separate Paperclip Review app remains queued. - Integrated current master after #18798 and #18799 merged the inbox and UI fixture fixes separately. Preserved master's inbox settlement fix and verified its entire file (6/6 tests). Those three files are no longer part of this PR's diff. Removed the temporary `profile-ci` label after both successful benchmark pairs; the normal planner still schedules every job because the CI configuration changes are global inputs. - Second AWS profile: native tests took 229.97s with the same 172 passes / 12 skips; package tests took 427.44s with 4,891 passes / 10 skips. The complete package job took 10m44, including setup and 79s debug compilation. - The PR uses the trusted workflow from master. Candidate worker/layout code runs now; workflow-level debug restores begin after merge and the first successful master cache writer. ## Risks - Extra workers can expose load-sensitive tests. The final full CI profile passed, but one run is not a long-term flake-rate measurement. - The cache is an optimization only. Misses rebuild, and test commands still execute. A new Cargo workspace member requires a cache-contract review. - Compiler alternatives remain experiments. Required TypeScript checks are unchanged. Typechecker experiment: three sequential checks per tool on identical built projects, with TypeScript 7.0.2, Bun 1.4.4, and tsrs 0.20.1-ts7.1.0-beta. Median seconds (TypeScript / Bun / tsrs): shared 0.429 / 0.083 / 0.157; UI 2.554 / 0.390 / 0.740; server 9.949 / 1.194 / 1.782. TypeScript and Bun passed all three projects. All tools caught the same four deliberate assignment, property, nullability, and generic-constraint errors. tsrs reported one additional server TS2345 diagnostic in the run-dispatch adapter, so it did not pass the project comparison. These local compiler times exclude generation and build steps; they are not full CI savings. ## Model Used OpenAI GPT-6 Codex. Tool use and code execution assisted this change. The exact deployment identifier and context window are not exposed in this session. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
214 lines
9.3 KiB
JavaScript
214 lines
9.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// The Runner's own crate is the one thing the shared Rust dependency cache
|
|
// leaves out: rust-cache drops workspace crates when it saves, and a fresh
|
|
// checkout would invalidate cargo's mtime fingerprints for them anyway. So
|
|
// every CI build compiled `paperclip-runner-core` in release mode from
|
|
// scratch (28-49s per run on 2026-10-11) although 221 of the 239 master
|
|
// commits of the preceding week left its inputs untouched.
|
|
//
|
|
// This script backs a second, content-addressed cache that holds only that
|
|
// crate's release artifacts (about 70 MB). The master writer saves them
|
|
// under a key made from the compiler, the checkout root and a hash of every
|
|
// input the build reads; a pull request whose merge tree carries
|
|
// byte-identical inputs restores them. Cargo judges a workspace crate fresh
|
|
// only while no source is newer than its dep-info file, and GitHub's cache
|
|
// keeps the artifacts' original mtimes, so `mark-current` touches the
|
|
// restored set after the checkout. Any input change selects a different key,
|
|
// the restore misses, and cargo compiles exactly as it did before.
|
|
//
|
|
// Subcommands:
|
|
// paths print the cached paths, one per line (repo-relative globs)
|
|
// hashed-inputs print the hashFiles() patterns that make up the key
|
|
// scope print the compiler/checkout part of the key
|
|
// mark-current make a restored artifact set newer than the checkout, or
|
|
// discard an incomplete one so cargo rebuilds instead
|
|
import { execFileSync } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import { existsSync, readdirSync, rmSync, statSync, utimesSync, lstatSync } from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
export const RUNNER_PACKAGE = "packages/paperclip-runner";
|
|
const RELEASE_DIR = `${RUNNER_PACKAGE}/runner/target/release`;
|
|
|
|
// Everything cargo writes for the crate's release lib and bin units:
|
|
// fingerprints (both units share the package-named directory prefix), the
|
|
// lib's rlib/rmeta and dep-info, the bin and its dep-info under deps, and the
|
|
// uplifted executable the staging step copies into dist/bin.
|
|
export const CACHED_PATHS = [
|
|
`${RELEASE_DIR}/.fingerprint/paperclip-runner-core-*`,
|
|
`${RELEASE_DIR}/deps/libpaperclip_runner_core-*`,
|
|
`${RELEASE_DIR}/deps/paperclip_runner_core-*.d`,
|
|
`${RELEASE_DIR}/deps/paperclip_runnerd-*`,
|
|
`${RELEASE_DIR}/paperclip-runnerd`,
|
|
`${RELEASE_DIR}/paperclip-runnerd.d`,
|
|
];
|
|
|
|
// Every file the release build of the crate reads, as hashFiles() patterns:
|
|
// the toolchain pin, the manifests and lockfile, the crate sources, and the
|
|
// protocol schemas and fixtures the sources include with include_str!. The
|
|
// three fixture trees are read only by test builds, but hashing them costs
|
|
// nothing and keeps the include_str! guard test simple: every include in the
|
|
// crate, whatever its form, must land under one of these patterns.
|
|
export const HASHED_INPUTS = [
|
|
`${RUNNER_PACKAGE}/rust-toolchain.toml`,
|
|
`${RUNNER_PACKAGE}/acpx-profiles.json`,
|
|
`${RUNNER_PACKAGE}/antigravity-distributions.json`,
|
|
`${RUNNER_PACKAGE}/runner/Cargo.toml`,
|
|
`${RUNNER_PACKAGE}/runner/Cargo.lock`,
|
|
`${RUNNER_PACKAGE}/runner/crates/**`,
|
|
`${RUNNER_PACKAGE}/protocol/**`,
|
|
`${RUNNER_PACKAGE}/test-fixtures/**`,
|
|
`${RUNNER_PACKAGE}/test/fixtures/**`,
|
|
"tests/runner-e2e/fixtures/**",
|
|
];
|
|
|
|
// A restored set is usable only when both units are complete: everything
|
|
// cargo's freshness check reads for a unit (the fingerprint hash and the
|
|
// dep-info it compares source mtimes against) and every output it checks for
|
|
// (the lib's rlib and rmeta, the bin under deps). Measured with cargo 1.97.1:
|
|
// without any one of these it recompiles the unit; without the `.json`
|
|
// fingerprint records, rustc's `.d` files or the uplifted binary and its `.d`
|
|
// it reports the crate fresh and recreates the uplifted copy from deps.
|
|
// Anything less than this set is discarded, with the missing file named in
|
|
// the job log, so cargo sees a plain miss rather than a half-restored crate.
|
|
export const REQUIRED = [
|
|
{ label: "the lib fingerprint hash", glob: `${RELEASE_DIR}/.fingerprint/paperclip-runner-core-*/lib-paperclip_runner_core` },
|
|
{ label: "the lib dep-info", glob: `${RELEASE_DIR}/.fingerprint/paperclip-runner-core-*/dep-lib-paperclip_runner_core` },
|
|
{ label: "the lib rlib", glob: `${RELEASE_DIR}/deps/libpaperclip_runner_core-*.rlib` },
|
|
{ label: "the lib rmeta", glob: `${RELEASE_DIR}/deps/libpaperclip_runner_core-*.rmeta` },
|
|
{ label: "the bin fingerprint hash", glob: `${RELEASE_DIR}/.fingerprint/paperclip-runner-core-*/bin-paperclip-runnerd` },
|
|
{ label: "the bin dep-info", glob: `${RELEASE_DIR}/.fingerprint/paperclip-runner-core-*/dep-bin-paperclip-runnerd` },
|
|
{ label: "the bin under deps", glob: `${RELEASE_DIR}/deps/paperclip_runnerd-*`, exclude: /\.d$/ },
|
|
];
|
|
|
|
const SCHEMA = "paperclip.runner-release-crate.v1";
|
|
|
|
function keySafe(value) {
|
|
return String(value).replace(/[^A-Za-z0-9._-]+/g, "_");
|
|
}
|
|
|
|
/**
|
|
* The compiler and checkout part of the cache key. The compiler decides the
|
|
* artifacts' metadata hashes; the checkout root is baked into cargo's
|
|
* dep-info for the protocol files the sources include by relative path, so an
|
|
* entry written under one root is useless under another (the RunsOn fleets
|
|
* check out under /home/runner/_work, GitHub-hosted runners under
|
|
* /home/runner/work). Hashing the root into the key turns that into a plain
|
|
* miss instead of a restore cargo then throws away.
|
|
*/
|
|
export function computeScope({ workspace = process.env.GITHUB_WORKSPACE ?? process.cwd(), rustcVersion = readRustcVersion() } = {}) {
|
|
const root = createHash("sha256").update(path.resolve(workspace)).digest("hex").slice(0, 12);
|
|
return `${keySafe(os.platform())}-${keySafe(os.arch())}-${keySafe(rustcVersion)}-${root}`;
|
|
}
|
|
|
|
export function readRustcVersion(env = process.env, cwd = process.cwd()) {
|
|
let output;
|
|
try {
|
|
output = execFileSync("rustc", ["--version", "--verbose"], { encoding: "utf8", env, cwd });
|
|
} catch {
|
|
return "no-rustc";
|
|
}
|
|
const field = (name) => output.match(new RegExp(`^${name}: (.+)$`, "m"))?.[1]?.trim() ?? "unknown";
|
|
return `${field("release")}-${field("commit-hash").slice(0, 9)}-${field("host")}`;
|
|
}
|
|
|
|
function expandGlob(root, pattern) {
|
|
// Patterns only ever use `*` inside a single path segment.
|
|
const segments = pattern.split("/");
|
|
let current = [root];
|
|
for (const segment of segments) {
|
|
const next = [];
|
|
for (const base of current) {
|
|
if (!segment.includes("*")) {
|
|
const candidate = path.join(base, segment);
|
|
if (existsSync(candidate)) next.push(candidate);
|
|
continue;
|
|
}
|
|
let entries;
|
|
try {
|
|
entries = readdirSync(base);
|
|
} catch {
|
|
continue;
|
|
}
|
|
const matcher = new RegExp(`^${segment.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*")}$`);
|
|
for (const entry of entries) {
|
|
if (matcher.test(entry)) next.push(path.join(base, entry));
|
|
}
|
|
}
|
|
current = next;
|
|
}
|
|
return current.sort();
|
|
}
|
|
|
|
function walk(target, visit) {
|
|
const info = lstatSync(target);
|
|
visit(target, info);
|
|
if (info.isDirectory()) {
|
|
for (const entry of readdirSync(target)) walk(path.join(target, entry), visit);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Touch every restored artifact so cargo's freshness check, which compares
|
|
* each source's mtime against the unit's dep-info, sees the checkout as
|
|
* older than the build. When the set is incomplete, remove whatever was
|
|
* restored and report it: cargo then compiles the crate as on a miss.
|
|
*/
|
|
export function markCurrent({ root = process.env.GITHUB_WORKSPACE ?? process.cwd(), now = new Date(),
|
|
required = REQUIRED, cachedPaths = CACHED_PATHS, schema = SCHEMA } = {}) {
|
|
const missing = required.find(({ glob, exclude }) => expandGlob(root, glob).filter((entry) => !exclude?.test(entry)).length === 0);
|
|
const matched = cachedPaths.flatMap((pattern) => expandGlob(root, pattern));
|
|
if (missing) {
|
|
for (const target of matched) rmSync(target, { recursive: true, force: true });
|
|
return { schema, action: "discarded", reason: `incomplete: ${missing.label} is missing`, removed: matched.length };
|
|
}
|
|
let files = 0;
|
|
let bytes = 0;
|
|
const seen = new Set();
|
|
for (const target of matched) {
|
|
walk(target, (entry, info) => {
|
|
if (info.isSymbolicLink()) return;
|
|
utimesSync(entry, now, now);
|
|
if (info.isFile()) {
|
|
files += 1;
|
|
// The uplifted binary is a hard link to the one under deps.
|
|
const { ino, size } = statSync(entry);
|
|
if (!seen.has(ino)) {
|
|
seen.add(ino);
|
|
bytes += size;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return { schema, action: "marked", files, bytes };
|
|
}
|
|
|
|
function main(argv) {
|
|
const [command] = argv;
|
|
switch (command) {
|
|
case "paths":
|
|
process.stdout.write(`${CACHED_PATHS.join("\n")}\n`);
|
|
return 0;
|
|
case "hashed-inputs":
|
|
process.stdout.write(`${HASHED_INPUTS.join("\n")}\n`);
|
|
return 0;
|
|
case "scope":
|
|
process.stdout.write(`${computeScope()}\n`);
|
|
return 0;
|
|
case "mark-current": {
|
|
const result = markCurrent();
|
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
return 0;
|
|
}
|
|
default:
|
|
process.stderr.write("usage: runner-release-crate-cache.mjs <paths|hashed-inputs|scope|mark-current>\n");
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
process.exitCode = main(process.argv.slice(2));
|
|
}
|