fix(docker): stop a stale-lockfile build early and keep beta and stable releases buildable (#21333)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The application image now takes its Runner from the
`runner-artifacts` stages, which install with a frozen lockfile
> - A contributor cannot commit `pnpm-lock.yaml`. After a change to a
manifest of the Runner, the lockfile on `master` is behind until the
refresh merges
> - In that time a plain `docker build` fails late, inside a long step,
with a message that is easy to miss. And a beta or a stable release can
be cut from such a commit, because the release workflows refresh the
lockfile for their own build
> - This pull request adds an early check with a clear instruction to
the image build, and the same check to the beta and the stable release
> - The benefit is a failure in seconds that says what to run, and beta
and stable tags that always build from source

## Linked Issues or Issue Description

This is the third part of a chain. The first part is #21331. The second
part takes the Runner of the application image from the
`runner-artifacts` stage. Refs #21204 and #21306 (the Runner image and
its lockfile rule). No issue exists for this change.

**What happened?**

A tree with a lockfile behind the manifests of the Runner fails `docker
build` after the daemon compile (169 s in the test). The error is
`ERR_PNPM_OUTDATED_LOCKFILE` in the middle of the largest `RUN` of the
`Dockerfile`.

**Expected behavior**

The build fails within seconds of the check running. The message names
the files and the command to run. The application's dependency install
starts from the check, so it cannot start before the check passes.
Stages that do not depend on it (the Runner's toolchain download and
daemon compile, and the tool layer of `production`) can already be
running, and the failed check cancels them. A beta or a stable release
from such a commit does not start.

How often this happens: of 72 nightly tags since 2026-08-24, 9 are on a
commit whose lockfile is behind the manifests of the Runner (2026-09-01,
09-18 through 09-23, 09-28 and 10-26). Of 12 beta tags, none is. A beta
is the promotion of a nightly, so a beta can be cut from such a commit.

**Steps to reproduce**

1. Change a dependency range in
`packages/paperclip-runner/package.json`. Do not refresh
`pnpm-lock.yaml`.
2. Run `docker build .`.

**Paperclip version or commit**

`master` with the previous pull request of this chain.

**Deployment mode**

Not applicable. This is the image build and the release tooling.

## What Changed

- `Dockerfile`: a `runner-lockfile` stage copies only the manifests the
Runner build installs from, the lockfile and the patches. It runs the
frozen, filtered, offline lockfile check, with the arguments of
`runnerLockState`. `deps` starts from it. For a stale lockfile it prints
the files and `pnpm install --resolution-only --ignore-scripts
--no-frozen-lockfile`. For any other failure it prints the output of
pnpm and says so.
- `scripts/check-release-runner-lockfile.mjs`: exports the Runner inputs
of a commit with `git archive` and gives them to `runnerLockState`
(`scripts/runner-image-publish.mjs`). Exit 0 for current, 1 for behind,
2 for an error.
- `scripts/release.sh` and `scripts/release-lib.sh`:
`require_runner_lockfile_current` runs for the `beta` and the `stable`
channel, after `--print-version` exits and before any build. It runs in
a dry run too. It does not run for `canary` or `nightly`.
- Both beta paths end in the `publish_beta` job: the promotion of a
nightly, and a `candidate/beta-*` branch. That job checks out the commit
that `select_beta` chose and runs `release.sh beta` there. So the check
reads the committed files of the commit the beta is built from. A beta
is refused before its soak starts. The stable that promotes it is
checked again.
- Tests: `server/src/__tests__/runner-lockfile-guards.test.ts` (18
tests). Three of them pin the checkout of `publish_beta`,
`preview_stable` and `publish_stable` to the selected commit. Two tests
plus one stub in `scripts/__tests__/release-dry-run-notes.test.mjs`
cover the beta, the candidate beta and the stable path.
- Docs: `doc/DOCKER.md`, `doc/RELEASING.md`,
`doc/runner-image-contract.md`.

## Verification

Builds: `linux/arm64`, local. They ran before the rebase onto `master`,
except the last one. `master` changed neither the `Dockerfile` nor a
manifest in between.

