Files
PaperClipAI/doc/runner-image-contract.md
T
Nicky LeachandClaude Fable 5.2 84a4d345b3 refactor(docker): take the application image's Runner from the runner-artifacts stage (#21332)
## 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. `master` publishes
it alone as the image `ghcr.io/paperclipai/paperclip-runner`, built by
the `runner-artifacts` stages of the `Dockerfile`
> - The application image does not use those stages. It has five stages
of its own that compile the daemon, it builds the Runner again inside
the server build, and it builds a second provider pack
> - So one `Dockerfile` holds two recipes for the Runner, and the two
results differ: another base image and another daemon binary
> - This pull request removes the second recipe. The application image
copies the Runner out of the `runner-artifacts` stage, which the same
build runs once
> - The benefit is one Runner recipe, and an application image whose
Runner is the Runner the contract describes. A later pull request can
replace the stage with the published image

## Linked Issues or Issue Description

This is the second part of a chain. The first part is #21331, which
removes the cache check that cannot run on this `Dockerfile`. Refs
#21204, #21229, #21230 (the Runner image), #21306 (the no-rebuild mode
of the vendor step), #21307 (the pull-request check of the application
image) and #21312. No issue exists for this change.

**Problem or motivation**

The stages `rust-toolchain`, `rust-chef`, `runner-plan`, `runner-deps`
and `runner-build` compile the daemon on Debian trixie. The server build
then runs the full build of the Runner package. The
`runner-provider-pack` stage builds the provider pack. The
`runner-artifacts` stages do all of that again for the Runner image, on
Debian bookworm, with a stripped daemon.

**Proposed solution**

Read only the `runner-artifacts` stage from the application stages.
Build it inline in every build. Do not pass a published image yet.

**Alternatives considered**

- Pass the published Runner image to the build in this pull request.
That needs the resolver, labels and a rule for commits without an image.
It is the next step, and this one must be safe alone.
- Keep the old stages as a fallback. Two recipes is the problem.

## What Changed

- `Dockerfile`: remove the five stages. `build` starts from `base`. It
copies `/runner-package/dist` and the build stamp from
`runner-artifacts`, sets `PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1` and
runs the vendor check before the first application build.
- `Dockerfile`: `runner-provider-pack` starts from `base`. One `RUN`
with a bind mount of `runner-artifacts` copies the pack, the receipt and
the archives, and moves the large files to their own tree. `build` and
`runner-provider-pack` now come after the stages they read.
- `Dockerfile`: the three `COPY` instructions of `production` that take
the pack are byte-identical. A test pins all three.
- `Dockerfile`: `build` declares the build argument
`PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST`, empty by default, and one step
runs the new `scripts/check-runner-image-expectation.mjs` on
`/runner-image.json` of `runner-artifacts`. **This pull request declares
the argument. No build sets it. The next pull request, which gives a
published Runner image to the build, is its first user.** With the
argument set, the build fails unless `runner-artifacts` is the published
image of exactly those inputs. `docker-app-check.yml` also runs when the
script changes.
- Comments: the `Dockerfile` has 220 comment lines, down from 247. The
comments of the two moved stages moved with them, unchanged, so the diff
shows them as added lines. Eight comments that named a removed stage or
a step that moved get the smallest correction. Two comments in
`prepare-runner-vendor.mjs` and `build-inputs.mjs` said that the
`Dockerfile` relies on the standalone rebuild; that clause is removed.
- Tests: replace the two cargo-chef tests of
`docker-build-stamp.test.ts` with three tests of the new shape. Update
the pack test, `docker-image-layer-reuse.test.ts`,
`vite-build-commit.test.ts`, the stage rules of
`runner-image-identity.test.ts`, and the include-layout test of
`runner-release-crate-cache.test.mjs`, which now reads
`runner-artifacts-runnerd`.
- Docs: `doc/DOCKER.md`, `doc/DEVELOPING.md`, and a new section "The
application image" in `doc/runner-image-contract.md`.

## Verification

All builds: `linux/arm64`, local, `--build-arg
PAPERCLIP_BUILD_COMMIT=<sha>` with one commit for every build. The
builds ran before the rebase onto `master`, on the head of #21310 as it
was before it merged. `master` changed neither the `Dockerfile` nor an
input of the Runner in between.

