Pre-push battery speed: concurrent validate stages and a faster portal build (epic &76)

Status: Done (2026-10-04) — !1564
Epic: &76
Issues: #2605 (B1, w2), #2606 (B2, w2), #1370 (B3, w3), #2607 (A1, w2), #2608 (A2, w2), #2609 (A3, w2), #2610 (A4, w5), #2611 (A5, w3), #2612 (A6, w3), #2613 (A7, w3), #2614 (A8, w3)
MRs:

  • MR 1, feat/image-build-speed: B1, B2, B3, then three related fixes from the design research, each its own commit: #2599 (esbuild verified in the portal tool layer), #2600 (the root image compiles only the packages it ships) and #2601 (an empty CARGO_TARGET_DIR means unset, through one helper). It is titled "Faster, verified image builds (#2605, #2606, #1370, #2599, #2600, #2601)". Its B1 commit adds this page (Status In progress) and its nav entry.

  • MR 2, feat/validate-concurrent-stages: A1–A8 in order, titled "Concurrent validate stage groups (#2607 … #2614)". It ships after MR 1 merges; its A8 commit closes the plan.

Each MR is one deliverable whose commits build on each other, so they ship under the maintainer’s one-MR-per-related-group ruling, one commit per issue. This is a Design + Scope plan; GitLab owns tracking; the plan freezes when B1 starts.

Context