- A tree with `ajv` changed from `^8.20.0` to `^8.19.0` in the manifest
of the Runner: `docker buildx build --target build` fails after 6 s at
`runner-lockfile`, with the message.
- The same tree after `pnpm install --resolution-only --ignore-scripts
--no-frozen-lockfile` on the host, which is what the image workflows
run: `--target build` builds. The check passes, the Runner stages
install, and the vendor step logs `reusing the current Runner build` in
both of its runs.
- After the rebase: `build` and `runner-provider-pack` built from this
branch without a build commit. The check passed.
- The release check with the real pnpm: `behind` for the first tree,
`current` for the second, exit 0 for this checkout.
- `vitest run server/src/__tests__/runner-lockfile-guards.test.ts` with
the other changed server tests, on macOS and in `node:24.22.3-bookworm`
(249 pass in 11 files on Linux). The test file typechecks.
- `node --test scripts/__tests__/release-dry-run-notes.test.mjs`: 14
pass. `scripts/release-lib.test.mjs`: 15 pass on Linux; on macOS 4 of
its tests fail on `master` too. `release-verify-workflow.test.mjs` and
`acpx-patch-packaging.test.mjs`, which read the release scripts: pass.
- `docker buildx build --check`: no warning.
- The Docker builds above ran before the second part of the chain got
its expectation step and before the beta guard. The expectation step was
built on the second part alone. This branch as it is now was not built
again; its tests ran.
- Not run: the release workflow, any `linux/amd64` build, the full test
suite. Only CI and a release dry run can prove the release path.

## Risks

- **A beta can be refused.** When the newest nightly is on a commit
whose lockfile is behind, `release.sh beta` stops, in the dry run and in
the real run. The operator must promote a nightly whose commit includes
the lockfile refresh, or cut a candidate branch that includes it. `node
scripts/check-release-runner-lockfile.mjs --commit <ref>` gives the
answer before the dispatch.
- **A stable can be refused** only when its beta was cut before this
change, or with release tooling that does not have the check. Promotions
run the release tooling of the source commit.
- The check runs in `release.sh`. In the beta workflow it runs in
`publish_beta`, after the approval of the `npm-beta` environment and
after the candidate verification. In the stable workflow it runs after
verification, not in the `preflight_stable` job. The selection jobs have
no pnpm.
- `release.sh stable` now needs `git`, `tar` and `pnpm` on `PATH` before
its first build step. The workflow has them.
- `scripts/__tests__/release-dry-run-notes.test.mjs` is not in a CI
command today. The Vitest file carries the enforced tests.
- The image build has one more small stage. It reads only manifests, so
a source change does not run it again.
- The digest of the Runner image changes again, because its identity
covers the whole `Dockerfile`.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Fable 5.2 (`claude-fable-5-2`), from Anthropic, through Claude
Code. The model used tools: it edited files, ran the tests and ran the
Docker builds that this description reports.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Nicky LeachandClaude Fable 5.2 authored and GitHub committed 2026-11-13 14:17:15 -08:00
1 parent 05fef9f27b
commit 999709b0a6
10 files changed
+373 -6

No files matched your search

