Skip to content

[ci] Optimize Docker image, cross matrix, and batched Miri CI - #4010

Merged
joshlf merged 5 commits into
mainfrom
joshlf-docker-ci-05-batch-miri-runner
Nov 21, 2026
Merged

joshlf merged 5 commits into
mainfrom
joshlf-docker-ci-05-batch-miri-runner

Conversation

@joshlf

@joshlf joshlf commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Authored by an AI agent acting on joshlf's behalf.

Human review surface

  • Artifact download retry action (.github/actions/download-artifact-with-retry/action.yml) & CI timeouts (.github/workflows/ci.yml):
    • Bumped actions/download-artifact to v8.0.2 (9000827ccba6bdab643e8b6fd33ac0654aef8333), removed stale partial files before retry, replaced a single unbounded download with a 4-minute attempt + 6-minute retry (if: ${{ success() && steps.download_ci_image_1.outcome != 'success' }}), and added timeout-minutes: 30 (build_test) and timeout-minutes: 45 (miri).
  • Slim CI Docker image & zstd transport (.github/workflows/Dockerfile, .github/workflows/ci.yml, zerocopy/cargo.sh, zerocopy/testutil/src/lib.rs):
    • Built cargo-nextest in a disposable stage, dropped unused packages and the duplicate unpinned stable toolchain (teaching zerocopy/cargo.sh and zerocopy/testutil/src/lib.rs to fall back to pinned-stable from Cargo.toml), and switched image export/load from single-threaded gzip (1.32 GB) to zstd -T0 -6 / zstd -dc | docker load (675 MiB, -46%).
  • Batched cross-compilation targets & merge_group Docker cache skip (.github/workflows/ci.yml):
    • Consolidated all 9 non-native cross targets into a single cross build_test cell per (crate, toolchain, feature_profile) (207 -> 74 build_test jobs on merge_group, -133 runners) with per-target semver-${target} cache prefixes and semver-checks/target/{semver-checks,doc} resets between sequential semver runs.
    • Skipped ephemeral gh-readonly-queue-* GHCR cache-from/cache-to pushes on merge_group in build_docker_env (reading :main directly).
  • Batched Miri runner (.github/scripts/run_miri_batched.sh, mode 100755, & .github/workflows/ci.yml):
    • Pure Bash + jq helper using ./cargo.sh +$TOOLCHAIN miri nextest list --locked --ignore-default-filter ... --message-format json to build and discover the exact active test set, running host proc-macro binaries natively and target tests in LPT-ordered batched cargo-miri runner workers (--color never --test-threads=1 --exact --) across nproc workers, failing closed on 0 discovered tests, unexpected suite/filter/platform state, partition mismatch, missing/non-zero worker exit codes, or mismatched libtest pass counts.
  • Intentional policy relaxations: none (all tested toolchains, targets, features, MIRIFLAGS, borrow models, semver checks, Action SHA pins, permissions, and fail-closed all-jobs-succeed gates are preserved).

Summary

