Repository navigation
[ci] Optimize Docker image, cross matrix, and batched Miri CI - #4010
Merged
Merged
Conversation
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
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Member
Author
Review Receipt
|
joshlf
force-pushed
the
joshlf-docker-ci-05-batch-miri-runner
branch
from
November 21, 2026 00:41
34e7f25 to
d318b8f
Compare
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
force-pushed
the
joshlf-docker-ci-05-batch-miri-runner
branch
from
November 21, 2026 00:45
d318b8f to
021c7da
Compare
This was referenced Nov 21, 2026
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Authored by an AI agent acting on joshlf's behalf.
Human review surface
.github/actions/download-artifact-with-retry/action.yml) & CI timeouts (.github/workflows/ci.yml):actions/download-artifacttov8.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 addedtimeout-minutes: 30(build_test) andtimeout-minutes: 45(miri).zstdtransport (.github/workflows/Dockerfile,.github/workflows/ci.yml,zerocopy/cargo.sh,zerocopy/testutil/src/lib.rs):cargo-nextestin a disposable stage, dropped unused packages and the duplicate unpinnedstabletoolchain (teachingzerocopy/cargo.shandzerocopy/testutil/src/lib.rsto fall back topinned-stablefromCargo.toml), and switched image export/load from single-threadedgzip(1.32 GB) tozstd -T0 -6/zstd -dc | docker load(675 MiB,-46%).merge_groupDocker cache skip (.github/workflows/ci.yml):crossbuild_testcell per(crate, toolchain, feature_profile)(207 -> 74build_testjobs onmerge_group,-133runners) with per-targetsemver-${target}cache prefixes andsemver-checks/target/{semver-checks,doc}resets between sequential semver runs.gh-readonly-queue-*GHCRcache-from/cache-topushes onmerge_groupinbuild_docker_env(reading:maindirectly)..github/scripts/run_miri_batched.sh, mode100755, &.github/workflows/ci.yml):jqhelper using./cargo.sh +$TOOLCHAIN miri nextest list --locked --ignore-default-filter ... --message-format jsonto build and discover the exact active test set, running host proc-macro binaries natively and target tests in LPT-ordered batchedcargo-miri runnerworkers (--color never --test-threads=1 --exact --) acrossnprocworkers, failing closed on 0 discovered tests, unexpected suite/filter/platform state, partition mismatch, missing/non-zero worker exit codes, or mismatchedlibtestpass counts.none(all tested toolchains, targets, features,MIRIFLAGS, borrow models, semver checks, Action SHA pins, permissions, and fail-closedall-jobs-succeedgates 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-jobci.ymlentry (with all 5 optimizations active) instead of 5 entries (1,060ci.ymljobs —6.7xfewer runner jobs):zstdarchive (1.32 GB -> 675 MiB,-46%; formerly [ci] Shrink zerocopy CI Docker image and use zstd #4002)build_test(292 -> 159ci.ymljobs onmerge_group,-46%; formerly [ci] Batch cross-compilation targets in build_test matrix #4004)merge_groupGHCR cache pushes inbuild_docker_env(-15sto-71sserial critical path; formerly [ci] Skip ephemeral GHCR cache push on merge_group Docker builds #4006)cargo-miri runnerexecution ([real measurement]4-corezerocopystableTree Borrows 172 tests:365.8s -> 193.3s,1.89xfaster /-47%, plus~2xheadroom against throttled runner VMs).CLEAN).jobs.miriis gated bygithub.event_name != 'pull_request', so livemirimatrix execution runs inmerge_group.