@@ -65,6 +65,13 @@ require_channel_tag_absent_at_head() {
}
require_on_master_branch() { :; }
require_clean_worktree() { :; }
require_runner_lockfile_current() {
if [ "\${FAKE_RUNNER_LOCKFILE_BEHIND:-}" = "1" ]; then
echo "Error: a beta or stable release needs a pnpm-lock.yaml that matches the Runner's manifests at HEAD." >&2
exit 1
fi
echo "[fixture] require_runner_lockfile_current"
}
require_npm_publish_auth() { :; }
git_local_tag_exists() { return 1; }
git_remote_tag_exists() { return 1; }
@@ -187,6 +194,32 @@ test("stable publish still requires release notes before publish work starts", (
assert.doesNotMatch(result.calls, /^pnpm /m);
});
test("beta and stable check the lockfile against the Runner's manifests before any build, in a dry run too", () => {
for (const args of [["stable"], ["beta"], ["beta", "--from-candidate"]]) {
const current = runRelease([...args, "--skip-verify", "--dry-run"]);
assert.match(current.output, /\[fixture\] require_runner_lockfile_current/, args.join(" "));
const behind = runRelease([...args, "--skip-verify", "--dry-run"], { FAKE_RUNNER_LOCKFILE_BEHIND: "1" });
assert.equal(behind.status, 1, args.join(" "));
assert.match(behind.output, /needs a pnpm-lock\.yaml that matches the Runner's manifests at HEAD/);
assert.doesNotMatch(behind.output, /==> Release plan/);
assert.doesNotMatch(behind.calls, /^pnpm /m);
}
});
test("canary and nightly do not check the lockfile, and printing a version does not", () => {
for (const args of [["canary", "--skip-verify", "--dry-run"], ["nightly", "--skip-verify", "--dry-run"]]) {
const result = runRelease(args, { FAKE_RUNNER_LOCKFILE_BEHIND: "1" });
assert.doesNotMatch(result.output, /Runner's manifests/, args[0]);
assert.match(result.output, /==> Release plan/, args[0]);
}
for (const channel of ["stable", "beta"]) {
const version = runRelease([channel, "--print-version"], { FAKE_RUNNER_LOCKFILE_BEHIND: "1" });
assert.equal(version.status, 0, channel);
assert.doesNotMatch(version.output, /Runner's manifests/, channel);
}
});
test("nightly dry-run publishes under the nightly identity without release notes", () => {
const result = runRelease(["nightly", "--skip-verify", "--dry-run"]);
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { RUNNER_IMAGE_CONTEXT_INPUTS } from "./runner-image-identity.mjs";
import { runnerLockState } from "./runner-image-publish.mjs";
export const LOCKFILE_REFRESH_COMMAND = "pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile";
export function runnerLockStateAtCommit({ repoRoot, commit = "HEAD", run = spawnSync, lockState = runnerLockState }) {
const scratch = mkdtempSync(path.join(tmpdir(), "paperclip-release-runner-lockfile-"));
try {
const archive = path.join(scratch, "context.tar");
const context = path.join(scratch, "context");
mkdirSync(context);
const steps = [
["export", "git", ["-C", repoRoot, "archive", "--format=tar", "--output", archive, commit, "--", ...RUNNER_IMAGE_CONTEXT_INPUTS]],
["unpack", "tar", ["-xf", archive, "-C", context]],
];
for (const [step, command, args] of steps) {
const result = run(command, args, { encoding: "utf8", stdio: ["ignore", "ignore", "pipe"] });
if (result.error) throw result.error;
if (result.status !== 0) {
throw new Error(`Could not ${step} the Runner's inputs at ${commit} (${command} exit ${result.status}): ${(result.stderr ?? "").trim().slice(-1000)}`);
}
}
return lockState(context);
} finally {
rmSync(scratch, { recursive: true, force: true });
}
}
export function runReleaseRunnerLockfileCheck(argv, {
repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."),
check = runnerLockStateAtCommit,
log = console.error,
} = {}) {
if (argv.length > 2 || (argv.length > 0 && (argv[0] !== "--commit" || !argv[1]))) {
log("Usage: check-release-runner-lockfile.mjs [--commit <commit>]");
return 2;
}
const commit = argv[1] ?? "HEAD";
const result = check({ repoRoot, commit });
if (result.state === "current") {
log(`pnpm-lock.yaml at ${commit} matches the Runner's manifests.`);
return 0;
}
log(`pnpm-lock.yaml at ${commit} is behind the Runner's manifests (${result.detail}). `
+ "An image build from this commit installs the Runner with a frozen lockfile and fails. "
+ `Release a commit that includes the lockfile refresh, which is the result of: ${LOCKFILE_REFRESH_COMMAND}`);
return 1;
}
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
try {
process.exitCode = runReleaseRunnerLockfileCheck(process.argv.slice(2));
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 2;
}
}
+6
View File
@@ -543,6 +543,12 @@ require_clean_worktree() {
fi
}
require_runner_lockfile_current() {
if ! node "$REPO_ROOT/scripts/check-release-runner-lockfile.mjs"; then
release_fail "a beta or stable release needs a pnpm-lock.yaml that matches the Runner's manifests at HEAD."
fi
}
require_on_master_branch() {
local current_branch
current_branch="$(git_current_branch)"
+4
View File
@@ -223,6 +223,10 @@ fi
require_clean_worktree
require_npm_publish_auth "$dry_run"
if [ "$channel" = "beta" ] || [ "$channel" = "stable" ]; then
require_runner_lockfile_current
fi
if [ "$channel" = "stable" ] && [ "$dry_run" = false ] && [ ! -f "$NOTES_FILE" ]; then
release_fail "stable release notes file is required at $NOTES_FILE before publishing stable."
fi