mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 06:50:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - `docker.yml` and `docker-merge-group.yml` bundle the native macOS SSH runtime produced by `macos-runner-runtime.yml`, reusing a cached artifact by inputs digest when possible > - `scripts/macos-runner-runtime-cache.mjs` only reused an artifact when the entire `docker.yml` run concluded `success` > - Whenever a `master` `docker.yml` run was cancelled downstream (e.g., on a flaky post-merge test shard) after both `macos_runner_runtime / build` and `verify_linux_controller` already passed, the next build threw away the verified artifact and rebuilt from scratch for ~9.5 minutes on `macos-15` before `build-and-push` could start > - This pull request checks job-level verification (`macos_runner_runtime / build` and `macos_runner_runtime / verify_linux_controller` both `completed` + `success`) on trusted `master` `docker.yml` runs when the overall run did not conclude `success` > - The benefit is that `macos_runner_runtime` stays on its ~1m cache-hit path instead of repeatedly burning ~9.5m on the `docker.yml` critical path ## Linked Issues or Issue Description **What happened?** `scripts/macos-runner-runtime-cache.mjs` discards already-verified macOS runtime artifacts from `master` `docker.yml` runs whenever the workflow is cancelled or fails downstream, causing repeated ~9.5m `macos-15` rebuilds before `build-and-push` can begin. **Expected behavior** Keep the exact trust boundary (`paperclipai/paperclip`, `.github/workflows/docker.yml`, `event === "push"`, `head_branch === "master"`, 40-hex `head_sha`) and reuse the verified artifact either when the overall run concluded `success` (fast path) or when both `macos_runner_runtime / build` and `macos_runner_runtime / verify_linux_controller` concluded `success` in that run. **Steps to reproduce** 1. Merge a commit to `master` where `macos_runner_runtime / build` and `macos_runner_runtime / verify_linux_controller` succeed, then an unrelated downstream check cancels `docker.yml`. 2. Merge the next commit with identical Runner inputs. 3. Observe `Find an identical runtime from a successful master image build` miss and rebuild the macOS binary and provider pack from scratch on `macos-15`. ## What Changed - `scripts/macos-runner-runtime-cache.mjs`: add `isTrustedMacRuntimeWorkflowRun` and `hasVerifiedMacRuntimeJobs`, check job-level success on trusted `master` `docker.yml` runs whose overall conclusion is not `success`, and inspect up to 10 unexpired matching artifacts. - `scripts/macos-runner-runtime-cache.test.mjs`: add unit tests verifying reuse from a master run cancelled downstream when both macOS jobs succeeded and rejection when either job is incomplete, cancelled, or failed. ## Verification - `node --test scripts/macos-runner-runtime-cache.test.mjs scripts/macos-runner-runtime.test.mjs`: 12/12 passed. ## Risks - Low risk. Trust boundary stays strictly restricted to canonical `master` `push` runs of `.github/workflows/docker.yml`, requires both the macOS build/qualification job and Linux controller verification job to have succeeded, and the consuming run still verifies the downloaded artifact in `verify_linux_controller`. ## Model Used - Google Antigravity agent (Gemini / Antigravity coding harness with shell execution and tool use). ## 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
70 lines
3.5 KiB
JavaScript
70 lines
3.5 KiB
JavaScript
import { createHash } from "node:crypto";
|
|
import { appendFileSync, readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { computeBuildInputsDigest } from "../packages/paperclip-runner/scripts/build-inputs.mjs";
|
|
|
|
export function macRuntimeInputsDigest(root) {
|
|
const hash = createHash("sha256").update(computeBuildInputsDigest(root).digest);
|
|
for (const file of [".github/workflows/macos-runner-runtime.yml", "scripts/macos-runner-runtime.mjs", "scripts/macos-runner-runtime-cache.mjs"]) {
|
|
hash.update(`\0${file}\0`).update(readFileSync(resolve(root, file)));
|
|
}
|
|
return `sha256:${hash.digest("hex")}`;
|
|
}
|
|
|
|
const REQUIRED_VERIFIED_JOB_NAMES = [
|
|
"macos_runner_runtime / build",
|
|
"macos_runner_runtime / verify_linux_controller",
|
|
];
|
|
|
|
export function isTrustedMacRuntimeWorkflowRun(run, repository) {
|
|
return run?.repository?.full_name === repository && run.path === ".github/workflows/docker.yml"
|
|
&& run.event === "push" && run.head_branch === "master"
|
|
&& /^[a-f0-9]{40}$/.test(run.head_sha ?? "");
|
|
}
|
|
|
|
export function isTrustedMacRuntimeProducer(run, repository) {
|
|
return isTrustedMacRuntimeWorkflowRun(run, repository) && run.conclusion === "success";
|
|
}
|
|
|
|
export function hasVerifiedMacRuntimeJobs(jobs) {
|
|
if (!Array.isArray(jobs)) return false;
|
|
return REQUIRED_VERIFIED_JOB_NAMES.every(name =>
|
|
jobs.some(job => job?.name === name && job.status === "completed" && job.conclusion === "success"),
|
|
);
|
|
}
|
|
|
|
export async function findMacRuntimeArtifact({ digest, repository, token, fetchImpl = fetch }) {
|
|
if (!token || repository !== "paperclipai/paperclip") return null;
|
|
const name = `macos-runner-runtime-${digest.slice(7)}`;
|
|
const get = async path => {
|
|
const response = await fetchImpl(`https://api.github.com/repos/${repository}/${path}`, {
|
|
headers: { authorization: `Bearer ${token}`, accept: "application/vnd.github+json" },
|
|
redirect: "error", signal: AbortSignal.timeout(10_000),
|
|
});
|
|
if (!response.ok) throw Error(`Runtime artifact lookup failed: ${response.status}`);
|
|
return response.json();
|
|
};
|
|
const result = await get(`actions/artifacts?name=${name}&per_page=20`);
|
|
for (const artifact of (result.artifacts ?? []).filter(item => item.name === name && !item.expired).slice(0, 10)) {
|
|
if (!Number.isSafeInteger(artifact.workflow_run?.id) || !/^sha256:[a-f0-9]{64}$/.test(artifact.digest ?? "")) continue;
|
|
const run = await get(`actions/runs/${artifact.workflow_run.id}`);
|
|
if (!isTrustedMacRuntimeWorkflowRun(run, repository)) continue;
|
|
if (run.conclusion === "success") return { runId: run.id, name };
|
|
const jobsResult = await get(`actions/runs/${artifact.workflow_run.id}/jobs?per_page=100`);
|
|
if (hasVerifiedMacRuntimeJobs(jobsResult?.jobs)) return { runId: run.id, name };
|
|
}
|
|
return null;
|
|
}
|
|
|
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
const root = fileURLToPath(new URL("..", import.meta.url));
|
|
const digest = macRuntimeInputsDigest(root);
|
|
const name = `macos-runner-runtime-${digest.slice(7)}`;
|
|
let cached;
|
|
try { cached = await findMacRuntimeArtifact({ digest, repository: process.env.GITHUB_REPOSITORY, token: process.env.GITHUB_TOKEN }); }
|
|
catch { process.stderr.write("No verified runtime artifact could be reused; building it from source.\n"); }
|
|
if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `digest=${digest}\nartifact_name=${name}\nrun_id=${cached?.runId ?? ""}\n`);
|
|
console.log(JSON.stringify({ digest, artifactName: name, reusedFromRun: cached?.runId ?? null }));
|
|
}
|