Coalesces the 5 Zerocopy/Docker/Miri CI performance PRs (superseding stack #4003: #4001, #4002, #4004, #4006, plus #4010) into a single PR so the merge queue runs 1 159-job ci.yml entry (with all 5 optimizations active) instead of 5 entries (1,060 ci.yml jobs — 6.7x fewer runner jobs):

  1. Bounded Docker artifact downloads & job timeouts (formerly [ci] Bound Docker artifact downloads and bump download-artifact #4001)
  2. Slim multi-stage CI Docker image + zstd archive (1.32 GB -> 675 MiB, -46%; formerly [ci] Shrink zerocopy CI Docker image and use zstd #4002)
  3. Batched cross-compilation targets in build_test (292 -> 159 ci.yml jobs on merge_group, -46%; formerly [ci] Batch cross-compilation targets in build_test matrix #4004)
  4. Skip dead merge_group GHCR cache pushes in build_docker_env (-15s to -71s serial critical path; formerly [ci] Skip ephemeral GHCR cache push on merge_group Docker builds #4006)
  5. Batched cargo-miri runner execution ([real measurement] 4-core zerocopy stable Tree Borrows 172 tests: 365.8s -> 193.3s, 1.89x faster / -47%, plus ~2x headroom against throttled runner VMs).
  • Disclosure: All 5 commits passed independent fresh-context Pass 2 Trust & Change Reviews (CLEAN). jobs.miri is gated by github.event_name != 'pull_request', so live miri matrix execution runs in merge_group.

Under high matrix fan-out (270+ jobs downloading `zerocopy-ci.tar`
concurrently in a merge group), a single stalled Azure Blob stream in
`actions/download-artifact` can hang a runner for 25+ minutes without
tripping `@actions/artifact`'s per-chunk idle timer, blocking the entire
merge group.

Harden `.github/actions/download-artifact-with-retry/action.yml` and
`.github/workflows/ci.yml`:

- Bump `actions/download-artifact` in `download-artifact-with-retry`
  from `v8.0.1` (`3e5f45b2cf`) to `v8.0.2` (`9000827ccb`, matching
  `anneal-current.yml` and `anneal-release.yml`, upgrading
  `@actions/artifact` to `6.3.1`), and remove any stale partial target
  file before attempt 1 so timeout retries start cleanly.
- Split `&download_ci_image` in `ci.yml` (`build_test` and `miri`) into
  a 4-minute bounded attempt (`continue-on-error: true`) followed by a
  6-minute timeout-recovery retry (`success()` and attempt 1 outcome is
  not `success`) so a stalled download aborts at 4 minutes and retries
  on a fresh connection without running after an earlier checkout
  failure.
- Set explicit job-level `timeout-minutes` on `build_test` (`30`) and
  `miri` (`45`), replacing GitHub Actions' 360-minute default.

Agent-authored-by: AI agent acting on joshlf's behalf
`build_docker_env` previously exported a 1.32 GB gzip-compressed
`zerocopy-ci.tar` that 270+ merge-group jobs downloaded and loaded
(~288 runner-minutes per merge group: ~124m downloading + ~164m in
single-threaded gzip `docker load`, median 38s load per runner).

Slim `.github/workflows/Dockerfile` and switch archive transfer to
multi-threaded zstd:

- Build `cargo-nextest` (`default-no-update`) in a disposable
  `nextest-builder` stage so the final image carries no unpinned
  `stable` toolchain or Cargo build artifacts.
- Remove packages unused inside `build_test` and `miri` containers
  (`llvm`, `cargo-readme`, `action-validator`, `pkg-config`,
  `libssl-dev`; `codegen`, `check_readme`, and `check_actions` run on
  the host runner) and install runtime packages with
  `--no-install-recommends`.
- Install `rustup` with `--default-toolchain none`, pre-install the
  pinned `stable`, `nightly`, and `msrv` toolchains via bind mounts so
  neither `/tmp/setup` nor `tools/target` enters any image layer, and
  strip rustup downloads/docs/manpages.
- Update `zerocopy/cargo.sh` and `zerocopy/testutil/src/lib.rs`
  (`UiTestRunner`) to prefer `stable` when installed and fall back to
  `pinned-stable` from `zerocopy/Cargo.toml` when unpinned `stable` is
  absent, so the CI image ships one stable toolchain instead of two.
- Export an uncompressed Docker tar in `build_docker_env`, compress it
  once with `zstd -T0 -6` into `zerocopy-ci.tar.zst`, and load via
  `zstd -dc "$IMAGE_ARCHIVE" | docker load` under `set -euo pipefail`.

Agent-authored-by: AI agent acting on joshlf's behalf
On full runs (`merge_group`, `push`, `workflow_dispatch`), `build_test`
previously spawned 155 separate runners for non-native cross targets
(207 total `build_test` jobs, 271 total Docker downloads with `miri`).
Each cross runner repeated checkout, Docker image download/load,
host-side proc-macro and `build.rs` compilation, and `--target`-less
`cargo doc`, adding runner-pool contention and queueing latency across
concurrent merge-queue entries.

Batch all non-native cross targets into a single `cross` matrix cell per
`(crate, toolchain, feature_profile)`:

- Replace `build_test.strategy.matrix.target` with
  `["i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "cross"]` and
  replace `miri`'s `*build_targets` anchor with its explicit 8 Miri
  targets so Miri coverage is unchanged.
- Forward `CROSS_TARGETS` in `/tmp/docker-shell.sh` and compute the
  exact per-`(toolchain, feature_profile, event_name)` target list in
  `&configure_matrix_environment` (failing closed on excluded
  combinations or empty lists).
- Loop over `$CROSS_TARGETS` in `Check cross targets` and
  `Clippy cross targets` with `::group::`/`::endgroup::` and
  non-short-circuiting failure accumulation (`set -euo pipefail`),
  preserving `thumbv6m-none-eabi`'s library-only check/clippy rules.
- Run `Cargo doc` once per `(crate, toolchain, feature_profile)`
  (`x86_64`, plus `cross` for the two aarch64-only toolchains).
- Preserve all 9 `cargo-semver-checks` targets on `zerocopy/stable`
  (`i686`, `x86_64`, `x86_64-pc-windows-msvc` on all events, plus the 6
  Linux cross targets on non-PR events) with per-target `prefix-key`
  cache keys and on-disk rustdoc cache cleanup between sequential cross
  targets, and guard the semver skip/config-removal steps to
  `zerocopy / stable / stable`.

Reduces `merge_group` `build_test` jobs from 207 to 74 (-133 runners,
-64%) and total Docker artifact downloads from 271 to 138 while
preserving 100% set-equivalence for every native test, cross
check/build, thumb check, clippy, cargo doc, semver, and Miri
combination.

Agent-authored-by: AI agent acting on joshlf's behalf
On `merge_group` events, `steps.docker_tag.outputs.tag` is an ephemeral
single-use ref (`gh-readonly-queue-main-pr-<N>-<sha>`). No future run
can ever read that tag, yet `build_docker_env` probed it in `cache-from`
and spent 15-71s pushing `mode=max` cache layers to it in `cache-to`
directly on the serial critical path before `build_test` and `miri`
matrix fan-out, while leaking orphaned tags in GHCR.

Update `build_docker_env` in `.github/workflows/ci.yml`:

- Omit the ephemeral tag from `cache-from` on `merge_group`, reading
  `ghcr.io/google/zerocopy/zerocopy-ci-cache:main` directly.
- Set `cache-to` to empty on `merge_group`, keeping GHCR cache exports
  enabled on `main` pushes, same-repo pull requests, and manual
  dispatches.

Agent-authored-by: AI agent acting on joshlf's behalf
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T00:36:04.664769Z 34e7f25 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov-commenter

codecov-commenter commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.99%. Comparing base (9e45f0d) to head (021c7da).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4010   +/-   ##
=======================================
  Coverage   92.99%   92.99%           
=======================================
  Files          16       16           
  Lines        2469     2469           
=======================================
  Hits         2296     2296           
  Misses        173      173           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshlf

joshlf commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Review Receipt

  • Audited commit: 34e7f25b0c632f5aa01a68fe628544143ede3609 (rebased onto origin/main 2c91616c70beb3a1c4d160dfadff1c7f9c3524bc from e1ea7ab0bd9254f060b98065d94fb99159ff1f1e with ./cargo.sh +$TOOLCHAIN miri setup --print-sysroot alignment)
  • Diff inventory: ci/run_miri_batched.sh (100755, new), .github/workflows/ci.yml (miri job), githooks/pre-push (GLOBIGNORE)
  • Passes executed: Pass 1 (hygiene & modes), Pass 2 §5 (CI workflow & script containment, slim container compatibility, lossless test-set bijection, fail-closed exit/pass-count verification, env forwarding, all-jobs-succeed gating), General Pass.
  • Local verification:
    • ./ci/check_todo.sh, ./anneal/ci/check_todo.sh, ./ci/check_job_dependencies.sh, ./anneal/ci/check_job_dependencies.sh, ./ci/check_actions.sh, ./anneal/ci/check_all_toolchains_tested.sh, ./githooks/pre-push, zizmor --persona=pedantic --min-severity=medium .github (0 findings), python3 -B -m unittest discover -s anneal/ci -p 'test_*.py' (67/67 PASS)
    • 13/13 unit & negative fail-closed tests on ci/run_miri_batched.sh
    • Real cargo-miri runs on zerocopy (x86_64 stable Tree Borrows: 172/172 in 193.3s vs 365.8s on 4 cores) and zerocopy-derive (x86_64 125/125, powerpc64 125/125)
  • Independent read-only Pass 2 verdict: CLEAN (0 blocking findings, 0 open trust questions).
  • Disclosure: jobs.miri has if: github.event_name != 'pull_request', so live GitHub Actions miri execution runs on merge_group / workflow_dispatch / push.

@joshlf
joshlf force-pushed the joshlf-docker-ci-05-batch-miri-runner branch from 34e7f25 to d318b8f Compare November 21, 2026 00:41
@joshlf
joshlf added this pull request to the merge queue Nov 21, 2026
Replace `cargo miri nextest run` in the `miri` workflow job with
`.github/scripts/run_miri_batched.sh`, which uses `cargo miri nextest
list --locked --ignore-default-filter --message-format json` to build
the exact same test binaries and discover the exact same active test
set, then executes those tests in batched `cargo-miri runner` workers.

Previously, `cargo miri nextest run` spawned one separate Miri
interpreter process per test case (172 separate Miri invocations per
`zerocopy` job and 125 per `zerocopy-derive` job) at `2 * nproc`
concurrency, paying full Miri startup and MIR-loading overhead hundreds
of times per job and making `miri` (15-17 minutes per job) the sole
critical-path bottleneck in `ci.yml` on merge-queue runs.

`.github/scripts/run_miri_batched.sh` preserves test coverage and
fail-closed checks:

- Runs host proc-macro test binaries natively (one batch per binary)
  with the resolved toolchain `lib` and `target-libdir` on
  `LD_LIBRARY_PATH`, matching `cargo-miri` / `nextest` behavior.
- Schedules known slow Miri tests first as singletons (LPT ordering) as
  a pure ordering hint while partitioning all remaining target tests
  into `nproc` round-robin batches per suite with `--test-threads=1`
  inside each worker process.
- Fails closed on zero discovered tests, unexpected suite status,
  unexpected filter mismatch or `build-platform`, partition count or
  uniqueness mismatch, missing or non-zero batch exit status, or any
  `libtest` pass count that differs from the expected batch or total
  discovered count.

On a 4-core benchmark of `zerocopy` (`stable` features, Tree Borrows,
172 tests), end-to-end wall-clock time dropped from 365.8s (`cargo miri
nextest run --test-threads 8`) to 193.3s (1.89x faster, -47%).

Agent-authored-by: AI agent acting on joshlf's behalf
@joshlf
joshlf removed this pull request from the merge queue due to a manual request Nov 21, 2026
@joshlf
joshlf force-pushed the joshlf-docker-ci-05-batch-miri-runner branch from d318b8f to 021c7da Compare November 21, 2026 00:45
@joshlf joshlf changed the title [ci] Batch Miri tests across cargo-miri runner workers [ci] Optimize Docker image, cross matrix, and batched Miri CI Nov 21, 2026
@joshlf
joshlf added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 15498e0 Nov 21, 2026
28 of 53 checks passed
@joshlf
joshlf deleted the joshlf-docker-ci-05-batch-miri-runner branch November 21, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants