perf(docker): consume attested Runner image in merge-queue builds and promote on master (#22993)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The repository includes `.github/workflows/docker-merge-group.yml`
and `scripts/merge-group-image.mjs` to pre-build production images in
the GitHub merge queue so `.github/workflows/docker.yml` can promote
verified bytes on `master` instead of rebuilding from scratch
> - Currently, `docker.yml` skips merge-queue promotion whenever
`needs.runner_image.outputs.mode == 'published'`, and
`docker-merge-group.yml` builds the Runner inline on 4-core
`ubuntu-latest` while waiting up to 15 minutes during promotion lookup
> - With `RUNNER_IMAGE_CONSUME_ENABLED=true`, that meant enabling the
merge queue would never promote pre-built images on normal commits
> - This pull request wires read-only attested Runner image consumption
into `docker-merge-group.yml`, records and verifies `runnerInputsDigest`
in `scripts/merge-group-image.mjs`, routes canonical `amd64` merge-group
builds to `cloud-release-32`, parallelizes disk cleanup, caps promotion
wait to 3 minutes, and allows `docker.yml` to promote verified
merge-queue images when `runner_image` resolves to `published`
> - The benefit is enabling fast pre-merge image promotion for
merge-queue commits without weakening attestation, Runner-digest
matching, or credential isolation

## Linked Issues or Issue Description

**What existing behavior does this improve?**
Pre-merge Docker image building and promotion across
`.github/workflows/docker-merge-group.yml`,
`scripts/merge-group-image.mjs`, and `.github/workflows/docker.yml`.

**Subsystem affected**
Cross-cutting (multiple of the above)

**Current behavior**
`docker-merge-group.yml` builds the Runner inline on `ubuntu-latest`
with serial disk cleanup, and `docker.yml` disables merge-queue
promotion whenever `needs.runner_image.outputs.mode == 'published'`.
`scripts/merge-group-image.mjs` also waits up to 15 minutes for an
in-flight merge-group run.

**Proposed behavior**
`docker-merge-group.yml` resolves an already-published Runner image
(non-blocking lookup, read-only permissions, `gh attestation verify`),
runs `amd64` on `vars.CORE_PUBLICATION_RUNNER || 'cloud-release-32'`,
skips unnecessary disk cleanup / runs cleanup in parallel, and records
`runnerInputsDigest` in `record.json`. `docker.yml` attempts merge-queue
promotion regardless of whether `runner_image` resolved `published` or
`inline`, passing `RUNNER_INPUTS_DIGEST` to `merge-group-image.mjs
verify` so promotion only succeeds when the merge-group image used the
exact same Runner inputs digest. Promotion wait is capped at 3 minutes
so `docker.yml` falls back quickly to building from source if a
merge-group build is still running.

**Reason and benefit**
Makes merge-queue pre-built image promotion work with published Runner
images so queued commits can promote verified bytes to GHCR instead of
rebuilding after merge.

**Breaking changes**
None.

## What Changed

- Added a read-only `runner_image` resolution and attestation
verification job to `.github/workflows/docker-merge-group.yml`
(non-blocking lookup, `persist-credentials: false`, SHA-pinned actions,
no secrets or registry writes).
- Routed canonical `amd64` merge-group builds in
`docker-merge-group.yml` to `vars.CORE_PUBLICATION_RUNNER ||
'cloud-release-32'`, skipped lockfile refresh when using a published
Runner, parallelized `Free runner disk` with a `>= 50 GiB` skip, and
passed `build-contexts`, `build-args`, and `labels` into `Build image
archive`.
- Updated `scripts/merge-group-image.mjs` to record and verify
`runnerInputsDigest`, include `scripts/runner-image-resolve.mjs` in
`pipelineFiles`, and cap `findWaitMs` at 3 minutes.
- Updated `.github/workflows/docker.yml` to output `inputs_digest` from
`runner_image`, run `Find the merge-queue build of this commit` even
when `mode == 'published'`, and verify `--runner-inputs-digest` before
promoting.
- Updated `scripts/merge-group-image.test.mjs`,
`server/src/__tests__/docker-build-stamp.test.ts`, and
`server/src/__tests__/docker-runner-workflows.test.ts`.

## Verification

- `node --test scripts/merge-group-image.test.mjs
scripts/__tests__/docker-cache-export-policy.test.mjs
scripts/__tests__/release-verify-workflow.test.mjs
scripts/macos-runner-runtime-workflow.test.mjs` (all passed)
- Vitest: `server/src/__tests__/docker-build-stamp.test.ts` (18/18
passed), `server/src/__tests__/docker-runner-workflows.test.ts` (11/11
passed)

## Risks

- Low risk. Promotion remains strictly fail-closed: `docker.yml` runs
`$BEFORE:scripts/merge-group-image.mjs`, refuses promotion on any
pipeline file change, verifies commit SHA, tree SHA, architecture,
archive blob digests, and exact `runnerInputsDigest`, and falls back to
building from source on any mismatch or timeout.

## Model Used

- Gemini 3 Pro (Antigravity agent with tool use, shell execution, and
local test verification)

## 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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-11-25 15:22:50 -06:00
1 parent 64bef50be0
commit 320d7fe76d
6 files changed
+300 -47

No files matched your search

+53 -12
View File
@@ -22,10 +22,12 @@ const architectures = ["amd64", "arm64"];
const indexTypes = ["application/vnd.oci.image.index.v1+json", "application/vnd.docker.distribution.manifest.list.v2+json"];
const manifestTypes = ["application/vnd.oci.image.manifest.v1+json", "application/vnd.docker.distribution.manifest.v2+json"];
// How long a master push waits for a merge-queue build that is still running.
// A build takes about 12 minutes and the exact-source gate about 14.
const findWaitMs = 15 * 60_000;
const findPollMs = 20_000;
// Capped at 3 minutes so a master push on a fast AWS runner falls back to
// building from source instead of stalling behind a slower merge-group leg.
const findWaitMs = 3 * 60_000;
const findPollMs = 15_000;
const fullSha = /^[a-f0-9]{40}$/;
const hex64 = /^[a-f0-9]{64}$/;
const digestPattern = /^sha256:[a-f0-9]{64}$/;
const sha256 = bytes => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
@@ -92,20 +94,31 @@ export function archiveImageDigest({ readEntry, arch }) {
}
/** What the merge-group build attests about the archive it uploads. */
export function createRecord({ sha, tree, arch, digest }) {
export function createRecord({ sha, tree, arch, digest, runnerInputsDigest = "" }) {
assert.match(sha ?? "", fullSha);
assert.match(tree ?? "", fullSha);
assert.ok(architectures.includes(arch));
assert.match(digest ?? "", digestPattern);
return { schema: recordSchema, repository, sha, tree, arch, digest };
assert.ok(runnerInputsDigest === "" || hex64.test(runnerInputsDigest), "runnerInputsDigest must be empty or 64 lowercase hex characters");
return {
schema: recordSchema,
repository,
sha,
tree,
arch,
digest,
...(runnerInputsDigest ? { runnerInputsDigest } : {}),
};
}
/**
* Prove the archive is the build of the tree this master push publishes. The
* commit SHA covers its tree; the tree is compared too, so a record can never
* vouch for different content under a reused name.
* vouch for different content under a reused name. When master resolved a
* published Runner image, the merge-group record must name the exact same
* Runner inputs digest (and vice versa for inline builds).
*/
export function verifyRecord({ record, sha, tree, arch, archiveDigest }) {
export function verifyRecord({ record, sha, tree, arch, archiveDigest, runnerInputsDigest = "" }) {
assert.equal(record?.schema, recordSchema, "Unknown merge-group image record");
assert.equal(record.repository, repository);
assert.equal(record.sha, sha, "The merge-group build is for a different commit");
@@ -113,6 +126,12 @@ export function verifyRecord({ record, sha, tree, arch, archiveDigest }) {
assert.equal(record.arch, arch, "The merge-group build is for a different architecture");
assert.match(record.digest ?? "", digestPattern);
assert.equal(archiveDigest, record.digest, "The archive is not the image the merge-group build recorded");
assert.ok(runnerInputsDigest === "" || hex64.test(runnerInputsDigest), "runnerInputsDigest must be empty or 64 lowercase hex characters");
assert.equal(
record.runnerInputsDigest ?? "",
runnerInputsDigest,
"The merge-group build used a different Runner image than master resolved",
);
return record.digest;
}
@@ -124,7 +143,21 @@ export function verifyRecord({ record, sha, tree, arch, archiveDigest }) {
* check from the copy of this script in the push's `before` commit, so a push
* cannot remove the check it is subject to.
*/
export const pipelineFiles = [workflowPath, ".github/workflows/docker.yml", ".github/workflows/macos-runner-runtime.yml", "scripts/macos-runner-runtime.mjs", "scripts/macos-runner-runtime-cache.mjs", "scripts/merge-group-image.mjs", "scripts/assert-orphan-reaping.sh"];
export const pipelineFiles = [
workflowPath,
".github/workflows/docker.yml",
".github/workflows/macos-runner-runtime.yml",
"scripts/macos-runner-runtime.mjs",
"scripts/macos-runner-runtime-cache.mjs",
"scripts/runner-image-resolve.mjs",
"scripts/runner-image-publish.mjs",
"scripts/runner-image-identity.mjs",
"scripts/runner-image-layout.mjs",
"scripts/runner-image-oci.mjs",
"scripts/standard-image-contract.mjs",
"scripts/merge-group-image.mjs",
"scripts/assert-orphan-reaping.sh",
];
export function assertPipelineUnchanged(changedFiles) {
const changed = changedFiles.filter(file => pipelineFiles.includes(file));
@@ -146,6 +179,12 @@ const option = name => {
assert.ok(value, `--${name} is required`);
return value;
};
const optionalOption = name => {
const index = process.argv.indexOf(`--${name}`);
if (index <= 0) return "";
const value = process.argv[index + 1];
return value === undefined || value.startsWith("--") ? "" : value;
};
const output = async (key, value) => {
if (process.env.GITHUB_OUTPUT) await appendFile(process.env.GITHUB_OUTPUT, `${key}=${value}\n`);
console.log(`${key}=${value}`);
@@ -158,7 +197,8 @@ async function main(command) {
// Runs in the credential-free merge-group build.
assert.equal(process.env.GITHUB_EVENT_NAME, "merge_group", "Records are written only by merge-group builds");
const digest = archiveImageDigest({ readEntry: tarReader(option("archive")), arch });
await writeFile(option("out"), `${JSON.stringify(createRecord({ sha, tree: gitTree(), arch, digest }), null, 2)}\n`);
const runnerInputsDigest = optionalOption("runner-inputs-digest");
await writeFile(option("out"), `${JSON.stringify(createRecord({ sha, tree: gitTree(), arch, digest, runnerInputsDigest }), null, 2)}\n`);
return output("digest", digest);
}
assert.ok(process.env.GITHUB_REPOSITORY === repository && process.env.GITHUB_REF === "refs/heads/master" &&
@@ -173,8 +213,8 @@ async function main(command) {
return response.json();
};
// Publication waits for the exact-source gate in any case, so waiting here
// for an unfinished build costs nothing while the build is the shorter of
// the two. Past the deadline the push builds from source.
// briefly for an almost-finished build costs nothing; past the deadline the
// push builds from source.
const deadline = Date.now() + findWaitMs;
let run;
for (;;) {
@@ -195,7 +235,8 @@ async function main(command) {
assertPipelineUnchanged(changedSince(option("since")));
const record = JSON.parse(await readFile(`${directory}/record.json`, "utf8"));
const archiveDigest = archiveImageDigest({ readEntry: tarReader(`${directory}/image.tar`), arch });
return output("digest", verifyRecord({ record, sha, tree: gitTree(), arch, archiveDigest }));
const runnerInputsDigest = optionalOption("runner-inputs-digest");
return output("digest", verifyRecord({ record, sha, tree: gitTree(), arch, archiveDigest, runnerInputsDigest }));
}
throw new Error(`Unknown command: ${command}`);
}
+25 -8
View File
@@ -96,10 +96,16 @@ test("reads a real tar archive through the system tar", () => {
} finally { rmSync(directory, { recursive: true, force: true }); }
});
test("promotion proves commit, tree, architecture and archive digest", () => {
test("promotion proves commit, tree, architecture, Runner inputs digest and archive digest", () => {
const digest = `sha256:${"e".repeat(64)}`;
const runnerInputsDigest = "1".repeat(64);
const record = createRecord({ sha, tree, arch: "amd64", digest });
assert.equal(verifyRecord({ record, sha, tree, arch: "amd64", archiveDigest: digest }), digest);
const publishedRecord = createRecord({ sha, tree, arch: "amd64", digest, runnerInputsDigest });
assert.equal(verifyRecord({ record: publishedRecord, sha, tree, arch: "amd64", archiveDigest: digest, runnerInputsDigest }), digest);
assert.throws(() => verifyRecord({ record: publishedRecord, sha, tree, arch: "amd64", archiveDigest: digest, runnerInputsDigest: "" }), /different Runner image/);
assert.throws(() => verifyRecord({ record, sha, tree, arch: "amd64", archiveDigest: digest, runnerInputsDigest }), /different Runner image/);
assert.throws(() => verifyRecord({ record: publishedRecord, sha, tree, arch: "amd64", archiveDigest: digest, runnerInputsDigest: "2".repeat(64) }), /different Runner image/);
for (const [change, pattern] of [
[{ sha: "f".repeat(40) }, /different commit/],
[{ tree: "f".repeat(40) }, /different tree/],
@@ -113,8 +119,19 @@ test("promotion proves commit, tree, architecture and archive digest", () => {
test("a push that changes the merge-group pipeline is built from source, not promoted", () => {
assert.doesNotThrow(() => assertPipelineUnchanged([]));
assert.doesNotThrow(() => assertPipelineUnchanged(["Dockerfile", "server/src/index.ts", "scripts/standard-image-contract.mjs"]));
for (const file of [".github/workflows/docker-merge-group.yml", ".github/workflows/docker.yml", "scripts/merge-group-image.mjs", "scripts/assert-orphan-reaping.sh"]) {
assert.doesNotThrow(() => assertPipelineUnchanged(["Dockerfile", "server/src/index.ts"]));
for (const file of [
".github/workflows/docker-merge-group.yml",
".github/workflows/docker.yml",
"scripts/runner-image-resolve.mjs",
"scripts/runner-image-publish.mjs",
"scripts/runner-image-identity.mjs",
"scripts/runner-image-layout.mjs",
"scripts/runner-image-oci.mjs",
"scripts/standard-image-contract.mjs",
"scripts/merge-group-image.mjs",
"scripts/assert-orphan-reaping.sh",
]) {
assert.throws(() => assertPipelineUnchanged(["server/src/index.ts", file]), /changes the merge-group image pipeline/, file);
}
});
@@ -162,7 +179,7 @@ test("the CLI refuses to record outside a merge group or promote outside a canon
]) for (const command of ["find", "verify"]) assert.match(run(command, env), /only for canonical master pushes/);
});
test("the merge-queue build has no publishing credentials or paid infrastructure", () => {
test("the merge-queue build has no publishing credentials or AWS release fleet access", () => {
const workflow = readFileSync(path.join(root, ".github", "workflows", "docker-merge-group.yml"), "utf8");
const triggers = workflow.split("\non:\n")[1].split("\n\n")[0];
assert.equal(triggers.trim(), "merge_group:", "only the merge queue triggers this build");
@@ -170,9 +187,9 @@ test("the merge-queue build has no publishing credentials or paid infrastructure
const permissions = [...workflow.matchAll(/^ permissions:\n((?: {6}.+\n)+)/gm)].map(match => match[1].trim());
assert.ok(permissions.length > 0);
for (const block of permissions) {
assert.ok(block.split("\n").map(line => line.trim()).every(line => /^(contents|actions): read$/.test(line)));
assert.ok(block.split("\n").map(line => line.trim()).every(line => /^(contents|actions|attestations): read$/.test(line)));
}
assert.doesNotMatch(workflow, /secrets\.|packages: write|id-token|attestations|docker\/login-action|cache-to:|push: true|environment:|runs-on\//);
assert.doesNotMatch(workflow, /secrets\.|packages: write|id-token|attestations: write|docker\/login-action|cache-to:|push: true|environment:|runs-on\//);
assert.doesNotMatch(workflow, /pull_request_target|workflow_run|workflow_dispatch/);
assert.match(workflow, /persist-credentials: false/);
assert.match(workflow, /github\.event\.merge_group\.base_ref == 'refs\/heads\/master'/);
@@ -190,7 +207,7 @@ test("master promotes only after proof and otherwise builds exactly as before",
const step = name => { const found = steps.find(item => item.startsWith(` - name: ${name}\n`)); assert.ok(found, name); return found; };
const order = name => steps.indexOf(step(name));
assert.match(step("Find the merge-queue build of this commit"),
/if: needs.runner_image.outputs.mode != 'published' && github.repository == 'paperclipai\/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs\/heads\/master'/);
/if: github.repository == 'paperclipai\/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs\/heads\/master'/);
for (const name of ["Find the merge-queue build of this commit", "Download the merge-queue image", "Promote the merge-queue image"]) {
assert.match(step(name), /continue-on-error: true/, `${name} must fall back to the build`);
}
@@ -202,7 +219,7 @@ test("master promotes only after proof and otherwise builds exactly as before",
assert.match(step(name), /git show "\$BEFORE:scripts\/merge-group-image.mjs" > "\$trusted"/);
assert.doesNotMatch(step(name), /node scripts\/merge-group-image\.mjs/);
}
assert.match(promote, /node "\$trusted" verify --arch "\$ARCH" --dir "\$DIRECTORY" --since "\$BEFORE"/);
assert.match(promote, /node "\$trusted" verify --arch "\$ARCH" --dir "\$DIRECTORY" --since "\$BEFORE" --runner-inputs-digest "\$RUNNER_INPUTS_DIGEST"/);
assert.ok(promote.indexOf('"$trusted" verify') < promote.indexOf("skopeo copy"));
assert.ok(promote.indexOf("skopeo copy --all --preserve-digests") < promote.indexOf('echo "digest=$digest" >> "$GITHUB_OUTPUT"'),
"the promoted digest becomes an output only after the exact bytes are pushed");