perf(ci): reuse verified macOS runtime artifacts from master runs cancelled downstream (#23044)

## 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
This commit is contained in:
Dotta authored and GitHub committed 2026-11-26 07:22:17 -06:00
1 parent 8f6d94169a
commit 880b0c3a7c
2 files changed
+51 -6

No files matched your search

+23 -4
View File
@@ -12,12 +12,28 @@ export function macRuntimeInputsDigest(root) {
return `sha256:${hash.digest("hex")}`;
}
export function isTrustedMacRuntimeProducer(run, repository) {
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" && run.conclusion === "success"
&& 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)}`;
@@ -30,10 +46,13 @@ export async function findMacRuntimeArtifact({ digest, repository, token, fetchI
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, 4)) {
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 (isTrustedMacRuntimeProducer(run, repository)) return { runId: run.id, name };
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;
}
+28 -2
View File
@@ -1,15 +1,41 @@
import assert from "node:assert/strict";
import test from "node:test";
import { findMacRuntimeArtifact, isTrustedMacRuntimeProducer } from "./macos-runner-runtime-cache.mjs";
import { findMacRuntimeArtifact, hasVerifiedMacRuntimeJobs, isTrustedMacRuntimeProducer, isTrustedMacRuntimeWorkflowRun } from "./macos-runner-runtime-cache.mjs";
const repository = "paperclipai/paperclip", digest = `sha256:${"a".repeat(64)}`;
const good = { id: 123, repository: { full_name: repository }, path: ".github/workflows/docker.yml", event: "push", head_branch: "master", conclusion: "success", head_sha: "b".repeat(40) };
const verifiedJobs = [
{ name: "macos_runner_runtime / build", status: "completed", conclusion: "success" },
{ name: "macos_runner_runtime / verify_linux_controller", status: "completed", conclusion: "success" },
];
test("reuses only successful master image builds from the protected repository", () => {
test("reuses only trusted master image builds from the protected repository", () => {
assert.equal(isTrustedMacRuntimeProducer(good, repository), true);
assert.equal(isTrustedMacRuntimeWorkflowRun({ ...good, conclusion: "cancelled" }, repository), true);
for (const change of [{ repository: { full_name: "fork/project" } }, { event: "pull_request" }, { head_branch: "feature" }, { conclusion: "failure" }, { path: ".github/workflows/macos-runner-runtime.yml" }]) {
assert.equal(isTrustedMacRuntimeProducer({ ...good, ...change }, repository), false);
}
assert.equal(hasVerifiedMacRuntimeJobs(verifiedJobs), true);
assert.equal(hasVerifiedMacRuntimeJobs([verifiedJobs[0]]), false);
assert.equal(hasVerifiedMacRuntimeJobs([verifiedJobs[0], { ...verifiedJobs[1], conclusion: "cancelled" }]), false);
assert.equal(hasVerifiedMacRuntimeJobs([verifiedJobs[0], { ...verifiedJobs[1], status: "in_progress", conclusion: null }]), false);
});
test("reuses a verified artifact from a master docker.yml run cancelled downstream, but rejects unverified jobs", async () => {
const name = `macos-runner-runtime-${digest.slice(7)}`;
const records = [201, 202].map(id => ({ name, workflow_run: { id }, digest: `sha256:${"c".repeat(64)}` }));
const fetchImpl = async url => ({
ok: true,
json: async () => {
if (url.includes("actions/artifacts")) return { artifacts: records };
if (url.endsWith("/actions/runs/201")) return { ...good, id: 201, conclusion: "cancelled" };
if (url.includes("/actions/runs/201/jobs")) return { jobs: [verifiedJobs[0], { ...verifiedJobs[1], conclusion: "cancelled" }] };
if (url.endsWith("/actions/runs/202")) return { ...good, id: 202, conclusion: "cancelled" };
if (url.includes("/actions/runs/202/jobs")) return { jobs: [...verifiedJobs, { name: "Watch exact-source verification", status: "completed", conclusion: "cancelled" }] };
throw Error(`unexpected url: ${url}`);
},
});
assert.deepEqual(await findMacRuntimeArtifact({ digest, repository, token: "fixture", fetchImpl }), { runId: 202, name });
});
test("a matching artifact from a pull request cannot replace the master runtime", async () => {