Plan: the battery compiles while build builds

Status

Done (2026-11-08) — U1–U3 delivered: the battery job compiled its tests while build made the images and waited for them in the registry, a train ran the unit tests once, and CI test builds carry line tables only; plan ci-dev-loop (#3042) later replaced the build and battery jobs and the registry wait with one car job

Issues: #2994 is the plan issue and U1’s; U2 and U3 get a unit issue on approval. Related: #2982 (ci-compile-once, whose D3 edge build → battery this plan replaces), #2946 (the reused VM), #2963 (the registry’s BLOB_UPLOAD_UNKNOWN), #2968 (the 4xlarge queue). Branches: chore/ci-battery-ahead, chore/ci-check-no-unit, chore/ci-test-debuginfo.

A Design + Scope plan: GitLab owns tracking; the plan freezes when U1 starts. The maintainer chose this design over a nextest archive and over an in-job overlap on 2026-11-07 (§ Decisions).

Context

!2201’s first train pipeline (3040287914) ran the ci-compile-once shape: every queue 0-4 s, no install and no tool compile in any trace. Its critical path is ci-image 145 s → xtask 85 s → build 831 s → battery 2,096 s, about 53 minutes. The battery’s trace (job 17833374348) splits as:

Battery step seconds what it waits on

runner prepare

66

ci devstack-up --from-digests

281

156 s pulling the tree’s images, 124 s refresh and reseed

ci build-tests

1,172

a cold compile of every test target in craig-tools (target/craig-tools); it reads no image, yet it starts only after build has finished

ci battery

479

nextest, 16,824 tests; its own inventory step compiles nothing (1.2 s)

check (807 s) runs unit last: a 321 s compile of the lib and bin tests and an 80 s run of 10,441 tests, every one of which the battery’s --run-ignored=all runs again. build took 831 s here and 1,014 s on the run before.

Evidence. The code this plan cites is chore/ci-image-v2 (!2201, the ci-compile-once chain), the tree U1 starts from. At planning time the primary checkout is on an older branch: xtask/src/cmd/ci/check.rs, infra_images.rs and plans/ci-compile-once.adoc exist only on that branch (git show chore/ci-image-v2:<path>), and the other cited files are older there (.gitlab-ci.yml still the 499-line shape). The function names cited (publish_digests, pull_manifest, read_manifest, tools_exec, require_network, tools_run_argv, tools_from_registry, publish_tools) exist in both revisions. pipeline_tests.rs is the contract-test file the Scope rows name.

Design

D1 — The battery needs only xtask

battery’s `needs: becomes [{job: xtask, artifacts: true}]. Its script runs ci build-tests first, then ci devstack-up --await-images, then ci battery. The compile overlaps build; by the time it ends (about 19 minutes after the job starts) build has normally finished (14-17 minutes after it starts, in parallel), so the wait is zero.

ci build-tests runs in craig-tools with no project network: ToolsRun.network becomes Option<String>, None emitting no --network (the default bridge, which the compile’s crate downloads need), and run_stage’s re-execution of `build-tests takes that form instead of tools_exec’s `require_network. craig-tools itself comes from the registry by its input hash, or is built and pushed when the hash is missing (tools_from_registry, unchanged; the build job then publishes craig-tools first, before the app images, so the two never both build it for long). `validate --profile full’s local order (devstack-up, then build-tests) does not change.

D2 — --await-images: the manifest from the tree, not from an artifact

Every image build publishes has a reference computable from the checkout alone: the app images <image>/ci/<repo>:<tree>-<tag> over docker::publish_specs() (images::ci_image_ref), the compose-built infra images over infra_images::compose_built_services() (infra_image_ref), and craig-devtools at its content tag under the tree. One function, tree_image_refs(image, tree), lists them; publish_digests and infra_images::publish build their lists through it, so the await and the publish cannot disagree.

ci devstack-up --await-images [--within 30m] replaces --from-digests everywhere: it lists the refs, asks the registry for each missing one’s digest (buildx::registry_digest: docker buildx imagetools inspect, which reads the manifest without pulling) every 20 s until every ref is held or the bound passes, then assembles the ImageManifest (tree, digest refs), writes it to target/ci/images.json as build does, and runs the existing pull_manifest. The bound failing names the refs still missing. A tag appears only when its push has completed, so a held ref is a complete image, and the tree key is the same proof build itself relies on when it reuses an image. The wait is on an observed condition, not a sleep that masks a race: nothing in the battery can make the images appear faster. The stack jobs that keep needs: [xtask, build] (e2e, the scheduled and manual stacks) use the same flag and resolve at once; build’s artifact entry in their `needs becomes artifacts: false. read_manifest and the --from-digests flag go.

Erratum (2026-11-07): buildx::registry_digest reads every failed inspect as "absent", so the await probes through a new buildx::registry_probe (held, absent, or failed; absent only when the inspect’s stderr ends : not found), and registry_digest wraps it unchanged; --within takes whole minutes (30m), xtask having no duration parser.

D3 — A failed job cancels the car’s other jobs

workflow:rules splits in two so that the MR-and-train rule carries auto_cancel: {on_job_failure: all} ("cancel the pipeline and all running jobs as soon as one job fails") and the main, tag and schedule rule does not: main’s `build is the cache writer (interruptible: false), and a cancelled export leaves a half-written cache tag. On a train, a red build or check therefore frees the battery’s VM within seconds instead of letting it compile for 19 minutes and then wait out --within.

D4 — The train runs the unit tests once

The battery’s --run-ignored=all runs every lib and bin test the unit stage runs (16,824 against 10,441; the same binaries, built in craig-tools). On a merge train check therefore runs lint and clippy only: the .car-rules train rule sets CRAIG_CHECK_FLAG: "--skip-unit" (rules:variables, the pattern of CRAIG_IMAGES_CACHE_FLAG), the plain-MR rule leaves it empty, and the script is xtask ci check $CRAIG_CHECK_FLAG --json. An MR pipeline keeps unit: its stack jobs are manual, so it is the only run of those tests before the train. ci check --skip-unit prints that the battery runs the unit tests, so a trace never reads as a silent skip.

D5 — Debuginfo in CI test builds: measured, then decided

Full debuginfo makes the 332 test binaries 30-60 GB and the link step long. CARGO_PROFILE_TEST_DEBUG=line-tables-only keeps file and line in every backtrace while dropping variable and type information. U3 measures a clean cargo nextest run --no-run --workspace --locked on luchs with and without it (wall, target/debug/deps size) and adopts it only if the compile’s wall falls by at least 8 %: then the variable goes on the check and battery jobs, docker::CI_PASSTHROUGH carries it into craig-tools (both of the battery’s compiles must see one value), and a contract test pins both. Otherwise U3 records the numbers on its issue and changes nothing.

Expected numbers

Wall per car: ci-image + xtask ≈ 4 min, then the battery: prepare 1 min, compile ≈ 19 min (less under D5), pull and refresh ≈ 5 min, nextest ≈ 8 min, about 36-37 min; e2e ends at about 34 min. Runner minutes per car: ≈ 86 today, ≈ 79 after D4 (the battery’s compute moves earlier but does not shrink). Acceptance for the plan: the first five cars after U1+U2 average ≤ 40 min wall and ≤ 82 runner-minutes, recorded on #2994 from the API’s job durations.

Risks

  • The bound expires (D2; fail-closed). build is slower than the battery’s compile plus 30 minutes, or red without D3 cancelling (an MR pipeline’s manual battery). The await fails naming the missing refs; the car drops and is read like any red car. Mitigation: the bound is a flag, and the first five cars' wait times go on #2994.

  • A registry probe errors mid-wait (D2; fail-closed). One imagetools inspect failing (a 5xx, #2963’s registry) ends the await with that error rather than counting as "not yet": a transient registry fault then costs a re-add, never a stack run against a partial image set. Mitigation: the error names the ref and the registry’s answer.

  • A half-written cache tag on main (D3; silent). on_job_failure: all would cancel main’s `build mid-export. Mitigation: the setting rides only the MR-and-train workflow rule; the contract test pins that `main’s rule has none.

  • A unit test red only in craig-ci (D4; fail-open on a train). A test that passes in craig-tools (noble) and fails in craig-ci (bookworm) would reach main through a train. Mitigation: every car’s MR pipeline ran unit in craig-ci before it joined the train, and `main’s own pipeline does not run tests either today.

  • Two jobs build craig-tools at once (D1; silent, harmless). When the tools hash is missing, build and battery may both build and push the same tag; the content is identical and the later push wins. Mitigation: build publishes craig-tools first, so the window is the tools build alone.

Decisions

  • Overlap and dedupe, not a nextest archive (2026-11-07, the maintainer). The archive is the truest compile-once, but the binaries exceed the 1 GB artifact cap many times over even stripped, and the registry route is the one #2963 has shown fragile. Rejected too: overlapping only the devstack-up inside the battery (about −5 min; it leaves the compile and the duplication in place).

  • One image hand-off, computed from the tree. --from-digests and --await-images would be two paths for one thing; the artifact carried nothing the checkout cannot compute. Pre-1.0: no shim keeps the old flag.

  • e2e keeps needs: build. It compiles nothing; its pre-build work is under a minute.

Scope

Unit Delivers Proof, docs, closes

U1

D1, D2, D3: battery on xtask only; ci build-tests off the network; tree_image_refs; ci devstack-up --await-images --within; --from-digests removed; craig-tools published first in build; the split workflow rule; the DAG comment at the top of the YAML.

Contract (pipeline_tests.rs, red first): battery’s `needs is exactly xtask; its script lines are build-tests, devstack-up --await-images, battery, in that order; no script line says --from-digests; the MR workflow rule carries on_job_failure: all and the main rule carries none; the stack jobs' build needs are artifacts: false. Unit: tree_image_refs equals the publish’s list for a fixture of specs; the await’s pure core resolves when every probe answers a digest, fails naming the missing refs at the bound, and fails at once on a probe error; a ToolsRun with no network emits no --network; build-tests re-executes without require_network; ci images --publish-digests’s step order has craig-tools before the app images (red: the old order). Live: one train car with the new shape; its battery trace shows `build-tests starting before build ends (job timestamps) and --await-images waiting 0 s. Docs: quality-gates.adoc § Battery stages (the battery row and the hand-off), deployment-guide.adoc § CI/CD Pipeline. CHANGELOG. Closes #2994.

U2

D4: ci check --skip-unit; CRAIG_CHECK_FLAG on the train rule; the printed line.

Contract: the train rule sets the flag and the MR rule does not; the script references it. Unit: check::stages with the flag is [lint, clippy], and ci check --skip-unit’s output names the battery as the unit tests' run (red: a silent skip). Live: a train car’s `check trace without a unit table and its battery’s --run-ignored=all summary ≥ the MR pipeline’s unit count. Docs: quality-gates.adoc § Battery stages (check row). CHANGELOG. Closes U2’s issue.

U3

D5: the measurement; if adopted, the variable on check and battery, the passthrough entry, the contract test.

The A/B numbers on U3’s issue (wall, deps size, a panicking test’s backtrace still naming file and line). If adopted: contract test (both jobs carry the variable; red: one job without it), unit test (CI_PASSTHROUGH names it). Docs: quality-gates.adoc (one sentence in the battery row). CHANGELOG if adopted. Closes U3’s issue either way.

Order: U1, then U2 stacked on it (one car each); U3 beside U2. .gitlab-ci.yml stays under 500 lines, needs: on every job, the CI lint API green on each unit; the acceptance numbers go on #2994 after U2 lands.

Edit this page · latest