Files
PaperClipAI/doc/runner-image-contract.md
T
Nicky LeachandClaude Fable 5.2 f79e2c5d84 feat(ci): add the Runner image resolver and a no-rebuild mode for the Runner vendor step (#21306)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The Runner is the part that executes agent work: a daemon
(`paperclip-runnerd`) and a provider pack of agent tools
> - `master` now publishes the Runner alone as the image
`ghcr.io/paperclipai/paperclip-runner`, one time for each set of Runner
inputs (#21204, #21229, #21230)
> - The application image still compiles its own Runner on every build.
The next steps make it copy the published Runner instead
> - Before a build can do that, it must answer one question the same way
as every other build: "does a published Runner exist for exactly this
tree?" It must also fail clearly when the Runner it was given does not
match the tree
> - This pull request adds the script that answers the question, and a
mode of the Runner vendor step that fails instead of rebuilding
> - The benefit is that the later change to the image build is small,
and that a wrong or unreachable answer can only mean "build the Runner
yourself"

## Linked Issues or Issue Description

Refs #21204, #21229 and #21230 (the Runner image). No issue exists for
this change.

**Problem or motivation**

Three builders make images that contain the Runner: `docker.yml`, the
merge-queue build and the release preview build. Each one would have to
repeat three steps to find the published Runner of its tree: check the
lockfile, compute the inputs digest in the build, and look up
`inputs-<digest>`. Three copies can decide differently. A build that
copies a Runner built elsewhere also has no Rust toolchain. If the
copied Runner does not match the tree, `prepare-runner-vendor.mjs`
starts a rebuild, and the build fails late at `cargo` with a message
that hides the cause.

**Proposed solution**

Add `scripts/runner-image-resolve.mjs`, the one place that decides. Add
`PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1` to
`prepare-runner-vendor.mjs`. Nothing calls the resolver and nothing sets
the variable in this pull request, so no workflow job changes.

**Alternatives considered**

- One command that builds and looks up. Two commands keep a registry
credential, when a caller has one, out of the step that builds.
- A wait for the publication of the commit. The decision whether the
application build waits is open, so the resolver has no wait mode. It
reports `absent` and stops.
- A build argument that names the expected inputs. No `Dockerfile`
declares one yet. The change that makes the application image copy the
Runner will add both ends together.

**Roadmap alignment**

This is build infrastructure. It adds no product feature and does not
overlap an item in `ROADMAP.md`.

This is part 1 of 4 of a stack ([stack
#21309](https://github.com/paperclipai/paperclip/stack/21309)). Merge
the parts in order:

1. #21306: the resolver and the no-rebuild mode (this pull request)
2. #21307: the report-only job in `docker.yml` and the pull-request
check of the application image's Runner path
3. #21308: reading a retained provider pack from its Runner image
4. #21310: a registry build cache for the Runner image build

## What Changed

- `scripts/runner-image-resolve.mjs` (new, 185 lines), with two commands
that share a directory:
- `inputs --dir <dir>` exports the `runner-artifacts-context` target,
runs the lockfile check on that export, and builds the
`runner-artifacts-identity` target when the lockfile is current. It
reads no credential. A lockfile that is behind stops there: no image is
published for such a tree.
- `resolve --dir <dir>` looks up `inputs-<digest>` and prints `mode`,
`reason`, `inputs_digest`, `image`, `slim_image`, `build_contexts` and
`labels`. It also writes them to `$GITHUB_OUTPUT` and a short report to
`$GITHUB_STEP_SUMMARY`.
- `mode` is `published` only for a complete publication whose full index
names these inputs and both platforms. Both images are pinned by index
digest. The slim digest is the one the full index names in
`io.paperclip.runner.slim-digest`; the slim tag is never read on its
own.
- Every other answer is `inline`, with the last four values empty:

  | `reason` | Meaning |
  | --- | --- |
  | `lock-behind` | `pnpm-lock.yaml` is behind the Runner's manifests |
  | `absent` | no tag exists |
| `incomplete`, `broken` | a publication stopped, or its two tags do not
belong together |
| `mismatch` | the full index names other inputs, or lacks a platform |
| `unknown` | the registry refused, failed or could not be reached, or
the lookup threw |

- The resolver reuses `runnerLockState`, `readRunnerImageManifest`,
`runnerPublicationState` and `runnerImageTags` from
`scripts/runner-image-publish.mjs`. That file now exports
`environmentCredentials`; it has no other change.
- `server/scripts/prepare-runner-vendor.mjs`: with
`PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1`, the step reuses a current
build as before. When the build is not current, it prints the reason,
starts no rebuild, leaves the stamp in place and exits with status 1. It
also fails when `PAPERCLIP_RUNNER_VENDOR_REBUILD=1` is set at the same
time. Without the variable the step is the same as before.
- `doc/runner-image-contract.md` has a new section, "Choosing the Runner
for an image build". `doc/DEVELOPING.md` describes the new variable.
- The resolver is not an input of the Runner image, so the inputs digest
does not change.

## Verification

macOS (Node 26.12.0), in `server/`:

- `node node_modules/vitest/vitest.mjs run
scripts/prepare-runner-vendor.test.mjs
src/__tests__/runner-image-resolve.test.ts
src/__tests__/runner-image-publish.test.ts
src/__tests__/runner-image-identity.test.ts
src/__tests__/runner-image-workflow.test.ts
src/__tests__/server-package-build-script.test.ts`: 179 tests pass in 6
files. 27 of them are new resolver tests and 3 are new tests of the
vendor step, whose end-to-end test also has a new case.
- `tsc` on the new test file, with the settings of
`server/src/__tests__/tsconfig.json`: no error.

Linux (`node:24.22.3-bookworm`, GNU tar 1.34, the worktree mounted
read-only): the same files, 179 tests pass.

Real runs, on clean exports of the tree (`git archive`), with no
credential, on a `linux/arm64` Docker host:

- On `master` at `62d673cc3f`: `inputs` gave `lock=current` and
`inputs_digest=0e6662ad9c8c6451556c76bf326723645d4afaab2decc73cd5e0025f7dd8d1ca`.
`resolve` gave `mode=published`,
`image=ghcr.io/paperclipai/paperclip-runner@sha256:84f2c051aa4ed16c5cc138c08e3533fa417e92177f7d15af5f2aa3e0ba467162`
and
`slim_image=ghcr.io/paperclipai/paperclip-runner@sha256:f63ea43666ed708f1b0e5d2ade8bdc002885bf04252b9ed6cee21f7920e54f3c`.
These are the two indexes that `master` published for those inputs.
- The same tree with one line added to a Runner source file: another
digest, `mode=inline`, `reason=absent`.
- On `master` at `bc71c23e0a`, which changed the Runner's inputs, before
its image was published: digest
`88fe2929321b4706c77f11a098572ce990fec4449d505544c62ef3a84c28308a`,
`mode=inline`, `reason=absent`.
- Four deliberate faults in the resolver each make a test fail: no index
check, only `absent` is inline, the identity is built for a lockfile
that is behind, and the slim image is taken by tag.

Never run:

- A lookup with a registry credential. The package is public, so no
caller needs one now.
- Any workflow. No workflow calls the resolver in this pull request.
- `linux/amd64`.
- The full test suite, the full typecheck and `pnpm build`. `pnpm verify
--explain` reports exit 2, "broader verification required", so CI must
supply them.

## Risks

- Low for existing behaviour: nothing calls the resolver, and the vendor
step is the same unless the new variable is set.
- The resolver does not verify the attestation of the image. The
workflow that consumes the image must do that from the digest the
resolver reports.
- The resolver reports both build contexts, `runner-artifacts` and
`runner-artifacts-slim`. A build that reads only one stage gets one
context it does not use.
- A `broken` publication is `inline`, not a failure. The Runner image
workflow fails for that state.

> 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`), Anthropic, used through Claude
Code with tool use (shell, file edits, local Docker builds).

## 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>
2026-11-12 22:03:15 -08:00

12 KiB

Runner image contract

The Runner image is the Runner built alone, as a plain file tree with no entrypoint and no operating system. An image build copies paths out of it instead of compiling the Runner again. Nothing in this repository consumes it yet. Its name is ghcr.io/paperclipai/paperclip-runner, and one build makes two variants:

  • full, the runner-artifacts target of the Dockerfile: every path below;
  • slim, the runner-artifacts-slim target: the same without the two paths marked "full only", the provider pack's transport archives.

Layout

Every path a consumer may copy (RUNNER_IMAGE_PATHS in scripts/runner-image-layout.mjs). Every file is readable by every user.

Path Content
/runner-image.json Identity and description of this image.
/paperclip-runnerd The daemon. A stripped release binary, mode 0755.
/provider-pack/ The remote provider pack, with provider-pack.json.
/provider-pack.archive.json Full only. Receipt of the pack's transport archives.
/provider-pack.archives/ Full only. The transport archives the receipt lists.
/runner-package/package.json The Runner package manifest.
/runner-package/dist/ The Runner's complete build output. dist/bin/paperclip-runnerd is the same file as /paperclip-runnerd.
/runner-package/node_modules/.cache/paperclip-runner-build-inputs.json The build stamp the Runner's build recorded for that output.
/runner-package/scripts/provision-grok.mjs Provisions the native Grok executable. Reads platforms.json by relative path.
/runner-package/src/providers/grok/platforms.json The Grok release pins.
/runner-package/src/live/runnerd-codex-transport.ts The transport source, as a contract file. It defines RUNNER_CLIENT_VERSION.
/bundles/runnerd-codex-transport.mjs The pack's dist/live/runnerd-codex-transport.js as one module. It imports without node_modules.
/pnpm-lock.yaml The lockfile the image was installed from.

Paths under /runner-package/ keep their place inside packages/paperclip-runner. runner-image.json describes one platform, and is the same file in both variants:

  • inputsDigest (the identity below) and buildInputsDigest (the digest in the Runner's build stamp);
  • sourceRevision: the commit that built the image, also in the pack as payload.runnerSourceRevision. An image is published once for its inputs, so later commits with the same inputs keep this revision;
  • publication: true only for a build with the build argument PAPERCLIP_RUNNER_IMAGE_PUBLICATION=1. Only then does the pack carry the identity, as payload.runnerInputsDigest. Another image build that runs the stage inline builds the same Runner but is not this image;
  • platform (linux, amd64 or arm64) and libc: the glibc the daemon was compiled on (Debian bookworm, the oldest a consumer runs) and the newest glibc version it needs;
  • providerPack: the pack's digest and target;
  • paths and sha256: the table above, and the digest of every single file;
  • fullImageOnly: the names in paths that only the full image has.

Layers

  1. The pack's dependency files of 1 MiB or more: provider binaries and Node.
  2. Everything else, with runner-image.json.
  3. Full only: the transport archive of each file in layer 1.
  4. Full only: the other transport archives, the overlay archive, the receipt.

The slim image is layers 1 and 2. The full image is those same two layer blobs, then layers 3 and 4, which hold transport content and nothing else. Layers 1 and 3 have the same bytes in every build with the same dependency files, so a new image shares them with the one before it. A large file under the pack's dist is the Runner's own output: it and its archive are in layers 2 and 4. An archive is named by its file's place in the receipt, which lists the dependency files first, so their names do not depend on dist.

Identity

Both variants are named by one digest: the variant is not part of the identity. The full image has the tag inputs-<digest> and the slim image inputs-<digest>-slim. scripts/runner-image-identity.mjs computes the digest from:

  • every file under the paths the build copies from the build context (RUNNER_IMAGE_CONTEXT_INPUTS, which include pnpm-lock.yaml): path, executable bit and content, and each symbolic link by its target;
  • the whole Dockerfile: the recipe, the base image pinned by digest and the toolchain pins. Any edit to it makes a new image;
  • the two platforms, linux/amd64 and linux/arm64.

The source revision is not part of it, and neither is the text of .dockerignore: a rule changes the digest only when it changes which of those files the build receives. The build computes the digest for itself:

docker buildx build --target runner-artifacts-identity --output type=local,dest=/tmp/identity .
jq -r .digest /tmp/identity/runner-image-identity.json

The install is frozen. It fails when the lockfile is behind the manifests the build reads (the root one, packages/paperclip-runner and packages/paperclip-eval-kernel). A contributor cannot edit the lockfile, so pull-request runs resolve it first. For a local build, run pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile.

Checks

CI builds each variant as an OCI archive and nothing else. node scripts/runner-image-oci.mjs unpack <oci archive> --out <tree> writes the tree of an image from its layers, so the tree CI checks is the bytes of the image. It refuses a whiteout, an absolute or .. path, a path written twice and an entry behind a link.

node scripts/runner-image-layout.mjs check <tree> --variant slim|full runs in the build and again on each unpacked tree. The variant has no default: a slim tree with the transport paths fails, and so does a full tree without them. The check fails unless:

  • every documented path exists, matches its digest in runner-image.json, and resolves inside the tree;
  • the build stamp names the inputs the identity names;
  • every artifact in provider-pack.json has its digest, the dist tree and each provider asset tree match their tree digests, and the pack names this image's revision and platform;
  • the pack names the inputs digest in a publication build and in no other. --expect-inputs-digest fails on any other build;
  • in a full image, every transport archive matches its receipt, and the archives extract to the pack. The check extracts them as a sandbox does (GNU tar with the options in provider-pack-layers.ts) and compares paths, content, link targets and all twelve permission bits, after the a+rX grant the build makes once the archives are written.

node scripts/runner-image-oci.mjs check-layers --slim <oci archive> --full <oci archive> checks "Layers" on the two archives, and that no file is in two layers.

The build also runs paperclip-runnerd --build-metadata on every base image in docker/runner-image/Dockerfile.smoke. Add a base there before a consumer uses it.

Consuming the image

Read the image only with COPY --from, and pin it by digest:

FROM ghcr.io/paperclipai/paperclip-runner@sha256:<digest> AS runner-artifacts
FROM debian:trixie-slim
COPY --from=runner-artifacts /paperclip-runnerd /usr/local/bin/paperclip-runnerd

A Dockerfile with a runner-artifacts or runner-artifacts-slim stage of its own, as in this repository, can take a built image or tree in its place with --build-context <stage>=<image or directory>. The stage is then not built.

Choosing the Runner for an image build

scripts/runner-image-resolve.mjs decides whether a build of a checkout can copy the published image. No build uses its answer yet. It has two commands, so that the one that builds reads no registry credential:

node scripts/runner-image-resolve.mjs inputs --dir "$dir"
node scripts/runner-image-resolve.mjs resolve --dir "$dir"

inputs exports the Runner build context, checks the lockfile and computes the inputs digest in the build, as the publication workflow does. Run it on the committed files, before any step that rewrites pnpm-lock.yaml. resolve looks up inputs-<digest> and reports:

  • mode: published or inline, and reason;
  • image and slim_image: both variants, pinned by index digest. The slim digest is the one the full index names (see "Pairing");
  • build_contexts: one --build-context value on each line, which replace the runner-artifacts and runner-artifacts-slim stages;
  • labels: io.paperclip.runner.image and io.paperclip.runner.inputs-digest, for the image that copies the Runner.

published needs a complete publication whose full index names these inputs and both platforms. Every other answer is inline, with the last four values empty: the lockfile is behind the Runner's manifests (lock-behind), the image does not exist (absent), a publication is incomplete or broken, the full index does not match (mismatch), or the registry refused, failed or could not be reached (unknown). An inline build runs the Runner stages itself and carries neither label. The command does not wait for a publication and does not verify the attestation of the image.

Publication

.github/workflows/runner-image.yml publishes on a master push in this repository and nowhere else. Other runs build and check, and publish nothing.

  • Lockfile. A master push builds from the committed pnpm-lock.yaml, so the digest is a function of the commit. When that file is behind the Runner's manifests, the run writes a notice, publishes nothing and stays green. The commit that merges the lockfile refresh publishes the image.
  • Once. The build runs only when inputs-<digest> does not exist.
  • Verified bytes. The build legs cannot write to the registry. The publish job pushes the images they checked by digest and joins each variant into a multi-platform index under a candidate- tag. It attests both indexes, and only then writes the two inputs- tags. candidate- tags are internal: one can name an index that is not attested, and the next run overwrites it. Do not consume them.
  • Order. It writes inputs-<digest>-slim first and inputs-<digest> last, so the full tag marks a complete publication. The full index names its slim index in the annotation io.paperclip.runner.slim-digest.
  • Pairing. Resolve the full tag first. Take the slim digest from that annotation of the full index, and pull the slim image by that digest. Never resolve inputs-<digest>-slim by tag on its own: while a publication is incomplete, that tag can name the slim image of another run.
  • Recovery. A run that stops between the two tags leaves a slim tag alone. Those inputs are not published. The next run for them builds again, replaces that tag with its own slim image and then writes the full tag. A full tag whose slim tag is missing or names another image fails every run for those inputs. An operator must then delete both package versions and re-run the workflow run of a master push with those inputs.
  • Create-only. The workflow never moves a tag of a complete publication, but the registry does not enforce that. Pin the index digest and verify it: gh attestation verify oci://ghcr.io/paperclipai/paperclip-runner@sha256:<digest> --repo paperclipai/paperclip --signer-workflow paperclipai/paperclip/.github/workflows/runner-image.yml --source-ref refs/heads/master
  • First publication. GitHub creates the package private. A maintainer must make it public once.

Known limits

  • A build without PAPERCLIP_RUNNER_SOURCE_REVISION or PAPERCLIP_BUILD_COMMIT has no pack. It is for local use.
  • The build runs the steps of the Runner's build script that write output, not its drift checks; repository CI runs those.
  • A build that vendors /runner-package/ reuses dist only when its own Runner build-inputs digest equals the stamp's. The image computes that digest in the .dockerignore-filtered context; a checkout gives another.
  • # syntax=docker/dockerfile:1.20 is a tag. A new frontend release under it does not change the identity.
  • The archive check does not tell a directory with its own archive member from one created only as a file's parent.
  • A lockfile that the lockfile refresh cannot bring up to the Runner's manifests leaves every master run green with only a notice, for as long as it lasts. No image is published in that time, and nothing fails.