- `docker buildx build --target production`, cold, before and after: 506
s and 410 s. Compressed size: 2,971 MB and 2,900 MB.
- The image config and the text of all 33 history rows are identical.
The row `COPY /provider-pack-transport/ /opt/paperclip-runner/ #
buildkit` matches the pattern of `retained-provider-pack-oci.ts` exactly
once.
- A comparison of every file of the two images (path, type, size, mode,
link target, and SHA-256 under `/app` and `/opt`). The differences are
in "Risks". All other files are byte-identical, the root `node_modules`
included.
- From the image after: the four `/app/packages/paperclip-runner/...`
paths and the contents of `/opt/paperclip-runner/` exist.
`paperclip-runnerd --build-metadata` runs. `provider-pack.json` has
`runnerSourceRevision` equal to the build commit and no
`runnerInputsDigest`. The entry points `index.js`, `live/index.js` and
`testing.js` of the Runner import.
- The vendor step logged `reusing the current Runner build` in both of
its runs. Every `Compiling` line of the log is in
`runner-artifacts-runnerd`.
- `--target build`, `--target runner-provider-pack` and `--target cloud`
built. The `build` stage has no `gcc`, `cc`, `cargo`, `rustc` or
`pkg-config`.
- `--target runner-artifacts` and `runner-artifacts-slim`, before and
after: `runner-image-layout.mjs check` and `runner-image-oci.mjs
check-layers` pass on both, in `node:24.22.3-bookworm`. The daemon,
`provider-pack.json` and the two stable layers have the same digests
before and after.
- Without a build commit: `build` and `runner-provider-pack` built, and
the pack was skipped with the same message. This run was on the next
branch of this chain, after the rebase. The last steps of `production`
were not run for this case.
- The expectation argument, on this `Dockerfile`, `--target build
--output type=cacheonly`, after the rebase:
- No argument, inline Runner: the build passes (233 s). The step passes.
- Argument, inline Runner: the build fails at the step. The message says
that the `runner-artifacts` of the build are not a published Runner
image.
- Argument `d4df566f…` and the published image of those inputs as
`--build-context
runner-artifacts=docker-image://ghcr.io/paperclipai/paperclip-runner@sha256:0cd8250b…`:
the step passes, and the build runs no Runner stage. The vendor step
then fails with `inputs changed since the recorded build`, because this
tree differs from the tree of that image by one comment line in
`build-inputs.mjs`. With that line put back, the same build completes,
and the vendor step reuses the published build.
- Another digest with the same context: the build fails at the step. The
message names the inputs the image has.
- A tree whose lockfile is behind the manifests of the Runner fails at
the frozen install of the Runner stages, after 169 s, with the message
that stage already had.
- `docker buildx build --check`: no warning, before and after.
`scripts/check-docker-deps-stage.mjs` and
`scripts/check-node-version-policy.mjs` pass.
- Tests, on macOS and in `node:24.22.3-bookworm`, after the rebase: the
changed server test files with the other tests that read the
`Dockerfile` or the image workflows (231 pass in 10 files on Linux),
`vite-build-commit.test.ts` (10 pass),
`runner-release-crate-cache.test.mjs` (11 pass),
`docker-deps-postinstall.test.mjs`. The changed server test files
typecheck.
- Not run: the full test suite, any `linux/amd64` build, `podman`, the
workflows and the release pipeline. Only CI can prove amd64,
`docker.yml`, `docker-merge-group.yml`, `release.yml`,
`docker-app-check.yml` and `runner-image.yml`.

## Risks

