Plan: CI compiles each thing once
Status
Done (2026-11-08) — U1–U6 delivered: every Rust job runs in one prebuilt craig-ci image, xtask is built once per pipeline, a car has one check job and one docs build, and main repeats nothing the train proved; plan ci-dev-loop (#3042) later replaced the car DAG, docker-promote and the registry hand-off with one car job and release-build
Issues: #2982 is the plan issue (retitled to this plan on approval; it carries the measurements). U1 closes #2980,
U2 closes #2982 and #2940, U5 closes #2981; U1, U3, U4 and U6 each get a unit issue on approval, which the unit
closes. Related: #2968 (the 4xlarge queue), #2969 (the runner cache’s S3 403), #2931, #2937, #2938, #2941 (the shape
being changed), #2779 (the floating tags).
Branches: chore/ci-image, chore/ci-xtask-once, chore/ci-car-dag, chore/ci-main-pipeline,
chore/docs-link-check.
A Design + Scope plan: GitLab owns tracking; the plan freezes when U1 starts. The maintainer decided the three forks in § Decisions on 2026-11-07.
Context
Two pipelines of one tree were profiled (train pipeline 3038692446 for !2178; main pipeline 3038934337 after its
merge), job traces read for Compiling lines, Finished … in times and queue durations.
| Repeated work (4xlarge minutes) | per car | per merge |
|---|---|---|
|
7 × 2.2 ≈ 15 |
≈ 7 |
|
≈ 7 |
≈ 3 |
xtask compiled in every job that runs it: 521 crates, 1-2.5 min on bookworm, 9-13 min on the Alpine |
≈ 15 |
≈ 27 |
|
3 VMs, ≈ 25 |
|
|
13 |
— |
Antora built twice ( |
≈ 8 |
≈ 13 |
|
— |
55 + 38 |
|
— |
40 |
|
— |
18 |
Total |
≈ 134, 11 VMs |
≈ 190 |
Each VM also waits 24-60 minutes for a 4xlarge (#2968): the pool is shared with canopy, and fewer VMs per car is the lever CRAIG owns. The runner’s distributed cache answers 403 (#2969), so every design here is cache-independent: GitLab artifacts and the container registry carry state between jobs, nothing else.
Earlier plans: ci-integration-build-once-fanout.adoc (#1739, Not started) is superseded by merge-trains-gate’s
build → battery ∥ e2e and by this plan; archiving it is a one-line follow-up, not a unit here.
Design
D1 — One CI image, keyed by its inputs
ci/Dockerfile.ci builds craig-ci: rust:1.97.0-bookworm with the pinned toolchain installed, cargo-nextest,
cargo-machete, cargo-audit, cargo-deny and cargo-cyclonedx at pinned versions (the only pin site, #2980), the Docker
CLI with the buildx and compose plugins from Docker’s signed apt repository (today’s .docker-host script), git-lfs,
age, sops, openssl, and the cargo registry pre-fetched for the Cargo.lock at build time. Its tag is the SHA-256 of
ci/Dockerfile.ci and rust-toolchain.toml (the craig-tools pattern, xtask/src/cmd/ci/buildx.rs:180-195), not of
Cargo.lock: a lock drift costs a delta fetch at run time, never an image rebuild.
cargo xtask ci image --ensure computes the tag, asks the registry, and builds and pushes only when absent. The
ci-image job runs first in every pipeline (needs: [], about 20 s when the image exists, 8-10 min when a toolchain
bump rebuilds it). Every Rust job declares image: $CI_REGISTRY_IMAGE/ci/craig-ci:$CRAIG_CI_IMAGE_TAG, the tag a
variable pinned in the YAML; a contract test recomputes the hash from the checkout and fails when the pin is stale,
naming cargo xtask ci image --bump as the fix. RUST_IMAGE, RUST_CI_IMAGE, the docker:27 + dind pair,
ci/Dockerfile.audit-tools and every apt-get, rustup and cargo install line leave the YAML. .cargo-cache goes
with them: the image carries the registry, and the cache it fed is unreadable anyway.
Erratum (2026-11-07, U1): cargo-cyclonedx is pinned at 0.5.9, not the latest 0.5.10: 0.5.10 publishes no release
binaries, and every tool in craig-ci is a checksummed release binary.
Erratum (2026-11-07, U1): until U5 retires docs-deadlinks, its viewer-emission leg skips: craig-ci carries no
node, and installing it in the job would be the run-time install D1 removes.
D2 — xtask built once per pipeline
The xtask job (needs: [ci-image]) runs cargo build -p xtask --config profile.dev.debug=false, copies the binary
to target/ci/bin/xtask and ships it as an artifact; it then runs the three content lints that docs-content-lints
ran (lints mandatory-docs, plan-lint, lints doc-pointer-integrity: file scans, about 30 s), so that job goes.
Every other job needs: [{job: xtask, artifacts: true}], puts target/ci/bin first on PATH through one
.xtask-bin template, and its script lines read xtask …. The pipeline contract (pipeline_tests.rs) changes in
three places: the verb prefix the script-line test accepts (xtask `), one allow-listed bootstrap line (the `xtask
job’s cargo build -p xtask …, exempt from FORBIDDEN’s `cargo build rule by job name, the only exemption), and
REQUIRED_OUTSIDE_DAG, where docs-content-lints becomes xtask (the lints now run there) and, with U3,
docs-xref-check becomes docs.
Inside craig-tools the re-execution runs cargo xtask today, in two places: xtask/src/docker.rs
(reexec_in_network, tools_exec) and xtask/src/cmd/ci/mod.rs:191-200 (StageCommand::argv, the cargo xtask ci
<stage> argv run_stage hands to tools_exec); so the battery and e2e compile xtask a second time in the container.
craig-tools is Playwright noble (glibc 2.39), the binary is bookworm (glibc 2.36) with rustls and no OpenSSL, and the
checkout is mounted at its own path: both sites take their argv head from one new helper that returns
current_exe() when it lies under the checkout and ["cargo", "xtask"] otherwise, so a developer’s cargo xtask dev
exec keeps working. A unit test pins both branches of the helper.
Erratum (2026-11-07): the re-execution reuses current_exe() only under target/ci/bin/ (the bookworm-built
artifact, glibc 2.36); a developer’s host-built binary can need a newer glibc than craig-tools' noble 2.39 (luchs
builds against 2.44), so it falls back to cargo xtask.
Erratum (2026-11-07): ci-image keeps cargo xtask ci image --ensure, since it runs before the xtask job; the
script-line test allows it in that job alone, as it allows the xtask job’s cargo build line.
#2940 (the per-job CARGO_ALIAS_XTASK and xtask-target cache) never reached main: it sits in car 6 (!2165). U2
closes it as superseded, and D6 rebases car 6 without that commit; nothing is removed from main.
Erratum (2026-11-07): car 6 merged before U1, so #2940’s alias and xtask-target cache did reach main; they leave
with .cargo-cache in U1 (with their two contract tests), and U2 closes #2940 with nothing left to remove.
D3 — The car DAG: xtask → check ∥ build ∥ docs → battery ∥ e2e
-
checkis one job again. A newcargo xtask ci checkruns thelint,clippyandunitstages in sequence on one target directory, each to completion with its own step table and JSON report, and exits red if any was: #2941’s property (a red lint hides nothing) holds without three VMs. The three stage verbs stay for the hook and forvalidate. -
buildis unchanged in substance (xtask ci images --publish-digests), now without the tool installs and the xtask compile. -
docsis one Antora build in the Antora image:--log-failure-level=warn(the xref gate, blocking), the review artifact and environment, and the source-level external-link check of D5 as a second script line that exits 42 on dead links, withallow_failure: {exit_codes: [42]}on the job, so the xref gate’s exit 2 still blocks and a dead external link never can. It replacesdocs-xref-check,docs-deadlinksandreview. -
feature-matrixruns onmainand on the schedule, never on a car: a bundle that stops building alone is a post-mergefix:(decision 2). -
.car-rules,.stack-rulesand D5 of ADR-086 keep their meaning; ADR-086 D2 is amended for the new job names.
Six VMs per car. The stack jobs keep $CI_BATTERY_RUNNER_TAG; everything stays on the 4xlarge (#2935).
Erratum (2026-11-07): CI_BATTERY_RUNNER_TAG is dropped (ADR-086 § D3, amended): every job runs on $CI_RUNNER_TAG.
D4 — main repeats nothing the train proved
The train pipeline ran on the merged result, so after the merge main holds a proven tree. On main: ci-image,
xtask, build (it writes the BuildKit cache the cars read), docker-promote (needs: [build], reading that cache
and the xtask artifact, no dind), secrets-policy (ADR-064’s keyed decrypt on protected refs), pages (an Antora build
with --log-failure-level=warn), feature-matrix, the GitLab scan templates and sbom/release on tags. Not on
main: clippy, docs-xref-check, docs-deadlinks, docs-content-lints, review. pentest, perf-load,
perf-stress and cluster-tests run on the schedule and by hand (when: manual on main), and when a build
artifact exists in their pipeline they take --from-digests instead of rebuilding (decision 1).
Erratum (2026-11-07): cargo-deny also stays on main when the dependency manifests change (#2658 put it there): a
33-second security scan of the merged lock, kept rather than dropped from the D4 set.
docker-promote reads and writes its own BuildKit cache group: ci images --push gains --write-cache, using
cache_ref(image, "release") (buildx.rs:43) as --cache-from and, on main, --cache-to, so each promote
rebuilds only the crates the merge changed. build and docker-promote keep separate groups because their
CARGO_PROFILE differs.
The 18-minute build on main against 3 m 34 s for the same tree on the train is a cache miss, a slow export, or
both. U4 compares the two traces' BuildKit step lines (#N CACHED against #N DONE <seconds>) stage by stage, then
reproduces the miss on the 4xlarge-equivalent path with --progress=plain, testing the three candidate causes in
order: the --write-cache run’s --cache-to export time itself (an export-only cost: fix by exporting once per
distinct input hash, skipping when the registry already holds the cache for that hash), GIT_DEPTH: "0" changing a
COPY . . input the train’s shallow clone lacked (fix: exclude .git in .dockerignore, or copy the same
set), and a cache ref the train writes to but main reads from a different group. The fix is whichever the
evidence names, with the evidence on the unit issue. Acceptance: build on main within 1.5× the train’s build
for the same tree.
Erratum (2026-11-07): the evidence on #2985 named other causes than the three candidates: the cache writer, main’s
interruptible `build, cancelled before it ran by the next merge’s pipeline; cargo’s crates.io fetch stalling inside
the BuildKit cook (1053 s against 10 s); and images keyed by commit, so main could not find the train’s images for
the same tree. The .git and cache-ref candidates were refuted, and the export is a secondary 100-240 s. U4 keys the
images by HEAD^{tree} and reuses existing tags, tags the cache per cook recipe and exports it only when missing,
makes build non-interruptible on main, and feeds craig-ci’s registry into the cook.
Erratum (2026-11-07): cluster-tests takes no --from-digests: its rig images take other build args and their own
tag (docker-compose.cluster.yml), so build’s images are not its images. It keeps its rules (the `CLUSTER_TESTS
schedule, manual on main, and the cluster-tests MR label) and builds its rig.
D5 — The link check reads the AsciiDoc sources
An Antora extension in docs/extensions/ (beside the mermaid one, registered in antora-playbook.yml) enables
Asciidoctor’s catalog_assets, collects every external http(s) link per page with attributes substituted, checks them
(HEAD then GET, bounded concurrency, retries, a timeout, the accept list and the exclusions ported from
.lychee.toml) over Node’s core https module (the antora:3.1.14 image runs Node 16, which has no default
fetch), writes build/link-check.json and prints one summary line per dead link naming page and URL. It never logs
through Antora’s logger at warn or error, so it cannot trip --log-failure-level=warn; the docs job’s second script
line reads the report and exits 42 when it holds a dead link (D3). Repo-root prose outside Antora goes through a
small node script on the same Asciidoctor.js, writing into the same report. No new dependency.
.lychee.toml, the lychee download, docs/extensions/lychee-preprocess.sh and cargo xtask docs deadlinks go
(alternatives weighed on #2981: asciidoc-aware-link-check, linkspector, adoc-link-checker). A site’s outage is no
car’s fault, so the leg stays advisory (ADR-086 D6).
D6 — Cutting over the pending cars
When U1-U4 are on main, every car still on the old shape is taken off the train, rebased onto main (or main
merged in, where a stack of MRs shares history), pushed and re-added with auto_merge=true. Car 6 (!2165) loses #2940,
which U2 supersedes, and keeps #2945. Each car’s issue gets the new pipeline id and its per-job timings beside the old
ones.
Decisions
-
pentest and perf-load leave the per-merge pipeline (schedule + manual). Advisory jobs that cost 93 runner-minutes per merge, on the pool the train queues for. Rejected: keeping them with
--from-digestsonly (still about 40 minutes per merge of a 4xlarge for a detector that runs nightly anyway). -
feature-matrix runs on
mainand nightly, not per car. It proves each bundle builds in isolation; a break is a post-mergefix:, never a wrong merged behaviour. Rejected: folding it intocheck(+6 min on every car’s critical path). -
docker-promote stays per code merge, reading the BuildKit cache
buildjust wrote and the xtask artifact; thelatestimages keep trackingmain(#2779 keeps its own scope). -
The image tag is a pin in the YAML, held by a test, not a floating tag. A floating tag would let one MR’s toolchain bump change the image under every other running car; a pin makes the change travel with the commit that needs it.
-
Keyed on the Dockerfile and toolchain, not on
Cargo.lock: a lock changes weekly, a toolchain quarterly; a delta fetch costs seconds, an image build ten minutes. -
checkis sequential on one VM. Wall time about 13-15 min against 11 for three parallel VMs; each VM waits 24-60 minutes for a runner, so one VM is faster end to end and two-thirds cheaper.
Risks
| Risk | Mode | Mitigation and test |
|---|---|---|
The pinned image tag drifts from its inputs and jobs run an old toolchain. |
silent |
The contract test recomputes the hash from the checkout and fails the |
A job pulls |
fail-closed |
Every job |
The xtask binary does not run in some job image. |
fail-closed |
All Rust jobs run in |
|
fail-open (throughput) |
|
A dead external link, or the check’s own HTTP flake, blocks a car through the |
fail-closed |
The leg exits 42 and only 42 is allowed to fail; the extension never logs at warn or error. Contract test: |
Removing |
fail-open (throughput) |
Measured in U1 on a car whose lock differs from the image’s: the delta fetch is seconds; the image rebuilds with the next toolchain bump regardless. |
Scope
| Unit | Delivers | Proves (tests) |
|---|---|---|
U1 |
|
Contract: the pin equals the input hash (red: an unbumped Dockerfile edit); no script or before_script line installs
anything; every job names |
U2 |
The |
Contract: every script line is an xtask verb or allow-listed (prefix changed; red: a |
U3 |
|
Contract: on a train exactly |
U4 |
|
Contract: on |
U5 |
The link-check Antora extension and the root-prose script (D5) in the |
Extension tests with node against a throwaway local HTTP server: a dead URL fails, a live one passes, an
attribute-derived URL is resolved, an excluded URL is skipped, a 429 is accepted. Contract: the |
U6 |
D6: the pending cars cut over. |
Each car’s issue carries the new train pipeline id and per-job timings beside the old; no car lands on the old shape after U4 merges. Operational: no code, docs or CHANGELOG; the unit issue lists the cars and closes when the last has landed. |
Order: U1 → U2 → U3 → U4, each a car stacked on the one before; U5 beside U3 (it changes only the docs job’s
Antora inputs); U6 after U4 merges. .gitlab-ci.yml stays under 500 lines (it shrinks), needs: on every job, the CI
lint API green on each unit.