The pre-push battery (.githooks/pre-push, template-synced) runs cargo xtask validate --skip-docker, then cargo deny, check-docs, cargo xtask e2e, a public cargo doc into target/doc-check, perf smoke and lfs. On 2026-10-03 one push took about 35 min:

  • validate: 1477 s (test-results/validate-report.json), of which:

    • rustdoc-private 411 s;

    • the lint stages 363 s, run one after another at about one core of 32;

    • nextest 367 s.

  • the hook after validate: about 625 s, of which the doc pass was 221 s. It has been 6.5–10 min on other pushes, because validate documents into target/doc-private with different flags, so the hook re-documents every changed crate.

  • on a source change, about 270 s more to rebuild the devstack images. The canopy-portal image is the floor: dx bundle compiles the wasm client and then the server, one after the other, from a cold target (#732 removed the persistent one).

Sweep 8 (!1560: #2593–#2598) removed the --no-cache rebuild (15–17 min on a lockfile push), the schema-lease leak (about 4 min a push) and the bring-up correctness holes. What remains is serial work that need not be serial. validate's checkpoint (xtask/src/validate_report.rs) refuses a stage whose inventory index is not greater than the last one recorded, and the gates run in-process through &mut self, so nothing overlaps today. services/canopy-portal/Dockerfile also builds the promoted production portal image (ADR-040 D2), so MR 1 changes a released artifact as well as the devstack.

Scope

In scope: B1–B3 and A1–A8.

Out of scope:

  • editing .githooks/pre-push: its duplicate deny pass, the serial steps and timing go to template feedback;

  • e2e parallelism: the fleet test clock, fault state and shared seeded households are process-global, and the battery bans retries (#1689). The isolation restructure is #2617;

  • separate clippy or feature-build target dirs, a jobserver, unstable rustdoc merging, a persistent portal target (reverses #732), a prebuilt dx builder image, and the portal crate-closure copy (#2604);

  • re-tuning the concurrency caps, which needs quiet-host measurements after MR 2 (#2615);

  • joining the rustdoc group before the integration arm instead of before nextest-unit, a measured follow-up (#2616).

Design

Decisions

# Decision

C1

Group members are child processes, never in-process closures.

  • Each member’s output is spooled whole per child and replayed in full; a member can be cancelled; nothing needs a Mutex.

  • Each member runs in its own process group. Cancellation signals the whole group, so no grandchild survives, and validate forwards SIGINT and SIGTERM to every live group.

  • In-process gates run as <self-exe> gate <id> (A1), following the #896 sub-gates' <self-exe> <subcmd> precedent.

  • No self-exe child runs after nextest-build, which relinks target/debug/xtask.

C2

The report stays in inventory order.

  • A group is a contiguous slice of STAGES with a declared join barrier (GroupDecl { id, join_before }), enforced at run time.

  • Members replay their captured output in inventory order with worker-measured timings.

  • The report schema change is additive (group fields, skip_serializing_if), so SCHEMA_VERSION stays 1.

C3

Concurrency is sized to the host, and serial is always available.

  • Caps::from_inputs(cores, mem_available, cgroup_limit, knob):

    • light slots clamp(P/8, 1, 4);

    • heavy slots clamp(flooravail − 8 GiB) / 16 GiB), 1, min(4, max(1, P/8), where avail is the lower of MemAvailable and the smallest memory.max − memory.current over the process’s cgroup and every ancestor;

    • heavy is 1 when memory is unknown.

  • Serial is the mode for a host with fewer than 8 cores, a non-unix host (no process-group containment), or CANOPY_VALIDATE_CONCURRENCY=serial. It runs the same groups through the same runner, one member at a time in inventory order, and joins every background group as soon as it is launched, so nothing overlaps. Members are child processes in both modes, so each one’s capture kind holds in both.

  • CANOPY_VALIDATE_CONCURRENCY=serial|auto (default auto). An invalid value fails preflight; it never silently defaults.

C4

The lint group drains. All its members run to completion, so one push reports every lint failure. The battery fails at the lowest-index failure.

C5

validate pre-warms the hook’s doc pass with a byte-identical twin (rustdoc-hook-twin, Blocking):

  • cargo doc --workspace --no-deps --quiet with env CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-target}/doc-check" and RUSTDOCFLAGS="-D rustdoc::broken_intra_doc_links", run from the repo root.

  • A test pins the rendered line against .githooks/pre-push verbatim, so a template change to the hook fails the pin and forces the twin’s update or removal.

  • The twin and rustdoc-private form a background group, joined before nextest-unit.

C6

The devstack images build in the background, and the in-order stage stays authoritative.

  • devstack-warm runs docker compose -p <project>-validate-warm --profile <P> build. It uses disjoint tags (compose names images <project>-<service>, and no built service sets image:), so the running stack and the anti-latch never see them.

  • It is Advisory: devstack-ready still rebuilds, finds every layer cached, and owns the verdict.

  • It is skipped on prebuilt or in-network runs, on a serial host, or when the devstack is current.

C7

The portal builds its client and server in parallel, with cached dependencies and no persistent target:

  • dx build --fullstack --release (it runs both with tokio::join! unless --force-sequential) replaces dx bundle, which is sequential and adds nothing for web.

  • the portal gets its own registry cache ids, so it no longer waits on the root build’s registry lock;

  • a pinned, sha256-verified sccache caches third-party compiles (host and wasm32);

  • #732’s no-persistent-target rule, and its test, stay.

MR 1: the portal build (services/canopy-portal/Dockerfile)

B1 — client and server in parallel.

  • Replace the dx bundle --platform web --fullstack --release --debug-symbols false RUN with dx build and the same flags plus --force-sequential false. Then copy the server executable and the public/ directory to /build/out.

  • The artifact check verifies what the release layout actually holds. A dioxus-cli 0.7.9 release build puts the wasm and JavaScript under public/assets/ and removes its temporary wasm/ directory, so the RUN asserts:

    • test -x /build/out/server and test -s /build/out/public/index.html;

    • every /assets/… path that index.html references (its src= and href= values) exists under /build/out/public/, extracted with grep -o and checked with test -s in a loop that fails the RUN on the first missing file;

    • at least one referenced asset ends in .wasm.

  • Erratum (2026-10-03): dioxus-cli 0.7.9 never references the wasm from index.html; the JS glue loads it (build/web.rs ~507-509). The check therefore also verifies every /assets/… .wasm path each referenced script names, and requires at least one.

  • Read the output paths from dioxus-cli 0.7.9’s "build completed" log line on the first build. The 0.7.10 source puts them under <target>/dx/canopy-portal/release/web/.

  • The runtime COPYs are unchanged. Correct the stale dx bundle text: the Dockerfile’s comments, xtask/src/lanes.rs (~157 and ~272) and ADR-047 Amendment 1.

  • Test: a pin that the portal RUN uses dx build and --force-sequential false, not dx bundle, copies both outputs, and carries the index.html asset check. It must not test for a public/wasm directory.

  • Acceptance: the e2e applicant-portal project and the 2 MB-gzip bundle budget pass.

B2 — the portal’s own registry cache.

  • The portal mounts take ids /canopy-portal/usr/local/cargo/registry and /canopy-portal/usr/local/cargo/git (targets unchanged, sharing=locked).

  • Amend every_cache_mount_carries_an_explicit_id_and_locked_sharing (xtask/src/devstack_guard.rs): ids equal their targets except these two, and the two Dockerfiles' registry ids now differ.

  • sharing=shared is unsafe, because cargo’s .package-cache lock lives outside the mount.

  • The cold-cache notice (cold_cache_notice and SHARED_CACHE_MOUNTS in devstack_guard.rs, reading BuildKit records through parse_cachemount_targets in docker.rs) matches records by mount target. After B2 the portal’s record would satisfy the root’s entry. Key the check by the record’s with id "…" value, give the portal’s ids their own entries, and correct the comment that says the portal shares the root’s registry mount. Test the parse and the match.

  • ADR-047 amendment.

B3 — sccache for dependency compiles.

  • Bake a pinned sccache musl static binary into the tool layer, its sha256 taken from the release’s .sha256 asset, following the #1180 pattern.

  • On the dx RUN only, set RUSTC_WRAPPER=sccache SCCACHE_DIR=/sccache with a --mount=type=cache,target=/sccache,id=/sccache,sharing=locked. After dx build, print sccache --show-stats and run sccache --stop-server, but exit with dx build's status, so a failed build fails the RUN.

  • dx base mode keeps an inherited RUSTC_WRAPPER.

  • Tests: the mount test covers the new mount.

  • Acceptance: a second build after a portal-source change shows sccache hits in the log, and the served bundle reflects the change (#1370’s stale-bundle probe). The MR records the portal build’s wall time before and after.

  • ADR-047 and ADR-040 §5 (supply chain) notes.

MR 2: concurrent validate stage groups (xtask)

  • Erratum (2026-10-04): at the maintainer’s direction the concurrent stage-group design (A1–A6, C1–C4) was not built; #2607–#2611 closed won’t-do and #2612 was rescoped. Instead clippy, rustdoc-private, the hook twin (A7) and the warm image build (A8) run as plain background child processes (xtask/src/validate_bg.rs), joined at fixed inventory positions.

A1 — cargo xtask gate <id>.

  • IN_PROCESS_GATES: &[(&str, fn() → Result<()>)] in xtask/src/cmd/validate.rs holds:

    • the 19 gates of stage_static_gates;

    • rules, vendor-check, capabilities and quality-budgets (closures become named fns).

  • gate <id> runs only the body: no lock, no bootstrap, no report. An unknown id returns an error listing the valid ids.

  • Until A6 reorders STAGES, each table entry still runs at its existing inventory position (the 23 entries are not yet contiguous), so behaviour is unchanged.

  • Tests: ids are unique and in STAGES order; the lookup works for a known and an unknown id.

A2 — sysmon labels for overlapping stages.

  • StageMsg { Serial, Enter, Leave } on the existing feed (xtask/src/sysmon.rs).

  • The sample label is the serial stage plus the running members, joined with +.

  • Tests: pure label composition.

A3 — host-sized caps.

  • C3’s Caps in a new validate-group module (not built; see the erratum above).

  • from_host() reads available_parallelism, and MemAvailable through the existing sysmon::parse_meminfo (made pub(crate)).

  • Cgroup headroom is hierarchical. from_host() reads the cgroup v2 path from /proc/self/cgroup and walks from that cgroup up through every visible ancestor to the mount root. At each level that has a memory.max other than max (unlimited), headroom is memory.max − memory.current, and memory.current includes the siblings' use. The cgroup headroom is the minimum over all levels; an unreadable level is skipped.

  • The pure core takes the per-level (max, current) list, so the walk is unit-tested without a filesystem. The arithmetic uses checked_*, and an underflow means memory is unknown.

  • The knob is checked in preflight.

  • Tests: a table:

    • 32 cores and 75 GiB gives {4, 4}; 16 cores and 16 GiB gives {2, 1}; 4 cores gives serial;

    • a leaf limit wins;

    • an unlimited leaf under a parent with 16 GiB left gives heavy 1, despite 75 GiB host availability;

    • a parent whose memory.current is mostly siblings' use;

    • the knob; unknown memory.

A4 — the group runner.

  • A pure Schedule: per-group queues, light and heavy counts, heavies spawned first, and a main-path heavy-slot request that wins a freed slot. Plus a pure ReplayQueue in inventory order. The main path’s heavy stages, feature-builds, nextest-build and doctest, each take a heavy slot through run_heavy_gate.

  • One Runner thread owns every Child, read through an mpsc inbox with recv_timeout(100 ms). Dropping the handle cancels every member, as below, and reaps it.

  • Containment. Each member starts in its own process group (std::os::unix::process::CommandExt::process_group(0)) with stdin(null).

    • Cancelling a member signals its whole group: rustix::process::kill_process_group with SIGTERM, then SIGKILL after a 5 s grace. rustix is already a workspace dependency with the process feature; xtask gains it under [target.'cfg(unix)'.dependencies].

    • So a cancelled cargo doc takes its rustc and rustdoc grandchildren with it, the capture pipes close, and the reader joins return.

  • Ctrl-C. Members are outside validate’s foreground process group, so terminal signals no longer reach them directly.

    • While any group is live, a watcher thread runs a current-thread tokio runtime on tokio::signal::unix (the workspace tokio already enables signal) for SIGINT and SIGTERM.

    • On either signal it cancels every member group as above, records the cancelled members, finalizes the report as interrupted, and exits with status 130 (SIGINT) or 143 (SIGTERM).

  • Non-unix hosts have no group containment, so concurrency is forced to serial there (C3), and a member is the direct child as today.

  • Capture. Generalize spawn_reader to a Sink { Tee, Spool(File) }.

    • Spool writes a member’s complete output to test-results/validate/groups/<stage>.log. join_group replays the whole spool to the terminal in inventory order, so nothing a member printed is lost, including gates that list violations and end with "see above".

    • The existing bounded diagnostic tail (RING_CAP and FINAL_TAIL_CAP) is kept separately for the report, exactly as FullTee keeps it today.

  • Tests:

    • the pure schedule: caps, priority, cancel, drain versus cancel-siblings;

    • replay order;

    • sh -c process tests, gated off non-unix as the existing ones are: reverse finish; a failure’s full output replayed and its tail recorded; a member printing more than the tail cap replays every line;

    • cancellation of sh -c 'sleep 30 & sleep 30': both the member and its backgrounded grandchild are gone, and the reader joins return within the grace period;

    • a SIGINT delivered to a test harness process cancels a live member group.

A5 — groups in the report.

  • StageSpec.group, StageResult.group and GROUPS in validate_report.rs.

  • launch_group checks admission against the contiguous slice; join_group records and replays.

  • A cancelled member is not_run, with no timing and a note.

  • checkpoint drains background events, surfaces a background failure, and refuses a stage at or past a live group’s join_before. finalize_pass refuses a live group; finalize_fail and Drop stop the runner first.

  • Tests: through a scripted-event runner, with no processes: admission errors; drain with two failures in either order; a cancelled member; a background failure at the next checkpoint; the live-group refusals.

A6 — the lint group.

  • Indices 11–47, Drain, in this order:

    • the 19 static gates (SelfGate);

    • deny, fmt and machete;

    • rules, vendor-check, capabilities and quality-budgets;

    • the ten #896 sub-gates (SelfXtask);

    • clippy last, Heavy.

  • The group’s join_before is policy-drift. After the lint join come policy-drift (it writes the policy cache, so it never overlaps the group), then feature-builds (serial, with a heavy slot, since it shares clippy’s target dir).

  • Index ranges in this plan are the final ones, after A8; the units name stages by id, and the implementer derives the positions at each commit.

  • The 23 former in-process gates change from ErrorChainOnly to FullTee, since they now run as children in every mode (C3). Edit the quality-budgets capture pin and the clippy < rustdoc-private < quality-budgets order pin (validate_report.rs), giving the reason in the commit.

  • Tests: every group is contiguous, each join_before follows its members, no self-exe member’s group joins after nextest-build, and policy-drift is ungrouped. The existing order pins still pass.

A7 — the rustdoc group and the hook twin.

  • Indices 48–49, CancelSiblings, launched right after the lint launch and joined before nextest-unit.

  • The members are rustdoc-private (argv unchanged) and rustdoc-hook-twin (C5), both Heavy.

  • Constants HOOK_DOC_ARGV and HOOK_DOC_RUSTDOCFLAGS, and hook_doc_target_dir(Option<OsString>), which gives target when the variable is unset or empty (through #2601’s helper), then appends /doc-check by string concatenation and passes it as env.

  • Tests: .githooks/pre-push contains hook_doc_line() verbatim; the target-dir rendering; the twin is Blocking; the inventory count.

  • Acceptance (recorded in the MR): after a validate, the hook’s doc command without --quiet prints no Documenting, Checking or Compiling line.

A8 — the background image build.

  • A pure warm_decision(prebuilt, in_network, caps, staleness, stored_profile) → Skip(reason) | Build { profile } implements C6.

  • One Heavy docker member, logging to test-results/validate/devstack-warm.log, launched at index 10 and joined before devstack-project-name. A failure is advisory and carries the log’s tail.

  • Its compose env is the one devstack-ready's build uses (feature_env_pair() and CANOPY_CARGO_PROFILE), so its layers are the ones the in-order build will reuse.

  • Tests: the decision table; the argv pin (-p <project>-validate-warm --profile P build, no up, --build or --no-cache); every built service in profiles full and e2e has no image:; the advisory-set pin edited to add it.

  • Acceptance: a warm build followed by the in-order build shows every step CACHED.

  • The plan closes here: Status Done (YYYY-MM-DD) — !N; the page to docs/modules/ROOT/pages/plans/archive/ with the nav moved; cargo xtask plan-lint --done docs/modules/ROOT/pages/plans/archive/prepush-battery-speed.adoc --allow-open for A1–A8 (they close when MR 2 merges), #2604, #2615, #2616 and #2617.

Conventions every unit follows

  • Every new function stays within clippy’s 40-line too_many_lines limit (clippy.toml). No std::sync::Mutex: state goes on channels and one owner thread. Cargo children are built with crate::cargo_child::command.

  • Tests are deterministic. The scheduler, report, caps and decision logic are pure and unit-tested without processes, and process tests use sh -c.

  • No gate is weakened, removed or made advisory, except devstack-warm, which is new and Advisory by design.

  • Each unit ships its CHANGELOG.adoc bullet and updates testing.adoc, tooling/xtask-catalog.adoc and ADR-047 where it changes what they say.

Units

  1. B1 (w2) — feat(portal): build client and server in parallel with dx build. This page and its nav entry.

  2. B2 (w2) — feat(portal): give the portal build its own registry cache.

  3. B3 (w3) — feat(portal): cache portal dependency compiles with sccache.

  4. A1 (w2) — feat(xtask): run one in-process validate gate as a subcommand.

  5. A2 (w2) — feat(xtask): label resource samples with every running stage.

  6. A3 (w2) — feat(xtask): size validate concurrency from host cores and memory.

  7. A4 (w5) — feat(xtask): run validate stage groups as concurrent children.

  8. A5 (w3) — feat(xtask): record concurrent stage groups in the validate report.

  9. A6 (w3) — feat(xtask): run validate’s lint stages as one concurrent group.

  10. A7 (w3) — feat(xtask): pre-warm the hook’s doc pass in a background group.

  11. A8 (w3) — feat(xtask): build devstack images in the background during validate. The plan close.

Verification

  1. Per unit (the implementer, in its worktree): cargo fmt; cargo clippy --all-targets — -D warnings with and without --profile test; cargo nextest run -p xtask; quality-budgets; test-lanes-lint --static.

  2. Per MR: git push (the pre-push battery). MR 1 also runs cargo xtask dev reload and records the portal build time.

  3. After MR 2: a paired performance measurement, recorded in the MR. The historical 1477 s run is context only: it had competing load and predates sweep 8.

    • Same commit, both modes. CANOPY_VALIDATE_CONCURRENCY=serial against auto.

    • Two scenarios, each from equivalent starting caches:

      • a warm push: a battery has just passed, nothing has changed, and every cache is warm;

      • a source-change push: one comment appended to a file in crates/canopy-common/src/ before each run, so the dependency graph and the devstack images rebuild the same way in both modes.

    • What is timed: the complete battery, the hook’s tail included. Time the hook’s own commands in order under time: cargo xtask validate --skip-docker, cargo deny check, cargo xtask check-docs, cargo xtask e2e, and the hook’s exact cargo doc line.

    • Run order: ABBA (serial, auto, auto, serial) per scenario, back to back on the same host, with the sampler’s load average recorded for each run. A pair whose load averages differ by more than 25% is re-run.

    • The bar: auto is faster than serial in both scenarios and both pairs, and serial passes too. Only the cap constants' tuning is deferred, to #2615.

Review log

round vendor resolved model verdict

1 (2026-10-03)

Anthropic

claude-opus-5-5

no-ship. Four blockers, all fixed: the lint group’s join barrier and the placement of policy-drift and feature-builds; a definition of serial mode and what it runs; the cold-cache notice that matched the portal’s new registry record by target; the missing type:: labels. Also taken: Heavy rustdoc members, final indices named by stage id, the warm build’s compose env, --allow-open at the close, the real stale dx bundle comments, dx build's exit status through the sccache tail, parse_meminfo reuse with checked cgroup arithmetic, heavy slots for nextest-build and doctest, and the production-image note.

2 (2026-10-03)

OpenAI

gpt-6-astra

no-ship. Five findings, all fixed:

* the portal artifact check tested a public/wasm directory that a 0.7.9 release build removes; it now checks index.html and every asset it references; * cancellation killed only direct children; members now run in their own process groups, with group signals and SIGINT/SIGTERM forwarding, and a grandchild test; * cgroup headroom read only the leaf; it now takes the minimum over every ancestor; * bounded replay dropped lint output; members now spool their full output and replay it whole, with the bounded tail kept for the report; * performance acceptance compared against a contaminated historical run; it is now a paired same-commit serial-against-auto measurement of the whole battery, in two scenarios, ABBA.

No round 3.

Edit this page · default