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 emptyCARGO_TARGET_DIRmeans unset, through one helper). It is titled "Faster, verified image builds (#2605, #2606, #1370, #2599, #2600, #2601)". Its B1 commit adds this page (StatusIn 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-privatewith 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 bundlecompiles 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.
|
C2 |
The report stays in inventory order.
|
C3 |
Concurrency is sized to the host, and serial is always available.
|
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 (
|
C6 |
The devstack images build in the background, and the in-order stage stays authoritative.
|
C7 |
The portal builds its client and server in parallel, with cached dependencies and no persistent target:
|
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 falseRUN withdx buildand the same flags plus--force-sequential false. Then copy the server executable and thepublic/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 temporarywasm/directory, so the RUN asserts:-
test -x /build/out/serverandtest -s /build/out/public/index.html; -
every
/assets/…path thatindex.htmlreferences (itssrc=andhref=values) exists under/build/out/public/, extracted withgrep -oand checked withtest -sin 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/….wasmpath 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 bundletext: 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 buildand--force-sequential false, notdx bundle, copies both outputs, and carries theindex.htmlasset check. It must not test for apublic/wasmdirectory. -
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/registryand/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=sharedis unsafe, because cargo’s.package-cachelock lives outside the mount. -
The cold-cache notice (
cold_cache_noticeandSHARED_CACHE_MOUNTSindevstack_guard.rs, reading BuildKit records throughparse_cachemount_targetsindocker.rs) matches records by mount target. After B2 the portal’s record would satisfy the root’s entry. Key the check by the record’swith 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
.sha256asset, following the #1180 pattern. -
On the dx RUN only, set
RUSTC_WRAPPER=sccache SCCACHE_DIR=/sccachewith a--mount=type=cache,target=/sccache,id=/sccache,sharing=locked. Afterdx build, printsccache --show-statsand runsccache --stop-server, but exit withdx 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<()>)]inxtask/src/cmd/validate.rsholds:-
the 19 gates of
stage_static_gates; -
rules,vendor-check,capabilitiesandquality-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
STAGESorder; 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
Capsin a new validate-group module (not built; see the erratum above). -
from_host()readsavailable_parallelism, andMemAvailablethrough the existingsysmon::parse_meminfo(madepub(crate)). -
Cgroup headroom is hierarchical.
from_host()reads the cgroup v2 path from/proc/self/cgroupand walks from that cgroup up through every visible ancestor to the mount root. At each level that has amemory.maxother thanmax(unlimited), headroom ismemory.max − memory.current, andmemory.currentincludes 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 useschecked_*, 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.currentis 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 pureReplayQueuein inventory order. The main path’s heavy stages,feature-builds,nextest-buildanddoctest, each take a heavy slot throughrun_heavy_gate. -
One
Runnerthread owns everyChild, read through anmpscinbox withrecv_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)) withstdin(null).-
Cancelling a member signals its whole group:
rustix::process::kill_process_groupwithSIGTERM, thenSIGKILLafter a 5 s grace. rustix is already a workspace dependency with theprocessfeature; xtask gains it under[target.'cfg(unix)'.dependencies]. -
So a cancelled
cargo doctakes 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 enablessignal) 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_readerto aSink { Tee, Spool(File) }.-
Spoolwrites a member’s complete output totest-results/validate/groups/<stage>.log.join_groupreplays 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_CAPandFINAL_TAIL_CAP) is kept separately for the report, exactly asFullTeekeeps it today.
-
-
Tests:
-
the pure schedule: caps, priority, cancel, drain versus cancel-siblings;
-
replay order;
-
sh -cprocess 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.groupandGROUPSinvalidate_report.rs. -
launch_groupchecks admission against the contiguous slice;join_grouprecords and replays. -
A cancelled member is
not_run, with no timing and a note. -
checkpointdrains background events, surfaces a background failure, and refuses a stage at or past a live group’sjoin_before.finalize_passrefuses a live group;finalize_failandDropstop 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,fmtandmachete; -
rules,vendor-check,capabilitiesandquality-budgets; -
the ten
#896sub-gates (SelfXtask); -
clippylast, Heavy.
-
-
The group’s
join_beforeispolicy-drift. After the lint join comepolicy-drift(it writes the policy cache, so it never overlaps the group), thenfeature-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
ErrorChainOnlytoFullTee, 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_beforefollows its members, no self-exe member’s group joins afternextest-build, andpolicy-driftis 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) andrustdoc-hook-twin(C5), both Heavy. -
Constants
HOOK_DOC_ARGVandHOOK_DOC_RUSTDOCFLAGS, andhook_doc_target_dir(Option<OsString>), which givestargetwhen the variable is unset or empty (through #2601’s helper), then appends/doc-checkby string concatenation and passes it as env. -
Tests:
.githooks/pre-pushcontainshook_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
--quietprints noDocumenting,CheckingorCompilingline.
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 beforedevstack-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()andCANOPY_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, noup,--buildor--no-cache); every built service in profiles full and e2e has noimage:; 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 todocs/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-openfor 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_lineslimit (clippy.toml). Nostd::sync::Mutex: state goes on channels and one owner thread. Cargo children are built withcrate::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.adocbullet and updatestesting.adoc,tooling/xtask-catalog.adocand ADR-047 where it changes what they say.
Units
-
B1 (w2) —
feat(portal): build client and server in parallel with dx build. This page and its nav entry. -
B2 (w2) —
feat(portal): give the portal build its own registry cache. -
B3 (w3) —
feat(portal): cache portal dependency compiles with sccache. -
A1 (w2) —
feat(xtask): run one in-process validate gate as a subcommand. -
A2 (w2) —
feat(xtask): label resource samples with every running stage. -
A3 (w2) —
feat(xtask): size validate concurrency from host cores and memory. -
A4 (w5) —
feat(xtask): run validate stage groups as concurrent children. -
A5 (w3) —
feat(xtask): record concurrent stage groups in the validate report. -
A6 (w3) —
feat(xtask): run validate’s lint stages as one concurrent group. -
A7 (w3) —
feat(xtask): pre-warm the hook’s doc pass in a background group. -
A8 (w3) —
feat(xtask): build devstack images in the background during validate. The plan close.
Verification
-
Per unit (the implementer, in its worktree):
cargo fmt;cargo clippy --all-targets — -D warningswith and without--profile test;cargo nextest run -p xtask;quality-budgets;test-lanes-lint --static. -
Per MR:
git push(the pre-push battery). MR 1 also runscargo xtask dev reloadand records the portal build time. -
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=serialagainstauto. -
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 exactcargo docline. -
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 |
2 (2026-10-03) |
OpenAI |
gpt-6-astra |
no-ship. Five findings, all fixed: * the portal artifact check tested a No round 3. |