- **The digest of the Runner image changes.** Its identity covers the
whole `Dockerfile`. The next `master` push publishes a new
`inputs-<digest>`. The contents do not change: see the comparison above.
- **A build that is given a Runner of other inputs fails; it does not
ship that Runner.** With the argument, it fails at the expectation step.
Without the argument, it fails at the vendor step when the build inputs
of the Runner differ. One comment line in `build-inputs.mjs` changes
those build inputs in this pull request, so the image published before
this pull request cannot be vendored into a tree after it.
- **What a consumer of the application image sees** (measured on
`linux/arm64`):
- The daemon is the stripped binary compiled on Debian bookworm: 23.2
MB, was 36.4 MB, at
`/app/packages/paperclip-runner/dist/bin/paperclip-runnerd` and at the
vendored copy in `server/dist`. Its hash changes. It has no symbols for
a crash backtrace.
- `/app/packages/paperclip-eval-kernel/dist` is absent. Only
`dist/eval/workflow-harness.js` of the Runner imports that package. Only
`eval/index.js` exports the harness again, and no module imports that
file. The server runtime bundle does not name the package.
- The provider pack: `provider-pack.json` is byte-identical. Two
provider executables and one licence file are hard links to their other
copy in the pack, where they were separate files. One empty directory is
absent. The pack is 195 MB smaller, and the layer of its large files
gets a new digest once.
- The transport archives have other bytes, because the Runner build
gives large files a fixed timestamp. The receipt names the same files
with the same digests.
- Paths, modes, owners, the image config and the layer order do not
change.
- **What a contributor and a maintainer of the image build see:**
- **The image build does not run the drift checks of the Runner.**
Before, the server build ran the full `build` script of the Runner, so a
failed drift check failed the image build on `master`. Now the Runner
stages run only the output steps of that script. Repository CI runs the
checks on every pull request. `.github/docker-context-checks.Dockerfile`
and three exceptions in `.dockerignore` exist for those checks in the
image build; a separate follow-up removes them, and this chain does not
edit them.
- **The dependency-caching layer of the daemon is gone.** Before,
cargo-chef compiled the Rust dependencies in a layer of their own, and a
change to the Rust source compiled only the Runner's own crates. Now
such a change compiles the dependencies again (146 s here for the whole
daemon). A change to the server, the UI or the Runner's TypeScript still
reuses the compiled daemon.
- **A lockfile behind the manifests of the Runner fails the build.**
Before, `docker build` resolved it inside the image. The image workflows
refresh the lockfile first. A local build prints the command to run. The
next pull request makes this failure early and clear.
- **The build needs more disk**: about 25 GB of builder storage here,
was about 20 GB, with the image export.
- Rollback: revert this pull request. Images that exist do not change.

> 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>
2026-11-13 09:48:49 -08:00

356 lines
20 KiB
Markdown

# 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. The application image of this
repository takes its Runner from the stage that builds it (see "The
application image"); no build reads the published image 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:
```sh
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` or a read-only bind mount
(`RUN --mount=type=bind,from=`), and pin it by digest:
```dockerfile
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.
### The application image
The `production` and `cloud` targets of the `Dockerfile` read only the
`runner-artifacts` stage, in two stages:
- `build` copies `/runner-package/dist` and the build stamp into
`packages/paperclip-runner` and sets
`PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1`. The server build then vendors
that output, and fails when the stamp does not match the Runner inputs of
the tree it builds. The lockfile is one of those inputs.
- `runner-provider-pack` copies `/provider-pack`, the receipt and the
archives, and moves each pack file of 1 MiB or more to a tree of its own.
`production` copies the three trees with the same three instructions as
before, so the paths under `/opt/paperclip-runner/` and the layers are the
same. A deployed server finds the transport layer of an application image
by the text of the instruction
`COPY --from=runner-provider-pack /provider-pack-transport/ /opt/paperclip-runner/`
in the image history (`retained-provider-pack-oci.ts`). Do not change it.
No workflow replaces the stage yet, so every application image build runs
the Runner stages itself: an inline Runner. An inline Runner is not this
image, and an application image says so in three ways:
- its pack names the build commit of the application image as
`payload.runnerSourceRevision`, the value of `PAPERCLIP_BUILD_COMMIT`;
- its pack has no `payload.runnerInputsDigest`;
- the image has neither label of "Choosing the Runner for an image build".
A build without `PAPERCLIP_BUILD_COMMIT` has no pack, as before.
`build` also declares the build argument
`PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST`, which no build sets yet. It is for
a build that replaces the stage with a published image. When the argument is
set, `scripts/check-runner-image-expectation.mjs` reads `/runner-image.json`
of the `runner-artifacts` the build was given, and the build fails unless
that file has `publication: true` and names exactly those inputs. An inline
Runner is never a publication, so the argument without the image fails too.
The check runs before the server build vendors the Runner.
### 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: on a `master` push,
the `runner_image_report` job of `.github/workflows/docker.yml` runs it and
writes the answer to the job summary, and nothing reads that job. The job
runs on the committed files, holds no credential (the Runner package is
public, so the lookup is anonymous) and cannot fail the run. The script has
two commands, so that the one that builds reads no registry credential:
```sh
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.
## Build cache
The build legs read a registry build cache,
`ghcr.io/paperclipai/paperclip-runner-buildcache:<arch>`. It is a package of
its own and holds no image, so the image package holds only attested images.
It covers the stages that do not take the commit: the Rust toolchain and the
compiled daemon. The last stage takes the source revision as a build
argument, so every build runs it: the frozen install, the Runner's build and
the provider pack. Of the two build commands of a leg, only the first reads
the registry cache; the second reads what the first left in the job's builder.
- **Effect.** BuildKit reuses a cached step only when the step and the
content of every file it reads are the same. The cache changes how long a
build takes, not what it builds, and the identity does not cover it.
- **Writer.** Only the `cache` job of the workflow writes it: on a `master`
push in this repository, after the publish job, for inputs that had no
image. When the image exists, nothing was built, and the run that published
it wrote the cache for those inputs. That job cannot sign, builds no further
than the daemon and never runs the install. Its token reaches the registry
login and no other step. It reads the cache it writes and keeps every step
of the cached stages (`mode=max`). Every other run reads the cache without
a credential and cannot write it.
- **Not on the way to an image.** No job waits for the `cache` job. When it
fails, the image is published and the next build is slower.
- **One write at a time.** The job holds one concurrency slot for each
architecture. GitHub keeps one waiting job in a group and cancels the one
that waited before it, so the newest write waits. A write from an older
commit that lands last costs time and nothing else.
- **No Actions cache.** The workflow never uses it: workflows that handle
pull requests can write it, and what they write must not reach a published
image.
- **Trust.** The daemon in a published image can come from a cached step
that an earlier `master` run compiled. Whoever can write the cache package
can decide what a later build reuses, so write access to it must stay as
narrow as write access to the image package.
- **Fetches.** A cached step does not run again. A download inside one (the
toolchain installer, the toolchain, the crates) is not repeated until the
inputs of that step change.
- **Weekly cold build.** A scheduled run builds both variants once a week
with no cache: it passes `--no-cache` and reads no registry cache. Like a
manual run, it resolves the lockfile, always builds, runs every check and
publishes nothing. A fork's schedule runs nothing. It fails when a download
is gone or when a step only works from the cache.
- **Missing cache.** A cache that does not exist or cannot be read is a
line in the build log, not a failure. The build then runs every step.
- **First write.** GitHub creates the cache package private. A maintainer
must make it public once. Until then every build runs cold.
## Reading the transport archives alone
The server needs the transport form of an older pack when a retained session
names a pack that is not the server's own. A pack with
`payload.runnerInputsDigest` came out of this image, so the server reads it
from `inputs-<digest>` (`retained-provider-pack-oci.ts`). It does not count
layers. It uses the rule of "Layers": the full image is the slim image, then
layers that hold transport content and nothing else.
- The full index must carry the annotations
`io.paperclip.runner.inputs-digest`, equal to the pack's digest of inputs,
`org.opencontainers.image.revision`, equal to the pack's
`runnerSourceRevision`, and `io.paperclip.runner.slim-digest`.
- The server reads the slim index by that digest, never by the slim tag, and
checks the bytes against the digest.
- For the pack's platform, the layers of the slim image must be the first
layers of the full image, as the same blobs in the same order. The layers
after them are the transport layers: at least one and at most eight.
- The server downloads only those layers. It refuses any entry in them that
is not a transport archive or the receipt, and any file that is in two of
them.
- The importer then checks every archive against the pack's manifest, as for
any other source.
- The record the server keeps of the source names the digest of inputs and
every transport layer under `runnerImage`. Its `transportLayerDigest` is
then the last of those layers and `transportLayerBytes` their total.
When the image cannot be read (a tag or the slim index does not exist, or the
registry refuses a request), the server reads the application image tagged
`sha-<runnerSourceRevision>`, as it does for a pack without
`runnerInputsDigest`. An image that can be read and does not match fails.
## 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.